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