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

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Removed unused arguments for some protected/private methods.


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