source: trunk/external-alma/atnf/PKSIO/PKSreader.cc@ 2235

Last change on this file since 2235 was 1883, checked in by Takeshi Nakazato, 14 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: read MS in reference table

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Bug fix on is_scantable() and similar routine in the codes.
They are now able to recognize reference table correctly.

splitant() is working with reference table. Thus, performance
is a bit improved since deep copy is no longer necessary.


File size: 6.5 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
46//--------------------------------------------------------------- getPKSreader
47
48// Return an appropriate PKSreader for a Parkes Multibeam dataset.
49
50PKSreader* getPKSreader(
51 const String name,
52 const Int retry,
53 const Int interpolate,
54 String &format)
55{
56 // Check accessibility of the input.
57 File inFile(name);
58 if (!inFile.exists()) {
59 format = "DATASET NOT FOUND";
60 return 0x0;
61 }
62
63 if (!inFile.isReadable()) {
64 format = "DATASET UNREADABLE";
65 return 0x0;
66 }
67
68 // Determine the type of input.
69 PKSreader *reader = 0x0;
70 if (inFile.isRegular()) {
71 // Is it MBFITS or SDFITS?
72 if (strstr(name.chars(), ".sdfits")) {
73 // Looks like SDFITS, possibly gzip'd.
74 format = "SDFITS";
75 reader = new PKSFITSreader("SDFITS");
76
77 } else {
78 RegularFileIO file(name);
79 char buf[32];
80 file.read(30, buf, False);
81 buf[30] = '\0';
82 if (String(buf) == "SIMPLE = T") {
83 file.seek(560);
84 file.read(26, buf, False);
85 buf[26] = '\0' ;
86 if ( String(buf) == "ORIGIN = 'NRAO Green Bank" ) {
87 // Looks like GBT SDFITS
88 format = "GBTFITS" ;
89 reader = new PKSFITSreader("GBTFITS") ;
90 }
91 else {
92 // Looks like SDFITS.
93 format = "SDFITS";
94 reader = new PKSFITSreader("SDFITS");
95 }
96 } else {
97 // Assume it's MBFITS.
98 format = "MBFITS";
99 reader = new PKSFITSreader("MBFITS", retry, interpolate);
100 }
101 }
102
103 } else if (inFile.isDirectory()) {
104 Bool isMS = ( (File(name+"/table.info").exists())
105 && File(name+"/table.dat").exists() );
106 if (isMS) {
107 RegularFileIO ifs(name+"/table.info") ;
108 char buf[128] ;
109 ifs.read(sizeof(buf),buf,False) ;
110 if ( strstr( buf, "Measurement Set" ) == NULL )
111 isMS = False ;
112 }
113 //if (File(name + "/DATA_DESCRIPTION").exists()) {
114 if (isMS) {
115 // MS version 2.
116 #ifdef NOPKSMS
117 format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
118 #else
119 format = "MS2";
120 reader = new PKSMS2reader();
121 #endif
122 }
123
124 } else {
125 format = "UNRECOGNIZED INPUT FORMAT";
126 }
127 return reader;
128}
129
130//--------------------------------------------------------------- getPKSreader
131
132// Search a list of directories for a Parkes Multibeam dataset and return an
133
134PKSreader* getPKSreader(
135 const String name,
136 const Vector<String> directories,
137 const Int retry,
138 const Int interpolate,
139 Int &iDir,
140 String &format)
141{
142 PKSreader *reader = 0x0;
143
144 iDir = -1;
145 Int nDir = directories.nelements();
146 for (Int i = 0; i < nDir; i++) {
147 String inName = directories(i) + "/" + name;
148 reader = getPKSreader(inName, retry, interpolate, format);
149 if (reader) {
150 iDir = i;
151 break;
152 }
153 }
154
155 return reader;
156}
157
158//--------------------------------------------------------------- getPKSreader
159
160// Open an appropriate PKSreader for a Parkes Multibeam dataset.
161
162PKSreader* getPKSreader(
163 const String name,
164 const String antenna,
165 const Int retry,
166 const Int interpolate,
167 String &format,
168 Vector<Bool> &beams,
169 Vector<Bool> &IFs,
170 Vector<uInt> &nChan,
171 Vector<uInt> &nPol,
172 Vector<Bool> &haveXPol,
173 Bool &haveBase,
174 Bool &haveSpectra)
175{
176 PKSreader *reader = getPKSreader(name, retry, interpolate, format);
177
178 // Try to open it.
179 if (reader) {
180 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
181 haveBase, haveSpectra)) {
182 format += " OPEN ERROR";
183 delete reader;
184 reader = 0x0;
185 }
186 }
187
188 return reader;
189}
190
191//--------------------------------------------------------------- getPKSreader
192
193// Search a list of directories for a Parkes Multibeam dataset and return an
194// appropriate PKSreader for it.
195PKSreader* getPKSreader(
196 const String name,
197 const String antenna,
198 const Vector<String> directories,
199 const Int retry,
200 const Int interpolate,
201 Int &iDir,
202 String &format,
203 Vector<Bool> &beams,
204 Vector<Bool> &IFs,
205 Vector<uInt> &nChan,
206 Vector<uInt> &nPol,
207 Vector<Bool> &haveXPol,
208 Bool &haveBase,
209 Bool &haveSpectra)
210{
211 PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
212 iDir, format);
213
214 // Try to open it.
215 if (reader) {
216 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
217 haveBase, haveSpectra)) {
218 format += " OPEN ERROR";
219 delete reader;
220 reader = 0x0;
221 }
222 }
223
224 return reader;
225}
Note: See TracBrowser for help on using the repository browser.