source: branches/casa-release-4_3/external-alma/atnf/PKSIO/NROFITSDataset.cc@ 3134

Last change on this file since 3134 was 2940, checked in by Malte Marquarding, 11 years ago

Finally fix aall warning: deprecated conversion from string constant to 'char*'

File size: 63.1 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 ctmp[4] = '\0' ;
1687 //cout << "ctmp = " << ctmp << endl ;
1688 for ( int i = 0 ; i < ARYNM ; i++ ) {
1689 if ( arrayid_[i] != -1 )
1690 continue ;
1691 else if ( strncmp( ctmp, ARYTP[i].c_str(), ARYTP[i].size() ) == 0 ) {
1692 //cout << "matched: i = " << i << ", ARYTP = " << ARYTP[i] << ", ctmp = " << ctmp << endl ;
1693 arrayid_[i] = index ;
1694 count++ ;
1695 }
1696 }
1697 fseek( fp_, scanLen_-4, SEEK_CUR ) ;
1698 index++ ;
1699 }
1700
1701 if ( count != ARYNM ) {
1702 os << LogIO::WARN << "NROFITSDataset::findData() failed to find rows for " ;
1703 for ( int i = 0 ; i < ARYNM ; i++ ) {
1704 if ( arrayid_[i] == -1 ) {
1705 os << LogIO::WARN << ARYTP[i] << " " ;
1706 }
1707 }
1708 os.post() ;
1709 }
1710
1711// for ( int i = 0 ; i < ARYNM ; i++ )
1712// //cout << "arrayid_[" << i << "] = " << arrayid_[i] << endl ;
1713 }
1714
1715long NROFITSDataset::getOffset( const char *name )
1716{
1717 map<string, FieldProperty>::iterator iter = properties_.find(string(name));
1718 long offset = (iter != properties_.end()) ? iter->second.offset : -1;
1719
1720 return offset ;
1721}
1722
1723int NROFITSDataset::getPolarizationNum()
1724{
1725 int npol = 0 ;
1726
1727 vector<char> type( 2 ) ;
1728 type[0] = 'C' ;
1729 type[1] = 'L' ;
1730 vector<double> crot ;
1731 vector<double> lagl ;
1732
1733 for ( int i = 0 ; i < ARYNM ; i++ ) {
1734 if ( POLTP[i][0] == type[0] ) {
1735 // circular polarization
1736 if( count( crot.begin(), crot.end(), POLDR[i] ) != 0 ) {
1737 crot.push_back( POLDR[i] ) ;
1738 npol++ ;
1739 }
1740 }
1741 else if ( POLTP[i][0] == type[1] ) {
1742 // linear polarization
1743 if ( count( lagl.begin(), lagl.end(), POLAN[i] ) != 0 ) {
1744 lagl.push_back( POLAN[i] ) ;
1745 npol++ ;
1746 }
1747 }
1748 }
1749
1750 if ( npol == 0 )
1751 npol = 1 ;
1752
1753
1754 return npol ;
1755}
1756
1757int NROFITSDataset::readHeader( string &v, const char *name )
1758{
1759 //
1760 // Read 'name' attribute defined as char from the FITS Header
1761 //
1762 int status = 0 ;
1763
1764 char buf[81] ;
1765 strcpy( buf, " " ) ;
1766 fseek( fp_, 0, SEEK_SET ) ;
1767 int count = 0 ;
1768 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1769 std::size_t retval = fread( buf, 1, 80, fp_ ) ;
1770 buf[80] = '\0' ;
1771 count++ ;
1772 }
1773 if ( strncmp( buf, "END", 3 ) == 0 ) {
1774 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1775 //cerr << "count = " << count << endl ;
1776 status = -1 ;
1777 return status ;
1778 }
1779 string str( buf ) ;
1780 int pos1 = str.find( '\'' ) + 1 ;
1781 int pos2 = str.find( '\'', pos1 ) ;
1782 unsigned int clen = pos2 - pos1 ;
1783 //cout << "string: " << str << endl ;
1784 //cout << "value: " << str.substr( pos1, clen ).c_str() << endl ;
1785 //cout << "clen = " << clen << endl ;
1786 v = str.substr( pos1, clen ) ;
1787 //cout << "v = \'" << v << "\'" << endl ;
1788
1789 return status ;
1790}
1791
1792int NROFITSDataset::readHeader( int &v, const char *name )
1793{
1794 //
1795 // Read 'name' attribute defined as int from the FITS Header
1796 //
1797 int status = 0 ;
1798
1799 char buf[81] ;
1800 strcpy( buf, " " ) ;
1801 fseek( fp_, 0, SEEK_SET ) ;
1802 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1803 std::size_t retval = fread( buf, 1, 80, fp_ ) ;
1804 buf[80] = '\0' ;
1805 //char bufo[9] ;
1806 //strncpy( bufo, buf, 8 ) ;
1807 //bufo[8] = '\0' ;
1808 //cout << "header: " << bufo << endl ;
1809 }
1810 if ( strncmp( buf, "END", 3 ) == 0 ) {
1811 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1812 status = -1 ;
1813 return status ;
1814 }
1815 string str( buf ) ;
1816 int pos1 = str.find( '=' ) + 1 ;
1817 int pos2 = str.find( '/' ) ;
1818 //cout << "string: " << str << endl ;
1819 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
1820 v = atoi( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
1821 //cout << "v = " << v << endl ;
1822
1823 //cout << "NROFITSDataset::readHeader() end to read" << endl ;
1824 return status ;
1825}
1826
1827
1828int NROFITSDataset::readHeader( float &v, const char *name )
1829{
1830 //
1831 // Read 'name' attribute defined as float from the FITS Header
1832 //
1833 int status = 0 ;
1834
1835 char buf[81] ;
1836 strcpy( buf, " " ) ;
1837 fseek( fp_, 0, SEEK_SET ) ;
1838 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1839 std::size_t retval = fread( buf, 1, 80, fp_ ) ;
1840 buf[80] = '\0' ;
1841 //char bufo[9] ;
1842 //strncpy( bufo, buf, 8 ) ;
1843 //bufo[8] = '\0' ;
1844 //cout << "header: " << bufo << endl ;
1845 }
1846 if ( strncmp( buf, "END", 3 ) == 0 ) {
1847 //cerr << "NROFITSDataset::readHeader() keyword " << name << " not found." << endl ;
1848 status = -1 ;
1849 return status ;
1850 }
1851 string str( buf ) ;
1852 int pos1 = str.find( '=' ) + 1 ;
1853 int pos2 = str.find( '/' ) ;
1854 //cout << "string: " << str << endl ;
1855 //cout << "value: " << str.substr( pos1, pos2 - pos1 ).c_str() << endl ;
1856 v = atof( str.substr( pos1, pos2 - pos1 ).c_str() ) ;
1857 //cout << "v = " << v << endl ;
1858
1859 return status ;
1860}
1861
1862int NROFITSDataset::readHeader( double &v, const char *name )
1863{
1864 //
1865 // Read 'name' attribute defined as double from the FITS Header
1866 //
1867 int status = 0 ;
1868
1869 char buf[81] ;
1870 strcpy( buf, " " ) ;
1871 fseek( fp_, 0, SEEK_SET ) ;
1872 while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
1873 std::size_t retval = fread( buf, 1, 80, fp_ ) ;
1874 buf[80] = '\0' ;
1875 char bufo[9] ;
1876 strncpy( bufo, buf, 8 ) ;
1877 bufo[8] = '\0' ;
1878 //cout << "header: \'" << bufo << "\' bufo = \'" << bufo << "\' ";
1879 //cout << strncmp( buf, name, strlen(name) ) << 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::readTable( char *v, const char *name, int clen, int idx )
1898{
1899 //
1900 // Read 'name' attribute defined as char from the idx-th row
1901 // of the FITS Scan Record
1902 //
1903 int status = movePointer( name, idx ) ;
1904 if ( status < 0 )
1905 return status ;
1906
1907 map<string, FieldProperty>::iterator iter = properties_.find(string(name));
1908 if (iter == properties_.end())
1909 return -1;
1910
1911 int xsize = iter->second.size;
1912
1913 // read data
1914 if ( xsize < clen ) {
1915 std::size_t retval = fread( v, 1, xsize, fp_ ) ;
1916 //v[xsize] = '\0' ;
1917 }
1918 else {
1919 std::size_t retval = fread( v, 1, clen-1, fp_ ) ;
1920 //v[clen-1] = '\0' ;
1921 }
1922
1923 return status ;
1924}
1925
1926int NROFITSDataset::readTable( int &v, const char *name, int b, int idx )
1927{
1928 //
1929 // Read 'name' attribute defined as int from the idx-th row
1930 // of the FITS Scan Record
1931 //
1932 int status = movePointer( name, idx ) ;
1933 if ( status < 0 )
1934 return status ;
1935
1936 // read data
1937 std::size_t retval = fread( &v, sizeof(int), 1, fp_ ) ;
1938 if ( b == 0 )
1939 convertEndian( v ) ;
1940
1941 return status ;
1942}
1943
1944int NROFITSDataset::readTable( float &v, const char *name, int b, int idx )
1945{
1946 //
1947 // Read 'name' attribute defined as float from the idx-th row
1948 // of the FITS Scan Record
1949 //
1950 int status = movePointer( name, idx ) ;
1951 if ( status < 0 )
1952 return status ;
1953
1954 // read data
1955 std::size_t retval = fread( &v, sizeof(float), 1, fp_ ) ;
1956 if ( b == 0 )
1957 convertEndian( v ) ;
1958
1959 return status ;
1960}
1961
1962int NROFITSDataset::readTable( double &v, const char *name, int b, int idx )
1963{
1964 //
1965 // Read 'name' attribute defined as double from the idx-th row
1966 // of the FITS Scan Record
1967 //
1968 int status = movePointer( name, idx ) ;
1969 if ( status < 0 )
1970 return status ;
1971
1972 // read data
1973 std::size_t retval = fread( &v, sizeof(double), 1, fp_ ) ;
1974 if ( b == 0 )
1975 convertEndian( v ) ;
1976
1977 return status ;
1978}
1979
1980int NROFITSDataset::readTable( vector<char *> &v, const char *name, int idx )
1981{
1982 //
1983 // Read 'name' attribute defined as char array from the FITS Scan Record
1984 //
1985 int status = movePointer( name, idx ) ;
1986 if ( status < 0 )
1987 return status ;
1988
1989 map<string, FieldProperty>::iterator iter = properties_.find(string(name));
1990 if (iter == properties_.end())
1991 return -1;
1992
1993 int xsize = iter->second.size;
1994
1995 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
1996 int clen = strlen( v[i] ) ;
1997 if ( clen > xsize ) {
1998 std::size_t retval = fread( v[i], 1, xsize, fp_ ) ;
1999 //v[i][xsize] = '\0' ;
2000 }
2001 else {
2002 std::size_t retval = fread( v[i], 1, clen, fp_ ) ;
2003 //v[i][clen-1] = '\0' ;
2004 }
2005 //cout << "v[" << i << "] = " << v[i] << endl ;
2006 }
2007
2008 return status ;
2009}
2010
2011int NROFITSDataset::readTable( vector<int> &v, const char *name, int b, int idx )
2012{
2013 //
2014 // Read 'name' attribute defined as int array from the FITS Scan Record
2015 //
2016 int status = movePointer( name, idx ) ;
2017 if ( status < 0 )
2018 return status ;
2019
2020 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2021 std::size_t retval = fread( &v[i], 1, sizeof(int), fp_ ) ;
2022 if ( b == 0 )
2023 convertEndian( v[i] ) ;
2024 //cout << "v[" << i << "] = " << v[i] << endl ;
2025 }
2026
2027 return status ;
2028}
2029
2030int NROFITSDataset::readTable( vector<float> &v, const char *name, int b, int idx )
2031{
2032 //
2033 // Read 'name' attribute defined as float array from the FITS Scan Record
2034 //
2035 int status = movePointer( name, idx ) ;
2036 if ( status < 0 )
2037 return status ;
2038
2039 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2040 std::size_t retval = fread( &v[i], 1, sizeof(float), fp_ ) ;
2041 if ( b == 0 )
2042 convertEndian( v[i] ) ;
2043 //cout << "v[" << i << "] = " << v[i] << endl ;
2044 }
2045
2046 return status ;
2047}
2048
2049int NROFITSDataset::readTable( vector<double> &v, const char *name, int b, int idx )
2050{
2051 //
2052 // Read 'name' attribute defined as double array from the FITS Scan Record
2053 //
2054 int status = movePointer( name, idx ) ;
2055 if ( status < 0 )
2056 return status ;
2057
2058 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2059 std::size_t retval = fread( &v[i], 1, sizeof(double), fp_ ) ;
2060 if ( b == 0 )
2061 convertEndian( v[i] ) ;
2062 //cout << "v[" << i << "] = " << v[i] << endl ;
2063 }
2064
2065 return status ;
2066}
2067
2068int NROFITSDataset::readColumn( vector<string> &v, const char *name, int idx )
2069{
2070 //
2071 // Read idx-th column of ARRYTP-dependent 'name' attributes
2072 // defined as char array from the FITS Scan Record
2073 //
2074 int status = movePointer( name ) ;
2075 if ( status < 0 )
2076 return status ;
2077
2078 map<string, FieldProperty>::iterator iter = properties_.find(string(name));
2079 if (iter == properties_.end())
2080 return -1;
2081
2082 int xsize = iter->second.size;
2083
2084 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2085 int offset = scanLen_ * arrayid_[i] + xsize * idx ;
2086 fseek( fp_, offset, SEEK_CUR ) ;
2087// int clen = (int)strlen( v[i] ) ;
2088// if ( clen > xsize ) {
2089// std::size_t retval = fread( v[i], 1, xsize, fp_ ) ;
2090// //v[i][xsize] = '\0' ;
2091// }
2092// else {
2093// std::size_t retval = fread( v[i], 1, clen-1, fp_ ) ;
2094// //v[i][clen-1] = '\0' ;
2095// }
2096 char c[xsize+1] ;
2097 std::size_t retval = fread( c, 1, xsize, fp_ ) ;
2098 c[xsize] = '\0' ;
2099 v[i] = string( c ) ;
2100 //cout << "v[" << i << "] = \'" << v[i] << "\'" << endl ;
2101 fseek( fp_, -xsize-offset, SEEK_CUR ) ;
2102 }
2103
2104 return status ;
2105}
2106
2107int NROFITSDataset::readColumn( vector<int> &v, const char *name, int b, int idx )
2108{
2109 //
2110 // Read idx-th column of ARRYTP-dependent 'name' attributes
2111 // defined as int array from the FITS Scan Record
2112 //
2113 int status = movePointer( name ) ;
2114 if ( status < 0 )
2115 return status ;
2116
2117 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2118 int offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
2119 fseek( fp_, offset, SEEK_CUR ) ;
2120 std::size_t retval = fread( &v[i], 1, sizeof(int), fp_ ) ;
2121 if ( b == 0 )
2122 convertEndian( v[i] ) ;
2123 //cout << "v[" << i << "] = " << v[i] << endl ;
2124 fseek( fp_, -sizeof(int)-offset, SEEK_CUR ) ;
2125 }
2126
2127 return status ;
2128}
2129
2130int NROFITSDataset::readColumn( vector<float> &v, const char *name, int b, int idx )
2131{
2132 //
2133 // Read idx-th column of ARRYTP-dependent 'name' attributes
2134 // defined as float array from the FITS Scan Record
2135 //
2136 int status = movePointer( name ) ;
2137 if ( status < 0 )
2138 return status ;
2139
2140 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2141 int offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
2142 fseek( fp_, offset, SEEK_CUR ) ;
2143 std::size_t retval = fread( &v[i], 1, sizeof(float), fp_ ) ;
2144 if ( b == 0 )
2145 convertEndian( v[i] ) ;
2146 //cout << "v[" << i << "] = " << v[i] << endl ;
2147 fseek( fp_, -sizeof(float)-offset, SEEK_CUR ) ;
2148 }
2149
2150 return status ;
2151}
2152
2153int NROFITSDataset::readColumn( vector<double> &v, const char *name, int b, int idx )
2154{
2155 //
2156 // Read idx-th column of ARRYTP-dependent 'name' attributes
2157 // defined as double array from the FITS Scan Record
2158 //
2159 int status = movePointer( name ) ;
2160 if ( status < 0 )
2161 return status ;
2162
2163 for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
2164 int offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
2165 fseek( fp_, offset, SEEK_CUR ) ;
2166 std::size_t retval = fread( &v[i], 1, sizeof(double), fp_ ) ;
2167 if ( b == 0 )
2168 convertEndian( v[i] ) ;
2169 //cout << "offset = " << offset << ", v[" << i << "] = " << v[i] << endl ;
2170 fseek( fp_, -sizeof(double)-offset, SEEK_CUR ) ;
2171 }
2172
2173// //cout << "v: " << endl ;
2174// for ( vector<double>::iterator i = v.begin() ; i != v.end() ; i++ )
2175// //cout << *i << " " ;
2176// //cout << endl ;
2177
2178 return status ;
2179}
2180
2181uInt NROFITSDataset::getArrayId( string type )
2182{
2183 uInt ib = 99;
2184 uInt len0 = type.size();
2185 for (uInt i = 0 ; i < arrayid_.size() ; i++) {
2186 uInt len = ARYTP[i].size();
2187 if ( len0 == len && type.compare( 0, len, ARYTP[i], 0, len ) == 0 ) {
2188 ib = i ;
2189 break ;
2190 }
2191 }
2192 return ib ;
2193}
2194
2195double NROFITSDataset::getStartIntTime( int i )
2196{
2197 double v ;
2198 readTable( v, "MJDST", same_, i ) ;
2199 return v/86400.0 ;
2200}
2201
2202double NROFITSDataset::getScanTime( int i )
2203{
2204 double startTime = getStartIntTime( i ) ;
2205 double interval = getIPTIM() ;
2206 interval /= 86400.0 ;
2207 return startTime+0.5*interval ;
2208}
2209
2210uInt NROFITSDataset::getPolNo( int irow )
2211{
2212 char rx[9] ;
2213 readTable( rx, "RX", 8, irow ) ;
2214 rx[8] = '\0' ;
2215 //cout << rx << endl ;
2216 return polNoFromRX( rx ) ;
2217}
2218
2219int NROFITSDataset::movePointer( const char *name, int idx )
2220{
2221 // find offset
2222 long offset = getOffset( name ) ;
2223 if ( offset == -1 ) {
2224 //cerr << "Error, " << name << " is not found in the name list." << endl ;
2225 return -1 ;
2226 }
2227
2228 offset += (long)(idx * scanLen_) ;
2229
2230 //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
2231 fseek( fp_, FITS_HEADER_SIZE+offset, SEEK_SET ) ;
2232
2233 return 0 ;
2234}
Note: See TracBrowser for help on using the repository browser.