| 1 | // G. Le Meur 04/2000
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include "sopnamsp.h"
 | 
|---|
| 4 | #include "fiospherehealpix.h"
 | 
|---|
| 5 | #include "pexceptions.h"
 | 
|---|
| 6 | #include "fiondblock.h"
 | 
|---|
| 7 | #include "datatype.h"
 | 
|---|
| 8 | #include <typeinfo>
 | 
|---|
| 9 | 
 | 
|---|
| 10 | //*******************************************************************
 | 
|---|
| 11 | // Class FIO_SphereHEALPix<T>
 | 
|---|
| 12 | //  Les objets delegues pour la gestion de persistance 
 | 
|---|
| 13 | //*******************************************************************
 | 
|---|
| 14 | 
 | 
|---|
| 15 | template <class T>
 | 
|---|
| 16 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix()
 | 
|---|
| 17 | {
 | 
|---|
| 18 |   dobj_= new SphereHEALPix<T>;
 | 
|---|
| 19 |   ownobj= true;
 | 
|---|
| 20 | }
 | 
|---|
| 21 | 
 | 
|---|
| 22 | template <class T>
 | 
|---|
| 23 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(string const& filename)
 | 
|---|
| 24 | {
 | 
|---|
| 25 |   dobj_= new SphereHEALPix<T>;
 | 
|---|
| 26 |   ownobj= true;
 | 
|---|
| 27 |   Read(filename);
 | 
|---|
| 28 | }
 | 
|---|
| 29 | 
 | 
|---|
| 30 | template <class T>
 | 
|---|
| 31 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(const SphereHEALPix<T>& obj)
 | 
|---|
| 32 | {
 | 
|---|
| 33 |   dobj_= new SphereHEALPix<T>(obj, true);
 | 
|---|
| 34 |   ownobj= true;
 | 
|---|
| 35 | }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | template <class T>
 | 
|---|
| 38 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(SphereHEALPix<T>* obj)
 | 
|---|
| 39 | {
 | 
|---|
| 40 |   dobj_= obj;
 | 
|---|
| 41 |   ownobj= false;
 | 
|---|
| 42 | }
 | 
|---|
| 43 | 
 | 
|---|
| 44 | template <class T>
 | 
|---|
| 45 | FIO_SphereHEALPix<T>::~FIO_SphereHEALPix()
 | 
|---|
| 46 | {
 | 
|---|
| 47 |   if (ownobj && dobj_) delete dobj_;
 | 
|---|
| 48 | }
 | 
|---|
| 49 | 
 | 
|---|
| 50 | template <class T>
 | 
|---|
| 51 | AnyDataObj* FIO_SphereHEALPix<T>::DataObj()
 | 
