| [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);
 | 
|---|
 | 83 | // Let's Read the SphereCoordSys object  -- ATTENTIOn - $CHECK$
 | 
|---|
 | 84 |   FIO_SphereCoordSys fio_scs( dobj_->GetCoordSys());
 | 
|---|
 | 85 |   fio_scs.Read(is);
 | 
|---|
 | 86 |   // Pour savoir s'il y avait un DVList Infodobj->Info();  associe
 | 
|---|
 | 87 |   char strg[256];
 | 
|---|
 | 88 |   is.GetLine(strg, 255);
 | 
|---|
 | 89 |   bool hadinfo= false;
 | 
|---|
 | 90 |   if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0)  hadinfo= true;
 | 
|---|
 | 91 |   if(hadinfo) 
 | 
|---|
 | 92 |     {    // Lecture eventuelle du DVList Info
 | 
|---|
 | 93 |       is >> dobj_->Info(); 
 | 
|---|
 | 94 |     }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |   int_4 nSide;
 | 
|---|
 | 97 |   is.GetI4(nSide);
 | 
|---|
 | 98 |   int_4 nPix;
 | 
|---|
 | 99 |   is.GetI4(nPix);
 | 
|---|
 | 100 |   double Omega;
 | 
|---|
 | 101 |   is.GetR8(Omega);
 | 
|---|
 | 102 |   dobj_->setParameters(nSide,nPix, Omega);
 | 
|---|
| [1955] | 103 | 
 | 
|---|
| [842] | 104 | // On lit les DataBlocks;
 | 
|---|
 | 105 |   FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
 | 
|---|
 | 106 |   fio_nd.Read(is);
 | 
|---|
| [1382] | 107 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| [842] | 108 |   fio_ndi1.Read(is);
 | 
|---|
| [1382] | 109 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| [842] | 110 |   fio_ndi2.Read(is);
 | 
|---|
| [1954] | 111 | 
 | 
|---|
| [1955] | 112 | 
 | 
|---|
| [842] | 113 | }
 | 
|---|
 | 114 |  
 | 
|---|
 | 115 | template <class T>
 | 
|---|
| [853] | 116 | void FIO_SphereHEALPix<T>::WriteSelf(POutPersist& os) const
 | 
|---|
| [842] | 117 | {
 | 
|---|
 | 118 |   if(dobj_ == NULL) 
 | 
|---|
 | 119 |     {
 | 
|---|
 | 120 |       cout << " WriteSelf:: dobj_= null " << endl;
 | 
|---|
 | 121 |       return;
 | 
|---|
 | 122 |     }
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 | //  On ecrit 3 uint_8 
 | 
|---|
 | 125 | //  0 : Numero de version,  1 : Size index,  2  reserve a l
 | 
|---|
 | 126 | uint_8 itab[3];
 | 
|---|
 | 127 | itab[0] = 1;
 | 
|---|
 | 128 | itab[1] = dobj_->SizeIndex();
 | 
|---|
 | 129 | itab[2] = 0;
 | 
|---|
 | 130 | os.Put(itab, 3);
 | 
|---|
 | 131 | // Let's write the SphereCoordSys object
 | 
|---|
 | 132 |   FIO_SphereCoordSys fio_scs( dobj_->GetCoordSys());
 | 
|---|
 | 133 |   fio_scs.Write(os);
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |   char strg[256];
 | 
|---|
 | 136 |   int_4 nSide= dobj_->SizeIndex();
 | 
|---|
 | 137 |   int_4 nPix = dobj_->NbPixels();
 | 
|---|
 | 138 |  
 | 
|---|
 | 139 |   if(dobj_->ptrInfo()) 
 | 
|---|
 | 140 |     {
 | 
|---|
| [853] | 141 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d HasInfo",nSide,nPix);
 | 
|---|
| [842] | 142 |       os.PutLine(strg);
 | 
|---|
 | 143 |       os << dobj_->Info();
 | 
|---|
 | 144 |     }
 | 
|---|
 | 145 |   else 
 | 
|---|
 | 146 |     { 
 | 
|---|
| [853] | 147 |       sprintf(strg,"SphereHEALPix: NSide=%6d  NPix=%9d ",nSide,nPix);
 | 
|---|
| [842] | 148 |       os.PutLine(strg);  
 | 
|---|
 | 149 |     }
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |   os.PutI4(nSide);
 | 
|---|
 | 152 |   os.PutI4(nPix);
 | 
|---|
 | 153 |   os.PutR8(dobj_->PixSolAngle());
 | 
|---|
 | 154 | // On ecrit les dataBlocks 
 | 
|---|
 | 155 |   FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
 | 
|---|
 | 156 |   fio_nd.Write(os);
 | 
|---|
| [1382] | 157 |   FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
 | 
|---|
| [842] | 158 |   fio_ndi1.Write(os);
 | 
|---|
| [1382] | 159 |   FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
 | 
|---|
| [842] | 160 |   fio_ndi2.Write(os);
 | 
|---|
 | 161 | }
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 | //*******************************************************************
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| [2082] | 166 | #pragma define_template FIO_SphereHEALPix<int_4>
 | 
|---|
| [853] | 167 | #pragma define_template FIO_SphereHEALPix<r_8>
 | 
|---|
 | 168 | #pragma define_template FIO_SphereHEALPix<r_4>
 | 
|---|
 | 169 | #pragma define_template FIO_SphereHEALPix< complex<r_4> >
 | 
|---|
 | 170 | #pragma define_template FIO_SphereHEALPix< complex<r_8> >
 | 
|---|
| [842] | 171 | #endif
 | 
|---|
 | 172 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| [2082] | 173 | template class FIO_SphereHEALPix<int_4>;
 | 
|---|
| [853] | 174 | template class FIO_SphereHEALPix<r_8>;
 | 
|---|
 | 175 | template class FIO_SphereHEALPix<r_4>;
 | 
|---|
 | 176 | template class FIO_SphereHEALPix< complex<r_4> >;
 | 
|---|
 | 177 | template class FIO_SphereHEALPix< complex<r_8> >;
 | 
|---|
| [842] | 178 | #endif
 | 
|---|