source: branches/hpc34/external-alma/atnf/PKSIO/NROFITSDataset.cc@ 2737

Last change on this file since 2737 was 2442, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: sdsave unit test

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

More refactoring


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