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

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

adding include<string.h>

File size: 6.5 KB
RevLine 
[1325]1//#---------------------------------------------------------------------------
2//# PKSreader.cc: Class to read Parkes multibeam data.
3//#---------------------------------------------------------------------------
[1757]4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
[1325]6//#
[1757]7//# This file is part of livedata.
[1325]8//#
[1757]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
[1325]15//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
[1757]16//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17//# more details.
[1325]18//#
[1757]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/>.
[1325]21//#
[1757]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
[1325]29//#
[1757]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 $
[1325]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>
[2579]45#include <string.h>
[1325]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,
[1757]55 String &format)
[1325]56{
57 // Check accessibility of the input.
58 File inFile(name);
59 if (!inFile.exists()) {
60 format = "DATASET NOT FOUND";
[1757]61 return 0x0;
[1325]62 }
63
64 if (!inFile.isReadable()) {
65 format = "DATASET UNREADABLE";
[1757]66 return 0x0;
[1325]67 }
68
69 // Determine the type of input.
[1757]70 PKSreader *reader = 0x0;
[1325]71 if (inFile.isRegular()) {
72 // Is it MBFITS or SDFITS?
[1757]73 if (strstr(name.chars(), ".sdfits")) {
74 // Looks like SDFITS, possibly gzip'd.
[1325]75 format = "SDFITS";
76 reader = new PKSFITSreader("SDFITS");
77
78 } else {
[1757]79 RegularFileIO file(name);
80 char buf[32];
81 file.read(30, buf, False);
82 buf[30] = '\0';
83 if (String(buf) == "SIMPLE = T") {
[1868]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 }
[1757]97 } else {
98 // Assume it's MBFITS.
99 format = "MBFITS";
100 reader = new PKSFITSreader("MBFITS", retry, interpolate);
101 }
[1325]102 }
103
104 } else if (inFile.isDirectory()) {
[1883]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) {
[1325]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 }
[1757]128 return reader;
129}
[1325]130
[1757]131//--------------------------------------------------------------- getPKSreader
[1325]132
[1757]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
[1325]179 // Try to open it.
180 if (reader) {
[1757]181 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
182 haveBase, haveSpectra)) {
[1325]183 format += " OPEN ERROR";
184 delete reader;
[1757]185 reader = 0x0;
[1325]186 }
187 }
188
[1757]189 return reader;
[1325]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,
[1757]198 const String antenna,
[1325]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{
[1757]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;
[1325]222 }
223 }
224
[1757]225 return reader;
[1325]226}
Note: See TracBrowser for help on using the repository browser.