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

Last change on this file since 3087 was 3066, checked in by Takeshi Nakazato, 9 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes/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...


Make NRO reader classes warning free.

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