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

Last change on this file since 1673 was 1371, checked in by ansari, 25 years ago

MAJ documentation, Makefile, ... - Reza 5/1/2001

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