| [842] | 1 | // G. Le Meur 04/2000
 | 
|---|
 | 2 | 
 | 
|---|
| [2615] | 3 | #include "sopnamsp.h"
 | 
|---|
| [842] | 4 | #include "fiospherehealpix.h"
 | 
|---|
 | 5 | #include "pexceptions.h"
 | 
|---|
 | 6 | #include "fiondblock.h"
 | 
|---|
| [1954] | 7 | #include "datatype.h"
 | 
|---|
 | 8 | #include <typeinfo>
 | 
|---|
| [842] | 9 | 
 | 
|---|
 | 10 | //*******************************************************************
 | 
|---|
| [853] | 11 | // Class FIO_SphereHEALPix<T>
 | 
|---|
| [842] | 12 | //  Les objets delegues pour la gestion de persistance 
 | 
|---|
 | 13 | //*******************************************************************
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | template <class T>
 | 
|---|
| [853] | 16 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix()
 | 
|---|
| [842] | 17 | {
 | 
|---|
| [853] | 18 |   dobj_= new SphereHEALPix<T>;
 | 
|---|
| [842] | 19 |   ownobj= true;
 | 
|---|
 | 20 | }
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | template <class T>
 | 
|---|
| [853] | 23 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(string const& filename)
 | 
|---|
| [842] | 24 | {
 | 
|---|
| [853] | 25 |   dobj_= new SphereHEALPix<T>;
 | 
|---|
| [842] | 26 |   ownobj= true;
 | 
|---|
 | 27 |   Read(filename);
 | 
|---|
 | 28 | }
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | template <class T>
 | 
|---|
| [853] | 31 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(const SphereHEALPix<T>& obj)
 | 
|---|
| [842] | 32 | {
 | 
|---|
| [853] | 33 |   dobj_= new SphereHEALPix<T>(obj, true);
 | 
|---|
| [842] | 34 |   ownobj= true;
 | 
|---|
 | 35 | }
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | template <class T>
 | 
|---|
| [853] | 38 | FIO_SphereHEALPix<T>::FIO_SphereHEALPix(SphereHEALPix<T>* obj)
 | 
|---|
| [842] | 39 | {
 | 
|---|
 | 40 |   dobj_= obj;
 | 
|---|
 | 41 |   ownobj= false;
 | 
|---|
 | 42 | }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | template <class T>
 | 
|---|
| [853] | 45 | FIO_SphereHEALPix<T>::~FIO_SphereHEALPix()
 | 
|---|
| [842] | 46 | {
 | 
|---|
 | 47 |   if (ownobj && dobj_) delete dobj_;
 | 
|---|
 | 48 | }
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | template <class T>
 | 
|---|
| [853] | 51 | AnyDataObj* FIO_SphereHEALPix<T>::DataObj()
 | 
|---|
| [842] | 52 | {
 | 
|---|
 | 53 |   return(dobj_);
 | 
|---|
 | 54 | }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | template <class T>
 | 
|---|
| [853] | 57 | void FIO_SphereHEALPix<T>::SetDataObj(AnyDataObj & o)
 | 
|---|
| [842] | 58 | {
 | 
|---|
| [853] | 59 |   SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
 | 
|---|
| [1954] | 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 |   }
 | 
|---|
| [842] | 66 |   if (ownobj && dobj_) delete dobj_;
 | 
|---|
 | 67 |   dobj_ = po; ownobj = false;
 | 
|---|
 | 68 | } 
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | template <class T>
 | 
|---|
| [853] | 71 | void FIO_SphereHEALPix<T>::ReadSelf(PInPersist& is)
 | 
|---|
| [842] | 72 | {
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 |   if(dobj_ == NULL) 
 | 
|---|
 | 75 |     {
 | 
|---|
| [853] | 76 |       dobj_= new SphereHEALPix<T>;
 | 
|---|
| [842] | 77 |       ownobj= true;      
 | 
|---|
 | 78 |     }
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | // On lit les 3 premiers uint_8
 | 
|---|
 | 81 | uint_8 itab[3];
 | 
|---|
 | 82 | is.Get(itab, 3);
 | 
|---|
| [2978] | 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 | 
 | 
|---|
| [842] | 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);
 | 
|---|
| [2978] | 108 |   dobj_->setParameters(nSide,nPix, Omega, fgring);
 | 
|---|
| [1955] | 109 | 
 | 
|---|
| [842] | 110 | // On lit les DataBlocks;
 | 
|---|
 | 111 |   FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
 | 
|---|
 | 112 |   fio_nd.Read(is);
 | 
|---|
| [1382] | 113 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| [842] | 114 |   fio_ndi1.Read(is);
 | 
|---|
| [1382] | 115 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| [842] | 116 |   fio_ndi2.Read(is);
 | 
|---|
| [1954] | 117 | 
 | 
|---|
| [1955] | 118 | 
 | 
|---|
| [842] | 119 | }
 | 
|---|
 | 120 |  
 | 
|---|
 | 121 | template <class T>
 | 
|---|
| [853] | 122 | void FIO_SphereHEALPix<T>::WriteSelf(POutPersist& os) const
 | 
|---|
| [842] | 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
 | 
|---|
| [2978] | 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
 | 
|---|
| [842] | 135 | uint_8 itab[3];
 | 
|---|
| [2978] | 136 | itab[0] = 2;
 | 
|---|
| [842] | 137 | itab[1] = dobj_->SizeIndex();
 | 
|---|
| [2978] | 138 | itab[2] = (dobj_->IfRING()) ? 0 : 1;
 | 
|---|
| [842] | 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 |     {
 | 
|---|
| [853] | 150 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d HasInfo",nSide,nPix);
 | 
|---|
| [842] | 151 |       os.PutLine(strg);
 | 
|---|
 | 152 |       os << dobj_->Info();
 | 
|---|
 | 153 |     }
 | 
|---|
 | 154 |   else 
 | 
|---|
 | 155 |     { 
 | 
|---|
| [853] | 156 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d ",nSide,nPix);
 | 
|---|
| [842] | 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);
 | 
|---|
| [1382] | 166 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| [842] | 167 |   fio_ndi1.Write(os);
 | 
|---|
| [1382] | 168 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| [842] | 169 |   fio_ndi2.Write(os);
 | 
|---|
 | 170 | }
 | 
|---|
 | 171 | 
 | 
|---|
 | 172 | //*******************************************************************
 | 
|---|
 | 173 | 
 | 
|---|
 | 174 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| [2978] | 175 | #pragma define_template FIO_SphereHEALPix<uint_2>
 | 
|---|
| [2082] | 176 | #pragma define_template FIO_SphereHEALPix<int_4>
 | 
|---|
| [853] | 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> >
 | 
|---|
| [842] | 181 | #endif
 | 
|---|
 | 182 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| [2869] | 183 | namespace SOPHYA {
 | 
|---|
| [2978] | 184 | template class FIO_SphereHEALPix<uint_2>;
 | 
|---|
| [2082] | 185 | template class FIO_SphereHEALPix<int_4>;
 | 
|---|
| [853] | 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> >;
 | 
|---|
| [2869] | 190 | }
 | 
|---|
| [842] | 191 | #endif
 | 
|---|