-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColumnCreator.cxx
388 lines (362 loc) · 14.7 KB
/
ColumnCreator.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: [email protected]
//
// Original author: Ben Dorman
// Column
#include "Column.h"
// Table
#include "Table.h"
// ColumnData
#include "ColumnData.h"
// ColumnVectorData
#include "ColumnVectorData.h"
// ColumnCreator
#include "ColumnCreator.h"
#include <stdlib.h>
#include <complex>
using std::complex;
namespace CCfits {
// Class CCfits::ColumnCreator
ColumnCreator::ColumnCreator (Table* p)
: m_parent(p)
{
}
ColumnCreator::~ColumnCreator()
{
}
Column * ColumnCreator::MakeColumn (const int index, const String &name, const String &format, const String &unit, const long repeat, const long width, const String &comment, const int decimals)
{
return 0;
}
Column * ColumnCreator::getColumn (int number, const String& name, const String& format, const String& unit)
{
long repeat=1;
long width=1;
int type=0;
double tscale = 1;
double tzero = 0;
getScaling(number, type, repeat, width, tscale, tzero);
return createColumn(number,ValueType(type),name,format,unit,repeat,width,tscale,tzero);
}
Column * ColumnCreator::createColumn (int number, ValueType type, const String &name, const String &format, const String &unit, long repeat, long width, double scaleFactor, double offset, const String &comment)
{
switch(type)
{
case Tstring:
if (repeat/width > 1)
{
// A vector column of strings. Not currently supported in CCfits,
// but for backward compatibility do not throw -- user may be
// loading a table with no intention of reading or writing to the
// vector string column.
std::cerr << "\n***CCfits Warning: Column " << number << " is detected to be a vector column of strings.\n"
<<" CCfits does not currently support reading and writing to vector string columns.\n"<<std::endl;
}
case VTstring:
m_column = new ColumnData<String>(number, name, type, format, unit,
m_parent, 1, width);
break;
case VTushort:
m_column = new ColumnVectorData<unsigned short>(number, name,
type, format,unit, m_parent, repeat);
m_column->zero(USBASE);
m_column->scale(1);
break;
case Tushort:
if (repeat == 1)
{
m_column = new ColumnData<unsigned short>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<unsigned short>(number, name,
type, format,unit, m_parent, repeat);
}
m_column->zero(USBASE);
m_column->scale(1);
break;
case VTshort:
m_column = new ColumnVectorData<short>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tshort:
if (repeat == 1)
{
m_column = new ColumnData<short>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<short>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTlogical:
m_column = new ColumnVectorData<bool>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tlogical:
if (repeat == 1)
{
m_column = new ColumnData<bool>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<bool>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTbyte:
case VTbit:
m_column = new ColumnVectorData<unsigned char>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tbit:
case Tbyte:
if (repeat == 1)
{
m_column = new ColumnData<unsigned char>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<unsigned char>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTint:
m_column = new ColumnVectorData<int>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tint:
if (repeat == 1)
{
m_column = new ColumnData<int>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<int>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTuint:
m_column = new ColumnVectorData<unsigned int>(number, name,
type, format,unit, m_parent, repeat);
m_column->zero(ULBASE);
m_column->scale(1);
break;
case Tuint:
if (repeat == 1)
{
m_column = new ColumnData<unsigned int>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<unsigned int>(number, name,
type, format,unit, m_parent, repeat);
}
m_column->zero(ULBASE);
m_column->scale(1);
break;
case VTlong:
m_column = new ColumnVectorData<long>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tlong:
if (repeat == 1)
{
m_column = new ColumnData<long>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<long>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTlonglong:
m_column = new ColumnVectorData<LONGLONG>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tlonglong:
if (repeat == 1)
{
m_column = new ColumnData<LONGLONG>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<LONGLONG>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTulong:
m_column = new ColumnVectorData<unsigned long>(number, name,
type, format,unit, m_parent, repeat);
m_column->zero(ULBASE);
m_column->scale(1);
break;
case Tulong:
if (repeat == 1)
{
m_column = new ColumnData<unsigned long>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<unsigned long>(number, name,
type, format,unit, m_parent, repeat);
}
m_column->zero(ULBASE);
m_column->scale(1);
break;
case VTfloat:
m_column = new ColumnVectorData<float>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tfloat:
if (repeat == 1)
{
m_column = new ColumnData<float>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<float>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTdouble:
m_column = new ColumnVectorData<double>(number, name,
type, format,unit, m_parent, repeat);
break;
case Tdouble:
if (repeat == 1)
{
m_column = new ColumnData<double>(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<double>(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTcomplex:
m_column = new ColumnVectorData<complex<float> >(number, name,
type, format,unit, m_parent, repeat);
break;
case Tcomplex:
if (repeat == 1)
{
m_column = new ColumnData<complex<float> >(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<complex<float> >(number, name,
type, format,unit, m_parent, repeat);
}
break;
case VTdblcomplex:
m_column = new ColumnVectorData<complex<double> >(number, name,
type, format,unit, m_parent, repeat);
break;
case Tdblcomplex:
if (repeat == 1)
{
m_column = new ColumnData<complex<double> >(number, name,
type, format,unit, m_parent);
}
else
{
m_column = new ColumnVectorData<complex<double> >(number, name,
type, format,unit, m_parent, repeat);
}
break;
default:
// replace with exception.
throw FitsFatal("Unknown ValueType in ColumnCreator");
}
if ( scaleFactor != 1)
{
m_column->scale(scaleFactor);
m_column->zero(offset);
}
return m_column;
}
void ColumnCreator::getScaling (int index, int& type, long& repeat, long& width, double& tscale, double& tzero)
{
int status (0);
if (fits_get_coltype(m_parent->fitsPointer(), index, &type, &repeat, &width, &status))
{
throw FitsError(status);
}
int absType (std::abs(type)) ;
FITSUtil::auto_array_ptr<char> pKeyname( new char[FLEN_KEYWORD]);
char* keyname = pKeyname.get();
sprintf(keyname, "%s%d",Column::TSCAL().c_str(),index);
bool scalePresent (!fits_read_key(m_parent->fitsPointer(),Tdouble,keyname,&tscale,0,&status));
// reset the status flag if there was no scale factor so cfitsio will not
// propagate the error code.
if (!scalePresent) status = 0;
sprintf(keyname, "%s%d", Column::TZERO().c_str(),index);
fits_read_key(m_parent->fitsPointer(),Tdouble,keyname,&tzero,0,&status);
// if there is no BSCALE key present or BSCALE == 1 ...
if (!scalePresent || (scalePresent && tscale == 1))
{
if ( !status )
{
switch (absType)
{
case Tshort:
if (tzero == USBASE)
{
type > 0 ? type = Tushort : type = VTushort ;
}
break;
case Tint:
if (tzero == ULBASE)
{
type > 0 ? type = Tuint : type = VTuint ;
}
break;
case Tlong:
if (tzero == ULBASE)
{
type > 0 ? type = Tulong : type = VTulong ;
}
break;
default:
break;
}
}
}
else // scale present and tmpScale != 1.
{
switch (absType)
{
case Tbit:
case Tbyte:
case Tint:
case Tshort:
type > 0 ? type = Tfloat: type = VTfloat;
break;
case Tlong:
case Tlonglong:
type > 0 ? type = Tdouble: type = VTdouble;
break;
default:
break; // do nothing.
}
}
}
// Additional Declarations
} // namespace CCfits