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

Last change on this file since 2947 was 1720, checked in by Malte Marquarding, 15 years ago

Update from livedata CVS repository

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