|---|
| 52 | {
 | 
|---|
| 53 |   return(dobj_);
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | template <class T>
 | 
|---|
| 57 | void FIO_SphereHEALPix<T>::SetDataObj(AnyDataObj & o)
 | 
|---|
| 58 | {
 | 
|---|
| 59 |   SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
 | 
|---|
| 60 |   if (po == NULL) { 
 | 
|---|
| 61 |     char buff[160];
 | 
|---|
| 62 |     sprintf(buff,"FIO_SphereHEALPix<%s>::SetDataObj(%s) - Object type error ! ",
 | 
|---|
| 63 |             DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
 | 
|---|
| 64 |     throw TypeMismatchExc(PExcLongMessage(buff));
 | 
|---|
| 65 |   }
 | 
|---|
| 66 |   if (ownobj && dobj_) delete dobj_;
 | 
|---|
| 67 |   dobj_ = po; ownobj = false;
 | 
|---|
| 68 | } 
 | 
|---|
| 69 | 
 | 
|---|
| 70 | template <class T>
 | 
|---|
| 71 | void FIO_SphereHEALPix<T>::ReadSelf(PInPersist& is)
 | 
|---|
| 72 | {
 | 
|---|
| 73 | 
 | 
|---|
| 74 |   if(dobj_ == NULL) 
 | 
|---|
| 75 |     {
 | 
|---|
| 76 |       dobj_= new SphereHEALPix<T>;
 | 
|---|
| 77 |       ownobj= true;      
 | 
|---|
| 78 |     }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | // On lit les 3 premiers uint_8
 | 
|---|
| 81 | uint_8 itab[3];
 | 
|---|
| 82 | is.Get(itab, 3);
 | 
|---|
| 83 |  
 | 
|---|
| 84 | //  Juin 2006 : NumVer 1->2 avec mise en place de HEALPix NESTED
 | 
|---|
| 85 | //  Si itab[2]==1 --> NESTED 
 | 
|---|
| 86 | bool fgring = true;
 | 
|---|
| 87 | if (itab[2] == 1) fgring = false;
 | 
|---|
| 88 | 
 | 
|---|
| 89 | // Let's Read the SphereCoordSys object  -- ATTENTIOn - $CHECK$
 | 
|---|
| 90 |   FIO_SphereCoordSys fio_scs( dobj_->GetCoordSys());
 | 
|---|
| 91 |   fio_scs.Read(is);
 | 
|---|
| 92 |   // Pour savoir s'il y avait un DVList Infodobj->Info();  associe
 | 
|---|
| 93 |   char strg[256];
 | 
|---|
| 94 |   is.GetLine(strg, 255);
 | 
|---|
| 95 |   bool hadinfo= false;
 | 
|---|
| 96 |   if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0)  hadinfo= true;
 | 
|---|
| 97 |   if(hadinfo) 
 | 
|---|
| 98 |     {    // Lecture eventuelle du DVList Info
 | 
|---|
| 99 |       is >> dobj_->Info(); 
 | 
|---|
| 100 |     }
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   int_4 nSide;
 | 
|---|
| 103 |   is.GetI4(nSide);
 | 
|---|
| 104 |   int_4 nPix;
 | 
|---|
| 105 |   is.GetI4(nPix);
 | 
|---|
| 106 |   double Omega;
 | 
|---|
| 107 |   is.GetR8(Omega);
 | 
|---|
| 108 |   dobj_->setParameters(nSide,nPix, Omega, fgring);
 | 
|---|
| 109 | 
 | 
|---|
| 110 | // On lit les DataBlocks;
 | 
|---|
| 111 |   FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
 | 
|---|
| 112 |   fio_nd.Read(is);
 | 
|---|
| 113 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| 114 |   fio_ndi1.Read(is);
 | 
|---|
| 115 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| 116 |   fio_ndi2.Read(is);
 | 
|---|
| 117 | 
 | 
|---|
| 118 | 
 | 
|---|
| 119 | }
 | 
|---|
| 120 |  
 | 
|---|
| 121 | template <class T>
 | 
|---|
| 122 | void FIO_SphereHEALPix<T>::WriteSelf(POutPersist& os) const
 | 
|---|
| 123 | {
 | 
|---|
| 124 |   if(dobj_ == NULL) 
 | 
|---|
| 125 |     {
 | 
|---|
| 126 |       cout << " WriteSelf:: dobj_= null " << endl;
 | 
|---|
| 127 |       return;
 | 
|---|
| 128 |     }
 | 
|---|
| 129 | 
 | 
|---|
| 130 | //  On ecrit 3 uint_8 
 | 
|---|
| 131 | //  0 : Numero de version,  1 : Size index,  2  reserve a l
 | 
|---|
| 132 | //  Juin 2006 : NumVer 1->2 avec mise en place de HEALPix NESTED
 | 
|---|
| 133 | //  totalement back-compatible , on utilise itab[2] qu'on met a 1
 | 
|---|
| 134 | //  pour NESTED
 | 
|---|
| 135 | uint_8 itab[3];
 | 
|---|
| 136 | itab[0] = 2;
 | 
|---|
| 137 | itab[1] = dobj_->SizeIndex();
 | 
|---|
| 138 | itab[2] = (dobj_->IfRING()) ? 0 : 1;
 | 
|---|
| 139 | os.Put(itab, 3);
 | 
|---|
| 140 | // Let's write the SphereCoordSys object
 | 
|---|
| 141 |   FIO_SphereCoordSys fio_scs( dobj_->GetCoordSys());
 | 
|---|
| 142 |   fio_scs.Write(os);
 | 
|---|
| 143 | 
 | 
|---|
| 144 |   char strg[256];
 | 
|---|
| 145 |   int_4 nSide= dobj_->SizeIndex();
 | 
|---|
| 146 |   int_4 nPix = dobj_->NbPixels();
 | 
|---|
| 147 |  
 | 
|---|
| 148 |   if(dobj_->ptrInfo()) 
 | 
|---|
| 149 |     {
 | 
|---|
| 150 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d HasInfo",nSide,nPix);
 | 
|---|
| 151 |       os.PutLine(strg);
 | 
|---|
| 152 |       os << dobj_->Info();
 | 
|---|
| 153 |     }
 | 
|---|
| 154 |   else 
 | 
|---|
| 155 |     { 
 | 
|---|
| 156 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d ",nSide,nPix);
 | 
|---|
| 157 |       os.PutLine(strg);  
 | 
|---|
| 158 |     }
 | 
|---|
| 159 | 
 | 
|---|
| 160 |   os.PutI4(nSide);
 | 
|---|
| 161 |   os.PutI4(nPix);
 | 
|---|
| 162 |   os.PutR8(dobj_->PixSolAngle());
 | 
|---|
| 163 | // On ecrit les dataBlocks 
 | 
|---|
| 164 |   FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
 | 
|---|
| 165 |   fio_nd.Write(os);
 | 
|---|
| 166 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| 167 |   fio_ndi1.Write(os);
 | 
|---|
| 168 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| 169 |   fio_ndi2.Write(os);
 | 
|---|
| 170 | }
 | 
|---|
| 171 | 
 | 
|---|
| 172 | //*******************************************************************
 | 
|---|
| 173 | 
 | 
|---|
| 174 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 175 | #pragma define_template FIO_SphereHEALPix<uint_2>
 | 
|---|
| 176 | #pragma define_template FIO_SphereHEALPix<int_4>
 | 
|---|
| 177 | #pragma define_template FIO_SphereHEALPix<r_8>
 | 
|---|
| 178 | #pragma define_template FIO_SphereHEALPix<r_4>
 | 
|---|
| 179 | #pragma define_template FIO_SphereHEALPix< complex<r_4> >
 | 
|---|
| 180 | #pragma define_template FIO_SphereHEALPix< complex<r_8> >
 | 
|---|
| 181 | #endif
 | 
|---|
| 182 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| 183 | namespace SOPHYA {
 | 
|---|
| 184 | template class FIO_SphereHEALPix<uint_2>;
 | 
|---|
| 185 | template class FIO_SphereHEALPix<int_4>;
 | 
|---|
| 186 | template class FIO_SphereHEALPix<r_8>;
 | 
|---|
| 187 | template class FIO_SphereHEALPix<r_4>;
 | 
|---|
| 188 | template class FIO_SphereHEALPix< complex<r_4> >;
 | 
|---|
| 189 | template class FIO_SphereHEALPix< complex<r_8> >;
 | 
|---|
| 190 | }
 | 
|---|
| 191 | #endif
 | 
|---|