source: trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc@ 2748

Last change on this file since 2748 was 2664, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Fix for serious bug in NRO FITS reader, which sets BEAMNO to wrong value
when array number is larger than 9.


File size: 64.3 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 refFreq_.resize( ARYNM, 0.0 ) ;
183}
184
185// fill data header
186int NROFITSDataset::fillHeader()
187{
188 LogIO os( LogOrigin( "NROFITSDataset", "fillHeader()", WHERE ) ) ;
189
190 // open file
191 if ( open() ) {
192 os << LogIO::SEVERE << "Error opening file " << filename_ << "." << LogIO::EXCEPTION ;
193 return -1 ;
194 }
195
196 // fill
197 int status = fillHeader( same_ ) ;
198
199 return status ;
200}
201
202int NROFITSDataset::fillHeader( int sameEndian )
203{
204 LogIO os( LogOrigin( "NROFITSDataset", "fillHeader()", WHERE ) ) ;
205
206 // fill array type
207 fillARYTP() ;
208
209 // read data header
210 float ftmp = 0.0 ;
211 if ( readHeader( LOFIL, "LOFIL" ) != 0 ) {
212 os << LogIO::NORMAL << "LOFIL set to 'FITS'." << LogIO::POST ;
213 LOFIL = "FITS" ;
214 }
215 // DEBUG
216 //cout << "LOFIL = \'" << LOFIL << "\'" << endl ;
217 //
218 if ( readHeader( VER, "VER" ) != 0 ) {
219 if ( readHeader( VER, "HISTORY NEWSTAR VER" ) != 0 ) {
220 os << LogIO::NORMAL << "VER set to 'V000'." << LogIO::POST ;
221 VER = "V000" ;
222 }
223 }
224 // DEBUG
225 //cout << "VER = \'" << VER << "\'" << endl ;
226 //
227 if ( readHeader( GROUP, "GROUP" ) != 0 ) {
228 if ( readHeader( GROUP, "HISTORY NEWSTAR GROUP" ) != 0 ) {
229 os << LogIO::NORMAL << "GROUP set to 'GRP0'." << LogIO::POST ;
230 GROUP = "GROUP0" ;
231 }
232 }
233 // DEBUG
234 //cout << "GROUP = \'" << GROUP << "\'" << endl ;
235 //
236 if ( readHeader( PROJ, "PROJECT" ) != 0 ) {
237 if ( readHeader( PROJ, "HISTORY NEWSTAR PROJECT" ) != 0 ) {
238 os << LogIO::NORMAL << "PROJ set to 'PROJ0'." << LogIO::POST ;
239 PROJ = "PROJECT0" ;
240 }
241 }
242 // DEBUG
243 //cout << "PROJ = \'" << PROJ << "\'" << endl ;
244 //
245 if ( readHeader( SCHED, "SCHED" ) != 0 ) {
246 if ( readHeader( SCHED, "HISTORY NEWSTAR SCHED" ) != 0 ) {
247 os << LogIO::NORMAL << "SCHED set to 'SCHED0'." << LogIO::POST ;
248 SCHED = "SCHED0" ;
249 }
250 }
251 // DEBUG
252 //cout << "SCHED = \'" << SCHED << "\'" << endl ;
253 //
254 if ( readHeader( OBSVR, "OBSERVER" ) != 0 ) {
255 os << LogIO::NORMAL << "OBSVR set to 'SOMEONE'" << LogIO::POST ;
256 OBSVR = "SOMEONE" ;
257 }
258 // DEBUG
259 //cout << "OBSVR = \'" << OBSVR << "\'" << endl ;
260 //
261 if ( readHeader( LOSTM, "STRSC" ) != 0 ) {
262 os << LogIO::WARN << "Error while reading data LOSTM." << LogIO::POST ;
263 return -1 ;
264 }
265 if ( LOSTM[0] == '9' ) {
266 LOSTM = "19" + LOSTM ;
267 }
268 else if ( LOSTM[0] == '0') {
269 LOSTM = "20" + LOSTM ;
270 }
271 // DEBUG
272 //cout << "LOSTM = \'" << LOSTM << "\'" << endl ;
273 //
274 if ( readHeader( LOETM, "STPSC" ) != 0 ) {
275 os << LogIO::WARN << "Error while reading data LOETM." << LogIO::POST ;
276 return -1 ;
277 }
278 if ( LOETM[0] == '9' ) {
279 LOETM = "19" + LOETM ;
280 }
281 else if ( LOETM[0] == '0') {
282 LOETM = "20" + LOETM ;
283 }
284 // DEBUG
285 //cout << "LOETM = \'" << LOETM << "\'" << endl ;
286 //
287 if ( readHeader( NSCAN, "NAXIS2", sameEndian ) != 0 ) {
288 os << LogIO::WARN << "Error while reading data NSCAN." << LogIO::POST ;
289 return -1 ;
290 }
291 // DEBUG
292 //cout << "NSCAN = " << NSCAN << endl ;
293 //
294 string subt ;
295 if ( readHeader( TITLE, "TITLE" ) != 0 ) {
296 int stat1 = readHeader( TITLE, "HISTORY NEWSTAR TITLE1" ) ;
297 int stat2 = readHeader( subt, "HISTORY NEWSTAR TITLE2" ) ;
298 if ( stat1 != 0 && stat2 != 0 ) {
299 os << LogIO::NORMAL << "TITLE set to 'NOTITLE'." << LogIO::POST ;
300 TITLE = "NOTITLE" ;
301 }
302 else {
303 //cout << "TITLE = \'" << TITLE << "\'" << endl ;
304 //cout << "subt = \'" << subt << "\'" << endl ;
305 TITLE = TITLE + subt ;
306 }
307 }
308 // DEBUG
309 //cout << "TITLE = \'" << TITLE << "\'" << endl ;
310 //
311 if ( readHeader( OBJ, "OBJECT" ) != 0 ) {
312 os << LogIO::NORMAL << "OBJ set to 'SOMEWHERE'." << LogIO::POST ;
313 OBJ = "NOOBJ" ;
314 }
315 // DEBUG
316 //cout << "OBJ = \'" << OBJ << "\'" << endl ;
317 //
318 if ( readHeader( ftmp, "EPOCH", sameEndian ) != 0 ) {
319 os << LogIO::WARN << "Error while reading data EPOCH." << LogIO::POST ;
320 return -1 ;
321 }
322 if ( ftmp == 1950.0 )
323 EPOCH = "B1950" ;
324 else if ( ftmp == 2000.0 )
325 EPOCH = "J2000" ;
326 else {
327 os << LogIO::WARN << "Unidentified epoch. set to 'XXXXX'" << LogIO::POST ;
328 EPOCH = "XXXXX" ;
329 }
330 // DEBUG
331 //cout << "EPOCH = \'" << EPOCH << "\'" << endl ;
332 //
333 string stmp ;
334 if ( readHeader( stmp, "RA" ) != 0 ) {
335 os << LogIO::WARN << "Error while reading data RA0." << LogIO::POST ;
336 return -1 ;
337 }
338 RA0 = radRA( stmp.c_str() ) ;
339 // DEBUG
340 //cout << "RA0 = " << RA0 << endl ;
341 //
342 if ( readHeader( stmp, "DEC" ) != 0 ) {
343 os << LogIO::WARN << "Error while reading data DEC0." << LogIO::POST ;
344 return -1 ;
345 }
346 DEC0 = radDEC( stmp.c_str() ) ;
347 // DEBUG
348 //cout << "DEC0 = " << DEC0 << endl ;
349 //
350 if ( readHeader( GLNG0, "GL0", sameEndian ) != 0 ) {
351 os << LogIO::WARN << "Error while reading data GLNG0." << LogIO::POST ;
352 return -1 ;
353 }
354 // DEBUG
355 //cout << "GLNG0 = " << GLNG0 << endl ;
356 //
357 if ( readHeader( GLAT0, "GB0", sameEndian ) != 0 ) {
358 os << LogIO::WARN << "Error while reading data GLAT0." << LogIO::POST ;
359 return -1 ;
360 }
361 // DEBUG
362 //cout << "GLAT0 = " << GLAT0 << endl ;
363 //
364 if ( readHeader( NCALB, "NCALB", sameEndian ) != 0 ) {
365 os << LogIO::WARN << "Error while reading data NCALB." << LogIO::POST ;
366 return -1 ;
367 }
368 // DEBUG
369 //cout << "NCALB = " << NCALB << endl ;
370 //
371 if ( readHeader( SCNCD, "SCNCD", sameEndian ) != 0 ) {
372 os << LogIO::NORMAL << "SCNCD set to 0 (RADEC)." << LogIO::POST ;
373 SCNCD = 0 ;
374 }
375 // DEBUG
376 //cout << "SCNCD = " << SCNCD << endl ;
377 //
378 if ( readHeader( SCMOD, "SCMOD1" ) != 0 ) {
379 os << LogIO::WARN << "Error while reading data SCMOD." << LogIO::POST ;
380 return -1 ;
381 }
382 string::size_type pos = SCMOD.find( ' ' ) ;
383 if ( pos != string::npos ) {
384 SCMOD = SCMOD.substr( 0, pos ) ;
385 SCMOD = SCMOD + " " ;
386 }
387 //cout << "SDMOD1 = \'" << SCMOD << "\'" << endl ;
388 if ( readHeader( stmp, "SCMOD2" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
389 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
390 stmp = stmp.substr( 0, pos ) ;
391 SCMOD = SCMOD + stmp + " " ;
392 //cout << "SCMOD2 = \'" << SCMOD << "\'" << endl ;
393 }
394 if ( readHeader( stmp, "SCMOD3" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
395 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
396 stmp = stmp.substr( 0, pos ) ;
397 SCMOD = SCMOD + stmp + " " ;
398 //cout << "SCMOD3 = \'" << SCMOD << "\'" << endl ;
399 }
400 if ( readHeader( stmp, "SCMOD4" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
401 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
402 stmp = stmp.substr( 0, pos ) ;
403 SCMOD = SCMOD + stmp + " " ;
404 //cout << "SCMOD4 = \'" << SCMOD << "\'" << endl ;
405 }
406 if ( readHeader( stmp, "SCMOD5" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
407 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
408 stmp = stmp.substr( 0, pos ) ;
409 SCMOD = SCMOD + stmp + " " ;
410 //cout << "SCMOD5 = \'" << SCMOD << "\'" << endl ;
411 }
412 if ( readHeader( stmp, "SCMOD6" ) == 0 && stmp.compare( 0, 1, " " ) != 0 ) {
413 if ( ( pos = stmp.find( ' ' ) ) != string::npos )
414 stmp = stmp.substr( 0, pos ) ;
415 SCMOD = SCMOD + stmp + " " ;
416 //cout << "SCMOD6 = \'" << SCMOD << "\'" << endl ;
417 }
418 // DEBUG
419 //cout << "SCMOD = \'" << SCMOD << "\'" << endl ;
420 //
421 if ( readHeader( URVEL, "VEL", sameEndian ) != 0 ) {
422 os << LogIO::WARN << "Error while reading data URVEL." << LogIO::POST ;
423 return -1 ;
424 }
425 // DEBUG
426 //cout << "URVEL = " << URVEL << endl ;
427 //
428 if ( readHeader( VREF, "VREF" ) != 0 ) {
429 os << LogIO::WARN << "Error while reading data VREF." << LogIO::POST ;
430 return -1 ;
431 }
432 // DEBUG
433 //cout << "VREF = \'" << VREF << "\'" << endl ;
434 //
435 if ( readHeader( VDEF, "VDEF" ) != 0 ) {
436 os << LogIO::WARN << "Error while reading data VDEF." << LogIO::POST ;
437 return -1 ;
438 }
439 // DEBUG
440 //cout << "VDEF = \'" << VDEF << "\'" << endl ;
441 //
442 if ( readHeader( SWMOD, "SWMOD" ) != 0 ) {
443 os << LogIO::WARN << "Error while reading data SWMOD." << LogIO::POST ;
444 return -1 ;
445 }
446 // DEBUG
447 //cout << "SWMOD = \'" << SWMOD << "\'" << endl ;
448 //
449 if ( readHeader( FRQSW, "FRQSW", sameEndian ) != 0 ) {
450 os << LogIO::NORMAL << "FRQSW set to 0." << LogIO::POST ;
451 FRQSW = 0.0 ;
452 }
453 // DEBUG
454 //cout << "FRQSW = " << FRQSW << endl ;
455 //
456 if ( readHeader( DBEAM, "DBEAM", sameEndian ) != 0 ) {
457 os << LogIO::WARN << "Error while reading data DBEAM." << LogIO::POST ;
458 return -1 ;
459 }
460 // DEBUG
461 //cout << "DBEAM = " << DBEAM << endl ;
462 //
463 if ( readHeader( MLTOF, "MLTOF", sameEndian ) != 0 ) {
464 os << LogIO::NORMAL << "MLTOF set to 0." << LogIO::POST ;
465 MLTOF = 0.0 ;
466 }
467 // DEBUG
468 //cout << "MLTOF = " << MLTOF << endl ;
469 //
470 if ( readHeader( CMTQ, "CMTQ", sameEndian ) != 0 ) {
471 os << LogIO::WARN << "Error while reading data CMTQ." << LogIO::POST ;
472 return -1 ;
473 }
474 // DEBUG
475 //cout << "CMTQ = " << CMTQ << endl ;
476 //
477 if ( readHeader( CMTE, "CMTE", sameEndian ) != 0 ) {
478 os << LogIO::WARN << "Error while reading data CMTE." << LogIO::POST ;
479 return -1 ;
480 }
481 // DEBUG
482 //cout << "CMTE = " << CMTE << endl ;
483 //
484 if ( readHeader( CMTSOM, "CMTSOM", sameEndian ) != 0 ) {
485 os << LogIO::WARN << "Error while reading data CMTSOM." << LogIO::POST ;
486 return -1 ;
487 }
488 // DEBUG
489 //cout << "CMTSOM = " << CMTSOM << endl ;
490 //
491 if ( readHeader( CMTNODE, "CMTNODE", sameEndian ) != 0 ) {
492 os << LogIO::WARN << "Error while reading data CMTNODE." << LogIO::POST ;
493 return -1 ;
494 }
495 // DEBUG
496 //cout << "CMTNODE = " << CMTNODE << endl ;
497 //
498 if ( readHeader( CMTI, "CMTI", sameEndian ) != 0 ) {
499 os << LogIO::WARN << "Error while reading data CMTI." << LogIO::POST ;
500 return -1 ;
501 }
502 // DEBUG
503 //cout << "CMTI = " << CMTI << endl ;
504 //
505 if ( readHeader( CMTTM, "CMTTM" ) != 0 ) {
506 os << LogIO::WARN << "Error while reading data CMTTM." << LogIO::POST ;
507 return -1 ;
508 }
509 // DEBUG
510 //cout << "CMTTM = \'" << CMTTM << "\'" << endl ;
511 //
512 if ( readHeader( SBDX, "SDBX", sameEndian ) != 0 ) {
513 os << LogIO::WARN << "Error while reading data SBDX." << LogIO::POST ;
514 return -1 ;
515 }
516 // DEBUG
517 //cout << "SBDX = " << SBDX << endl ;
518 //
519 if ( readHeader( SBDY, "SDBY", sameEndian ) != 0 ) {
520 os << LogIO::WARN << "Error while reading data SBDY." << LogIO::POST ;
521 return -1 ;
522 }
523 // DEBUG
524 //cout << "SBDY = " << SBDY << endl ;
525 //
526 if ( readHeader( SBDZ1, "SDBZ1", sameEndian ) != 0 ) {
527 os << LogIO::WARN << "Error while reading data SBDZ1." << LogIO::POST ;
528 return -1 ;
529 }
530 // DEBUG
531 //cout << "SBDZ1 = " << SBDZ1 << endl ;
532 //
533 if ( readHeader( SBDZ2, "SDBZ2", sameEndian ) != 0 ) {
534 os << LogIO::WARN << "Error while reading data SBDZ2." << LogIO::POST ;
535 return -1 ;
536 }
537 // DEBUG
538 //cout << "SBDZ2 = " << SBDZ2 << endl ;
539 //
540 if ( readHeader( DAZP, "DAZP", sameEndian ) != 0 ) {
541 os << LogIO::NORMAL << "DAZP set to 0." << LogIO::POST ;
542 DAZP = 0.0 ;
543 }
544 // DEBUG
545 //cout << "DAZP = " << DAZP << endl ;
546 //
547 if ( readHeader( DELP, "DELP", sameEndian ) != 0 ) {
548 os << LogIO::NORMAL << "DELP set to 0." << LogIO::POST ;
549 DELP = 0.0 ;
550 }
551 // DEBUG
552 //cout << "DELP = " << DELP << endl ;
553 //
554 if ( readHeader( CHBIND, "CHBIND", sameEndian ) != 0 ) {
555 os << LogIO::NORMAL << "CHBIND set to 1." << LogIO::POST ;
556 CHBIND = 1 ;
557 }
558 // DEBUG
559 //cout << "CHBIND = " << CHBIND << endl ;
560 //
561 if ( readHeader( NUMCH, "NCH", sameEndian ) != 0 ) {
562 if ( readTable( NUMCH, "NCH", sameEndian ) != 0 ) {
563 os << LogIO::NORMAL << "NUMCH set to " << chmax_ << "." << LogIO::POST ;
564 NUMCH = chmax_ ;
565 }
566 }
567 // DEBUG
568 //cout << "NUMCH = " << NUMCH << endl ;
569 //
570 if ( readHeader( CHMIN, "CHMIN", sameEndian ) != 0 ) {
571 os << LogIO::NORMAL << "CHMIN set to 1." << LogIO::POST ;
572 CHMIN = 1 ;
573 }
574 // DEBUG
575 //cout << "CHMIN = " << CHMIN << endl ;
576 //
577 if ( readHeader( CHMAX, "CHMAX", sameEndian ) != 0 ) {
578 os << LogIO::NORMAL << "CHMAX set to " << chmax_ << "." << LogIO::POST ;
579 CHMAX = chmax_ ;
580 }
581 // DEBUG
582 //cout << "CHMAX = " << CHMAX << endl ;
583 //
584 if ( readHeader( ALCTM, "ALCTM", sameEndian ) != 0 ) {
585 if ( readTable( ALCTM, "ALCTM", sameEndian ) != 0 ) {
586 os << LogIO::WARN << "Error while reading data ALCTM." << LogIO::POST ;
587 return -1 ;
588 }
589 }
590 // DEBUG
591 //cout << "ALCTM = " << ALCTM << endl ;
592 //
593 int itmp ;
594 if ( readHeader( itmp, "INTEG", sameEndian ) != 0 ) {
595 if ( readTable( itmp, "INTEG", sameEndian ) != 0 ) {
596 os << LogIO::WARN << "Error while reading data IPTIM." << LogIO::POST ;
597 return -1 ;
598 }
599 }
600 IPTIM = (double)itmp ;
601 // DEBUG
602 //cout << "IPTIM = " << IPTIM << endl ;
603 //
604 if ( readHeader( PA, "PA", sameEndian ) != 0 ) {
605 if ( readTable( PA, "PA", sameEndian ) != 0 ) {
606 os << LogIO::WARN << "Error while reading data PA." << LogIO::POST ;
607 return -1 ;
608 }
609 }
610 // DEBUG
611 //cout << "PA = " << PA << endl ;
612 //
613
614 // find data index for each ARYTP
615 findData() ;
616 vector<char *> v( ARYNM ) ;
617 if ( readColumn( RX, "RX" ) != 0 ) {
618 os << LogIO::WARN << "Error while reading data RX." << LogIO::POST ;
619 return -1 ;
620 }
621 // DEBUG
622 //nro_debug_output( "RX", ARYNM, RX ) ;
623 //
624 if ( readColumn( HPBW, "HPBW", sameEndian ) != 0 ) {
625 os << LogIO::WARN << "Error while reading data HPBW." << LogIO::POST ;
626 return -1 ;
627 }
628 // DEBUG
629// nro_debug_output( "HPBW", ARYNM, HPBW ) ;
630 //
631 if ( readColumn( EFFA, "EFFA", sameEndian ) != 0 ) {
632 os << LogIO::WARN << "Error while reading data EFFA." << LogIO::POST ;
633 return -1 ;
634 }
635 // DEBUG
636// nro_debug_output( "EFFA", ARYNM, EFFA ) ;
637 //
638 if ( readColumn( EFFB, "EFFB", sameEndian ) != 0 ) {
639 os << LogIO::WARN << "Error while reading data EFFB." << LogIO::POST ;
640 return -1 ;
641 }
642 // DEBUG
643// nro_debug_output( "EFFB", ARYNM, EFFB ) ;
644 //
645 if ( readColumn( EFFL, "EFFL", sameEndian ) != 0 ) {
646 os << LogIO::WARN << "Error while reading data EFFL." << LogIO::POST ;
647 return -1 ;
648 }
649 // DEBUG
650// nro_debug_output( "EFFL", ARYNM, EFFL ) ;
651 //
652 if ( readColumn( EFSS, "EFSS", sameEndian ) != 0 ) {
653 os << LogIO::WARN << "Error while reading data EFSS." << LogIO::POST ;
654 return -1 ;
655 }
656 // DEBUG
657// nro_debug_output( "EFSS", ARYNM, EFSS ) ;
658 //
659 if ( readColumn( GAIN, "GAIN", sameEndian ) != 0 ) {
660 os << LogIO::WARN << "Error while reading data GAIN." << LogIO::POST ;
661 return -1 ;
662 }
663 // DEBUG
664// nro_debug_output( "GAIN", ARYNM, GAIN ) ;
665 //
666 if ( readColumn( HORN, "HORN" ) != 0 ) {
667 os << LogIO::WARN << "Error while reading data HORN." << LogIO::POST ;
668 return -1 ;
669 }
670 // DEBUG
671// nro_debug_output( "HORN", ARYNM, HORN ) ;
672 //
673 if ( readColumn( POLTP, "POLTP" ) != 0 ) {
674 os << LogIO::WARN << "Error while reading data POLTP." << LogIO::POST ;
675 return -1 ;
676 }
677 // DEBUG
678// nro_debug_output( "POLTP", ARYNM, POLTP ) ;
679 //
680 vector<int> ipoldr( ARYNM, 0 ) ;
681 if ( readColumn( ipoldr, "POLDR", sameEndian ) != 0 ) {
682 os << LogIO::WARN << "Error while reading data POLDR." << LogIO::POST ;
683 return -1 ;
684 }
685 for ( int i = 0 ; i < ARYNM ; i++ )
686 POLDR[i] = (double)ipoldr[i] ;
687 // DEBUG
688// nro_debug_output( "POLDR", ARYNM, POLDR ) ;
689 //
690 if ( readColumn( POLAN, "POLAN", sameEndian ) != 0 ) {
691 os << LogIO::WARN << "Error while reading data POLAN." << LogIO::POST ;
692 return -1 ;
693 }
694 // DEBUG
695// nro_debug_output( "POLAN", ARYNM, POLAN ) ;
696 //
697 if ( readColumn( DFRQ, "DFRQ", sameEndian ) != 0 ) {
698 os << LogIO::WARN << "Error while reading data DFRQ." << LogIO::POST ;
699 return -1 ;
700 }
701 // DEBUG
702// nro_debug_output( "DFRQ", ARYNM, DFRQ ) ;
703 //
704 if ( readColumn( SIDBD, "SIDBD" ) != 0 ) {
705 os << LogIO::WARN << "Error while reading data SIDBD." << LogIO::POST ;
706 return -1 ;
707 }
708 // DEBUG
709// nro_debug_output( "SIDBD", ARYNM, SIDBD ) ;
710 //
711 if ( readColumn( REFN, "REFN", sameEndian ) != 0 ) {
712 os << LogIO::WARN << "Error while reading data REFN." << LogIO::POST ;
713 return -1 ;
714 }
715 // DEBUG
716// nro_debug_output( "REFN", ARYNM, REFN ) ;
717 //
718 if ( readColumn( IPINT, "IPINT", sameEndian ) != 0 ) {
719 os << LogIO::WARN << "Error while reading data IPINT." << LogIO::POST ;
720 return -1 ;
721 }
722 // DEBUG
723// nro_debug_output( "IPINT", ARYNM, IPINT ) ;
724 //
725 if ( readColumn( MULTN, "MULTN", sameEndian ) != 0 ) {
726 os << LogIO::WARN << "Error while reading data MULTN." << LogIO::POST ;
727 return -1 ;
728 }
729 // DEBUG
730// nro_debug_output( "MULTN", ARYNM, MULTN ) ;
731 //
732 if ( readColumn( MLTSCF, "MLTSCF", sameEndian ) != 0 ) {
733 os << LogIO::WARN << "Error while reading data MLTSCF." << LogIO::POST ;
734 return -1 ;
735 }
736 // DEBUG
737// nro_debug_output( "MLTSCF", ARYNM, MLTSCF ) ;
738 //
739 if ( readColumn( LAGWIND, "LAGWIN" ) != 0 ) {
740 os << LogIO::WARN << "Error while reading data LAGWIND." << LogIO::POST ;
741 return -1 ;
742 }
743 // DEBUG
744// nro_debug_output( "LAGWIND", ARYNM, LAGWIND ) ;
745 //
746 if ( readColumn( BEBW, "BEBW", sameEndian ) != 0 ) {
747 os << LogIO::WARN << "Error while reading data BEBW." << LogIO::POST ;
748 return -1 ;
749 }
750 // DEBUG
751// nro_debug_output( "BEBW", ARYNM, BEBW ) ;
752 //
753 if ( readColumn( BERES, "BERES", sameEndian ) != 0 ) {
754 os << LogIO::WARN << "Error while reading data BERES." << LogIO::POST ;
755 return -1 ;
756 }
757 // DEBUG
758// nro_debug_output( "BERES", ARYNM, BERES ) ;
759 //
760 if ( readColumn( CHWID, "CHWID", sameEndian ) != 0 ) {
761 os << LogIO::WARN << "Error while reading data CHWID." << LogIO::POST ;
762 return -1 ;
763 }
764 // DEBUG
765// nro_debug_output( "CHWID", ARYNM, CHWID ) ;
766 //
767 if ( readARRY() != 0 ) {
768 os << LogIO::WARN << "Error while reading data ARRY." << LogIO::POST ;
769 return -1 ;
770 }
771 // DEBUG
772// nro_debug_output( "ARRY", NRO_FITS_ARYMAX, ARRY ) ;
773 //
774 if ( readColumn( NFCAL, "NFCAL", sameEndian ) != 0 ) {
775 os << LogIO::WARN << "Error while reading data NFCAL." << LogIO::POST ;
776 return -1 ;
777 }
778 // DEBUG
779// nro_debug_output( "NFCAL", ARYNM, NFCAL ) ;
780 //
781 if ( readColumn( F0CAL, "F0CAL", sameEndian ) != 0 ) {
782 os << LogIO::WARN << "Error while reading data F0CAL." << LogIO::POST ;
783 return -1 ;
784 }
785 // DEBUG
786// nro_debug_output( "F0CAL", ARYNM, F0CAL ) ;
787 //
788 for ( int i= 0 ; i < 10 ; i++) {
789 vector<double> vv( ARYNM, 0 ) ;
790 if ( readColumn( vv, "FQCAL", sameEndian, i ) != 0 ) {
791 os << LogIO::WARN << "Error while reading data FQCAL." << LogIO::POST ;
792 return -1 ;
793 }
794 for ( int j = 0 ; j < ARYNM ; j++ ) {
795 FQCAL[j][i] = vv[j] ;
796 }
797 }
798 // DEBUG
799// nro_debug_output( "FQCAL", ARYNM, 10, FQCAL ) ;
800 //
801 for ( int i= 0 ; i < 10 ; i++) {
802 vector<double> vv( ARYNM, 0 ) ;
803 if ( readColumn( vv, "CHCAL", sameEndian, i ) != 0 ) {
804 os << LogIO::WARN << "Error while reading data CHCAL." << LogIO::POST ;
805 return -1 ;
806 }
807 for ( int j = 0 ; j < ARYNM ; j++ ) {
808 CHCAL[j][i] = vv[j] ;
809 }
810 }
811 // DEBUG
812// nro_debug_output( "CHCAL", ARYNM, 10, CHCAL ) ;
813 //
814 for ( int i= 0 ; i < 10 ; i++) {
815 vector<double> vv( ARYNM, 0 ) ;
816 if ( readColumn( vv, "CWCAL", sameEndian, i ) != 0 ) {
817 os << LogIO::WARN << "Error while reading data CWCAL." << LogIO::POST ;
818 return -1 ;
819 }
820 for ( int j = 0 ; j < ARYNM ; j++ ) {
821 CWCAL[j][i] = vv[j] ;
822 }
823 }
824 // DEBUG
825// nro_debug_output( "CWCAL", ARYNM, 10, CWCAL ) ;
826 //
827 if ( readHeader( SCNLEN, "NAXIS1", sameEndian ) != 0 ) {
828 os << LogIO::WARN << "Error while reading data SCNLEN." << LogIO::POST ;
829 return -1 ;
830 }
831 // DEBUG
832 //cout << "SCNLEN = " << SCNLEN << endl ;
833 //
834 if ( readHeader( SBIND, "SBIND", sameEndian ) != 0 ) {
835 os << LogIO::NORMAL << "SBIND set to 0." << LogIO::POST ;
836 SBIND = 0 ;
837 }
838 // DEBUG
839 //cout << "SBIND = " << SBIND << endl ;
840 //
841 if ( readHeader( IBIT, "IBIT", sameEndian ) != 0 ) {
842 os << LogIO::NORMAL << "IBIT set to 8." << LogIO::POST ;
843 IBIT = 8 ; // 8 bit? 12 bit?
844 }
845 // DEBUG
846 //cout << "IBIT = " << IBIT << endl ;
847 //
848 if ( readHeader( SITE, "TELESCOP" ) != 0 ) {
849 os << LogIO::WARN << "Error while reading data SITE." << LogIO::POST ;
850 return -1 ;
851 }
852 // DEBUG
853 //cout << "SITE = \'" << SITE << "\'" << endl ;
854 //
855 if ( readColumn( DSBFC, "DSBFC", sameEndian ) != 0 ) {
856 os << LogIO::NORMAL << "All DSBFC elements set to 1." << LogIO::POST ;
857 for ( int i = 0 ; i < ARYNM ; i++ )
858 DSBFC[i] = 1.0 ;
859 }
860 // DEBUG
861// nro_debug_output( "DSBFC", ARYNM, DSBFC ) ;
862 //
863
864 show() ;
865
866 return 0 ;
867}
868
869int NROFITSDataset::fillRecord( int i )
870{
871 LogIO os( LogOrigin( "NROFITSDataset", "fillRecord()", WHERE ) ) ;
872
873 int status = 0 ;
874 string str4( 4, ' ' ) ;
875 string str8( 8, ' ' ) ;
876 string str24( 24, ' ' ) ;
877
878 strcpy( record_->LSFIL, str4.c_str() ) ;
879 status = readTable( record_->LSFIL, "LSFIL", 4, i ) ;
880 if ( status ) {
881 os << LogIO::WARN << "Error while reading LSFIL." << LogIO::POST ;
882 return status ;
883 }
884 // DEBUG
885 //cout << "LSFIL(" << i << ") = " << record_->LSFIL << endl ;
886 //
887 status = readTable( record_->ISCAN, "ISCN", same_, i ) ;
888 if ( status ) {
889 os << LogIO::WARN << "Error while reading ISCAN." << LogIO::POST ;
890 return status ;
891 }
892 // DEBUG
893 //cout << "ISCAN(" << i << ") = " << record_->ISCAN << endl ;
894 //
895 vector<int> itmp( 6, 0 ) ;
896 status = readTable( itmp, "LAVST", same_, i ) ;
897 if ( status ) {
898 os << LogIO::WARN << "Error while reading LAVST." << LogIO::POST ;
899 return status ;
900 }
901 else {
902 sprintf( record_->LAVST, "%4d%02d%02d%02d%02d%02d.000", itmp[0], itmp[1], itmp[2], itmp[3], itmp[4], itmp[5] ) ;
903 }
904 // DEBUG
905 //cout << "LAVST(" << i << ") = " << record_->LAVST << endl ;
906 //
907 strcpy( record_->SCANTP, str8.c_str() ) ;
908 status = readTable( record_->SCANTP, "SCNTP", strlen(record_->SCANTP), i ) ;
909 if ( status ) {
910 os << LogIO::WARN << "Error while reading SCANTP." << LogIO::POST ;
911 return status ;
912 }
913 // DEBUG
914 //cout << "SCANTP(" << i << ") = " << record_->SCANTP << endl ;
915 //
916 char *name1 = "" ;
917 char *name2 = "" ;
918 if ( SCNCD == 0 ) {
919 name1 = "DRA" ;
920 name2 = "DDEC" ;
921 }
922 else if ( SCNCD == 1 ) {
923 name1 = "DGL" ;
924 name2 = "DGB" ;
925 }
926 else {
927 name1 = "DAZ" ;
928 name2 = "DEL" ;
929 }
930 status = readTable( record_->DSCX, name1, same_, i ) ;
931 if ( status ) {
932 os << LogIO::WARN << "Error while reading DSCX." << LogIO::POST ;
933 return status ;
934 }
935 // DEBUG
936 //cout << "DSCX(" << i << ") = " << record_->DSCX << endl ;
937 //
938 status = readTable( record_->DSCY, name2, same_, i ) ;
939 if ( status ) {
940 os << LogIO::WARN << "Error while reading DSCY." << LogIO::POST ;
941 return status ;
942 }
943 // DEBUG
944 //cout << "DSCY(" << i << ") = " << record_->DSCY << endl ;
945 //
946 if ( SCNCD == 0 ) {
947 name1 = "RA" ;
948 name2 = "DEC" ;
949 }
950 else if ( SCNCD == 1 ) {
951 name1 = "GL" ;
952 name2 = "GB" ;
953 }
954 else {
955 name1 = "AZ" ;
956 name2 = "EL" ;
957 }
958 status = readTable( record_->SCX, name1, same_, i ) ;
959 if ( status ) {
960 os << LogIO::WARN << "Error while reading SCX." << LogIO::POST ;
961 return status ;
962 }
963 // DEBUG
964 //cout << "SCX(" << i << ") = " << record_->SCX << endl ;
965 //
966 status = readTable( record_->SCY, name2, same_, i ) ;
967 if ( status ) {
968 os << LogIO::WARN << "Error while reading SCY." << LogIO::POST ;
969 return status ;
970 }
971 // DEBUG
972 //cout << "SCY(" << i << ") = " << record_->SCY << endl ;
973 //
974 status = readTable( record_->PAZ, "PAZ", same_, i ) ;
975 if ( status ) {
976 os << LogIO::WARN << "Error while reading PAZ." << LogIO::POST ;
977 return status ;
978 }
979 // DEBUG
980 //cout << "PAZ(" << i << ") = " << record_->PAZ << endl ;
981 //
982 status = readTable( record_->PEL, "PEL", same_, i ) ;
983 if ( status ) {
984 os << LogIO::WARN << "Error while reading PEL." << LogIO::POST ;
985 return status ;
986 }
987 // DEBUG
988 //cout << "PEL(" << i << ") = " << record_->PEL << endl ;
989 //
990 status = readTable( record_->RAZ, "RAZ", same_, i ) ;
991 if ( status ) {
992 os << LogIO::WARN << "Error while reading RAZ." << LogIO::POST ;
993 return status ;
994 }
995 // DEBUG
996 //cout << "RAZ(" << i << ") = " << record_->RAZ << endl ;
997 //
998 status = readTable( record_->REL, "REL", same_, i ) ;
999 if ( status ) {
1000 os << LogIO::WARN << "Error while reading REL." << LogIO::POST ;
1001 return status ;
1002 }
1003 // DEBUG
1004 //cout << "REL(" << i << ") = " << record_->REL << endl ;
1005 //
1006 status = readTable( record_->XX, "XX", same_, i ) ;
1007 if ( status ) {
1008 os << LogIO::WARN << "Error while reading XX." << LogIO::POST ;
1009 return status ;
1010 }
1011 // DEBUG
1012 //cout << "XX(" << i << ") = " << record_->XX << endl ;
1013 //
1014 status = readTable( record_->YY, "YY", same_, i ) ;
1015 if ( status ) {
1016 os << LogIO::WARN << "Error while reading YY." << LogIO::POST ;
1017 return status ;
1018 }
1019 // DEBUG
1020 //cout << "YY(" << i << ") = " << record_->YY << endl ;
1021 //
1022 strcpy( record_->ARRYT, str4.c_str() ) ;
1023 status = readTable( record_->ARRYT, "ARRYT", strlen(record_->ARRYT), i ) ;
1024 for (int j = strlen(record_->ARRYT)-1 ; j >= 0 ; j--) {
1025 if (record_->ARRYT[j] == ' ') record_->ARRYT[j] = '\0';
1026 else break;
1027 }
1028 if ( status ) {
1029 os << LogIO::WARN << "Error while reading ARRYT." << LogIO::POST ;
1030 return status ;
1031 }
1032 // DEBUG
1033 //cout << "ARRYT(" << i << ") = " << record_->ARRYT << endl ;
1034 //
1035 double dtmp ;
1036 status = readTable( dtmp, "TEMP", same_, i ) ;
1037 if ( status ) {
1038 os << LogIO::WARN << "Error while reading TEMP." << LogIO::POST ;
1039 return status ;
1040 }
1041 else {
1042 record_->TEMP = dtmp ;
1043 }
1044 // DEBUG
1045 //cout << "TEMP(" << i << ") = " << record_->TEMP << endl ;
1046 //
1047 status = readTable( dtmp, "PATM", same_, i ) ;
1048 if ( status ) {
1049 os << LogIO::WARN << "Error while reading PATM." << LogIO::POST ;
1050 return status ;
1051 }
1052 else {
1053 record_->PATM = dtmp ;
1054 }
1055 // DEBUG
1056 //cout << "PATM(" << i << ") = " << record_->PATM << endl ;
1057 //
1058 status = readTable( dtmp, "PH2O", same_, i ) ;
1059 if ( status ) {
1060 os << LogIO::WARN << "Error while reading PH2O." << LogIO::POST ;
1061 return status ;
1062 }
1063 else {
1064 record_->PH2O = dtmp ;
1065 }
1066 // DEBUG
1067 //cout << "PH2O(" << i << ") = " << record_->PH2O << endl ;
1068 //
1069 status = readTable( dtmp, "VWIND", same_, i ) ;
1070 if ( status ) {
1071 os << LogIO::WARN << "Error while reading VWIND." << LogIO::POST ;
1072 return status ;
1073 }
1074 else {
1075 record_->VWIND = dtmp ;
1076 }
1077 // DEBUG
1078 //cout << "VWIND(" << i << ") = " << record_->VWIND << endl ;
1079 //
1080 status = readTable( dtmp, "DWIND", same_, i ) ;
1081 if ( status ) {
1082 os << LogIO::WARN << "Error while reading DWIND." << LogIO::POST ;
1083 return status ;
1084 }
1085 else {
1086 record_->DWIND = dtmp ;
1087 }
1088 // DEBUG
1089 //cout << "DWIND(" << i << ") = " << record_->DWIND << endl ;
1090 //
1091 status = readTable( dtmp, "TAU", same_, i ) ;
1092 if ( status ) {
1093 os << LogIO::WARN << "Error while reading TAU." << LogIO::POST ;
1094 return status ;
1095 }
1096 else {
1097 record_->TAU = dtmp ;
1098 }
1099 // DEBUG
1100 //cout << "TAU(" << i << ") = " << record_->TAU << endl ;
1101 //
1102 status = readTable( dtmp, "TSYS", same_, i ) ;
1103 if ( status ) {
1104 os << LogIO::WARN << "Error while reading TSYS." << LogIO::POST ;
1105 return status ;
1106 }
1107 else {
1108 record_->TSYS = dtmp ;
1109 }
1110 // DEBUG
1111 //cout << "TSYS(" << i << ") = " << record_->TSYS << endl ;
1112 //
1113 status = readTable( dtmp, "BATM", same_, i ) ;
1114 if ( status ) {
1115 os << LogIO::WARN << "Error while reading BATM." << LogIO::POST ;
1116 return status ;
1117 }
1118 else {
1119 record_->BATM = dtmp ;
1120 }
1121 // DEBUG
1122 //cout << "BATM(" << i << ") = " << record_->BATM << endl ;
1123 //
1124 status = readTable( record_->VRAD, "VRAD", same_, i ) ;
1125 if ( status ) {
1126 os << LogIO::WARN << "Error while reading TEMP." << LogIO::POST ;
1127 return status ;
1128 }
1129 // DEBUG
1130 //cout << "VRAD(" << i << ") = " << record_->VRAD << endl ;
1131 //
1132 status = readTable( record_->FREQ0, "FRQ0", same_, i ) ;
1133 if ( status ) {
1134 os << LogIO::WARN << "Error while reading FREQ0." << LogIO::POST ;
1135 return status ;
1136 }
1137 // DEBUG
1138 //cout << "FREQ0(" << i << ") = " << record_->FREQ0 << endl ;
1139 //
1140 status = readTable( record_->FQTRK, "FQTRK", same_, i ) ;
1141 if ( status ) {
1142 os << LogIO::WARN << "Error while reading FQTRK." << LogIO::POST ;
1143 return status ;
1144 }
1145 // DEBUG
1146 //cout << "FQTRK(" << i << ") = " << record_->FQTRK << endl ;
1147 //
1148 status = readTable( record_->FQIF1, "FQIF1", same_, i ) ;
1149 if ( status ) {
1150 os << LogIO::WARN << "Error while reading FQIF1." << LogIO::POST ;
1151 return status ;
1152 }
1153 // DEBUG
1154 //cout << "FQIF1(" << i << ") = " << record_->FQIF1 << endl ;
1155 //
1156 status = readTable( record_->ALCV, "ALCV", same_, i ) ;
1157 if ( status ) {
1158 os << LogIO::WARN << "Error while reading ALCV." << LogIO::POST ;
1159 return status ;
1160 }
1161 // DEBUG
1162 //cout << "ALCV(" << i << ") = " << record_->ALCV << endl ;
1163 //
1164 record_->IDMY0 = 0 ;
1165 status = readTable( record_->DPFRQ, "DPFRQ", same_, i ) ;
1166 if ( status ) {
1167 //os << LogIO::WARN << "Error DPFRQ set to 0." << LogIO::POST ;
1168 record_->DPFRQ = 0.0 ;
1169 }
1170 // DEBUG
1171 //cout << "DPFRQ(" << i << ") = " << record_->DPFRQ << endl ;
1172 //
1173 status = readTable( record_->SFCTR, "SFCTR", same_, i ) ;
1174 if ( status ) {
1175 os << LogIO::WARN << "Error while reading SFCTR." << LogIO::POST ;
1176 return status ;
1177 }
1178 // DEBUG
1179 //cout << "SFCTR(" << i << ") = " << record_->SFCTR << endl ;
1180 //
1181 status = readTable( record_->ADOFF, "ADOFF", same_, i ) ;
1182 if ( status ) {
1183 os << LogIO::WARN << "Error while reading ADOFF." << LogIO::POST ;
1184 return status ;
1185 }
1186 // DEBUG
1187 //cout << "ADOFF(" << i << ") = " << record_->ADOFF << endl ;
1188 //
1189 //status = readTable( record_->JDATA, "LDATA", same_, i ) ;
1190 status = readTable( JDATA, "LDATA", same_, i ) ;
1191 if ( status ) {
1192 os << LogIO::WARN << "Error while reading JDATA." << LogIO::POST ;
1193 return status ;
1194 }
1195 // DEBUG
1196// for ( int i = 0 ; i < chmax_ ; i++ )
1197// //cout << "JDATA[" << i << "] = " << JDATA[i] << " " ;
1198// //cout << endl ;
1199 //
1200
1201
1202 // Update IPTIM since it depends on the row for NROFITS
1203 int integ ;
1204 status = readTable( integ, "INTEG", same_, i ) ;
1205 if ( !status ) {
1206 IPTIM = (double)integ ;
1207 }
1208
1209 return status ;
1210}
1211
1212vector< vector<double> > NROFITSDataset::getSpectrum()
1213{
1214 vector< vector<double> > spec;
1215
1216 for ( int i = 0 ; i < rowNum_ ; i++ ) {
1217 spec.push_back( getSpectrum( i ) ) ;
1218 }
1219
1220 return spec ;
1221}
1222
1223vector<double> NROFITSDataset::getSpectrum( int i )
1224{
1225 vector<double> spec( chmax_, 0.0 ) ;
1226 vector<double> specout( chmax_, 0.0 ) ;
1227 NRODataRecord *record = getRecord( i ) ;
1228 double scale = record->SFCTR ;
1229 double offset = record->ADOFF ;
1230 double dscale = MLTSCF[getIndex( i )] ;
1231 //vector<int> ispec = record->JDATA ;
1232 vector<int> ispec = JDATA ;
1233 for ( int ii = 0 ; ii < chmax_ ; ii++ ) {
1234 spec[ii] = (double)( ispec[ii] * scale + offset ) * dscale ;
1235 }
1236
1237 // for AOS, re-gridding is needed
1238 if ( strncmp( record->ARRYT, "H", 1 ) == 0
1239 || strncmp( record->ARRYT, "W", 1 ) == 0
1240 || strncmp( record->ARRYT, "U", 1 ) == 0 ) {
1241
1242 string arryt = string( record->ARRYT ) ;
1243 uInt ib = getArrayId( arryt ) ;
1244 vector<double> fqcal = getFQCAL()[ib] ;
1245 vector<double> chcal = getCHCAL()[ib] ;
1246 int ncal = getNFCAL()[ib] ;
1247
1248// //cout << "NRODataset::getFrequencies() ncal = " << ncal << endl ;
1249 while ( ncal < (int)fqcal.size() ) {
1250 fqcal.pop_back() ;
1251 chcal.pop_back() ;
1252 }
1253 Vector<Double> xin( chcal ) ;
1254 Vector<Double> yin( fqcal ) ;
1255 int nchan = getNUMCH() ;
1256 Vector<Double> xout( nchan ) ;
1257 indgen( xout ) ;
1258 Vector<Double> yout ;
1259 InterpolateArray1D<Double, Double>::interpolate( yout, xout, xin, yin, InterpolateArray1D<Double,Double>::cubic ) ;
1260 // debug
1261 //cout << "i=" << i << endl ;
1262// if ( i == 16 ) {
1263// ofstream ofs0( "spgrid0.dat" ) ;
1264// for ( int ii = 0 ; ii < getNUMCH() ; ii++ )
1265// ofs0 << xout[ii] << "," ;
1266// ofs0 << endl ;
1267// for ( int ii = 0 ; ii < getNUMCH() ; ii++ )
1268// ofs0 << setprecision(16) << record->FREQ0+yout[ii] << "," ;
1269// ofs0 << endl ;
1270// ofs0.close() ;
1271// }
1272 //
1273 Vector<Double> z( nchan ) ;
1274 Double bw = abs( yout[nchan-1] - yout[0] ) ;
1275 bw += 0.5 * abs( yout[nchan-1] - yout[nchan-2] + yout[1] - yout[0] ) ;
1276 Double dz = bw / (Double)nchan ;
1277 if ( yout[0] > yout[nchan-1] )
1278 dz = - dz ;
1279 z[0] = yout[0] - 0.5 * ( yout[1] - yout[0] - dz ) ;
1280 for ( int ii = 1 ; ii < nchan ; ii++ )
1281 z[ii] = z[ii-1] + dz ;
1282 Vector<Double> zi( nchan+1 ) ;
1283 Vector<Double> yi( nchan+1 ) ;
1284 zi[0] = z[0] - 0.5 * dz ;
1285 zi[1] = z[0] + 0.5 * dz ;
1286 yi[0] = yout[0] - 0.5 * ( yout[1] - yout[0] ) ;
1287 yi[1] = yout[0] + 0.5 * ( yout[1] - yout[0] ) ;
1288 for ( int ii = 2 ; ii < nchan ; ii++ ) {
1289 zi[ii] = zi[ii-1] + dz ;
1290 yi[ii] = yi[ii-1] + 0.5 * ( yout[ii] - yout[ii-2] ) ;
1291 }
1292 zi[nchan] = z[nchan-1] + 0.5 * dz ;
1293 yi[nchan] = yout[nchan-1] + 0.5 * ( yout[nchan-1] - yout[nchan-2] ) ;
1294// // debug
1295// //cout << "nchan=" << nchan << ", bw=" << bw << ", dz=" << dz
1296// << ", y[1]-y[0]=" << yout[1]-yout[0] << endl ;
1297// //cout << "z: " << z[0] << " - " << z[nchan-1]
1298// << ", zi: " << zi[0] << " - " << zi[nchan] << endl ;
1299// //cout << "y: " << yout[0] << " - " << yout[nchan-1]
1300// << ", yi: " << yi[0] << " - " << yi[nchan] << endl ;
1301// ofstream ofs1( "spgrid1.dat", ios::out | ios::app ) ;
1302// ofs1 << "spid=" << i << ", ARRYT=" << record->ARRYT << endl ;
1303// ofs1 << "z[0]=" << z[0] << ", yout[0]=" << yout[0] << endl ;
1304// for ( int ii = 1; ii < nchan ; ii++ ) {
1305// ofs1 << " dz=" << z[ii]-z[ii-1] << ", dy=" << yout[ii]-yout[ii-1] << endl ;
1306// ofs1 << "z[" << ii << "]=" << z[ii] << ", yout[" << ii << "]=" << yout[ii] << endl ;
1307// }
1308// ofs1.close() ;
1309// ofstream ofs2( "spgrid2.dat", ios::out | ios::app ) ;
1310// ofs2 << "spid=" << i << ", ARRYT=" << record->ARRYT << endl ;
1311// for ( int ii = 0 ; ii < nchan+1 ; ii++ )
1312// ofs2 << "zi[" << ii << "]=" << zi[ii] << ", yi[" << ii << "]=" << yi[ii] << endl ;
1313// ofs2.close() ;
1314// //
1315 int ichan = 0 ;
1316 double wsum = 0.0 ;
1317 // debug
1318 //ofstream ofs3( "spgrid3.dat", ios::out | ios::app ) ;
1319 if ( dz > 0.0 ) {
1320 for ( int ii = 0 ; ii < nchan ; ii++ ) {
1321 double zl = zi[ii] ;
1322 double zr = zi[ii+1] ;
1323 for ( int j = ichan ; j < nchan ; j++ ) {
1324 double yl = yi[j] ;
1325 double yr = yi[j+1] ;
1326 if ( yl <= zl ) {
1327 if ( yr <= zl ) {
1328 continue ;
1329 }
1330 else if ( yr <= zr ) {
1331 specout[ii] += spec[j] * ( yr - zl ) ;
1332 wsum += ( yr - zl ) ;
1333 }
1334 else {
1335 specout[ii] += spec[j] * dz ;
1336 wsum += dz ;
1337 ichan = j ;
1338 break ;
1339 }
1340 }
1341 else if ( yl < zr ) {
1342 if ( yr <= zr ) {
1343 specout[ii] += spec[j] * ( yr - yl ) ;
1344 wsum += ( yr - yl ) ;
1345 }
1346 else {
1347 specout[ii] += spec[j] * ( zr - yl ) ;
1348 wsum += ( zr - yl ) ;
1349 ichan = j ;
1350 break ;
1351 }
1352 }
1353 else {
1354 ichan = j - 1 ;
1355 break ;
1356 }
1357 }
1358 specout[ii] /= wsum ;
1359 wsum = 0.0 ;
1360 }
1361 }
1362 else if ( dz < 0.0 ) {
1363 for ( int ii = 0 ; ii < nchan ; ii++ ) {
1364 double zl = zi[ii] ;
1365 double zr = zi[ii+1] ;
1366 for ( int j = ichan ; j < nchan ; j++ ) {
1367 double yl = yi[j] ;
1368 double yr = yi[j+1] ;
1369 if ( yl >= zl ) {
1370 if ( yr >= zl ) {
1371 continue ;
1372 }
1373 else if ( yr >= zr ) {
1374 specout[ii] += spec[j] * abs( yr - zl ) ;
1375 wsum += abs( yr - zl ) ;
1376 }
1377 else {
1378 specout[ii] += spec[j] * abs( dz ) ;
1379 wsum += abs( dz ) ;
1380 ichan = j ;
1381 break ;
1382 }
1383 }
1384 else if ( yl > zr ) {
1385 if ( yr >= zr ) {
1386 specout[ii] += spec[j] * abs( yr - yl ) ;
1387 wsum += abs( yr - yl ) ;
1388 }
1389 else {
1390 specout[ii] += spec[j] * abs( zr - yl ) ;
1391 wsum += abs( zr - yl ) ;
1392 ichan = j ;
1393 break ;
1394 }
1395 }
1396 else {
1397 ichan = j - 1 ;
1398 break ;
1399 }
1400 }
1401 specout[ii] /= wsum ;
1402 wsum = 0.0 ;
1403 }
1404 }
1405 //specout = spec ;
1406 //ofs3.close() ;
1407 }
1408 else {
1409 specout = spec ;
1410 }
1411
1412 return specout ;
1413}
1414
1415int NROFITSDataset::getIndex( int irow )
1416{
1417 NRODataRecord *record = getRecord( irow ) ;
1418 string str = record->ARRYT ;
1419 string::size_type pos = str.find( " " ) ;
1420 if ( pos != string::npos )
1421 str = str.substr( 0, pos ) ;
1422 int index = -1 ;
1423 for ( int i = 0 ; i < ARYNM ; i++ ) {
1424 if ( str.compare( 0, 3, ARYTP[i] ) == 0 ) {
1425 index = i ;
1426 break ;
1427 }
1428 }
1429 return index ;
1430}
1431
1432double NROFITSDataset::radRA( string ra )
1433{
1434 int pos1 = ra.find( ':' ) ;
1435 int pos2 ;
1436 string ch = ra.substr( 0, pos1 ) ;
1437 //cout << "ch = \'" << ch << "\'" << endl ;
1438 pos2 = pos1 + 1 ;
1439 pos1 = ra.find( ':', pos2 ) ;
1440 string cm = ra.substr( pos2, pos1 - pos2 ) ;
1441 //cout << "cm = \'" << cm << "\'" << endl ;
1442 pos2 = pos1 + 1 ;
1443 pos1 = ra.size() ;
1444 string cs = ra.substr( pos2, pos1 - pos2 ) ;
1445 //cout << "cs = \'" << cs << "\'" << endl ;
1446 double h ;
1447 if ( ra[0] != '-' )
1448 h = atof( ch.c_str() ) + atof( cm.c_str() ) / 60.0 + atof( cs.c_str() ) / 3600.0 ;
1449 else
1450 h = atof( ch.c_str() ) - atof( cm.c_str() ) / 60.0 - atof( cs.c_str() ) / 3600.0 ;
1451 double rra = h * M_PI / 12.0 ;
1452 return rra ;
1453}
1454
1455double NROFITSDataset::radDEC( string dec )
1456{
1457 int pos1 = dec.find( ':' ) ;
1458 int pos2 ;
1459 string cd = dec.substr( 0, pos1 ) ;
1460 //cout << "cd = \'" << cd << "\'" << endl ;
1461 pos2 = pos1 + 1 ;
1462 pos1 = dec.find( ':', pos2 ) ;
1463 string cm = dec.substr( pos2, pos1 - pos2 ) ;
1464 //cout << "cm = \'" << cm << "\'" << endl ;
1465 pos2 = pos1 + 1 ;
1466 pos1 = dec.size() ;
1467 string cs = dec.substr( pos2, pos1 - pos2 ) ;
1468 //cout << "cs = \'" << cs << "\'" << endl ;
1469 double h ;
1470 if ( dec[0] != '-' )
1471 h = atof( cd.c_str() ) + atof( cm.c_str() ) / 60.0 + atof( cs.c_str() ) / 3600.0 ;
1472 else
1473 h = atof( cd.c_str() ) - atof( cm.c_str() ) / 60.0 - atof( cs.c_str() ) / 3600.0 ;
1474 double rdec = h * M_PI / 180.0 ;
1475 return rdec ;
1476}
1477
1478void NROFITSDataset::getField()
1479{
1480 for ( int i = 0 ; i < numField_ ; i++ ) {
1481 char key1[9] ;
1482 char key2[9] ;
1483 char key3[9] ;
1484 if ( i < 9 ) {
1485 sprintf( key1, "TFORM%d ", i+1 ) ;
1486 sprintf( key2, "TTYPE%d ", i+1 ) ;
1487 sprintf( key3, "TUNIT%d ", i+1 ) ;
1488 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1489 }
1490 else if ( i < 99 ) {
1491 sprintf( key1, "TFORM%2d ", i+1 ) ;
1492 sprintf( key2, "TTYPE%2d ", i+1 ) ;
1493 sprintf( key3, "TUNIT%2d ", i+1 ) ;
1494 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1495 }
1496 else {
1497 sprintf( key1, "TFORM%3d", i+1 ) ;
1498 sprintf( key2, "TTYPE%3d", i+1 ) ;
1499 sprintf( key3, "TUNIT%3d", i+1 ) ;
1500 //cout << "key1 = " << key1 << ", key2 = " << key2 << ", key3 = " << key3 << endl ;
1501 }
1502 //char tmp[9] ;
1503 string tmp ;
1504 //strcpy( tmp, " " ) ;
1505 if ( readHeader( tmp, key1 ) != 0 ) {
1506 cerr << "Error while reading field keyword for scan header." << endl ;
1507 return ;
1508 }
1509 //forms_[i] = string( tmp ) ;
1510 forms_[i] = tmp ;
1511 string::size_type spos = forms_[i].find( " " ) ;
1512 if ( spos != string::npos )
1513 forms_[i] = forms_[i].substr( 0, spos ) ;
1514 //strcpy( tmp, " " ) ;
1515 if ( readHeader( tmp, key2 ) != 0 ) {
1516 cerr << "Error while reading field type for scan header." << endl ;
1517 return ;
1518 }
1519 //names_[i] = string( tmp ) ;
1520 names_[i] = tmp ;
1521 spos = names_[i].find( " " ) ;
1522 if ( spos != string::npos )
1523 names_[i] = names_[i].substr( 0, spos ) ;
1524 //strcpy( tmp, " " ) ;
1525 if ( forms_[i].find( "A" ) != string::npos ) {
1526 //cout << "skip to get unit: name = " << forms_[i] << endl ;
1527 //strcpy( tmp, "none " ) ;
1528 tmp = "none" ;
1529 }
1530 else {
1531 //cout << "get unit: name = " << forms_[i] << endl ;
1532 if ( readHeader( tmp, key3 ) != 0 ) {
1533 //strcpy( tmp, "none " ) ;
1534 tmp = "none" ;
1535 }
1536 }
1537 //units_[i] = string( tmp ) ;
1538 units_[i] = tmp ;
1539 spos = units_[i].find( " " ) ;
1540 if ( spos != string::npos )
1541 units_[i] = units_[i].substr( 0, spos ) ;
1542 //cout << "i = " << i << ": name=" << forms_[i] << " type=" << names_[i] << " unit=" << units_[i] << endl ;
1543 }
1544}
1545
1546void NROFITSDataset::fillARYTP()
1547{
1548 string arry ;
1549 int count = 0 ;
1550 string arry1 ;
1551 string arry2 ;
1552 string arry3 ;
1553 string arry4 ;
1554 char arytp[4];
1555 if ( readHeader( arry, "ARRY1" ) == 0 )
1556 arry1 = arry ;
1557 else
1558 arry1 = "00000000000000000000" ;
1559 for ( int i = 0 ; i < 20 ; i++ ) {
1560 if ( arry1[i] == '1' ) {
1561 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1562 sprintf( arytp, "H%d", i+1 ) ;
1563 ARYTP[count++] = string( arytp ) ;
1564 }
1565 }
1566 if ( readHeader( arry, "ARRY2" ) == 0 )
1567 arry2 = arry ;
1568 else
1569 arry2 = "00000000000000000000" ;
1570 for ( int i = 0 ; i < 10 ; i++ ) {
1571 if ( arry2[i] == '1' ) {
1572 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1573 sprintf( arytp, "W%d", i+1 ) ;
1574 ARYTP[count++] = string( arytp ) ;
1575 }
1576 }
1577 for ( int i = 10 ; i < 15 ; i++ ) {
1578 if ( arry2[i] == '1' ) {
1579 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1580 sprintf( arytp, "U%d", i-9 ) ;
1581 ARYTP[count++] = string( arytp ) ;
1582 }
1583 }
1584 for ( int i = 15 ; i < 20 ; i++ ) {
1585 if ( arry2[i] == '1' ) {
1586 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1587 sprintf( arytp, "X%d", i-14 ) ;
1588 ARYTP[count++] = string( arytp ) ;
1589 }
1590 }
1591 if ( readHeader( arry, "ARRY3" ) == 0 )
1592 arry3 = arry ;
1593 else
1594 arry3 = "00000000000000000000" ;
1595 for ( int i = 0 ; i < 20 ; i++ ) {
1596 if ( arry3[i] == '1' ) {
1597 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1598 sprintf( arytp, "A%d", i+1 ) ;
1599 ARYTP[count++] = string( arytp ) ;
1600 }
1601 }
1602 if ( readHeader( arry, "ARRY4" ) == 0 )
1603 arry4 = arry ;
1604 else
1605 arry4 = "00000000000000000000" ;
1606 for ( int i = 0 ; i < 20 ; i++ ) {
1607 if ( arry4[i] == '1' ) {
1608 for (int j = 0 ; j < 4 ; j++) arytp[j] = '\0';
1609 sprintf( arytp, "A%d", i+21 ) ;
1610 ARYTP[count++] = string( arytp ) ;
1611 }
1612 }
1613 //nro_debug_output("ARYTP", ARYTP.size(), ARYTP);
1614}
1615
1616int NROFITSDataset::readARRY()
1617{
1618 LogIO os( LogOrigin( "NROFITSDataset", "readARRY()", WHERE ) ) ;
1619
1620 string arry1 ;
1621 string arry2 ;
1622 string arry3 ;
1623 string arry4 ;
1624 int status = readHeader( arry1, "ARRY1" ) ;
1625 if ( status ) {
1626 os << LogIO::SEVERE << "Error while reading ARRY1" << LogIO::POST ;
1627 return status ;
1628 }
1629 status = readHeader( arry2, "ARRY2" ) ;
1630 if ( status ) {
1631 os << LogIO::SEVERE << "Error while reading ARRY2" << LogIO::POST ;
1632 return status ;
1633 }
1634 status = readHeader( arry3, "ARRY3" ) ;
1635 if ( status ) {
1636 os << LogIO::SEVERE << "Error while reading ARRY3" << LogIO::POST ;
1637 return status ;
1638 }
1639 status = readHeader( arry4, "ARRY4" ) ;
1640 if ( status ) {
1641 os << LogIO::SEVERE << "Error while reading ARRY4" << LogIO::POST ;
1642 return status ;
1643 }
1644 int index = 0 ;
1645 for ( int i = 0 ; i < 20 ; i++ ) {
1646 // AOSH
1647 if ( arry1[i] == '1' )
1648 ARRY[index] = 1 ;
1649 else
1650 ARRY[index] = 0 ;
1651 // AOSW, AOSU, FX
1652 if ( arry2[i] == '1' )
1653 ARRY[index+20] = 1 ;
1654 else
1655 ARRY[index+20] = 0 ;
1656 // AC45 (1-20)
1657 if ( arry3[i] == '1' )
1658 ARRY[index+40] = 1 ;
1659 else
1660 ARRY[index+40] = 0 ;
1661 // AC45 (21-35)
1662 if ( i < 15 ) {
1663 if ( arry4[i] == '1' )
1664 ARRY[index+60] = 1 ;
1665 else
1666 ARRY[index+60] = 0 ;
1667 }
1668 index++ ;
1669 }
1670 return status ;
1671}
1672
1673void NROFITSDataset::findData()
1674{
1675 LogIO os( LogOrigin( "NROFITSDataset", "findData()", WHERE ) ) ;
1676
1677 // skip header
1678 fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
1679
1680 // get offset
1681 int offset = getOffset( "ARRYT" ) ;
1682 if ( offset == -1 ) {
1683 //cerr << "Error, ARRYT is not found in the name list." << endl ;
1684 return ;
1685 }
1686 //cout << "offset for ARRYT is " << offset << " bytes." << endl ;
1687 fseek( fp_, offset, SEEK_CUR ) ;
1688 int count = 0 ;
1689 int index = 0 ;
1690 while ( count < ARYNM && index < rowNum_ ) {
1691 char ctmp[5] ;
1692 fread( ctmp, 1, 4, fp_ ) ;
1693 ctmp[4] = '\0' ;
1694 //cout << "ctmp = " << ctmp << endl ;
1695 for ( int i = 0 ; i < ARYNM ; i++ ) {
1696 if ( arrayid_[i] != -1 )
1697 continue ;
1698 else if ( strncmp( ctmp, ARYTP[i].c_str(), ARYTP[i].size() ) == 0 ) {
1699 //cout << "matched: i = " << i << ", ARYTP = " << ARYTP[i] << ", ctmp = " << ctmp << endl ;
1700 arrayid_[i] = index ;
1701 count++ ;
1702 }
1703 }
1704 fseek( fp_, scanLen_-4, SEEK_CUR ) ;
1705 index++ ;
1706 }
1707
1708 if ( count != ARYNM ) {
1709 os << LogIO::WARN << "NROFITSDataset::findData() failed to find rows for " ;
1710 for ( int i = 0 ; i < ARYNM ; i++ ) {
1711 if ( arrayid_[i] == -1 ) {
1712 os << LogIO::WARN << ARYTP[i] << " " ;
1713 }
1714 }
1715 os.post() ;
1716 }
1717
1718// for ( int i = 0 ; i < ARYNM ; i++ )
1719// //cout << "arrayid_[" << i << "] = " << arrayid_[i] << endl ;
1720 }
1721
1722int NROFITSDataset::getOffset( char *name )
1723{
1724 int offset = 0 ;
1725 string sname( name ) ;
1726 bool found = false ;
1727 for ( int i = 0 ; i < numField_ ; i++ ) {
1728 // escape if name is found
1729 //cout << "names_[" << i << "] = " << names_[i] << " sname = " << sname << endl ;
1730 if ( names_[i] == sname ) {
1731 found = true ;
1732 break ;
1733 }
1734
1735 // form analysis
1736 string substr1 = forms_[i].substr( 0, forms_[i].size()-1 ) ;
1737 string substr2 = forms_[i].substr( forms_[i].size()-1, 1 ) ;
1738 //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
1739 int o1 = atoi( substr1.c_str() ) ;
1740 int o2 = 0 ;
1741 if ( substr2 == "A" )
1742 o2 = sizeof(char) ;
1743 else if ( substr2 == "J" )
1744 o2 = sizeof(int) ;
1745 else if ( substr2 == "F" )
1746 o2 = sizeof(float) ;
1747 else if ( substr2 == "D" )
1748 o2 = sizeof(double) ;
1749 //cout << "o1 = " << o1 << ", o2 = " << o2 << endl ;
1750 offset += o1 * o2 ;
1751 }
1752
1753 if ( !found )
1754 offset = -1 ;
1755
1756 return offset ;
1757}
1758
1759int NROFITSDataset::getPolarizationNum()
1760{
1761 int npol = 0 ;
1762
1763 vector<char> type( 2 ) ;
1764 type[0] = 'C' ;
1765 type[1] = 'L' ;
1766 vector<double> crot ;
1767 vector<double> lagl ;
1768
1769 for ( int i = 0 ; i < ARYNM ; i++ ) {
1770 if ( POLTP[i][0] == type[0] ) {
1771 // circular polarization
1772 if( count( crot.begin(), crot.end(), POLDR[i] ) != 0 ) {
1773 crot.push_back( POLDR[i] ) ;
1774 npol++ ;
1775 }
1776 }
1777 else if ( POLTP[i][0] == type[1] ) {
1778 // linear polarization
1779 if ( count( lagl.begin(), lagl.end(), POLAN[i] ) != 0 ) {
1780 lagl.push_back( POLAN[i] ) ;
1781 npol++ ;
1782 }
1783 }
1784 }
1785
1786 if ( npol == 0 )
1787 npol = 1 ;
1788
1789
1790 return npol ;
1791}
1792
1793int NROFITSDataset::readHeader( string &v, char *name )
1794{
1795 //
1796 // Read 'name' attribute defined as char from the FITS Header
1797 //
1798 int status = 0 ;
1799
1800 char buf[81] ;
1801 strcpy( buf, " " ) ;
1802 fseek( fp_, 0, SEEK_SET ) ;
1803 int count = 0 ;
1804 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1805 fread( buf, 1, 80, fp_ ) ;
1806 buf[80] = '\0' ;
1807 count++ ;
1808 }
1809 if ( strncmp( buf, "END", 3 ) == 0 ) {
1810 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1811 //cerr << "count = " << count << endl ;
1812 status = -1 ;
1813 return status ;
1814 }
1815 string str( buf ) ;
1816 int pos1 = str.find( '\'' ) + 1 ;
1817 int pos2 = str.find( '\'', pos1 ) ;
1818 unsigned int clen = pos2 - pos1 ;
1819 //cout << "string: " << str << endl ;
1820 //cout << "value: " << str.substr( pos1, clen ).c_str() << endl ;
1821 //cout << "clen = " << clen << endl ;
1822 v = str.substr( pos1, clen ) ;
1823 //cout << "v = \'" << v << "\'" << endl ;
1824
1825 return status ;
1826}
1827
1828int NROFITSDataset::readHeader( int &v, char *name, int b )
1829{
1830 //
1831 // Read 'name' attribute defined as int from the FITS Header
1832 //
1833 int status = 0 ;
1834
1835 char buf[81] ;
1836 strcpy( buf, " " ) ;
1837 fseek( fp_, 0, SEEK_SET ) ;
1838 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1839 fread( buf, 1, 80, fp_ ) ;
1840 buf[80] = '\0' ;
1841 //char bufo[9] ;
1842 //strncpy( bufo, buf, 8 ) ;
1843 //bufo[8] = '\0' ;
1844 //cout << "header: " << bufo << endl ;
1845 }
1846 if ( strncmp( buf, "END", 3 ) == 0 ) {
1847 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1848 status = -1 ;
1849 return status ;
1850 }
1851 string str( buf ) ;
1852 int pos1 = str.find( '=' ) + 1 ;
1853 int pos2 = str.find( '/' ) ;
1854 //cout << "string: " << str << endl ;
1855 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
1856 v = atoi( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
1857 //cout << "v = " << v << endl ;
1858
1859 //cout << "NROFITSDataset::readHeader() end to read" << endl ;
1860 return status ;
1861}
1862
1863
1864int NROFITSDataset::readHeader( float &v, char *name, int b )
1865{
1866 //
1867 // Read 'name' attribute defined as float from the FITS Header
1868 //
1869 int status = 0 ;
1870
1871 char buf[81] ;
1872 strcpy( buf, " " ) ;
1873 fseek( fp_, 0, SEEK_SET ) ;
1874 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1875 fread( buf, 1, 80, fp_ ) ;
1876 buf[80] = '\0' ;
1877 //char bufo[9] ;
1878 //strncpy( bufo, buf, 8 ) ;
1879 //bufo[8] = '\0' ;
1880 //cout << "header: " << bufo << endl ;
1881 }
1882 if ( strncmp( buf, "END", 3 ) == 0 ) {
1883 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1884 status = -1 ;
1885 return status ;
1886 }
1887 string str( buf ) ;
1888 int pos1 = str.find( '=' ) + 1 ;
1889 int pos2 = str.find( '/' ) ;
1890 //cout << "string: " << str << endl ;
1891 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
1892 v = atof( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
1893 //cout << "v = " << v << endl ;
1894
1895 return status ;
1896}
1897
1898int NROFITSDataset::readHeader( double &v, char *name, int b )
1899{
1900 //
1901 // Read 'name' attribute defined as double from the FITS Header
1902 //
1903 int status = 0 ;
1904
1905 char buf[81] ;
1906 strcpy( buf, " " ) ;
1907 fseek( fp_, 0, SEEK_SET ) ;
1908 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1909 fread( buf, 1, 80, fp_ ) ;
1910 buf[80] = '\0' ;
1911 char bufo[9] ;
1912 strncpy( bufo, buf, 8 ) ;
1913 bufo[8] = '\0' ;
1914 //cout << "header: \'" << bufo << "\' bufo = \'" << bufo << "\' ";
1915 //cout << strncmp( buf, name, strlen(name) ) << endl ;
1916 }
1917 if ( strncmp( buf, "END", 3 ) == 0 ) {
1918 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1919 status = -1 ;
1920 return status ;
1921 }
1922 string str( buf ) ;
1923 int pos1 = str.find( '=' ) + 1 ;
1924 int pos2 = str.find( '/' ) ;
1925 //cout << "string: " << str << endl ;
1926 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
1927 v = atof( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
1928 //cout << "v = " << v << endl ;
1929
1930 return status ;
1931}
1932
1933int NROFITSDataset::readTable( char *v, char *name, int clen, int idx )
1934{
1935 //
1936 // Read 'name' attribute defined as char from the idx-th row
1937 // of the FITS Scan Record
1938 //
1939 int status = movePointer( name, idx ) ;
1940 if ( status < 0 )
1941 return status ;
1942
1943 // get length of char
1944 int index = -1 ;
1945 for ( int i = 0 ; i < numField_ ; i++ ) {
1946 if ( names_[i] == name ) {
1947 index = i ;
1948 break ;
1949 }
1950 }
1951 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
1952 int xsize = atoi( substr.c_str() ) ;
1953 //cout << "xsize = " << xsize << endl ;
1954
1955 // read data
1956 if ( xsize < clen ) {
1957 fread( v, 1, xsize, fp_ ) ;
1958 //v[xsize] = '\0' ;
1959 }
1960 else {
1961 fread( v, 1, clen-1, fp_ ) ;
1962 //v[clen-1] = '\0' ;
1963 }
1964
1965 return status ;
1966}
1967
1968int NROFITSDataset::readTable( int &v, char *name, int b, int idx )
1969{
1970 //
1971 // Read 'name' attribute defined as int from the idx-th row
1972 // of the FITS Scan Record
1973 //
1974 int status = movePointer( name, idx ) ;
1975 if ( status < 0 )
1976 return status ;
1977
1978 // read data
1979 fread( &v, sizeof(int), 1, fp_ ) ;
1980 if ( b == 0 )
1981 convertEndian( v ) ;
1982
1983 return status ;
1984}
1985
1986int NROFITSDataset::readTable( float &v, char *name, int b, int idx )
1987{
1988 //
1989 // Read 'name' attribute defined as float from the idx-th row
1990 // of the FITS Scan Record
1991 //
1992 int status = movePointer( name, idx ) ;
1993 if ( status < 0 )
1994 return status ;
1995
1996 // read data
1997 fread( &v, sizeof(float), 1, fp_ ) ;
1998 if ( b == 0 )
1999 convertEndian( v ) ;
2000
2001 return status ;
2002}
2003
2004int NROFITSDataset::readTable( double &v, char *name, int b, int idx )
2005{
2006 //
2007 // Read 'name' attribute defined as double from the idx-th row
2008 // of the FITS Scan Record
2009 //
2010 int status = movePointer( name, idx ) ;
2011 if ( status < 0 )
2012 return status ;
2013
2014 // read data
2015 fread( &v, sizeof(double), 1, fp_ ) ;
2016 if ( b == 0 )
2017 convertEndian( v ) ;
2018
2019 return status ;
2020}
2021
2022int NROFITSDataset::readTable( vector<char *> &v, char *name, int idx )
2023{
2024 //
2025 // Read 'name' attribute defined as char array from the FITS Scan Record
2026 //
2027 int status = movePointer( name, idx ) ;
2028 if ( status < 0 )
2029 return status ;
2030
2031 // get length of char
2032 int index = -1 ;
2033 for ( int i = 0 ; i < numField_ ; i++ ) {
2034 if ( names_[i] == name ) {
2035 index = i ;
2036 break ;
2037 }
2038 }
2039 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
2040 int xsize = atoi( substr.c_str() ) ;
2041 //cout << "xsize = " << xsize << endl ;
2042
2043 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2044 int clen = strlen( v[i] ) ;
2045 if ( clen > xsize ) {
2046 fread( v[i], 1, xsize, fp_ ) ;
2047 //v[i][xsize] = '\0' ;
2048 }
2049 else {
2050 fread( v[i], 1, clen, fp_ ) ;
2051 //v[i][clen-1] = '\0' ;
2052 }
2053 //cout << "v[" << i << "] = " << v[i] << endl ;
2054 }
2055
2056 return status ;
2057}
2058
2059int NROFITSDataset::readTable( vector<int> &v, char *name, int b, int idx )
2060{
2061 //
2062 // Read 'name' attribute defined as int array from the FITS Scan Record
2063 //
2064 int status = movePointer( name, idx ) ;
2065 if ( status < 0 )
2066 return status ;
2067
2068 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2069 fread( &v[i], 1, sizeof(int), fp_ ) ;
2070 if ( b == 0 )
2071 convertEndian( v[i] ) ;
2072 //cout << "v[" << i << "] = " << v[i] << endl ;
2073 }
2074
2075 return status ;
2076}
2077
2078int NROFITSDataset::readTable( vector<float> &v, char *name, int b, int idx )
2079{
2080 //
2081 // Read 'name' attribute defined as float array from the FITS Scan Record
2082 //
2083 int status = movePointer( name, idx ) ;
2084 if ( status < 0 )
2085 return status ;
2086
2087 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2088 fread( &v[i], 1, sizeof(float), fp_ ) ;
2089 if ( b == 0 )
2090 convertEndian( v[i] ) ;
2091 //cout << "v[" << i << "] = " << v[i] << endl ;
2092 }
2093
2094 return status ;
2095}
2096
2097int NROFITSDataset::readTable( vector<double> &v, char *name, int b, int idx )
2098{
2099 //
2100 // Read 'name' attribute defined as double array from the FITS Scan Record
2101 //
2102 int status = movePointer( name, idx ) ;
2103 if ( status < 0 )
2104 return status ;
2105
2106 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2107 fread( &v[i], 1, sizeof(double), fp_ ) ;
2108 if ( b == 0 )
2109 convertEndian( v[i] ) ;
2110 //cout << "v[" << i << "] = " << v[i] << endl ;
2111 }
2112
2113 return status ;
2114}
2115
2116int NROFITSDataset::readColumn( vector<string> &v, char *name, int idx )
2117{
2118 //
2119 // Read idx-th column of ARRYTP-dependent 'name' attributes
2120 // defined as char array from the FITS Scan Record
2121 //
2122 int status = movePointer( name ) ;
2123 if ( status < 0 )
2124 return status ;
2125
2126 // get length of char
2127 int index = -1 ;
2128 for ( int i = 0 ; i < numField_ ; i++ ) {
2129 if ( names_[i] == name ) {
2130 index = i ;
2131 break ;
2132 }
2133 }
2134 string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
2135 int xsize = atoi( substr.c_str() ) ;
2136 //cout << "xsize = " << xsize << endl ;
2137
2138 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2139 int offset = scanLen_ * arrayid_[i] + xsize * idx ;
2140 fseek( fp_, offset, SEEK_CUR ) ;
2141// int clen = (int)strlen( v[i] ) ;
2142// if ( clen > xsize ) {
2143// fread( v[i], 1, xsize, fp_ ) ;
2144// //v[i][xsize] = '\0' ;
2145// }
2146// else {
2147// fread( v[i], 1, clen-1, fp_ ) ;
2148// //v[i][clen-1] = '\0' ;
2149// }
2150 char c[xsize+1] ;
2151 fread( c, 1, xsize, fp_ ) ;
2152 c[xsize] = '\0' ;
2153 v[i] = string( c ) ;
2154 //cout << "v[" << i << "] = \'" << v[i] << "\'" << endl ;
2155 fseek( fp_, -xsize-offset, SEEK_CUR ) ;
2156 }
2157
2158 return status ;
2159}
2160
2161int NROFITSDataset::readColumn( vector<int> &v, char *name, int b, int idx )
2162{
2163 //
2164 // Read idx-th column of ARRYTP-dependent 'name' attributes
2165 // defined as int array from the FITS Scan Record
2166 //
2167 int status = movePointer( name ) ;
2168 if ( status < 0 )
2169 return status ;
2170
2171 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2172 int offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
2173 fseek( fp_, offset, SEEK_CUR ) ;
2174 fread( &v[i], 1, sizeof(int), fp_ ) ;
2175 if ( b == 0 )
2176 convertEndian( v[i] ) ;
2177 //cout << "v[" << i << "] = " << v[i] << endl ;
2178 fseek( fp_, -sizeof(int)-offset, SEEK_CUR ) ;
2179 }
2180
2181 return status ;
2182}
2183
2184int NROFITSDataset::readColumn( vector<float> &v, char *name, int b, int idx )
2185{
2186 //
2187 // Read idx-th column of ARRYTP-dependent 'name' attributes
2188 // defined as float array from the FITS Scan Record
2189 //
2190 int status = movePointer( name ) ;
2191 if ( status < 0 )
2192 return status ;
2193
2194 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2195 int offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
2196 fseek( fp_, offset, SEEK_CUR ) ;
2197 fread( &v[i], 1, sizeof(float), fp_ ) ;
2198 if ( b == 0 )
2199 convertEndian( v[i] ) ;
2200 //cout << "v[" << i << "] = " << v[i] << endl ;
2201 fseek( fp_, -sizeof(float)-offset, SEEK_CUR ) ;
2202 }
2203
2204 return status ;
2205}
2206
2207int NROFITSDataset::readColumn( vector<double> &v, char *name, int b, int idx )
2208{
2209 //
2210 // Read idx-th column of ARRYTP-dependent 'name' attributes
2211 // defined as double array from the FITS Scan Record
2212 //
2213 int status = movePointer( name ) ;
2214 if ( status < 0 )
2215 return status ;
2216
2217 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2218 int offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
2219 fseek( fp_, offset, SEEK_CUR ) ;
2220 fread( &v[i], 1, sizeof(double), fp_ ) ;
2221 if ( b == 0 )
2222 convertEndian( v[i] ) ;
2223 //cout << "offset = " << offset << ", v[" << i << "] = " << v[i] << endl ;
2224 fseek( fp_, -sizeof(double)-offset, SEEK_CUR ) ;
2225 }
2226
2227// //cout << "v: " << endl ;
2228// for ( vector<double>::iterator i = v.begin() ; i != v.end() ; i++ )
2229// //cout << *i << " " ;
2230// //cout << endl ;
2231
2232 return status ;
2233}
2234
2235uInt NROFITSDataset::getArrayId( string type )
2236{
2237 uInt ib = 99;
2238 uInt len0 = type.size();
2239 for (uInt i = 0 ; i < arrayid_.size() ; i++) {
2240 uInt len = ARYTP[i].size();
2241 if ( len0 == len && type.compare( 0, len, ARYTP[i], 0, len ) == 0 ) {
2242 ib = i ;
2243 break ;
2244 }
2245 }
2246 return ib ;
2247}
2248
2249double NROFITSDataset::getStartIntTime( int i )
2250{
2251 double v ;
2252 readTable( v, "MJDST", same_, i ) ;
2253 return v/86400.0 ;
2254}
2255
2256double NROFITSDataset::getScanTime( int i )
2257{
2258 double startTime = getStartIntTime( i ) ;
2259 double interval = getIPTIM() ;
2260 interval /= 86400.0 ;
2261 return startTime+0.5*interval ;
2262}
2263
2264uInt NROFITSDataset::getPolNo( int irow )
2265{
2266 char rx[9] ;
2267 readTable( rx, "RX", 8, irow ) ;
2268 rx[8] = '\0' ;
2269 //cout << rx << endl ;
2270 return polNoFromRX( rx ) ;
2271}
2272
2273int NROFITSDataset::movePointer( char *name, int idx )
2274{
2275 // find offset
2276 int offset = getOffset( name ) ;
2277 if ( offset == -1 ) {
2278 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2279 return -1 ;
2280 }
2281
2282 offset += idx * scanLen_ ;
2283
2284 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2285 fseek( fp_, FITS_HEADER_SIZE+offset, SEEK_SET ) ;
2286
2287 return 0 ;
2288}
2289
2290// double NROFITSDataset::toLSR( double v, double t, double x, double y )
2291// {
2292// return v ;
2293// }
Note: See TracBrowser for help on using the repository browser.