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

Last change on this file since 2609 was 2579, checked in by ShinnosukeKawakami, 12 years ago

adding include<string.h>

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