source: Sophya/trunk/SophyaLib/SkyMap/fiospherehealpix.cc@ 2693

Last change on this file since 2693 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 4.3 KB
Line 
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
15template <class T>
16FIO_SphereHEALPix<T>::FIO_SphereHEALPix()
17{
18 dobj_= new SphereHEALPix<T>;
19 ownobj= true;
20}
21
22template <class T>
23FIO_SphereHEALPix<T>::FIO_SphereHEALPix(string const& filename)
24{
25 dobj_= new SphereHEALPix<T>;
26 ownobj= true;
27 Read(filename);
28}
29
30template <class T>
31FIO_SphereHEALPix<T>::FIO_SphereHEALPix(const SphereHEALPix<T>& obj)
32{
33 dobj_= new SphereHEALPix<T>(obj, true);
34 ownobj= true;
35}
36
37template <class T>
38FIO_SphereHEALPix<T>::FIO_SphereHEALPix(SphereHEALPix<T>* obj)
39{
40 dobj_= obj;
41 ownobj= false;
42}
43
44template <class T>
45FIO_SphereHEALPix<T>::~FIO_SphereHEALPix()
46{
47 if (ownobj && dobj_) delete dobj_;
48}
49
50template <class T>
51AnyDataObj* FIO_SphereHEALPix<T>::DataObj()
52{
53 return(dobj_);
54}
55
56template <class T>
57void 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
70template <class T>
71void 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
81uint_8 itab[3];
82is.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);
103
104// On lit les DataBlocks;
105 FIO_NDataBlock<T> fio_nd(&dobj_->pixels_);
106 fio_nd.Read(is);
107 FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
108 fio_ndi1.Read(is);
109 FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
110 fio_ndi2.Read(is);
111
112
113}
114
115template <class T>
116void FIO_SphereHEALPix<T>::WriteSelf(POutPersist& os) const
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
126uint_8 itab[3];
127itab[0] = 1;
128itab[1] = dobj_->SizeIndex();
129itab[2] = 0;
130os.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 {
141 sprintf(strg,"SphereHEALPix: NSide=%6d NPix=%9d HasInfo",nSide,nPix);
142 os.PutLine(strg);
143 os << dobj_->Info();
144 }
145 else
146 {
147 sprintf(strg,"SphereHEALPix: NSide=%6d NPix=%9d ",nSide,nPix);
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);
157 FIO_NDataBlock<int_4> fio_ndi1(&dobj_->sliceBeginIndex_);
158 fio_ndi1.Write(os);
159 FIO_NDataBlock<int_4> fio_ndi2(&dobj_->sliceLenght_);
160 fio_ndi2.Write(os);
161}
162
163//*******************************************************************
164
165#ifdef __CXX_PRAGMA_TEMPLATES__
166#pragma define_template FIO_SphereHEALPix<int_4>
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> >
171#endif
172#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
173template class FIO_SphereHEALPix<int_4>;
174template class FIO_SphereHEALPix<r_8>;
175template class FIO_SphereHEALPix<r_4>;
176template class FIO_SphereHEALPix< complex<r_4> >;
177template class FIO_SphereHEALPix< complex<r_8> >;
178#endif
Note: See TracBrowser for help on using the repository browser.