source: trunk/external/atnf/PKSIO/PKSreader.cc@ 1705

Last change on this file since 1705 was 1452, checked in by Malte Marquarding, 16 years ago

update from livedata CVS

File size: 5.8 KB
Line 
1//#---------------------------------------------------------------------------
2//# PKSreader.cc: Class to read Parkes multibeam data.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2008
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: PKSreader.cc,v 19.12 2008-11-17 06:58:07 cal103 Exp $
29//#---------------------------------------------------------------------------
30//# Original: 2000/08/23, Mark Calabretta, ATNF
31//#---------------------------------------------------------------------------
32
33#include <atnf/PKSIO/PKSreader.h>
34#include <atnf/PKSIO/PKSFITSreader.h>
35
36#ifndef NOPKSMS
37#include <atnf/PKSIO/PKSMS2reader.h>
38#endif
39
40#include <casa/IO/RegularFileIO.h>
41#include <casa/OS/File.h>
42
43//--------------------------------------------------------------- getPKSreader
44
45// Return an appropriate PKSreader for a Parkes Multibeam dataset.
46
47PKSreader* getPKSreader(
48 const String name,
49 const Int retry,
50 const Int interpolate,
51 String &format)
52{
53 // Check accessibility of the input.
54 File inFile(name);
55 if (!inFile.exists()) {
56 format = "DATASET NOT FOUND";
57 return 0x0;
58 }
59
60 if (!inFile.isReadable()) {
61 format = "DATASET UNREADABLE";
62 return 0x0;
63 }
64
65 // Determine the type of input.
66 PKSreader *reader = 0x0;
67 if (inFile.isRegular()) {
68 // Is it MBFITS or SDFITS?
69 if (strstr(name.chars(), ".sdfits")) {
70 // Looks like SDFITS, possibly gzip'd.
71 format = "SDFITS";
72 reader = new PKSFITSreader("SDFITS");
73
74 } else {
75 RegularFileIO file(name);
76 char buf[32];
77 file.read(30, buf, False);
78 buf[30] = '\0';
79 if (String(buf) == "SIMPLE = T") {
80 // Looks like SDFITS.
81 format = "SDFITS";
82 reader = new PKSFITSreader("SDFITS");
83
84 } else {
85 // Assume it's MBFITS.
86 format = "MBFITS";
87 reader = new PKSFITSreader("MBFITS", retry, interpolate);
88 }
89 }
90
91 } else if (inFile.isDirectory()) {
92 if (File(name + "/DATA_DESCRIPTION").exists()) {
93 // MS version 2.
94 #ifdef NOPKSMS
95 format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
96 #else
97 format = "MS2";
98 reader = new PKSMS2reader();
99 #endif
100 }
101
102 } else {
103 format = "UNRECOGNIZED INPUT FORMAT";
104 }
105
106 return reader;
107}
108
109//--------------------------------------------------------------- getPKSreader
110
111// Search a list of directories for a Parkes Multibeam dataset and return an
112// appropriate PKSreader for it.
113
114PKSreader* getPKSreader(
115 const String name,
116 const Vector<String> directories,
117 const Int retry,
118 const Int interpolate,
119 Int &iDir,
120 String &format)
121{
122 PKSreader *reader = 0x0;
123
124 iDir = -1;
125 Int nDir = directories.nelements();
126 for (Int i = 0; i < nDir; i++) {
127 String inName = directories(i) + "/" + name;
128 reader = getPKSreader(inName, retry, interpolate, format);
129 if (reader) {
130 iDir = i;
131 break;
132 }
133 }
134
135 return reader;
136}
137
138//--------------------------------------------------------------- getPKSreader
139
140// Open an appropriate PKSreader for a Parkes Multibeam dataset.
141
142PKSreader* getPKSreader(
143 const String name,
144 const Int retry,
145 const Int interpolate,
146 String &format,
147 Vector<Bool> &beams,
148 Vector<Bool> &IFs,
149 Vector<uInt> &nChan,
150 Vector<uInt> &nPol,
151 Vector<Bool> &haveXPol,
152 Bool &haveBase,
153 Bool &haveSpectra)
154{
155 PKSreader *reader = getPKSreader(name, retry, interpolate, format);
156
157 // Try to open it.
158 if (reader) {
159 if (reader->open(name, beams, IFs, nChan, nPol, haveXPol, haveBase,
160 haveSpectra)) {
161 format += " OPEN ERROR";
162 delete reader;
163 reader = 0x0;
164 }
165 }
166
167 return reader;
168}
169
170//--------------------------------------------------------------- getPKSreader
171
172// Search a list of directories for a Parkes Multibeam dataset and open an
173// appropriate PKSreader for it.
174
175PKSreader* getPKSreader(
176 const String name,
177 const Vector<String> directories,
178 const Int retry,
179 const Int interpolate,
180 Int &iDir,
181 String &format,
182 Vector<Bool> &beams,
183 Vector<Bool> &IFs,
184 Vector<uInt> &nChan,
185 Vector<uInt> &nPol,
186 Vector<Bool> &haveXPol,
187 Bool &haveBase,
188 Bool &haveSpectra)
189{
190 PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
191 iDir, format);
192
193 // Try to open it.
194 if (reader) {
195 if (reader->open(name, beams, IFs, nChan, nPol, haveXPol, haveBase,
196 haveSpectra)) {
197 format += " OPEN ERROR";
198 delete reader;
199 reader = 0x0;
200 }
201 }
202
203 return reader;
204}
Note: See TracBrowser for help on using the repository browser.