source: branches/casa-release-4_3-test02/external-alma/atnf/PKSIO/PKSreader.cc@ 3066

Last change on this file since 3066 was 2907, checked in by TakTsutsumi, 11 years ago

New Development: No

JIRA Issue: Yes CAS-6303

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: test_sdsave

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Modified the way search the FITS header keywords

allowing more random ordering.
Fixed GBTFITSreader to work for GBT SDFITS with a single
binary table and a minor fix in PKSFiller side to force
npol=1 when pksrecord.polno = -1.


File size: 7.0 KB
Line 
1//#---------------------------------------------------------------------------
2//# PKSreader.cc: Class to read Parkes multibeam data.
3//#---------------------------------------------------------------------------
4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
6//#
7//# This file is part of livedata.
8//#
9//# livedata is free software: you can redistribute it and/or modify it under
10//# the terms of the GNU General Public License as published by the Free
11//# Software Foundation, either version 3 of the License, or (at your option)
12//# any later version.
13//#
14//# livedata is distributed in the hope that it will be useful, but WITHOUT
15//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17//# more details.
18//#
19//# You should have received a copy of the GNU General Public License along
20//# with livedata. If not, see <http://www.gnu.org/licenses/>.
21//#
22//# Correspondence concerning livedata may be directed to:
23//# Internet email: mcalabre@atnf.csiro.au
24//# Postal address: Dr. Mark Calabretta
25//# Australia Telescope National Facility, CSIRO
26//# PO Box 76
27//# Epping NSW 1710
28//# AUSTRALIA
29//#
30//# http://www.atnf.csiro.au/computing/software/livedata.html
31//# $Id: PKSreader.cc,v 19.13 2009-09-29 07:33:39 cal103 Exp $
32//#---------------------------------------------------------------------------
33//# Original: 2000/08/23, Mark Calabretta, ATNF
34//#---------------------------------------------------------------------------
35
36#include <atnf/PKSIO/PKSreader.h>
37#include <atnf/PKSIO/PKSFITSreader.h>
38
39#ifndef NOPKSMS
40#include <atnf/PKSIO/PKSMS2reader.h>
41#endif
42
43#include <casa/IO/RegularFileIO.h>
44#include <casa/OS/File.h>
45#include <string.h>
46
47//--------------------------------------------------------------- getPKSreader
48
49// Return an appropriate PKSreader for a Parkes Multibeam dataset.
50
51PKSreader* getPKSreader(
52 const String name,
53 const Int retry,
54 const Int interpolate,
55 String &format)
56{
57 // Check accessibility of the input.
58 File inFile(name);
59 if (!inFile.exists()) {
60 format = "DATASET NOT FOUND";
61 return 0x0;
62 }
63
64 if (!inFile.isReadable()) {
65 format = "DATASET UNREADABLE";
66 return 0x0;
67 }
68
69 // Determine the type of input.
70 PKSreader *reader = 0x0;
71 if (inFile.isRegular()) {
72 // Is it MBFITS or SDFITS?
73 if (strstr(name.chars(), ".sdfits")) {
74 // Looks like SDFITS, possibly gzip'd.
75 format = "SDFITS";
76 reader = new PKSFITSreader("SDFITS");
77
78 } else {
79 RegularFileIO file(name);
80 //char buf[32];
81 char buf[80];
82 //file.read(30, buf, False);
83 file.read(80, buf, False);
84 //buf[30] = '\0';
85 //if (String(buf) == "SIMPLE = T") {
86 if (String(buf).contains("SIMPLE = T")) {
87 //file.seek(560);
88 //file.read(26, buf, False);
89 //buf[26] = '\0' ;
90 Int nbread=1;
91 while (nbread) {
92 nbread=file.read(80, buf, False);
93 //if ( String(buf) == "ORIGIN = 'NRAO Green Bank" ) {
94 if ( String(buf).contains("ORIGIN = 'NRAO Green Bank" )) {
95 // Looks like GBT SDFITS
96 format = "GBTFITS" ;
97 reader = new PKSFITSreader("GBTFITS") ;
98 break;
99 }
100 else {
101 if ( String(buf).find("END ")==0 ) {
102 // Looks like SDFITS.
103 format = "SDFITS";
104 reader = new PKSFITSreader("SDFITS");
105 break;
106 }
107 }
108 }//while loop
109 } else {
110 // Assume it's MBFITS.
111 format = "MBFITS";
112 reader = new PKSFITSreader("MBFITS", retry, interpolate);
113 }
114 }
115
116 } else if (inFile.isDirectory()) {
117 Bool isMS = ( (File(name+"/table.info").exists())
118 && File(name+"/table.dat").exists() );
119 if (isMS) {
120 RegularFileIO ifs(name+"/table.info") ;
121 char buf[128] ;
122 ifs.read(sizeof(buf),buf,False) ;
123 if ( strstr( buf, "Measurement Set" ) == NULL )
124 isMS = False ;
125 }
126 //if (File(name + "/DATA_DESCRIPTION").exists()) {
127 if (isMS) {
128 // MS version 2.
129 #ifdef NOPKSMS
130 format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
131 #else
132 format = "MS2";
133 reader = new PKSMS2reader();
134 #endif
135 }
136
137 } else {
138 format = "UNRECOGNIZED INPUT FORMAT";
139 }
140 return reader;
141}
142
143//--------------------------------------------------------------- getPKSreader
144
145// Search a list of directories for a Parkes Multibeam dataset and return an
146
147PKSreader* getPKSreader(
148 const String name,
149 const Vector<String> directories,
150 const Int retry,
151 const Int interpolate,
152 Int &iDir,
153 String &format)
154{
155 PKSreader *reader = 0x0;
156
157 iDir = -1;
158 Int nDir = directories.nelements();
159 for (Int i = 0; i < nDir; i++) {
160 String inName = directories(i) + "/" + name;
161 reader = getPKSreader(inName, retry, interpolate, format);
162 if (reader) {
163 iDir = i;
164 break;
165 }
166 }
167
168 return reader;
169}
170
171//--------------------------------------------------------------- getPKSreader
172
173// Open an appropriate PKSreader for a Parkes Multibeam dataset.
174
175PKSreader* getPKSreader(
176 const String name,
177 const String antenna,
178 const Int retry,
179 const Int interpolate,
180 String &format,
181 Vector<Bool> &beams,
182 Vector<Bool> &IFs,
183 Vector<uInt> &nChan,
184 Vector<uInt> &nPol,
185 Vector<Bool> &haveXPol,
186 Bool &haveBase,
187 Bool &haveSpectra)
188{
189 PKSreader *reader = getPKSreader(name, retry, interpolate, format);
190
191 // Try to open it.
192 if (reader) {
193 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
194 haveBase, haveSpectra)) {
195 format += " OPEN ERROR";
196 delete reader;
197 reader = 0x0;
198 }
199 }
200
201 return reader;
202}
203
204//--------------------------------------------------------------- getPKSreader
205
206// Search a list of directories for a Parkes Multibeam dataset and return an
207// appropriate PKSreader for it.
208PKSreader* getPKSreader(
209 const String name,
210 const String antenna,
211 const Vector<String> directories,
212 const Int retry,
213 const Int interpolate,
214 Int &iDir,
215 String &format,
216 Vector<Bool> &beams,
217 Vector<Bool> &IFs,
218 Vector<uInt> &nChan,
219 Vector<uInt> &nPol,
220 Vector<Bool> &haveXPol,
221 Bool &haveBase,
222 Bool &haveSpectra)
223{
224 PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
225 iDir, format);
226
227 // Try to open it.
228 if (reader) {
229 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
230 haveBase, haveSpectra)) {
231 format += " OPEN ERROR";
232 delete reader;
233 reader = 0x0;
234 }
235 }
236
237 return reader;
238}
Note: See TracBrowser for help on using the repository browser.