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

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

classe FITS_AutoReader

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