source: branches/newfiller/external-alma/atnf/PKSIO/NROFITSDataset.cc@ 3110

Last change on this file since 3110 was 1757, checked in by Kana Sugimoto, 14 years ago

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


File size: 74.9 KB
Line 
1//#---------------------------------------------------------------------------
2//# NROFITSDataset.cc: Class for NRO 45m FITS dataset.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2006
5//# Associated Universities, Inc. Washington DC, USA.
6//#
7//# This library is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU Library General Public License as published by
9//# the Free Software Foundation; either version 2 of the License, or (at your
10//# option) any later version.
11//#
12//# This library is distributed in the hope that it will be useful, but WITHOUT
13//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15//# License for more details.
16//#
17//# You should have received a copy of the GNU Library General Public License
18//# along with this library; if not, write to the Free Software Foundation,
19//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning AIPS++ should be addressed as follows:
22//# Internet email: aips2-request@nrao.edu.
23//# Postal address: AIPS++ Project Office
24//# National Radio Astronomy Observatory
25//# 520 Edgemont Road
26//# Charlottesville, VA 22903-2475 USA
27//#
28//# $Id$
29//#---------------------------------------------------------------------------
30//# Original: 2009/02/27, Takeshi Nakazato, NAOJ
31//#---------------------------------------------------------------------------
32
33#include <atnf/PKSIO/NROFITSDataset.h>
34#include <scimath/Mathematics/InterpolateArray1D.h>
35
36#include <iostream>
37#include <fstream>
38#include <casa/math.h>
39#include <casa/iomanip.h>
40
41using namespace std ;
42
43//header size (8*2880bytes)
44#define FITS_HEADER_SIZE 23040
45
46// constructor
47NROFITSDataset::NROFITSDataset( string name )
48 : NRODataset( name )
49{
50 LogIO os( LogOrigin( "NROFITSDataset", "NROFITSDataset()", WHERE ) ) ;
51
52 fp_ = NULL ;
53 dataid_ = -1 ;
54 record_ = new NRODataRecord() ;
55 record_->LDATA = NULL ; // never use LDATA
56
57 // open file
58 if ( open() )
59 os << LogIO::SEVERE << "error while opening file " << filename_ << LogIO::EXCEPTION ;
60
61 // data initialization
62 readHeader( numField_, "TFIELDS", same_ ) ;
63 forms_.resize( numField_ ) ;
64 names_.resize( numField_ ) ;
65 units_.resize( numField_ ) ;
66 getField() ;
67
68 // check endian
69 // FITS file is always BIG_ENDIAN, but it is not true for NRO data
70 vector<int> itmp( 6 ) ;
71 if ( readTable( itmp, "LAVST", true, 0 ) != 0 ) {
72 os << LogIO::WARN << "Error while checking endian." << LogIO::POST ;
73 return ;
74 }
75// os << "itmp = " << itmp[0] << " "
76// << itmp[1] << " " << itmp[2] << " "
77// << itmp[3] << " " << itmp[4] << " "
78// << itmp[5] << LogIO::POST ;
79 // check endian by looking month value in LAVST (start time)
80 if ( itmp[1] > 0 && itmp[1] < 13 ) {
81 same_ = 1 ;
82 os << LogIO::NORMAL << "same endian " << LogIO::POST ;
83 }
84 else {
85 same_ = 0 ;
86 os << LogIO::NORMAL << "different endian " << LogIO::POST ;
87 }
88
89 // memory allocation
90 initialize() ;
91}
92
93// destructor
94NROFITSDataset::~NROFITSDataset()
95{
96 // close file
97 close() ;
98}
99
100// data initialization
101void NROFITSDataset::initialize()
102{
103 LogIO os( LogOrigin( "NROFITSDataset", "initialize()", WHERE ) ) ;
104
105 int status = 0 ;
106 status = readHeader( ARYNM, "ARYNM", same_ ) ;
107 if ( status != 0 )
108 ARYNM = 1 ;
109 readHeader( rowNum_, "NAXIS2", same_ ) ;
110 readHeader( scanLen_, "NAXIS1", same_ ) ;
111 status = 0 ;
112 scanNum_ = rowNum_ / ARYNM ;
113 int nchan = 0 ;
114 if ( readTable( nchan, "NCH", same_ ) != 0 ) {
115 os << LogIO::WARN << "Error while checking maximum channel number." << LogIO::POST ;
116 return ;
117 }
118 chmax_ = nchan ;
119 datasize_ = sizeof( int ) * chmax_ ;
120 //record_->JDATA.resize( chmax_ ) ;
121 JDATA.resize( chmax_ ) ;
122 // zero clear
123 for ( uInt i = 0 ; i < JDATA.size() ; i++ )
124 JDATA[i] = 0 ;
125
126 RX.resize( ARYNM ) ;
127 HPBW.resize( ARYNM ) ;
128 EFFA.resize( ARYNM ) ;
129 EFFB.resize( ARYNM ) ;
130 EFFL.resize( ARYNM ) ;
131 EFSS.resize( ARYNM ) ;
132 GAIN.resize( ARYNM ) ;
133 HORN.resize( ARYNM ) ;
134 POLTP.resize( ARYNM ) ;
135 POLDR.resize( ARYNM ) ;
136 POLAN.resize( ARYNM ) ;
137 DFRQ.resize( ARYNM ) ;
138 SIDBD.resize( ARYNM ) ;
139 REFN.resize( ARYNM ) ;
140 IPINT.resize( ARYNM ) ;
141 MULTN.resize( ARYNM ) ;
142 MLTSCF.resize( ARYNM ) ;
143 LAGWIND.resize( ARYNM ) ;
144 BEBW.resize( ARYNM ) ;
145 BERES.resize( ARYNM ) ;
146 CHWID.resize( ARYNM ) ;
147 ARRY.resize( NRO_FITS_ARYMAX ) ;
148 NFCAL.resize( ARYNM ) ;
149 F0CAL.resize( ARYNM ) ;
150 FQCAL.resize( ARYNM ) ;
151 CHCAL.resize( ARYNM ) ;
152 CWCAL.resize( ARYNM ) ;
153 DSBFC.resize( ARYNM ) ;
154
155 ARYTP.resize( ARYNM ) ;
156 arrayid_.resize( ARYNM ) ;
157 for ( int i = 0 ; i < ARYNM ; i++ )
158 arrayid_[i] = -1 ;
159
160 for ( int i = 0 ; i < ARYNM ; i++ ) {
161 FQCAL[i].resize( 10 ) ;
162 CHCAL[i].resize( 10 ) ;
163 CWCAL[i].resize( 10 ) ;
164 }
165
166 datasize_ += sizeof( char ) * ARYNM * 16 // RX
167 + sizeof( double ) * ARYNM * 6 // HPBW, EFFA, EFFB, EFFL, EFSS GAIN
168 + sizeof( char ) * ARYNM * 4 // HORN
169 + sizeof( char ) * ARYNM * 4 // POLTP
170 + sizeof( double ) * ARYNM * 3 // POLDR, POLAN, DFRQ
171 + sizeof( char ) * ARYNM * 4 // SIDBID
172 + sizeof( int ) * ARYNM * 3 // REFN, IPINT, MULTN
173 + sizeof( double ) * ARYNM // MLTSCF
174 + sizeof( char ) * ARYNM * 8 // LAGWIND
175 + sizeof( double ) * ARYNM * 3 // BEBW, BERES, CHWID
176 + sizeof( int ) * NRO_FITS_ARYMAX // ARRY
177 + sizeof( int ) * ARYNM // NFCAL
178 + sizeof( double ) * ARYNM // F0CAL
179 + sizeof( double ) * ARYNM * 10 * 3 // FQCAL, CHCAL, CWCAL
180 + sizeof( char ) * 180 ; // CDMY1
181}
182
183// fill data header
184int NROFITSDataset::fillHeader()
185{
186 LogIO os( LogOrigin( "NROFITSDataset", "fillHeader()", WHERE ) ) ;
187
188 // open file
189 if ( open() ) {
190 os << LogIO::SEVERE << "Error opening file " << filename_ << "." << LogIO::EXCEPTION ;
191 return -1 ;
192 }
193
194 // fill
195 int status = fillHeader( same_ ) ;
196
197 return status ;
198}
199
200int NROFITSDataset::fillHeader( int sameEndian )
201{
202 LogIO os( LogOrigin( "NROFITSDataset", "fillHeader()", WHERE ) ) ;
203
204 // fill array type
205 fillARYTP() ;
206
207 // read data header
208 float ftmp = 0.0 ;
209 if ( readHeader( LOFIL, "LOFIL" ) != 0 ) {
210 os << LogIO::NORMAL << "LOFIL set to 'FITS'." << LogIO::POST ;
211 LOFIL = "FITS" ;
212 }
213 // DEBUG
214 //cout << "LOFIL = \'" << LOFIL << "\'" << endl ;
215 //
216 if ( readHeader( VER, "VER" ) != 0 ) {
217 if ( readHeader( VER, "HISTORY NEWSTAR VER" ) != 0 ) {
218 os << LogIO::NORMAL << "VER set to 'V000'." << LogIO::POST ;
219 VER = "V000" ;
220 }
221 }
222 // DEBUG
223 //cout << "VER = \'" << VER << "\'" << endl ;
224 //
225 if ( readHeader( GROUP, "GROUP" ) != 0 ) {
226 if ( readHeader( GROUP, "HISTORY NEWSTAR GROUP" ) != 0 ) {
227 os << LogIO::NORMAL << "GROUP set to 'GRP0'." << LogIO::POST ;
228 GROUP = "GROUP0" ;
229 }
230 }
231 // DEBUG
232 //cout << "GROUP = \'" << GROUP << "\'" << endl ;
233 //
234 if ( readHeader( PROJ, "PROJECT" ) != 0 ) {
235 if ( readHeader( PROJ, "HISTORY NEWSTAR PROJECT" ) != 0 ) {
236 os << LogIO::NORMAL << "PROJ set to 'PROJ0'." << LogIO::POST ;
237 PROJ = "PROJECT0" ;
238 }
239 }
240 // DEBUG
241 //cout << "PROJ = \'" << PROJ << "\'" << endl ;
242 //
243 if ( readHeader( SCHED, "SCHED" ) != 0 ) {
244 if ( readHeader( SCHED, "HISTORY NEWSTAR SCHED" ) != 0 ) {
245 os << LogIO::NORMAL << "SCHED set to 'SCHED0'." << LogIO::POST ;
246 SCHED = "SCHED0" ;
247 }
248 }
249 // DEBUG
250 //cout << "SCHED = \'" << SCHED << "\'" << endl ;
251 //
252 if ( readHeader( OBSVR, "OBSERVER" ) != 0 ) {
253 os << LogIO::NORMAL << "OBSVR set to 'SOMEONE'" << LogIO::POST ;
254 OBSVR = "SOMEONE" ;
255 }
256 // DEBUG
257 //cout << "OBSVR = \'" << OBSVR << "\'" << endl ;
258 //
259 if ( readHeader( LOSTM, "STRSC" ) != 0 ) {
260 os << LogIO::WARN << "Error while reading data LOSTM." << LogIO::POST ;
261 return -1 ;
262 }
263 if ( LOSTM[0] == '9' ) {
264 LOSTM = "19" + LOSTM ;
265 }
266 else if ( LOSTM[0] == '0') {
267 LOSTM = "20" + LOSTM ;
268 }
269 // DEBUG
270 //cout << "LOSTM = \'" << LOSTM << "\'" << endl ;
271 //
272 if ( readHeader( LOETM, "STPSC" ) != 0 ) {
273 os << LogIO::WARN << "Error while reading data LOETM." << LogIO::POST ;
274 return -1 ;
275 }
276 if ( LOETM[0] == '9' ) {
277 LOETM = "19" + LOETM ;
278 }
279 else if ( LOETM[0] == '0') {
280 LOETM = "20" + LOETM ;
281 }
282 // DEBUG
283 //cout << "LOETM = \'" << LOETM << "\'" << endl ;
284 //
285 if ( readHeader( NSCAN, "NAXIS2", sameEndian ) != 0 ) {
286 os << LogIO::WARN << "Error while reading data NSCAN." << LogIO::POST ;
287 return -1 ;
288 }
289 // DEBUG
290 //cout << "NSCAN = " << NSCAN << endl ;
291 //
292 string subt ;
293 if ( readHeader( TITLE, "TITLE" ) != 0 ) {
294 int stat1 = readHeader( TITLE, "HISTORY NEWSTAR TITLE1" ) ;
295 int stat2 = readHeader( subt, "HISTORY NEWSTAR TITLE2" ) ;
296 if ( stat1 != 0 && stat2 != 0 ) {
297 os << LogIO::NORMAL << "TITLE set to 'NOTITLE'." << LogIO::POST ;
298 TITLE = "NOTITLE" ;
299 }
300 else {
301 //cout << "TITLE = \'" << TITLE << "\'" << endl ;
302 //cout << "subt = \'" << subt << "\'" << endl ;
303 TITLE = TITLE + subt ;
304 }
305 }
306 // DEBUG
307 //cout << "TITLE = \'" << TITLE << "\'" << endl ;
308 //
309 if ( readHeader( OBJ, "OBJECT" ) != 0 ) {
310 os << LogIO::NORMAL << "OBJ set to 'SOMEWHERE'." << LogIO::POST ;
311 OBJ = "NOOBJ" ;
312 }
313 // DEBUG
314 //cout << "OBJ = \'" << OBJ << "\'" << endl ;
315 //
316 if ( readHeader( ftmp, "EPOCH", sameEndian ) != 0 ) {
317 os << LogIO::WARN << "Error while reading data EPOCH." << LogIO::POST ;
318 return -1 ;
319 }
320 if ( ftmp == 1950.0 )
321 EPOCH = "B1950" ;
322 else if ( ftmp == 2000.0 )
323 EPOCH = "J2000" ;
324 else {
325 os << LogIO::WARN << "Unidentified epoch. set to 'XXXXX'" << LogIO::POST ;
326 EPOCH = "XXXXX" ;
327 }
328 // DEBUG
329 //cout << "EPOCH = \'" << EPOCH << "\'" << endl ;
330 //
331 string stmp ;
332 if ( readHeader( stmp, "RA" ) != 0 ) {
333 os << LogIO::WARN << "Error while reading data RA0." << LogIO::POST ;
334 return -1 ;
335 }
336 RA0 = radRA( stmp.c_str() ) ;
337 // DEBUG
338 //cout << "RA0 = " << RA0 << endl ;
339 //
340 if ( readHeader( stmp, "DEC" ) != 0 ) {
341 os << LogIO::WARN << "Error while reading data DEC0." << LogIO::POST ;
342 return -1 ;
343 }
344 DEC0 = radDEC( stmp.c_str() ) ;
345 // DEBUG
346 //cout << "DEC0 = " << DEC0 << endl ;
347 //
348 if ( readHeader( GLNG0, "GL0", sameEndian ) != 0 ) {
349 os << LogIO::WARN << "Error while reading data GLNG0." << LogIO::POST ;
350 return -1 ;
351 }
352 // DEBUG
353 //cout << "GLNG0 = " << GLNG0 << endl ;
354 //
355 if ( readHeader( GLAT0, "GB0", sameEndian ) != 0 ) {
356 os << LogIO::WARN << "Error while reading data GLAT0." << LogIO::POST ;
357 return -1 ;
358 }
359 // DEBUG
360 //cout << "GLAT0 = " << GLAT0 << endl ;
361 //
362 if ( readHeader( NCALB, "NCALB", sameEndian ) != 0 ) {
363 os << LogIO::WARN << "Error while reading data NCALB." << LogIO::POST ;
364 return -1 ;
365 }
366 // DEBUG
367 //cout << "NCALB = " << NCALB << endl ;
368 //
369 if ( readHeader( SCNCD, "SCNCD", sameEndian ) != 0 ) {
370 os << LogIO::NORMAL << "SCNCD set to 0 (RADEC)." << LogIO::POST ;
371 SCNCD = 0 ;
372 }
373 // DEBUG
374 //cout << "SCNCD = " << SCNCD << endl ;
375 //
376 if ( readHeader( SCMOD, "SCMOD1" ) != 0 ) {
377 os << LogIO::WARN << "Error while reading data SCMOD." << LogIO::POST ;
378 return -1 ;
379 }
380 string::size_type pos = SCMOD.find( ' ' ) ;
381 if ( pos != string::npos ) {
382 SCMOD = SCMOD.substr( 0, pos ) ;
383 SCMOD = SCMOD + " " ;
384 }
385 //cout << "SDMOD1 = \'" << SCMOD << "\'" << endl ;
386 if ( readHeader( stmp, "SCMOD2" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
387 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
388 stmp = stmp.substr( 0, pos ) ;
389 SCMOD = SCMOD + stmp + " " ;
390 //cout << "SCMOD2 = \'" << SCMOD << "\'" << endl ;
391 }
392 if ( readHeader( stmp, "SCMOD3" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
393 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
394 stmp = stmp.substr( 0, pos ) ;
395 SCMOD = SCMOD + stmp + " " ;
396 //cout << "SCMOD3 = \'" << SCMOD << "\'" << endl ;
397 }
398 if ( readHeader( stmp, "SCMOD4" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
399 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
400 stmp = stmp.substr( 0, pos ) ;
401 SCMOD = SCMOD + stmp + " " ;
402 //cout << "SCMOD4 = \'" << SCMOD << "\'" << endl ;
403 }
404 if ( readHeader( stmp, "SCMOD5" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
405 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
406 stmp = stmp.substr( 0, pos ) ;
407 SCMOD = SCMOD + stmp + " " ;
408 //cout << "SCMOD5 = \'" << SCMOD << "\'" << endl ;
409 }
410 if ( readHeader( stmp, "SCMOD6" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
411 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
412 stmp = stmp.substr( 0, pos ) ;
413 SCMOD = SCMOD + stmp + " " ;
414 //cout << "SCMOD6 = \'" << SCMOD << "\'" << endl ;
415 }
416 // DEBUG
417 //cout << "SCMOD = \'" << SCMOD << "\'" << endl ;
418 //
419 if ( readHeader( URVEL, "VEL", sameEndian ) != 0 ) {
420 os << LogIO::WARN << "Error while reading data URVEL." << LogIO::POST ;
421 return -1 ;
422 }
423 // DEBUG
424 //cout << "URVEL = " << URVEL << endl ;
425 //
426 if ( readHeader( VREF, "VREF" ) != 0 ) {
427 os << LogIO::WARN << "Error while reading data VREF." << LogIO::POST ;
428 return -1 ;
429 }
430 // DEBUG
431 //cout << "VREF = \'" << VREF << "\'" << endl ;
432 //
433 if ( readHeader( VDEF, "VDEF" ) != 0 ) {
434 os << LogIO::WARN << "Error while reading data VDEF." << LogIO::POST ;
435 return -1 ;
436 }
437 // DEBUG
438 //cout << "VDEF = \'" << VDEF << "\'" << endl ;
439 //
440 if ( readHeader( SWMOD, "SWMOD" ) != 0 ) {
441 os << LogIO::WARN << "Error while reading data SWMOD." << LogIO::POST ;
442 return -1 ;
443 }
444 // DEBUG
445 //cout << "SWMOD = \'" << SWMOD << "\'" << endl ;
446 //
447 if ( readHeader( FRQSW, "FRQSW", sameEndian ) != 0 ) {
448 os << LogIO::NORMAL << "FRQSW set to 0." << LogIO::POST ;
449 FRQSW = 0.0 ;
450 }
451 // DEBUG
452 //cout << "FRQSW = " << FRQSW << endl ;
453 //
454 if ( readHeader( DBEAM, "DBEAM", sameEndian ) != 0 ) {
455 os << LogIO::WARN << "Error while reading data DBEAM." << LogIO::POST ;
456 return -1 ;
457 }
458 // DEBUG
459 //cout << "DBEAM = " << DBEAM << endl ;
460 //
461 if ( readHeader( MLTOF, "MLTOF", sameEndian ) != 0 ) {
462 os << LogIO::NORMAL << "MLTOF set to 0." << LogIO::POST ;
463 MLTOF = 0.0 ;
464 }
465 // DEBUG
466 //cout << "MLTOF = " << MLTOF << endl ;
467 //
468 if ( readHeader( CMTQ, "CMTQ", sameEndian ) != 0 ) {
469 os << LogIO::WARN << "Error while reading data CMTQ." << LogIO::POST ;
470 return -1 ;
471 }
472 // DEBUG
473 //cout << "CMTQ = " << CMTQ << endl ;
474 //
475 if ( readHeader( CMTE, "CMTE", sameEndian ) != 0 ) {
476 os << LogIO::WARN << "Error while reading data CMTE." << LogIO::POST ;
477 return -1 ;
478 }
479 // DEBUG
480 //cout << "CMTE = " << CMTE << endl ;
481 //
482 if ( readHeader( CMTSOM, "CMTSOM", sameEndian ) != 0 ) {
483 os << LogIO::WARN << "Error while reading data CMTSOM." << LogIO::POST ;
484 return -1 ;
485 }
486 // DEBUG
487 //cout << "CMTSOM = " << CMTSOM << endl ;
488 //
489 if ( readHeader( CMTNODE, "CMTNODE", sameEndian ) != 0 ) {
490 os << LogIO::WARN << "Error while reading data CMTNODE." << LogIO::POST ;
491 return -1 ;
492 }
493 // DEBUG
494 //cout << "CMTNODE = " << CMTNODE << endl ;
495 //
496 if ( readHeader( CMTI, "CMTI", sameEndian ) != 0 ) {
497 os << LogIO::WARN << "Error while reading data CMTI." << LogIO::POST ;
498 return -1 ;
499 }
500 // DEBUG
501 //cout << "CMTI = " << CMTI << endl ;
502 //
503 if ( readHeader( CMTTM, "CMTTM" ) != 0 ) {
504 os << LogIO::WARN << "Error while reading data CMTTM." << LogIO::POST ;
505 return -1 ;
506 }
507 // DEBUG
508 //cout << "CMTTM = \'" << CMTTM << "\'" << endl ;
509 //
510 if ( readHeader( SBDX, "SDBX", sameEndian ) != 0 ) {
511 os << LogIO::WARN << "Error while reading data SBDX." << LogIO::POST ;
512 return -1 ;
513 }
514 // DEBUG
515 //cout << "SBDX = " << SBDX << endl ;
516 //
517 if ( readHeader( SBDY, "SDBY", sameEndian ) != 0 ) {
518 os << LogIO::WARN << "Error while reading data SBDY." << LogIO::POST ;
519 return -1 ;
520 }
521 // DEBUG
522 //cout << "SBDY = " << SBDY << endl ;
523 //
524 if ( readHeader( SBDZ1, "SDBZ1", sameEndian ) != 0 ) {
525 os << LogIO::WARN << "Error while reading data SBDZ1." << LogIO::POST ;
526 return -1 ;
527 }
528 // DEBUG
529 //cout << "SBDZ1 = " << SBDZ1 << endl ;
530 //
531 if ( readHeader( SBDZ2, "SDBZ2", sameEndian ) != 0 ) {
532 os << LogIO::WARN << "Error while reading data SBDZ2." << LogIO::POST ;
533 return -1 ;
534 }
535 // DEBUG
536 //cout << "SBDZ2 = " << SBDZ2 << endl ;
537 //
538 if ( readHeader( DAZP, "DAZP", sameEndian ) != 0 ) {
539 os << LogIO::NORMAL << "DAZP set to 0." << LogIO::POST ;
540 DAZP = 0.0 ;
541 }
542 // DEBUG
543 //cout << "DAZP = " << DAZP << endl ;
544 //
545 if ( readHeader( DELP, "DELP", sameEndian ) != 0 ) {
546 os << LogIO::NORMAL << "DELP set to 0." << LogIO::POST ;
547 DELP = 0.0 ;
548 }
549 // DEBUG
550 //cout << "DELP = " << DELP << endl ;
551 //
552 if ( readHeader( CHBIND, "CHBIND", sameEndian ) != 0 ) {
553 os << LogIO::NORMAL << "CHBIND set to 1." << LogIO::POST ;
554 CHBIND = 1 ;
555 }
556 // DEBUG
557 //cout << "CHBIND = " << CHBIND << endl ;
558 //
559 if ( readHeader( NUMCH, "NCH", sameEndian ) != 0 ) {
560 if ( readTable( NUMCH, "NCH", sameEndian ) != 0 ) {
561 os << LogIO::NORMAL << "NUMCH set to " << chmax_ << "." << LogIO::POST ;
562 NUMCH = chmax_ ;
563 }
564 }
565 // DEBUG
566 //cout << "NUMCH = " << NUMCH << endl ;
567 //
568 if ( readHeader( CHMIN, "CHMIN", sameEndian ) != 0 ) {
569 os << LogIO::NORMAL << "CHMIN set to 1." << LogIO::POST ;
570 CHMIN = 1 ;
571 }
572 // DEBUG
573 //cout << "CHMIN = " << CHMIN << endl ;
574 //
575 if ( readHeader( CHMAX, "CHMAX", sameEndian ) != 0 ) {
576 os << LogIO::NORMAL << "CHMAX set to " << chmax_ << "." << LogIO::POST ;
577 CHMAX = chmax_ ;
578 }
579 // DEBUG
580 //cout << "CHMAX = " << CHMAX << endl ;
581 //
582 if ( readHeader( ALCTM, "ALCTM", sameEndian ) != 0 ) {
583 if ( readTable( ALCTM, "ALCTM", sameEndian ) != 0 ) {
584 os << LogIO::WARN << "Error while reading data ALCTM." << LogIO::POST ;
585 return -1 ;
586 }
587 }
588 // DEBUG
589 //cout << "ALCTM = " << ALCTM << endl ;
590 //
591 int itmp ;
592 if ( readHeader( itmp, "INTEG", sameEndian ) != 0 ) {
593 if ( readTable( itmp, "INTEG", sameEndian ) != 0 ) {
594 os << LogIO::WARN << "Error while reading data IPTIM." << LogIO::POST ;
595 return -1 ;
596 }
597 }
598 IPTIM = (double)itmp ;
599 // DEBUG
600 //cout << "IPTIM = " << IPTIM << endl ;
601 //
602 if ( readHeader( PA, "PA", sameEndian ) != 0 ) {
603 if ( readTable( PA, "PA", sameEndian ) != 0 ) {
604 os << LogIO::WARN << "Error while reading data PA." << LogIO::POST ;
605 return -1 ;
606 }
607 }
608 // DEBUG
609 //cout << "PA = " << PA << endl ;
610 //
611
612 // find data index for each ARYTP
613 findData() ;
614 vector<char *> v( ARYNM ) ;
615 if ( readColumn( RX, "RX" ) != 0 ) {
616 os << LogIO::WARN << "Error while reading data RX." << LogIO::POST ;
617 return -1 ;
618 }
619 // DEBUG
620// for ( int i = 0 ; i < ARYNM ; i++ ) {
621// if ( i == 0 ) {
622// //cout << "RX " ;
623// }
624// else if ( ( i % 5 ) == 0 ) {
625// //cout << endl << " " ;
626// }
627// //cout << "\'" << RX[i] << "\' " ;
628// }
629// //cout << endl ;
630 //
631 if ( readColumn( HPBW, "HPBW", sameEndian ) != 0 ) {
632 os << LogIO::WARN << "Error while reading data HPBW." << LogIO::POST ;
633 return -1 ;
634 }
635 // DEBUG
636// for ( int i = 0 ; i < ARYNM ; i++ ) {
637// if ( i == 0 ) {
638// //cout << "HPBW " ;
639// }
640// else if ( ( i % 5 ) == 0 ) {
641// //cout << endl << " " ;
642// }
643// //cout << HPBW[i] << " " ;
644// }
645// //cout << endl ;
646 //
647 if ( readColumn( EFFA, "EFFA", sameEndian ) != 0 ) {
648 os << LogIO::WARN << "Error while reading data EFFA." << LogIO::POST ;
649 return -1 ;
650 }
651 // DEBUG
652// for ( int i = 0 ; i < ARYNM ; i++ ) {
653// if ( i == 0 ) {
654// //cout << "EFFA " ;
655// }
656// else if ( ( i % 5 ) == 0 ) {
657// //cout << endl << " " ;
658// }
659// //cout << EFFA[i] << " " ;
660// }
661// //cout << endl ;
662 //
663 if ( readColumn( EFFB, "EFFB", sameEndian ) != 0 ) {
664 os << LogIO::WARN << "Error while reading data EFFB." << LogIO::POST ;
665 return -1 ;
666 }
667 // DEBUG
668// for ( int i = 0 ; i < ARYNM ; i++ ) {
669// if ( i == 0 ) {
670// //cout << "EFFB " ;
671// }
672// else if ( ( i % 5 ) == 0 ) {
673// //cout << endl << " " ;
674// }
675// //cout << EFFB[i] << " " ;
676// }
677// //cout << endl ;
678 //
679 if ( readColumn( EFFL, "EFFL", sameEndian ) != 0 ) {
680 os << LogIO::WARN << "Error while reading data EFFL." << LogIO::POST ;
681 return -1 ;
682 }
683 // DEBUG
684// for ( int i = 0 ; i < ARYNM ; i++ ) {
685// if ( i == 0 ) {
686// //cout << "EFFL " ;
687// }
688// else if ( ( i % 5 ) == 0 ) {
689// //cout << endl << " " ;
690// }
691// //cout << EFFL[i] << " " ;
692// }
693// //cout << endl ;
694 //
695 if ( readColumn( EFSS, "EFSS", sameEndian ) != 0 ) {
696 os << LogIO::WARN << "Error while reading data EFSS." << LogIO::POST ;
697 return -1 ;
698 }
699 // DEBUG
700// for ( int i = 0 ; i < ARYNM ; i++ ) {
701// if ( i == 0 ) {
702// //cout << "EFSS " ;
703// }
704// else if ( ( i % 5 ) == 0 ) {
705// //cout << endl << " " ;
706// }
707// //cout << EFSS[i] << " " ;
708// }
709// //cout << endl ;
710 //
711 if ( readColumn( GAIN, "GAIN", sameEndian ) != 0 ) {
712 os << LogIO::WARN << "Error while reading data GAIN." << LogIO::POST ;
713 return -1 ;
714 }
715 // DEBUG
716// for ( int i = 0 ; i < ARYNM ; i++ ) {
717// if ( i == 0 ) {
718// //cout << "GAIN " ;
719// }
720// else if ( ( i % 5 ) == 0 ) {
721// //cout << endl << " " ;
722// }
723// //cout << GAIN[i] << " " ;
724// }
725// //cout << endl ;
726 //
727 if ( readColumn( HORN, "HORN" ) != 0 ) {
728 os << LogIO::WARN << "Error while reading data HORN." << LogIO::POST ;
729 return -1 ;
730 }
731 // DEBUG
732// for ( int i = 0 ; i < ARYNM ; i++ ) {
733// if ( i == 0 ) {
734// //cout << "HORN " ;
735// }
736// else if ( ( i % 5 ) == 0 ) {
737// //cout << endl << " " ;
738// }
739// //cout << "\'" << HORN[i] << "\' " ;
740// }
741// //cout << endl ;
742 //
743 if ( readColumn( POLTP, "POLTP" ) != 0 ) {
744 os << LogIO::WARN << "Error while reading data POLTP." << LogIO::POST ;
745 return -1 ;
746 }
747 // DEBUG
748// for ( int i = 0 ; i < ARYNM ; i++ ) {
749// if ( i == 0 ) {
750// //cout << "POLTP " ;
751// }
752// else if ( ( i % 5 ) == 0 ) {
753// //cout << endl << " " ;
754// }
755// //cout << "\'" << POLTP[i] << "\' " ;
756// }
757// //cout << endl ;
758 //
759 vector<int> ipoldr( ARYNM, 0 ) ;
760 if ( readColumn( ipoldr, "POLDR", sameEndian ) != 0 ) {
761 os << LogIO::WARN << "Error while reading data POLDR." << LogIO::POST ;
762 return -1 ;
763 }
764 for ( int i = 0 ; i < ARYNM ; i++ )
765 POLDR[i] = (double)ipoldr[i] ;
766 // DEBUG
767// for ( int i = 0 ; i < ARYNM ; i++ ) {
768// if ( i == 0 ) {
769// //cout << "POLDR " ;
770// }
771// else if ( ( i % 5 ) == 0 ) {
772// //cout << endl << " " ;
773// }
774// //cout << POLDR[i] << " " ;
775// }
776// //cout << endl ;
777 //
778 if ( readColumn( POLAN, "POLAN", sameEndian ) != 0 ) {
779 os << LogIO::WARN << "Error while reading data POLAN." << LogIO::POST ;
780 return -1 ;
781 }
782 // DEBUG
783// for ( int i = 0 ; i < ARYNM ; i++ ) {
784// if ( i == 0 ) {
785// //cout << "POLAN " ;
786// }
787// else if ( ( i % 5 ) == 0 ) {
788// //cout << endl << " " ;
789// }
790// //cout << POLAN[i] << " " ;
791// }
792// //cout << endl ;
793 //
794 if ( readColumn( DFRQ, "DFRQ", sameEndian ) != 0 ) {
795 os << LogIO::WARN << "Error while reading data DFRQ." << LogIO::POST ;
796 return -1 ;
797 }
798 // DEBUG
799// for ( int i = 0 ; i < ARYNM ; i++ ) {
800// if ( i == 0 ) {
801// //cout << "DFRQ " ;
802// }
803// else if ( ( i % 5 ) == 0 ) {
804// //cout << endl << " " ;
805// }
806// //cout << DFRQ[i] << " " ;
807// }
808// //cout << endl ;
809 //
810 if ( readColumn( SIDBD, "SIDBD" ) != 0 ) {
811 os << LogIO::WARN << "Error while reading data SIDBD." << LogIO::POST ;
812 return -1 ;
813 }
814 // DEBUG
815// for ( int i = 0 ; i < ARYNM ; i++ ) {
816// if ( i == 0 ) {
817// //cout << "SIDBD " ;
818// }
819// else if ( ( i % 5 ) == 0 ) {
820// //cout << endl << " " ;
821// }
822// //cout << "\'" << SIDBD[i] << "\' " ;
823// }
824// //cout << endl ;
825 //
826 if ( readColumn( REFN, "REFN", sameEndian ) != 0 ) {
827 os << LogIO::WARN << "Error while reading data REFN." << LogIO::POST ;
828 return -1 ;
829 }
830 // DEBUG
831// for ( int i = 0 ; i < ARYNM ; i++ ) {
832// if ( i == 0 ) {
833// //cout << "REFN " ;
834// }
835// else if ( ( i % 5 ) == 0 ) {
836// //cout << endl << " " ;
837// }
838// //cout << REFN[i] << " " ;
839// }
840// //cout << endl ;
841 //
842 if ( readColumn( IPINT, "IPINT", sameEndian ) != 0 ) {
843 os << LogIO::WARN << "Error while reading data IPINT." << LogIO::POST ;
844 return -1 ;
845 }
846 // DEBUG
847// for ( int i = 0 ; i < ARYNM ; i++ ) {
848// if ( i == 0 ) {
849// //cout << "IPINT " ;
850// }
851// else if ( ( i % 5 ) == 0 ) {
852// //cout << endl << " " ;
853// }
854// //cout << IPINT[i] << " " ;
855// }
856// //cout << endl ;
857 //
858 if ( readColumn( MULTN, "MULTN", sameEndian ) != 0 ) {
859 os << LogIO::WARN << "Error while reading data MULTN." << LogIO::POST ;
860 return -1 ;
861 }
862 // DEBUG
863// for ( int i = 0 ; i < ARYNM ; i++ ) {
864// if ( i == 0 ) {
865// //cout << "MULTN " ;
866// }
867// else if ( ( i % 5 ) == 0 ) {
868// //cout << endl << " " ;
869// }
870// //cout << MULTN[i] << " " ;
871// }
872// //cout << endl ;
873 //
874 if ( readColumn( MLTSCF, "MLTSCF", sameEndian ) != 0 ) {
875 os << LogIO::WARN << "Error while reading data MLTSCF." << LogIO::POST ;
876 return -1 ;
877 }
878 // DEBUG
879// for ( int i = 0 ; i < ARYNM ; i++ ) {
880// if ( i == 0 ) {
881// //cout << "MLTSCF " ;
882// }
883// else if ( ( i % 5 ) == 0 ) {
884// //cout << endl << " " ;
885// }
886// //cout << MLTSCF[i] << " " ;
887// }
888// //cout << endl ;
889 //
890 if ( readColumn( LAGWIND, "LAGWIN" ) != 0 ) {
891 os << LogIO::WARN << "Error while reading data LAGWIND." << LogIO::POST ;
892 return -1 ;
893 }
894 // DEBUG
895// for ( int i = 0 ; i < ARYNM ; i++ ) {
896// if ( i == 0 ) {
897// //cout << "LAGWIND " ;
898// }
899// else if ( ( i % 5 ) == 0 ) {
900// //cout << endl << " " ;
901// }
902// //cout << "\'" << LAGWIND[i] << "\' " ;
903// }
904// //cout << endl ;
905 //
906 if ( readColumn( BEBW, "BEBW", sameEndian ) != 0 ) {
907 os << LogIO::WARN << "Error while reading data BEBW." << LogIO::POST ;
908 return -1 ;
909 }
910 // DEBUG
911// for ( int i = 0 ; i < ARYNM ; i++ ) {
912// if ( i == 0 ) {
913// //cout << "BEBW " ;
914// }
915// else if ( ( i % 5 ) == 0 ) {
916// //cout << endl << " " ;
917// }
918// //cout << BEBW[i] << " " ;
919// }
920// //cout << endl ;
921 //
922 if ( readColumn( BERES, "BERES", sameEndian ) != 0 ) {
923 os << LogIO::WARN << "Error while reading data BERES." << LogIO::POST ;
924 return -1 ;
925 }
926 // DEBUG
927// for ( int i = 0 ; i < ARYNM ; i++ ) {
928// if ( i == 0 ) {
929// //cout << "BERES " ;
930// }
931// else if ( ( i % 5 ) == 0 ) {
932// //cout << endl << " " ;
933// }
934// //cout << BERES[i] << " " ;
935// }
936// //cout << endl ;
937 //
938 if ( readColumn( CHWID, "CHWID", sameEndian ) != 0 ) {
939 os << LogIO::WARN << "Error while reading data CHWID." << LogIO::POST ;
940 return -1 ;
941 }
942 // DEBUG
943// for ( int i = 0 ; i < ARYNM ; i++ ) {
944// if ( i == 0 ) {
945// //cout << "CHWID " ;
946// }
947// else if ( ( i % 5 ) == 0 ) {
948// //cout << endl << " " ;
949// }
950// //cout << CHWID[i] << " " ;
951// }
952// //cout << endl ;
953 //
954 if ( readARRY() != 0 ) {
955 os << LogIO::WARN << "Error while reading data ARRY." << LogIO::POST ;
956 return -1 ;
957 }
958 // DEBUG
959// for ( int i = 0 ; i < NRO_FITS_ARYMAX ; i++ ) {
960// if ( i == 0 ) {
961// //cout << "ARRY " ;
962// }
963// else if ( ( i % 20 ) == 0 ) {
964// //cout << endl << " " ;
965// }
966// //cout << ARRY[i] << " " ;
967// }
968// //cout << endl ;
969 //
970 if ( readColumn( NFCAL, "NFCAL", sameEndian ) != 0 ) {
971 os << LogIO::WARN << "Error while reading data NFCAL." << LogIO::POST ;
972 return -1 ;
973 }
974 // DEBUG
975// for ( int i = 0 ; i < ARYNM ; i++ ) {
976// if ( i == 0 ) {
977// //cout << "NFCAL " ;
978// }
979// else if ( ( i % 5 ) == 0 ) {
980// //cout << endl << " " ;
981// }
982// //cout << NFCAL[i] << " " ;
983// }
984// //cout << endl ;
985 //
986 if ( readColumn( F0CAL, "F0CAL", sameEndian ) != 0 ) {
987 os << LogIO::WARN << "Error while reading data F0CAL." << LogIO::POST ;
988 return -1 ;
989 }
990 // DEBUG
991// for ( int i = 0 ; i < ARYNM ; i++ ) {
992// if ( i == 0 ) {
993// //cout << "F0CAL " ;
994// }
995// else if ( ( i % 5 ) == 0 ) {
996// //cout << endl << " " ;
997// }
998// //cout << F0CAL[i] << " " ;
999// }
1000// //cout << endl ;
1001 //
1002 for ( int i= 0 ; i < 10 ; i++) {
1003 vector<double> vv( ARYNM, 0 ) ;
1004 if ( readColumn( vv, "FQCAL", sameEndian, i ) != 0 ) {
1005 os << LogIO::WARN << "Error while reading data FQCAL." << LogIO::POST ;
1006 return -1 ;
1007 }
1008 for ( int j = 0 ; j < ARYNM ; j++ ) {
1009 FQCAL[j][i] = vv[j] ;
1010 }
1011 }
1012 // DEBUG
1013// for ( int i = 0 ; i < ARYNM ; i++ ) {
1014// for ( int j = 0 ; j < 10 ; j++ ) {
1015// if ( j == 0 ) {
1016// if ( i < 10 )
1017// //cout << "FQCAL0" << i << " " ;
1018// else
1019// //cout << "FQCAL" << i << " " ;
1020// }
1021// else if ( ( j % 5 ) == 0 ) {
1022// //cout << endl << " " ;
1023// }
1024// //cout << FQCAL[i][j] << " " ;
1025// }
1026// //cout << endl ;
1027// }
1028 //
1029 for ( int i= 0 ; i < 10 ; i++) {
1030 vector<double> vv( ARYNM, 0 ) ;
1031 if ( readColumn( vv, "CHCAL", sameEndian, i ) != 0 ) {
1032 os << LogIO::WARN << "Error while reading data CHCAL." << LogIO::POST ;
1033 return -1 ;
1034 }
1035 for ( int j = 0 ; j < ARYNM ; j++ ) {
1036 CHCAL[j][i] = vv[j] ;
1037 }
1038 }
1039 // DEBUG
1040// for ( int i = 0 ; i < ARYNM ; i++ ) {
1041// for ( int j = 0 ; j < 10 ; j++ ) {
1042// if ( j == 0 ) {
1043// if ( i < 10 )
1044// //cout << "CHCAL0" << i << " " ;
1045// else
1046// //cout << "CHCAL" << i << " " ;
1047// }
1048// else if ( ( j % 5 ) == 0 ) {
1049// //cout << endl << " " ;
1050// }
1051// //cout << CHCAL[i][j] << " " ;
1052// }
1053// //cout << endl ;
1054// }
1055 //
1056 for ( int i= 0 ; i < 10 ; i++) {
1057 vector<double> vv( ARYNM, 0 ) ;
1058 if ( readColumn( vv, "CWCAL", sameEndian, i ) != 0 ) {
1059 os << LogIO::WARN << "Error while reading data CWCAL." << LogIO::POST ;
1060 return -1 ;
1061 }
1062 for ( int j = 0 ; j < ARYNM ; j++ ) {
1063 CWCAL[j][i] = vv[j] ;
1064 }
1065 }
1066 // DEBUG
1067// for ( int i = 0 ; i < ARYNM ; i++ ) {
1068// for ( int j = 0 ; j < 10 ; j++ ) {
1069// if ( j == 0 ) {
1070// if ( i < 10 )
1071// //cout << "CWCAL0" << i << " " ;
1072// else
1073// //cout << "CWCAL" << i << " " ;
1074// }
1075// else if ( ( j % 5 ) == 0 ) {
1076// //cout << endl << " " ;
1077// }
1078// //cout << CWCAL[i][j] << " " ;
1079// }
1080// //cout << endl ;
1081// }
1082 //
1083 if ( readHeader( SCNLEN, "NAXIS1", sameEndian ) != 0 ) {
1084 os << LogIO::WARN << "Error while reading data SCNLEN." << LogIO::POST ;
1085 return -1 ;
1086 }
1087 // DEBUG
1088 //cout << "SCNLEN = " << SCNLEN << endl ;
1089 //
1090 if ( readHeader( SBIND, "SBIND", sameEndian ) != 0 ) {
1091 os << LogIO::NORMAL << "SBIND set to 0." << LogIO::POST ;
1092 SBIND = 0 ;
1093 }
1094 // DEBUG
1095 //cout << "SBIND = " << SBIND << endl ;
1096 //
1097 if ( readHeader( IBIT, "IBIT", sameEndian ) != 0 ) {
1098 os << LogIO::NORMAL << "IBIT set to 8." << LogIO::POST ;
1099 IBIT = 8 ; // 8 bit? 12 bit?
1100 }
1101 // DEBUG
1102 //cout << "IBIT = " << IBIT << endl ;
1103 //
1104 if ( readHeader( SITE, "TELESCOP" ) != 0 ) {
1105 os << LogIO::WARN << "Error while reading data SITE." << LogIO::POST ;
1106 return -1 ;
1107 }
1108 // DEBUG
1109 //cout << "SITE = \'" << SITE << "\'" << endl ;
1110 //
1111 if ( readColumn( DSBFC, "DSBFC", sameEndian ) != 0 ) {
1112 os << LogIO::NORMAL << "All DSBFC elements set to 1." << LogIO::POST ;
1113 for ( int i = 0 ; i < ARYNM ; i++ )
1114 DSBFC[i] = 1.0 ;
1115 }
1116 // DEBUG
1117// for ( int i = 0 ; i < ARYNM ; i++ ) {
1118// if ( i == 0 ) {
1119// //cout << "DSBFC " ;
1120// }
1121// else if ( ( i % 5 ) == 0 ) {
1122// //cout << endl << " " ;
1123// }
1124// //cout << DSBFC[i] << " " ;
1125// }
1126// //cout << endl ;
1127 //
1128
1129 show() ;
1130
1131 return 0 ;
1132}
1133
1134int NROFITSDataset::fillRecord( int i )
1135{
1136 LogIO os( LogOrigin( "NROFITSDataset", "fillRecord()", WHERE ) ) ;
1137
1138 int status = 0 ;
1139 string str4( 4, ' ' ) ;
1140 string str8( 8, ' ' ) ;
1141 string str24( 24, ' ' ) ;
1142
1143 strcpy( record_->LSFIL, str4.c_str() ) ;
1144 status = readTable( record_->LSFIL, "LSFIL", 4, i ) ;
1145 if ( status ) {
1146 os << LogIO::WARN << "Error while reading LSFIL." << LogIO::POST ;
1147 return status ;
1148 }
1149 // DEBUG
1150 //cout << "LSFIL(" << i << ") = " << record_->LSFIL << endl ;
1151 //
1152 status = readTable( record_->ISCAN, "ISCN", same_, i ) ;
1153 if ( status ) {
1154 os << LogIO::WARN << "Error while reading ISCAN." << LogIO::POST ;
1155 return status ;
1156 }
1157 // DEBUG
1158 //cout << "ISCAN(" << i << ") = " << record_->ISCAN << endl ;
1159 //
1160 vector<int> itmp( 6, 0 ) ;
1161 status = readTable( itmp, "LAVST", same_, i ) ;
1162 if ( status ) {
1163 os << LogIO::WARN << "Error while reading LAVST." << LogIO::POST ;
1164 return status ;
1165 }
1166 else {
1167 sprintf( record_->LAVST, "%d%d%d%d%d%d.000", itmp[0], itmp[1], itmp[2], itmp[3], itmp[4], itmp[5] ) ;
1168 }
1169 // DEBUG
1170 //cout << "LAVST(" << i << ") = " << record_->LAVST << endl ;
1171 //
1172 strcpy( record_->SCANTP, str8.c_str() ) ;
1173 status = readTable( record_->SCANTP, "SCNTP", strlen(record_->SCANTP), i ) ;
1174 if ( status ) {
1175 os << LogIO::WARN << "Error while reading SCANTP." << LogIO::POST ;
1176 return status ;
1177 }
1178 // DEBUG
1179 //cout << "SCANTP(" << i << ") = " << record_->SCANTP << endl ;
1180 //
1181 char *name1 = "" ;
1182 char *name2 = "" ;
1183 if ( SCNCD == 0 ) {
1184 name1 = "DRA" ;
1185 name2 = "DDEC" ;
1186 }
1187 else if ( SCNCD == 1 ) {
1188 name1 = "DGL" ;
1189 name2 = "DGB" ;
1190 }
1191 else {
1192 name1 = "DAZ" ;
1193 name2 = "DEL" ;
1194 }
1195 status = readTable( record_->DSCX, name1, same_, i ) ;
1196 if ( status ) {
1197 os << LogIO::WARN << "Error while reading DSCX." << LogIO::POST ;
1198 return status ;
1199 }
1200 // DEBUG
1201 //cout << "DSCX(" << i << ") = " << record_->DSCX << endl ;
1202 //
1203 status = readTable( record_->DSCY, name2, same_, i ) ;
1204 if ( status ) {
1205 os << LogIO::WARN << "Error while reading DSCY." << LogIO::POST ;
1206 return status ;
1207 }
1208 // DEBUG
1209 //cout << "DSCY(" << i << ") = " << record_->DSCY << endl ;
1210 //
1211 if ( SCNCD == 0 ) {
1212 name1 = "RA" ;
1213 name2 = "DEC" ;
1214 }
1215 else if ( SCNCD == 1 ) {
1216 name1 = "GL" ;
1217 name2 = "GB" ;
1218 }
1219 else {
1220 name1 = "AZ" ;
1221 name2 = "EL" ;
1222 }
1223 status = readTable( record_->SCX, name1, same_, i ) ;
1224 if ( status ) {
1225 os << LogIO::WARN << "Error while reading SCX." << LogIO::POST ;
1226 return status ;
1227 }
1228 // DEBUG
1229 //cout << "SCX(" << i << ") = " << record_->SCX << endl ;
1230 //
1231 status = readTable( record_->SCY, name2, same_, i ) ;
1232 if ( status ) {
1233 os << LogIO::WARN << "Error while reading SCY." << LogIO::POST ;
1234 return status ;
1235 }
1236 // DEBUG
1237 //cout << "SCY(" << i << ") = " << record_->SCY << endl ;
1238 //
1239 status = readTable( record_->PAZ, "PAZ", same_, i ) ;
1240 if ( status ) {
1241 os << LogIO::WARN << "Error while reading PAZ." << LogIO::POST ;
1242 return status ;
1243 }
1244 // DEBUG
1245 //cout << "PAZ(" << i << ") = " << record_->PAZ << endl ;
1246 //
1247 status = readTable( record_->PEL, "PEL", same_, i ) ;
1248 if ( status ) {
1249 os << LogIO::WARN << "Error while reading PEL." << LogIO::POST ;
1250 return status ;
1251 }
1252 // DEBUG
1253 //cout << "PEL(" << i << ") = " << record_->PEL << endl ;
1254 //
1255 status = readTable( record_->RAZ, "RAZ", same_, i ) ;
1256 if ( status ) {
1257 os << LogIO::WARN << "Error while reading RAZ." << LogIO::POST ;
1258 return status ;
1259 }
1260 // DEBUG
1261 //cout << "RAZ(" << i << ") = " << record_->RAZ << endl ;
1262 //
1263 status = readTable( record_->REL, "REL", same_, i ) ;
1264 if ( status ) {
1265 os << LogIO::WARN << "Error while reading REL." << LogIO::POST ;
1266 return status ;
1267 }
1268 // DEBUG
1269 //cout << "REL(" << i << ") = " << record_->REL << endl ;
1270 //
1271 status = readTable( record_->XX, "XX", same_, i ) ;
1272 if ( status ) {
1273 os << LogIO::WARN << "Error while reading XX." << LogIO::POST ;
1274 return status ;
1275 }
1276 // DEBUG
1277 //cout << "XX(" << i << ") = " << record_->XX << endl ;
1278 //
1279 status = readTable( record_->YY, "YY", same_, i ) ;
1280 if ( status ) {
1281 os << LogIO::WARN << "Error while reading YY." << LogIO::POST ;
1282 return status ;
1283 }
1284 // DEBUG
1285 //cout << "YY(" << i << ") = " << record_->YY << endl ;
1286 //
1287 strcpy( record_->ARRYT, str4.c_str() ) ;
1288 status = readTable( record_->ARRYT, "ARRYT", strlen(record_->ARRYT), i ) ;
1289 record_->ARRYT[3] = '\0' ;
1290 if ( status ) {
1291 os << LogIO::WARN << "Error while reading ARRYT." << LogIO::POST ;
1292 return status ;
1293 }
1294 // DEBUG
1295 //cout << "ARRYT(" << i << ") = " << record_->ARRYT << endl ;
1296 //
1297 double dtmp ;
1298 status = readTable( dtmp, "TEMP", same_, i ) ;
1299 if ( status ) {
1300 os << LogIO::WARN << "Error while reading TEMP." << LogIO::POST ;
1301 return status ;
1302 }
1303 else {
1304 record_->TEMP = dtmp ;
1305 }
1306 // DEBUG
1307 //cout << "TEMP(" << i << ") = " << record_->TEMP << endl ;
1308 //
1309 status = readTable( dtmp, "PATM", same_, i ) ;
1310 if ( status ) {
1311 os << LogIO::WARN << "Error while reading PATM." << LogIO::POST ;
1312 return status ;
1313 }
1314 else {
1315 record_->PATM = dtmp ;
1316 }
1317 // DEBUG
1318 //cout << "PATM(" << i << ") = " << record_->PATM << endl ;
1319 //
1320 status = readTable( dtmp, "PH2O", same_, i ) ;
1321 if ( status ) {
1322 os << LogIO::WARN << "Error while reading PH2O." << LogIO::POST ;
1323 return status ;
1324 }
1325 else {
1326 record_->PH2O = dtmp ;
1327 }
1328 // DEBUG
1329 //cout << "PH2O(" << i << ") = " << record_->PH2O << endl ;
1330 //
1331 status = readTable( dtmp, "VWIND", same_, i ) ;
1332 if ( status ) {
1333 os << LogIO::WARN << "Error while reading VWIND." << LogIO::POST ;
1334 return status ;
1335 }
1336 else {
1337 record_->VWIND = dtmp ;
1338 }
1339 // DEBUG
1340 //cout << "VWIND(" << i << ") = " << record_->VWIND << endl ;
1341 //
1342 status = readTable( dtmp, "DWIND", same_, i ) ;
1343 if ( status ) {
1344 os << LogIO::WARN << "Error while reading DWIND." << LogIO::POST ;
1345 return status ;
1346 }
1347 else {
1348 record_->DWIND = dtmp ;
1349 }
1350 // DEBUG
1351 //cout << "DWIND(" << i << ") = " << record_->DWIND << endl ;
1352 //
1353 status = readTable( dtmp, "TAU", same_, i ) ;
1354 if ( status ) {
1355 os << LogIO::WARN << "Error while reading TAU." << LogIO::POST ;
1356 return status ;
1357 }
1358 else {
1359 record_->TAU = dtmp ;
1360 }
1361 // DEBUG
1362 //cout << "TAU(" << i << ") = " << record_->TAU << endl ;
1363 //
1364 status = readTable( dtmp, "TSYS", same_, i ) ;
1365 if ( status ) {
1366 os << LogIO::WARN << "Error while reading TSYS." << LogIO::POST ;
1367 return status ;
1368 }
1369 else {
1370 record_->TSYS = dtmp ;
1371 }
1372 // DEBUG
1373 //cout << "TSYS(" << i << ") = " << record_->TSYS << endl ;
1374 //
1375 status = readTable( dtmp, "BATM", same_, i ) ;
1376 if ( status ) {
1377 os << LogIO::WARN << "Error while reading BATM." << LogIO::POST ;
1378 return status ;
1379 }
1380 else {
1381 record_->BATM = dtmp ;
1382 }
1383 // DEBUG
1384 //cout << "BATM(" << i << ") = " << record_->BATM << endl ;
1385 //
1386 status = readTable( record_->VRAD, "VRAD", same_, i ) ;
1387 if ( status ) {
1388 os << LogIO::WARN << "Error while reading TEMP." << LogIO::POST ;
1389 return status ;
1390 }
1391 // DEBUG
1392 //cout << "VRAD(" << i << ") = " << record_->VRAD << endl ;
1393 //
1394 status = readTable( record_->FREQ0, "FRQ0", same_, i ) ;
1395 if ( status ) {
1396 os << LogIO::WARN << "Error while reading FREQ0." << LogIO::POST ;
1397 return status ;
1398 }
1399 // DEBUG
1400 //cout << "FREQ0(" << i << ") = " << record_->FREQ0 << endl ;
1401 //
1402 status = readTable( record_->FQTRK, "FQTRK", same_, i ) ;
1403 if ( status ) {
1404 os << LogIO::WARN << "Error while reading FQTRK." << LogIO::POST ;
1405 return status ;
1406 }
1407 // DEBUG
1408 //cout << "FQTRK(" << i << ") = " << record_->FQTRK << endl ;
1409 //
1410 status = readTable( record_->FQIF1, "FQIF1", same_, i ) ;
1411 if ( status ) {
1412 os << LogIO::WARN << "Error while reading FQIF1." << LogIO::POST ;
1413 return status ;
1414 }
1415 // DEBUG
1416 //cout << "FQIF1(" << i << ") = " << record_->FQIF1 << endl ;
1417 //
1418 status = readTable( record_->ALCV, "ALCV", same_, i ) ;
1419 if ( status ) {
1420 os << LogIO::WARN << "Error while reading ALCV." << LogIO::POST ;
1421 return status ;
1422 }
1423 // DEBUG
1424 //cout << "ALCV(" << i << ") = " << record_->ALCV << endl ;
1425 //
1426 record_->IDMY0 = 0 ;
1427 status = readTable( record_->DPFRQ, "DPFRQ", same_, i ) ;
1428 if ( status ) {
1429 //os << LogIO::WARN << "Error DPFRQ set to 0." << LogIO::POST ;
1430 record_->DPFRQ = 0.0 ;
1431 }
1432 // DEBUG
1433 //cout << "DPFRQ(" << i << ") = " << record_->DPFRQ << endl ;
1434 //
1435 status = readTable( record_->SFCTR, "SFCTR", same_, i ) ;
1436 if ( status ) {
1437 os << LogIO::WARN << "Error while reading SFCTR." << LogIO::POST ;
1438 return status ;
1439 }
1440 // DEBUG
1441 //cout << "SFCTR(" << i << ") = " << record_->SFCTR << endl ;
1442 //
1443 status = readTable( record_->ADOFF, "ADOFF", same_, i ) ;
1444 if ( status ) {
1445 os << LogIO::WARN << "Error while reading ADOFF." << LogIO::POST ;
1446 return status ;
1447 }
1448 // DEBUG
1449 //cout << "ADOFF(" << i << ") = " << record_->ADOFF << endl ;
1450 //
1451 //status = readTable( record_->JDATA, "LDATA", same_, i ) ;
1452 status = readTable( JDATA, "LDATA", same_, i ) ;
1453 if ( status ) {
1454 os << LogIO::WARN << "Error while reading JDATA." << LogIO::POST ;
1455 return status ;
1456 }
1457 // DEBUG
1458// for ( int i = 0 ; i < chmax_ ; i++ )
1459// //cout << "JDATA[" << i << "] = " << JDATA[i] << " " ;
1460// //cout << endl ;
1461 //
1462 return status ;
1463}
1464
1465vector< vector<double> > NROFITSDataset::getSpectrum()
1466{
1467 vector< vector<double> > spec;
1468
1469 for ( int i = 0 ; i < rowNum_ ; i++ ) {
1470 spec.push_back( getSpectrum( i ) ) ;
1471 }
1472
1473 return spec ;
1474}
1475
1476vector<double> NROFITSDataset::getSpectrum( int i )
1477{
1478 vector<double> spec( chmax_, 0.0 ) ;
1479 vector<double> specout( chmax_, 0.0 ) ;
1480 NRODataRecord *record = getRecord( i ) ;
1481 double scale = record->SFCTR ;
1482 double offset = record->ADOFF ;
1483 double dscale = MLTSCF[getIndex( i )] ;
1484 //vector<int> ispec = record->JDATA ;
1485 vector<int> ispec = JDATA ;
1486 for ( int ii = 0 ; ii < chmax_ ; ii++ ) {
1487 spec[ii] = (double)( ispec[ii] * scale + offset ) * dscale ;
1488 }
1489
1490 // for AOS, re-gridding is needed
1491 if ( strncmp( record->ARRYT, "H", 1 ) == 0
1492 || strncmp( record->ARRYT, "W", 1 ) == 0
1493 || strncmp( record->ARRYT, "U", 1 ) == 0 ) {
1494
1495 string arryt = string( record->ARRYT ) ;
1496 uInt ib = getArrayId( arryt ) ;
1497 vector<double> fqcal = getFQCAL()[ib] ;
1498 vector<double> chcal = getCHCAL()[ib] ;
1499 int ncal = getNFCAL()[ib] ;
1500
1501// //cout << "NRODataset::getFrequencies() ncal = " << ncal << endl ;
1502 while ( ncal < (int)fqcal.size() ) {
1503 fqcal.pop_back() ;
1504 chcal.pop_back() ;
1505 }
1506 Vector<Double> xin( chcal ) ;
1507 Vector<Double> yin( fqcal ) ;
1508 int nchan = getNUMCH() ;
1509 Vector<Double> xout( nchan ) ;
1510 indgen( xout ) ;
1511 Vector<Double> yout ;
1512 InterpolateArray1D<Double, Double>::interpolate( yout, xout, xin, yin, InterpolateArray1D<Double,Double>::cubic ) ;
1513 // debug
1514 //cout << "i=" << i << endl ;
1515 if ( i == 16 ) {
1516 ofstream ofs0( "spgrid0.dat" ) ;
1517 for ( int ii = 0 ; ii < getNUMCH() ; ii++ )
1518 ofs0 << xout[ii] << "," ;
1519 ofs0 << endl ;
1520 for ( int ii = 0 ; ii < getNUMCH() ; ii++ )
1521 ofs0 << setprecision(16) << record->FREQ0+yout[ii] << "," ;
1522 ofs0 << endl ;
1523 ofs0.close() ;
1524 }
1525 //
1526 Vector<Double> z( nchan ) ;
1527 Double bw = abs( yout[nchan-1] - yout[0] ) ;
1528 bw += 0.5 * abs( yout[nchan-1] - yout[nchan-2] + yout[1] - yout[0] ) ;
1529 Double dz = bw / (Double)nchan ;
1530 if ( yout[0] > yout[nchan-1] )
1531 dz = - dz ;
1532 z[0] = yout[0] - 0.5 * ( yout[1] - yout[0] - dz ) ;
1533 for ( int ii = 1 ; ii < nchan ; ii++ )
1534 z[ii] = z[ii-1] + dz ;
1535 Vector<Double> zi( nchan+1 ) ;
1536 Vector<Double> yi( nchan+1 ) ;
1537 zi[0] = z[0] - 0.5 * dz ;
1538 zi[1] = z[0] + 0.5 * dz ;
1539 yi[0] = yout[0] - 0.5 * ( yout[1] - yout[0] ) ;
1540 yi[1] = yout[0] + 0.5 * ( yout[1] - yout[0] ) ;
1541 for ( int ii = 2 ; ii < nchan ; ii++ ) {
1542 zi[ii] = zi[ii-1] + dz ;
1543 yi[ii] = yi[ii-1] + 0.5 * ( yout[ii] - yout[ii-2] ) ;
1544 }
1545 zi[nchan] = z[nchan-1] + 0.5 * dz ;
1546 yi[nchan] = yout[nchan-1] + 0.5 * ( yout[nchan-1] - yout[nchan-2] ) ;
1547// // debug
1548// //cout << "nchan=" << nchan << ", bw=" << bw << ", dz=" << dz
1549// << ", y[1]-y[0]=" << yout[1]-yout[0] << endl ;
1550// //cout << "z: " << z[0] << " - " << z[nchan-1]
1551// << ", zi: " << zi[0] << " - " << zi[nchan] << endl ;
1552// //cout << "y: " << yout[0] << " - " << yout[nchan-1]
1553// << ", yi: " << yi[0] << " - " << yi[nchan] << endl ;
1554// ofstream ofs1( "spgrid1.dat", ios::out | ios::app ) ;
1555// ofs1 << "spid=" << i << ", ARRYT=" << record->ARRYT << endl ;
1556// ofs1 << "z[0]=" << z[0] << ", yout[0]=" << yout[0] << endl ;
1557// for ( int ii = 1; ii < nchan ; ii++ ) {
1558// ofs1 << " dz=" << z[ii]-z[ii-1] << ", dy=" << yout[ii]-yout[ii-1] << endl ;
1559// ofs1 << "z[" << ii << "]=" << z[ii] << ", yout[" << ii << "]=" << yout[ii] << endl ;
1560// }
1561// ofs1.close() ;
1562// ofstream ofs2( "spgrid2.dat", ios::out | ios::app ) ;
1563// ofs2 << "spid=" << i << ", ARRYT=" << record->ARRYT << endl ;
1564// for ( int ii = 0 ; ii < nchan+1 ; ii++ )
1565// ofs2 << "zi[" << ii << "]=" << zi[ii] << ", yi[" << ii << "]=" << yi[ii] << endl ;
1566// ofs2.close() ;
1567// //
1568 int ichan = 0 ;
1569 double wsum = 0.0 ;
1570 // debug
1571 //ofstream ofs3( "spgrid3.dat", ios::out | ios::app ) ;
1572 if ( dz > 0.0 ) {
1573 for ( int ii = 0 ; ii < nchan ; ii++ ) {
1574 double zl = zi[ii] ;
1575 double zr = zi[ii+1] ;
1576 for ( int j = ichan ; j < nchan ; j++ ) {
1577 double yl = yi[j] ;
1578 double yr = yi[j+1] ;
1579 if ( yl <= zl ) {
1580 if ( yr <= zl ) {
1581 continue ;
1582 }
1583 else if ( yr <= zr ) {
1584 specout[ii] += spec[j] * ( yr - zl ) ;
1585 wsum += ( yr - zl ) ;
1586 }
1587 else {
1588 specout[ii] += spec[j] * dz ;
1589 wsum += dz ;
1590 ichan = j ;
1591 break ;
1592 }
1593 }
1594 else if ( yl < zr ) {
1595 if ( yr <= zr ) {
1596 specout[ii] += spec[j] * ( yr - yl ) ;
1597 wsum += ( yr - yl ) ;
1598 }
1599 else {
1600 specout[ii] += spec[j] * ( zr - yl ) ;
1601 wsum += ( zr - yl ) ;
1602 ichan = j ;
1603 break ;
1604 }
1605 }
1606 else {
1607 ichan = j - 1 ;
1608 break ;
1609 }
1610 }
1611 specout[ii] /= wsum ;
1612 wsum = 0.0 ;
1613 }
1614 }
1615 else if ( dz < 0.0 ) {
1616 for ( int ii = 0 ; ii < nchan ; ii++ ) {
1617 double zl = zi[ii] ;
1618 double zr = zi[ii+1] ;
1619 for ( int j = ichan ; j < nchan ; j++ ) {
1620 double yl = yi[j] ;
1621 double yr = yi[j+1] ;
1622 if ( yl >= zl ) {
1623 if ( yr >= zl ) {
1624 continue ;
1625 }
1626 else if ( yr >= zr ) {
1627 specout[ii] += spec[j] * abs( yr - zl ) ;
1628 wsum += abs( yr - zl ) ;
1629 }
1630 else {
1631 specout[ii] += spec[j] * abs( dz ) ;
1632 wsum += abs( dz ) ;
1633 ichan = j ;
1634 break ;
1635 }
1636 }
1637 else if ( yl > zr ) {
1638 if ( yr >= zr ) {
1639 specout[ii] += spec[j] * abs( yr - yl ) ;
1640 wsum += abs( yr - yl ) ;
1641 }
1642 else {
1643 specout[ii] += spec[j] * abs( zr - yl ) ;
1644 wsum += abs( zr - yl ) ;
1645 ichan = j ;
1646 break ;
1647 }
1648 }
1649 else {
1650 ichan = j - 1 ;
1651 break ;
1652 }
1653 }
1654 specout[ii] /= wsum ;
1655 wsum = 0.0 ;
1656 }
1657 }
1658 //specout = spec ;
1659 //ofs3.close() ;
1660 }
1661 else {
1662 specout = spec ;
1663 }
1664
1665 return specout ;
1666}
1667
1668int NROFITSDataset::getIndex( int irow )
1669{
1670 NRODataRecord *record = getRecord( irow ) ;
1671 string str = record->ARRYT ;
1672 string::size_type pos = str.find( " " ) ;
1673 if ( pos != string::npos )
1674 str = str.substr( 0, pos ) ;
1675 int index = -1 ;
1676 for ( int i = 0 ; i < ARYNM ; i++ ) {
1677 if ( str.compare( 0, 3, ARYTP[i] ) == 0 ) {
1678 index = i ;
1679 break ;
1680 }
1681 }
1682 return index ;
1683}
1684
1685double NROFITSDataset::radRA( string ra )
1686{
1687 int pos1 = ra.find( ':' ) ;
1688 int pos2 ;
1689 string ch = ra.substr( 0, pos1 ) ;
1690 //cout << "ch = \'" << ch << "\'" << endl ;
1691 pos2 = pos1 + 1 ;
1692 pos1 = ra.find( ':', pos2 ) ;
1693 string cm = ra.substr( pos2, pos1 - pos2 ) ;
1694 //cout << "cm = \'" << cm << "\'" << endl ;
1695 pos2 = pos1 + 1 ;
1696 pos1 = ra.size() ;
1697 string cs = ra.substr( pos2, pos1 - pos2 ) ;
1698 //cout << "cs = \'" << cs << "\'" << endl ;
1699 double h ;
1700 if ( ra[0] != '-' )
1701 h = atof( ch.c_str() ) + atof( cm.c_str() ) / 60.0 + atof( cs.c_str() ) / 3600.0 ;
1702 else
1703 h = atof( ch.c_str() ) - atof( cm.c_str() ) / 60.0 - atof( cs.c_str() ) / 3600.0 ;
1704 double rra = h * M_PI / 12.0 ;
1705 return rra ;
1706}
1707
1708double NROFITSDataset::radDEC( string dec )
1709{
1710 int pos1 = dec.find( ':' ) ;
1711 int pos2 ;
1712 string cd = dec.substr( 0, pos1 ) ;
1713 //cout << "cd = \'" << cd << "\'" << endl ;
1714 pos2 = pos1 + 1 ;
1715 pos1 = dec.find( ':', pos2 ) ;
1716 string cm = dec.substr( pos2, pos1 - pos2 ) ;
1717 //cout << "cm = \'" << cm << "\'" << endl ;
1718 pos2 = pos1 + 1 ;
1719 pos1 = dec.size() ;
1720 string cs = dec.substr( pos2, pos1 - pos2 ) ;
1721 //cout << "cs = \'" << cs << "\'" << endl ;
1722 double h ;
1723 if ( dec[0] != '-' )
1724 h = atof( cd.c_str() ) + atof( cm.c_str() ) / 60.0 + atof( cs.c_str() ) / 3600.0 ;
1725 else
1726 h = atof( cd.c_str() ) - atof( cm.c_str() ) / 60.0 - atof( cs.c_str() ) / 3600.0 ;
1727 double rdec = h * M_PI / 180.0 ;
1728 return rdec ;
1729}
1730
1731void NROFITSDataset::getField()
1732{
1733 for ( int i = 0 ; i < numField_ ; i++ ) {
1734 char key1[9] ;
1735 char key2[9] ;
1736 char key3[9] ;
1737 if ( i < 9 ) {
1738 sprintf( key1, "TFORM%d ", i+1 ) ;
1739 sprintf( key2, "TTYPE%d ", i+1 ) ;
1740 sprintf( key3, "TUNIT%d ", i+1 ) ;
1741 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1742 }
1743 else if ( i < 99 ) {
1744 sprintf( key1, "TFORM%2d ", i+1 ) ;
1745 sprintf( key2, "TTYPE%2d ", i+1 ) ;
1746 sprintf( key3, "TUNIT%2d ", i+1 ) ;
1747 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1748 }
1749 else {
1750 sprintf( key1, "TFORM%3d", i+1 ) ;
1751 sprintf( key2, "TTYPE%3d", i+1 ) ;
1752 sprintf( key3, "TUNIT%3d", i+1 ) ;
1753 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1754 }
1755 //char tmp[9] ;
1756 string tmp ;
1757 //strcpy( tmp, " " ) ;
1758 if ( readHeader( tmp, key1 ) != 0 ) {
1759 cerr << "Error while reading field keyword for scan header." << endl ;
1760 return ;
1761 }
1762 //forms_[i] = string( tmp ) ;
1763 forms_[i] = tmp ;
1764 string::size_type spos = forms_[i].find( " " ) ;
1765 if ( spos != string::npos )
1766 forms_[i] = forms_[i].substr( 0, spos ) ;
1767 //strcpy( tmp, " " ) ;
1768 if ( readHeader( tmp, key2 ) != 0 ) {
1769 cerr << "Error while reading field type for scan header." << endl ;
1770 return ;
1771 }
1772 //names_[i] = string( tmp ) ;
1773 names_[i] = tmp ;
1774 spos = names_[i].find( " " ) ;
1775 if ( spos != string::npos )
1776 names_[i] = names_[i].substr( 0, spos ) ;
1777 //strcpy( tmp, " " ) ;
1778 if ( forms_[i].find( "A" ) != string::npos ) {
1779 //cout << "skip to get unit: name = " << forms_[i] << endl ;
1780 //strcpy( tmp, "none " ) ;
1781 tmp = "none" ;
1782 }
1783 else {
1784 //cout << "get unit: name = " << forms_[i] << endl ;
1785 if ( readHeader( tmp, key3 ) != 0 ) {
1786 //strcpy( tmp, "none " ) ;
1787 tmp = "none" ;
1788 }
1789 }
1790 //units_[i] = string( tmp ) ;
1791 units_[i] = tmp ;
1792 spos = units_[i].find( " " ) ;
1793 if ( spos != string::npos )
1794 units_[i] = units_[i].substr( 0, spos ) ;
1795 //cout << "i = " << i << ": name=" << forms_[i] << " type=" << names_[i] << " unit=" << units_[i] << endl ;
1796 }
1797}
1798
1799void NROFITSDataset::fillARYTP()
1800{
1801 string arry ;
1802 int count = 0 ;
1803 string arry1 ;
1804 string arry2 ;
1805 string arry3 ;
1806 string arry4 ;
1807 if ( readHeader( arry, "ARRY1" ) == 0 )
1808 arry1 = arry ;
1809 else
1810 arry1 = "00000000000000000000" ;
1811 for ( int i = 0 ; i < 20 ; i++ ) {
1812 if ( arry1[i] == '1' ) {
1813 char arytp[4] ;
1814 sprintf( arytp, "H%d", i+1 ) ;
1815 ARYTP[count++] = string( arytp ) ;
1816 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1817 }
1818 }
1819 if ( readHeader( arry, "ARRY2" ) == 0 )
1820 arry2 = arry ;
1821 else
1822 arry2 = "00000000000000000000" ;
1823 for ( int i = 0 ; i < 20 ; i++ ) {
1824 if ( arry2[i] == '1' ) {
1825 if ( i < 10 ) {
1826 char arytp[4] ;
1827 sprintf( arytp, "W%d", i+1 ) ;
1828 ARYTP[count++] = string( arytp ) ;
1829 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1830 }
1831 else if ( i < 15 ) {
1832 char arytp[4] ;
1833 sprintf( arytp, "U%d", i-9 ) ;
1834 ARYTP[count++] = string( arytp ) ;
1835 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1836 }
1837 else {
1838 char arytp[4] ;
1839 sprintf( arytp, "X%d", i-14 ) ;
1840 ARYTP[count++] = string( arytp ) ;
1841 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1842 }
1843 }
1844 }
1845 if ( readHeader( arry, "ARRY3" ) == 0 )
1846 arry3 = arry ;
1847 else
1848 arry3 = "00000000000000000000" ;
1849 for ( int i = 0 ; i < 20 ; i++ ) {
1850 if ( arry3[i] == '1' ) {
1851 char arytp[4] ;
1852 sprintf( arytp, "A%d", i+1 ) ;
1853 ARYTP[count++] = string( arytp ) ;
1854 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1855 }
1856 }
1857 if ( readHeader( arry, "ARRY4" ) == 0 )
1858 arry4 = arry ;
1859 else
1860 arry4 = "00000000000000000000" ;
1861 for ( int i = 0 ; i < 20 ; i++ ) {
1862 if ( arry4[i] == '1' ) {
1863 char arytp[4] ;
1864 sprintf( arytp, "A%d", i+21 ) ;
1865 ARYTP[count++] = string( arytp ) ;
1866 //cout << "ARYTP[" << count-1 << "] = " << ARYTP[count-1] << endl ;
1867 }
1868 }
1869}
1870
1871int NROFITSDataset::readARRY()
1872{
1873 LogIO os( LogOrigin( "NROFITSDataset", "readARRY()", WHERE ) ) ;
1874
1875 string arry1 ;
1876 string arry2 ;
1877 string arry3 ;
1878 string arry4 ;
1879 int status = readHeader( arry1, "ARRY1" ) ;
1880 if ( status ) {
1881 os << LogIO::SEVERE << "Error while reading ARRY1" << LogIO::POST ;
1882 return status ;
1883 }
1884 status = readHeader( arry2, "ARRY2" ) ;
1885 if ( status ) {
1886 os << LogIO::SEVERE << "Error while reading ARRY2" << LogIO::POST ;
1887 return status ;
1888 }
1889 status = readHeader( arry3, "ARRY3" ) ;
1890 if ( status ) {
1891 os << LogIO::SEVERE << "Error while reading ARRY3" << LogIO::POST ;
1892 return status ;
1893 }
1894 status = readHeader( arry4, "ARRY4" ) ;
1895 if ( status ) {
1896 os << LogIO::SEVERE << "Error while reading ARRY4" << LogIO::POST ;
1897 return status ;
1898 }
1899 int index = 0 ;
1900 for ( int i = 0 ; i < 20 ; i++ ) {
1901 // AOSH
1902 if ( arry1[i] == '1' )
1903 ARRY[index] = 1 ;
1904 else
1905 ARRY[index] = 0 ;
1906 // AOSW, AOSU, FX
1907 if ( arry2[i] == '1' )
1908 ARRY[index+20] = 1 ;
1909 else
1910 ARRY[index+20] = 0 ;
1911 // AC45 (1-20)
1912 if ( arry3[i] == '1' )
1913 ARRY[index+40] = 1 ;
1914 else
1915 ARRY[index+40] = 0 ;
1916 // AC45 (21-35)
1917 if ( i < 15 ) {
1918 if ( arry4[i] == '1' )
1919 ARRY[index+60] = 1 ;
1920 else
1921 ARRY[index+60] = 0 ;
1922 }
1923 index++ ;
1924 }
1925 return status ;
1926}
1927
1928void NROFITSDataset::findData()
1929{
1930 LogIO os( LogOrigin( "NROFITSDataset", "findData()", WHERE ) ) ;
1931
1932 // skip header
1933 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
1934
1935 // get offset
1936 int offset = getOffset( "ARRYT" ) ;
1937 if ( offset == -1 ) {
1938 //cerr << "Error, ARRYT is not found in the name list." << endl ;
1939 return ;
1940 }
1941 //cout << "offset for ARRYT is " << offset << " bytes." << endl ;
1942 fseek( fp_, offset, SEEK_CUR ) ;
1943 int count = 0 ;
1944 int index = 0 ;
1945 while ( count < ARYNM && index < rowNum_ ) {
1946 char ctmp[5] ;
1947 fread( ctmp, 1, 4, fp_ ) ;
1948 ctmp[4] = '\0' ;
1949 //cout << "ctmp = " << ctmp << endl ;
1950 for ( int i = 0 ; i < ARYNM ; i++ ) {
1951 if ( arrayid_[i] != -1 )
1952 continue ;
1953 else if ( strncmp( ctmp, ARYTP[i].c_str(), ARYTP[i].size() ) == 0 ) {
1954 //cout << "matched: i = " << i << ", ARYTP = " << ARYTP[i] << ", ctmp = " << ctmp << endl ;
1955 arrayid_[i] = index ;
1956 count++ ;
1957 }
1958 }
1959 fseek( fp_, scanLen_-4, SEEK_CUR ) ;
1960 index++ ;
1961 }
1962
1963 if ( count != ARYNM ) {
1964 os << LogIO::WARN << "NROFITSDataset::findData() failed to find rows for " ;
1965 for ( int i = 0 ; i < ARYNM ; i++ ) {
1966 if ( arrayid_[i] == -1 ) {
1967 os << LogIO::WARN << ARYTP[i] << " " ;
1968 }
1969 }
1970 os.post() ;
1971 }
1972
1973// for ( int i = 0 ; i < ARYNM ; i++ )
1974// //cout << "arrayid_[" << i << "] = " << arrayid_[i] << endl ;
1975 }
1976
1977int NROFITSDataset::getOffset( char *name )
1978{
1979 int offset = 0 ;
1980 string sname( name ) ;
1981 bool found = false ;
1982 for ( int i = 0 ; i < numField_ ; i++ ) {
1983 // escape if name is found
1984 //cout << "names_[" << i << "] = " << names_[i] << " sname = " << sname << endl ;
1985 if ( names_[i] == sname ) {
1986 found = true ;
1987 break ;
1988 }
1989
1990 // form analysis
1991 string substr1 = forms_[i].substr( 0, forms_[i].size()-1 ) ;
1992 string substr2 = forms_[i].substr( forms_[i].size()-1, 1 ) ;
1993 //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
1994 int o1 = atoi( substr1.c_str() ) ;
1995 int o2 = 0 ;
1996 if ( substr2 == "A" )
1997 o2 = sizeof(char) ;
1998 else if ( substr2 == "J" )
1999 o2 = sizeof(int) ;
2000 else if ( substr2 == "F" )
2001 o2 = sizeof(float) ;
2002 else if ( substr2 == "D" )
2003 o2 = sizeof(double) ;
2004 //cout << "o1 = " << o1 << ", o2 = " << o2 << endl ;
2005 offset += o1 * o2 ;
2006 }
2007
2008 if ( !found )
2009 offset = -1 ;
2010
2011 return offset ;
2012}
2013
2014int NROFITSDataset::getPolarizationNum()
2015{
2016 int npol = 0 ;
2017
2018 vector<char> type( 2 ) ;
2019 type[0] = 'C' ;
2020 type[1] = 'L' ;
2021 vector<double> crot ;
2022 vector<double> lagl ;
2023
2024 for ( int i = 0 ; i < ARYNM ; i++ ) {
2025 if ( POLTP[i][0] == type[0] ) {
2026 // circular polarization
2027 if( count( crot.begin(), crot.end(), POLDR[i] ) != 0 ) {
2028 crot.push_back( POLDR[i] ) ;
2029 npol++ ;
2030 }
2031 }
2032 else if ( POLTP[i][0] == type[1] ) {
2033 // linear polarization
2034 if ( count( lagl.begin(), lagl.end(), POLAN[i] ) != 0 ) {
2035 lagl.push_back( POLAN[i] ) ;
2036 npol++ ;
2037 }
2038 }
2039 }
2040
2041 if ( npol == 0 )
2042 npol = 1 ;
2043
2044
2045 return npol ;
2046}
2047
2048int NROFITSDataset::readHeader( string &v, char *name )
2049{
2050 //
2051 // Read 'name' attribute defined as char from the FITS Header
2052 //
2053 int status = 0 ;
2054
2055 char buf[81] ;
2056 strcpy( buf, " " ) ;
2057 fseek( fp_, 0, SEEK_SET ) ;
2058 int count = 0 ;
2059 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
2060 fread( buf, 1, 80, fp_ ) ;
2061 buf[80] = '\0' ;
2062 count++ ;
2063 }
2064 if ( strncmp( buf, "END", 3 ) == 0 ) {
2065 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
2066 //cerr << "count = " << count << endl ;
2067 status = -1 ;
2068 return status ;
2069 }
2070 string str( buf ) ;
2071 int pos1 = str.find( '\'' ) + 1 ;
2072 int pos2 = str.find( '\'', pos1 ) ;
2073 unsigned int clen = pos2 - pos1 ;
2074 //cout << "string: " << str << endl ;
2075 //cout << "value: " << str.substr( pos1, clen ).c_str() << endl ;
2076 //cout << "clen = " << clen << endl ;
2077 v = str.substr( pos1, clen ) ;
2078 //cout << "v = \'" << v << "\'" << endl ;
2079
2080 return status ;
2081}
2082
2083int NROFITSDataset::readHeader( int &v, char *name, int b )
2084{
2085 //
2086 // Read 'name' attribute defined as int from the FITS Header
2087 //
2088 int status = 0 ;
2089
2090 char buf[81] ;
2091 strcpy( buf, " " ) ;
2092 fseek( fp_, 0, SEEK_SET ) ;
2093 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
2094 fread( buf, 1, 80, fp_ ) ;
2095 buf[80] = '\0' ;
2096 //char bufo[9] ;
2097 //strncpy( bufo, buf, 8 ) ;
2098 //bufo[8] = '\0' ;
2099 //cout << "header: " << bufo << endl ;
2100 }
2101 if ( strncmp( buf, "END", 3 ) == 0 ) {
2102 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
2103 status = -1 ;
2104 return status ;
2105 }
2106 string str( buf ) ;
2107 int pos1 = str.find( '=' ) + 1 ;
2108 int pos2 = str.find( '/' ) ;
2109 //cout << "string: " << str << endl ;
2110 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
2111 v = atoi( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
2112 //cout << "v = " << v << endl ;
2113
2114 //cout << "NROFITSDataset::readHeader() end to read" << endl ;
2115 return status ;
2116}
2117
2118
2119int NROFITSDataset::readHeader( float &v, char *name, int b )
2120{
2121 //
2122 // Read 'name' attribute defined as float from the FITS Header
2123 //
2124 int status = 0 ;
2125
2126 char buf[81] ;
2127 strcpy( buf, " " ) ;
2128 fseek( fp_, 0, SEEK_SET ) ;
2129 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
2130 fread( buf, 1, 80, fp_ ) ;
2131 buf[80] = '\0' ;
2132 //char bufo[9] ;
2133 //strncpy( bufo, buf, 8 ) ;
2134 //bufo[8] = '\0' ;
2135 //cout << "header: " << bufo << endl ;
2136 }
2137 if ( strncmp( buf, "END", 3 ) == 0 ) {
2138 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
2139 status = -1 ;
2140 return status ;
2141 }
2142 string str( buf ) ;
2143 int pos1 = str.find( '=' ) + 1 ;
2144 int pos2 = str.find( '/' ) ;
2145 //cout << "string: " << str << endl ;
2146 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
2147 v = atof( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
2148 //cout << "v = " << v << endl ;
2149
2150 return status ;
2151}
2152
2153int NROFITSDataset::readHeader( double &v, char *name, int b )
2154{
2155 //
2156 // Read 'name' attribute defined as double from the FITS Header
2157 //
2158 int status = 0 ;
2159
2160 char buf[81] ;
2161 strcpy( buf, " " ) ;
2162 fseek( fp_, 0, SEEK_SET ) ;
2163 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
2164 fread( buf, 1, 80, fp_ ) ;
2165 buf[80] = '\0' ;
2166 char bufo[9] ;
2167 strncpy( bufo, buf, 8 ) ;
2168 bufo[8] = '\0' ;
2169 //cout << "header: \'" << bufo << "\' bufo = \'" << bufo << "\' ";
2170 //cout << strncmp( buf, name, strlen(name) ) << endl ;
2171 }
2172 if ( strncmp( buf, "END", 3 ) == 0 ) {
2173 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
2174 status = -1 ;
2175 return status ;
2176 }
2177 string str( buf ) ;
2178 int pos1 = str.find( '=' ) + 1 ;
2179 int pos2 = str.find( '/' ) ;
2180 //cout << "string: " << str << endl ;
2181 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
2182 v = atof( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
2183 //cout << "v = " << v << endl ;
2184
2185 return status ;
2186}
2187
2188int NROFITSDataset::readTable( char *v, char *name )
2189{
2190 //
2191 // Read 'name' attribute defined as char from the 0-th row
2192 // of the FITS Scan Record
2193 //
2194 int status = readTable( v, name, (int)strlen( v ), 0 ) ;
2195
2196 return status ;
2197}
2198
2199int NROFITSDataset::readTable( char *v, char *name, int clen, int idx )
2200{
2201 //
2202 // Read 'name' attribute defined as char from the idx-th row
2203 // of the FITS Scan Record
2204 //
2205 int status = 0 ;
2206
2207 // skip header
2208 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2209
2210 // find offset
2211 int offset = getOffset( name ) ;
2212 if ( offset == -1 ) {
2213 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2214 return -1 ;
2215 }
2216 offset += idx * scanLen_ ;
2217 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2218 fseek( fp_, offset, SEEK_CUR ) ;
2219
2220 // get length of char
2221 int index = -1 ;
2222 for ( int i = 0 ; i < numField_ ; i++ ) {
2223 if ( names_[i] == name ) {
2224 index = i ;
2225 break ;
2226 }
2227 }
2228 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
2229 int xsize = atoi( substr.c_str() ) ;
2230 //cout << "xsize = " << xsize << endl ;
2231
2232 // read data
2233 if ( xsize < clen ) {
2234 fread( v, 1, xsize, fp_ ) ;
2235 //v[xsize] = '\0' ;
2236 }
2237 else {
2238 fread( v, 1, clen-1, fp_ ) ;
2239 //v[clen-1] = '\0' ;
2240 }
2241
2242 return status ;
2243}
2244
2245int NROFITSDataset::readTable( int &v, char *name, int b )
2246{
2247 //
2248 // Read 'name' attribute defined as int from the 0-th row
2249 // of the FITS Scan Record
2250 //
2251 int status = readTable( v, name, b, 0 ) ;
2252
2253 return status ;
2254}
2255
2256int NROFITSDataset::readTable( int &v, char *name, int b, int idx )
2257{
2258 //
2259 // Read 'name' attribute defined as int from the idx-th row
2260 // of the FITS Scan Record
2261 //
2262 int status = 0 ;
2263 // skip header
2264 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2265
2266 // find offset
2267 int offset = getOffset( name ) ;
2268 if ( offset == -1 ) {
2269 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2270 return -1 ;
2271 }
2272 offset += idx * scanLen_ ;
2273 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2274 fseek( fp_, offset, SEEK_CUR ) ;
2275
2276 // read data
2277 fread( &v, sizeof(int), 1, fp_ ) ;
2278 if ( b == 0 )
2279 convertEndian( v ) ;
2280
2281 return status ;
2282}
2283
2284int NROFITSDataset::readTable( float &v, char *name, int b )
2285{
2286 //
2287 // Read 'name' attribute defined as float from the 0-th row
2288 // of the FITS Scan Record
2289 //
2290 int status = readTable( v, name, b, 0 ) ;
2291
2292 return status ;
2293}
2294
2295int NROFITSDataset::readTable( float &v, char *name, int b, int idx )
2296{
2297 //
2298 // Read 'name' attribute defined as float from the idx-th row
2299 // of the FITS Scan Record
2300 //
2301 int status = 0 ;
2302
2303 // skip header
2304 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2305
2306 // find offset
2307 int offset = getOffset( name ) ;
2308 if ( offset == -1 ) {
2309 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2310 return -1 ;
2311 }
2312 offset += idx * scanLen_ ;
2313 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2314 fseek( fp_, offset, SEEK_CUR ) ;
2315
2316 // read data
2317 fread( &v, sizeof(float), 1, fp_ ) ;
2318 if ( b == 0 )
2319 convertEndian( v ) ;
2320
2321 return status ;
2322}
2323
2324int NROFITSDataset::readTable( double &v, char *name, int b )
2325{
2326 //
2327 // Read 'name' attribute defined as double from the 0-th row
2328 // of the FITS Scan Record
2329 //
2330 int status = readTable( v, name, b, 0 ) ;
2331
2332 return status ;
2333}
2334
2335int NROFITSDataset::readTable( double &v, char *name, int b, int idx )
2336{
2337 //
2338 // Read 'name' attribute defined as double from the idx-th row
2339 // of the FITS Scan Record
2340 //
2341 int status = 0 ;
2342
2343 // skip header
2344 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2345
2346 // find offset
2347 int offset = getOffset( name ) ;
2348 if ( offset == -1 ) {
2349 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2350 return -1 ;
2351 }
2352 offset += idx * scanLen_ ;
2353 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2354 fseek( fp_, offset, SEEK_CUR ) ;
2355
2356 // read data
2357 fread( &v, sizeof(double), 1, fp_ ) ;
2358 if ( b == 0 )
2359 convertEndian( v ) ;
2360
2361 return status ;
2362}
2363
2364int NROFITSDataset::readTable( vector<char *> &v, char *name, int idx )
2365{
2366 //
2367 // Read 'name' attribute defined as char array from the FITS Scan Record
2368 //
2369 int status = 0 ;
2370
2371 // skip header
2372 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2373
2374 // find offset
2375 int offset = getOffset( name ) ;
2376 if ( offset == -1 ) {
2377 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2378 return -1 ;
2379 }
2380 offset += idx * scanLen_ ;
2381 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2382 fseek( fp_, offset, SEEK_CUR ) ;
2383
2384 // get length of char
2385 int index = -1 ;
2386 for ( int i = 0 ; i < numField_ ; i++ ) {
2387 if ( names_[i] == name ) {
2388 index = i ;
2389 break ;
2390 }
2391 }
2392 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
2393 int xsize = atoi( substr.c_str() ) ;
2394 //cout << "xsize = " << xsize << endl ;
2395
2396 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2397 int clen = strlen( v[i] ) ;
2398 if ( clen > xsize ) {
2399 fread( v[i], 1, xsize, fp_ ) ;
2400 //v[i][xsize] = '\0' ;
2401 }
2402 else {
2403 fread( v[i], 1, clen, fp_ ) ;
2404 //v[i][clen-1] = '\0' ;
2405 }
2406 //cout << "v[" << i << "] = " << v[i] << endl ;
2407 }
2408
2409 return status ;
2410}
2411
2412int NROFITSDataset::readTable( vector<int> &v, char *name, int b, int idx )
2413{
2414 //
2415 // Read 'name' attribute defined as int array from the FITS Scan Record
2416 //
2417 int status = 0 ;
2418
2419 // skip header
2420 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2421
2422 // find offset
2423 int offset = getOffset( name ) ;
2424 if ( offset == -1 ) {
2425 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2426 return -1 ;
2427 }
2428 offset += idx * scanLen_ ;
2429 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2430 fseek( fp_, offset, SEEK_CUR ) ;
2431
2432 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2433 fread( &v[i], 1, sizeof(int), fp_ ) ;
2434 if ( b == 0 )
2435 convertEndian( v[i] ) ;
2436 //cout << "v[" << i << "] = " << v[i] << endl ;
2437 }
2438
2439 return status ;
2440}
2441
2442int NROFITSDataset::readTable( vector<float> &v, char *name, int b, int idx )
2443{
2444 //
2445 // Read 'name' attribute defined as float array from the FITS Scan Record
2446 //
2447 int status = 0 ;
2448
2449 // skip header
2450 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2451
2452 // find offset
2453 int offset = getOffset( name ) ;
2454 if ( offset == -1 ) {
2455 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2456 return -1 ;
2457 }
2458 offset += idx * scanLen_ ;
2459 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2460 fseek( fp_, offset, SEEK_CUR ) ;
2461
2462 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2463 fread( &v[i], 1, sizeof(float), fp_ ) ;
2464 if ( b == 0 )
2465 convertEndian( v[i] ) ;
2466 //cout << "v[" << i << "] = " << v[i] << endl ;
2467 }
2468
2469 return status ;
2470}
2471
2472int NROFITSDataset::readTable( vector<double> &v, char *name, int b, int idx )
2473{
2474 //
2475 // Read 'name' attribute defined as double array from the FITS Scan Record
2476 //
2477 int status = 0 ;
2478
2479 // skip header
2480 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2481
2482 // find offset
2483 int offset = getOffset( name ) ;
2484 if ( offset == -1 ) {
2485 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2486 return -1 ;
2487 }
2488 offset += idx * scanLen_ ;
2489 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2490 fseek( fp_, offset, SEEK_CUR ) ;
2491
2492 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2493 fread( &v[i], 1, sizeof(double), fp_ ) ;
2494 if ( b == 0 )
2495 convertEndian( v[i] ) ;
2496 //cout << "v[" << i << "] = " << v[i] << endl ;
2497 }
2498
2499 return status ;
2500}
2501
2502int NROFITSDataset::readColumn( vector<string> &v, char *name )
2503{
2504 //
2505 // Read 0-th column of ARRYTP-dependent 'name' attributes
2506 // defined as char array from the FITS Scan Record
2507 //
2508 int status = readColumn( v, name, 0 ) ;
2509
2510 return status ;
2511}
2512
2513int NROFITSDataset::readColumn( vector<string> &v, char *name, int idx )
2514{
2515 //
2516 // Read idx-th column of ARRYTP-dependent 'name' attributes
2517 // defined as char array from the FITS Scan Record
2518 //
2519 int status = 0 ;
2520
2521 // skip header
2522 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2523
2524 // find offset
2525 int offset = getOffset( name ) ;
2526 if ( offset == -1 ) {
2527 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2528 return -1 ;
2529 }
2530 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2531 fseek( fp_, offset, SEEK_CUR ) ;
2532
2533 // get length of char
2534 int index = -1 ;
2535 for ( int i = 0 ; i < numField_ ; i++ ) {
2536 if ( names_[i] == name ) {
2537 index = i ;
2538 break ;
2539 }
2540 }
2541 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
2542 int xsize = atoi( substr.c_str() ) ;
2543 //cout << "xsize = " << xsize << endl ;
2544
2545 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2546 offset = scanLen_ * arrayid_[i] + xsize * idx ;
2547 fseek( fp_, offset, SEEK_CUR ) ;
2548// int clen = (int)strlen( v[i] ) ;
2549// if ( clen > xsize ) {
2550// fread( v[i], 1, xsize, fp_ ) ;
2551// //v[i][xsize] = '\0' ;
2552// }
2553// else {
2554// fread( v[i], 1, clen-1, fp_ ) ;
2555// //v[i][clen-1] = '\0' ;
2556// }
2557 char c[xsize+1] ;
2558 fread( c, 1, xsize, fp_ ) ;
2559 c[xsize] = '\0' ;
2560 v[i] = string( c ) ;
2561 //cout << "v[" << i << "] = \'" << v[i] << "\'" << endl ;
2562 fseek( fp_, -xsize-offset, SEEK_CUR ) ;
2563 }
2564
2565 return status ;
2566}
2567
2568int NROFITSDataset::readColumn( vector<int> &v, char *name, int b )
2569{
2570 //
2571 // Read 0-th column of ARRYTP-dependent 'name' attributes
2572 // defined as int array from the FITS Scan Record
2573 //
2574 int status = readColumn( v, name, b, 0 ) ;
2575
2576 return status ;
2577}
2578
2579int NROFITSDataset::readColumn( vector<int> &v, char *name, int b, int idx )
2580{
2581 //
2582 // Read idx-th column of ARRYTP-dependent 'name' attributes
2583 // defined as int array from the FITS Scan Record
2584 //
2585 int status = 0 ;
2586
2587 // skip header
2588 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2589
2590 // find offset
2591 int offset = getOffset( name ) ;
2592 if ( offset == -1 ) {
2593 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2594 return -1 ;
2595 }
2596 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2597 fseek( fp_, offset, SEEK_CUR ) ;
2598
2599 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2600 offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
2601 fseek( fp_, offset, SEEK_CUR ) ;
2602 fread( &v[i], 1, sizeof(int), fp_ ) ;
2603 if ( b == 0 )
2604 convertEndian( v[i] ) ;
2605 //cout << "v[" << i << "] = " << v[i] << endl ;
2606 fseek( fp_, -sizeof(int)-offset, SEEK_CUR ) ;
2607 }
2608
2609 return status ;
2610}
2611
2612int NROFITSDataset::readColumn( vector<float> &v, char *name, int b )
2613{
2614 //
2615 // Read 0-th column of ARRYTP-dependent 'name' attributes
2616 // defined as float array from the FITS Scan Record
2617 //
2618 int status = readColumn( v, name, b, 0 ) ;
2619
2620 return status ;
2621}
2622
2623int NROFITSDataset::readColumn( vector<float> &v, char *name, int b, int idx )
2624{
2625 //
2626 // Read idx-th column of ARRYTP-dependent 'name' attributes
2627 // defined as float array from the FITS Scan Record
2628 //
2629 int status = 0 ;
2630
2631 // skip header
2632 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2633
2634 // find offset
2635 int offset = getOffset( name ) ;
2636 if ( offset == -1 ) {
2637 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2638 return -1 ;
2639 }
2640 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2641 fseek( fp_, offset, SEEK_CUR ) ;
2642
2643 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2644 offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
2645 fseek( fp_, offset, SEEK_CUR ) ;
2646 fread( &v[i], 1, sizeof(float), fp_ ) ;
2647 if ( b == 0 )
2648 convertEndian( v[i] ) ;
2649 //cout << "v[" << i << "] = " << v[i] << endl ;
2650 fseek( fp_, -sizeof(float)-offset, SEEK_CUR ) ;
2651 }
2652
2653 return status ;
2654}
2655
2656int NROFITSDataset::readColumn( vector<double> &v, char *name, int b )
2657{
2658 //
2659 // Read 0-th column of ARRYTP-dependent 'name' attributes
2660 // defined as double array from the FITS Scan Record
2661 //
2662 int status = readColumn( v, name, b, 0 ) ;
2663
2664 return status ;
2665}
2666
2667int NROFITSDataset::readColumn( vector<double> &v, char *name, int b, int idx )
2668{
2669 //
2670 // Read idx-th column of ARRYTP-dependent 'name' attributes
2671 // defined as double array from the FITS Scan Record
2672 //
2673 int status = 0 ;
2674
2675 // skip header
2676 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
2677
2678 // find offset
2679 int offset = getOffset( name ) ;
2680 if ( offset == -1 ) {
2681 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2682 return -1 ;
2683 }
2684 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2685 fseek( fp_, offset, SEEK_CUR ) ;
2686
2687 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2688 offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
2689 fseek( fp_, offset, SEEK_CUR ) ;
2690 fread( &v[i], 1, sizeof(double), fp_ ) ;
2691 if ( b == 0 )
2692 convertEndian( v[i] ) ;
2693 //cout << "offset = " << offset << ", v[" << i << "] = " << v[i] << endl ;
2694 fseek( fp_, -sizeof(double)-offset, SEEK_CUR ) ;
2695 }
2696
2697// //cout << "v: " << endl ;
2698// for ( vector<double>::iterator i = v.begin() ; i != v.end() ; i++ )
2699// //cout << *i << " " ;
2700// //cout << endl ;
2701
2702 return status ;
2703}
2704
2705uInt NROFITSDataset::getArrayId( string type )
2706{
2707 uInt ib = 99 ;
2708 for ( uInt i = 0 ; i < arrayid_.size() ; i++ ) {
2709 uInt len = ARYTP[i].size() ;
2710 if ( type.compare( 0, len, ARYTP[i], 0, len ) == 0 ) {
2711 ib = i ;
2712 break ;
2713 }
2714 }
2715 return ib ;
2716}
Note: See TracBrowser for help on using the repository browser.