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

Last change on this file since 2777 was 2768, 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: test_sdsave

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Speedup NRO filler for NEWSTAR data.

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