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