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

Last change on this file since 3109 was 3105, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Do not use C++11 feature.

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