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

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

New Development: No

JIRA Issue: Yes CAS-2819

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

More bug fix on TIME value


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