source: Sophya/trunk/SophyaExt/FitsIOServer/fitsautoreader.cc@ 1351

Last change on this file since 1351 was 1351, checked in by yvon, 25 years ago

les enums dans les flots cout sont castes en (int)

dominique

File size: 6.0 KB
RevLine 
[1301]1#include "pexceptions.h"
2#include "fitsautoreader.h"
3#include "dvlist.h"
4
5///////////////////////////////////////////////////////////////////////
6// ---- gestion de persistance I/O format fits--
7// objets
8////////////////////////////////////////////////////////////////////
9
10FITS_AutoReader::FITS_AutoReader() {InitNull();};
11FITS_AutoReader::FITS_AutoReader(const char inputfile[])
12{
13 InitNull();
14 inFits_ = new FitsInFile (inputfile);
15}
16FITS_AutoReader::FITS_AutoReader(string const & inputfile)
17{
18 InitNull();
19 inFits_ = new FitsInFile (inputfile);
20}
21FITS_AutoReader::~FITS_AutoReader()
22{
23 if (inFits_ != NULL) delete inFits_;
24 if (dobj_ != NULL) delete dobj_;
25}
26
[1334]27int FITS_AutoReader::NbBlocks()
28{
29 return inFits_->NbBlocks();
30}
[1301]31
32AnyDataObj* FITS_AutoReader::ReadObject(int hdunum) const
33{
[1334]34 if (hdunum<=0)
35 {
36 throw PException(" FITS_AutoReader::ReadObject : hdu number must be positive");
37 }
[1301]38 inFits_->ReadHeader(hdunum);
[1334]39 if (inFits_->IsFitsEOF()) return NULL;
40 if (inFits_->IsFitsERROR())
41 {
42 throw IOExc("FITS_AutoReader::ReadObject: FITSIO error in reading");
43 }
[1301]44 DVList dvl=inFits_->DVListFromFits();
45 string nameObj = dvl.GetS("CONTENT");
[1334]46 // cout << " SOPHYA object identified as: " << dvl.GetS("CONTENT") << endl;
[1301]47 if (nameObj == string("TArray") )
48 {
49 return newTArray();
50 }
51 else if (nameObj == string("SphereHEALPix") )
52 {
53 return newSphereHEALPix();
54 }
55 else if (nameObj == string("LocalMap") )
56 {
57 return newLocalMap();
58 }
59 else if (nameObj == string("NTuple") )
60 {
61 return newNTuple();
62 }
63 else if (nameObj == string("XNTuple") )
64 {
65 return newXNTuple();
66 }
67 // on n'a trouve aucun nom d'objet connu de SOPHYA, on fait une
68 // recherche qualitative.
69 //
70 // si c'est une image fits, on cree un TArray
71 else if (inFits_->IsFitsImage())
72 {
73 return newTArray();
74 }
75 // si c'est une bintable on cherche le mot cle ORDERING pour identifier
76 // une spherehelpix
77 else if (inFits_->IsFitsTable())
78 {
79 if (dvl.GetS("ORDERING") != string("")) return newSphereHEALPix();
80 // sinon on cherche ntuple ou xntuple
81 else
82 {
83 int index=0;
84 for (int k=0; k < inFits_->NbColsFromFits(); k++)
85 {
86 if (inFits_->ColTypeFromFits(k) != FitsFile::FitsDataType_float)
87 {
88 index = 1;
89 break;
90 }
91 }
92 if (index == 0) return newNTuple();
93 else return newXNTuple();
94 }
95 }
96 else
97 {
[1334]98 cout << " WARNING ( FITS_AutoReader::ReadObject) : object not recognized as a SOPHYA object" << endl;
99 return new DVList(dvl);
[1301]100 }
101
102}
103
104AnyDataObj* FITS_AutoReader::newTArray() const
105{
106 FitsFile::FitsDataType dtype = inFits_->ImageType();
107 switch (dtype)
108 {
109 case FitsFile::FitsDataType_double :
110 {
111 TArray<r_8>* matptr = new TArray<r_8>;
112 FITS_TArray<r_8> fta(matptr);
113 fta.Read(*inFits_, inFits_->currentHeaderIndex());
114 return matptr;
115 }
116 case FitsFile::FitsDataType_float :
117 {
118 TArray<r_4>* matptr = new TArray<r_4>;
119 FITS_TArray<r_4> fta(matptr);
120 fta.Read(*inFits_, inFits_->currentHeaderIndex());
121 return matptr;
122 }
123 case FitsFile::FitsDataType_int :
124 {
125 TArray<int_4>* matptr = new TArray<int_4>;
126 FITS_TArray<int_4> fta(matptr);
127 fta.Read(*inFits_, inFits_->currentHeaderIndex());
128 return matptr;
129 }
130 default :
[1351]131 cout << "type = " << (int) dtype << endl;
[1301]132 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for TArray");
133 }
134}
135
136AnyDataObj* FITS_AutoReader::newSphereHEALPix() const
137{
138 FitsFile::FitsDataType dtype;
139 if (inFits_->IsFitsTable()) dtype = inFits_->ColTypeFromFits(0);
140 else
141 {
142 cout << " WARNING : Sperehealpix not binary table : unusual " << endl;
143 dtype = inFits_->ImageType();
144 }
145 switch (dtype)
146 {
147 case FitsFile::FitsDataType_double :
148 {
149 SphereHEALPix<r_8>* sphptr = new SphereHEALPix<r_8>;
150 FITS_SphereHEALPix<r_8> fta(sphptr);
151 fta.Read(*inFits_, inFits_->currentHeaderIndex());
152 return sphptr;
153 }
154 case FitsFile::FitsDataType_float :
155 {
156 SphereHEALPix<r_4>* sphptr = new SphereHEALPix<r_4>;
157 FITS_SphereHEALPix<r_4> fta(sphptr);
158 fta.Read(*inFits_, inFits_->currentHeaderIndex());
159 return sphptr;
160 }
161 case FitsFile::FitsDataType_int :
162 {
163 SphereHEALPix<int_4>* sphptr = new SphereHEALPix<int_4>;
164 FITS_SphereHEALPix<int_4> fta(sphptr);
165 fta.Read(*inFits_, inFits_->currentHeaderIndex());
166 return sphptr;
167 }
168 default :
[1351]169 cout << "type = " << (int) dtype << endl;
[1301]170 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for SphereHEALpix");
171 }
172}
173
174AnyDataObj* FITS_AutoReader::newLocalMap() const
175{
176 FitsFile::FitsDataType dtype;
177 if (inFits_->IsFitsTable()) dtype = inFits_->ColTypeFromFits(0);
178 else
179 {
180 cout << " WARNING : Localmap not binary table : unusual " << endl;
181 dtype = inFits_->ImageType();
182 }
183 switch (dtype)
184 {
185 case FitsFile::FitsDataType_double :
186 {
187 LocalMap<r_8>* locmptr = new LocalMap<r_8>;
188 FITS_LocalMap<r_8> fta(locmptr);
189 fta.Read(*inFits_, inFits_->currentHeaderIndex());
190 return locmptr;
191 }
192 case FitsFile::FitsDataType_float :
193 {
194 LocalMap<r_4>* locmptr = new LocalMap<r_4>;
195 FITS_LocalMap<r_4> fta(locmptr);
196 fta.Read(*inFits_, inFits_->currentHeaderIndex());
197 return locmptr;
198 }
199 case FitsFile::FitsDataType_int :
200 {
201 LocalMap<int_4>* locmptr = new LocalMap<int_4>;
202 FITS_LocalMap<int_4> fta(locmptr);
203 fta.Read(*inFits_, inFits_->currentHeaderIndex());
204 return locmptr;
205 }
206 default :
[1351]207 cout << "type = " << (int) dtype << endl;
[1301]208 throw IOExc("FITS_AutoReader::ReadObject : unsupported data type for LocalMap");
209 }
210}
211NTuple* FITS_AutoReader::newNTuple() const
212{
213 NTuple* ntptr = new NTuple;
214 FITS_NTuple fta(ntptr);
215 fta.Read(*inFits_, inFits_->currentHeaderIndex());
216 return ntptr;
217}
218XNTuple* FITS_AutoReader::newXNTuple() const
219{
220 XNTuple* xntptr = new XNTuple;
221 FITS_XNTuple fta(xntptr);
222 fta.Read(*inFits_, inFits_->currentHeaderIndex());
223 return xntptr;
224}
225
Note: See TracBrowser for help on using the repository browser.