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

Last change on this file since 3115 was 3110, checked in by Kana Sugimoto, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Put in Release Notes: No

Module(s): sdsaveold

Description: A trivial fix to the handling of numField_ in NRO filler.

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