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

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

Update from livedata CVS repository

File size: 5.8 KB
RevLine 
[1325]1//#---------------------------------------------------------------------------
2//# PKSreader.cc: Class to read Parkes multibeam data.
3//#---------------------------------------------------------------------------
[1720]4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
[1325]6//#
[1720]7//# This file is part of livedata.
[1325]8//#
[1720]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
[1720]16//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17//# more details.
[1325]18//#
[1720]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//#
[1720]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//#
[1720]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>
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,
[1452]54 String &format)
[1325]55{
56 // Check accessibility of the input.
57 File inFile(name);
58 if (!inFile.exists()) {
59 format = "DATASET NOT FOUND";
[1452]60 return 0x0;
[1325]61 }
62
63 if (!inFile.isReadable()) {
64 format = "DATASET UNREADABLE";
[1452]65 return 0x0;
[1325]66 }
67
68 // Determine the type of input.
[1452]69 PKSreader *reader = 0x0;
[1325]70 if (inFile.isRegular()) {
71 // Is it MBFITS or SDFITS?
[1427]72 if (strstr(name.chars(), ".sdfits")) {
73 // Looks like SDFITS, possibly gzip'd.
[1325]74 format = "SDFITS";
75 reader = new PKSFITSreader("SDFITS");
76
77 } else {
[1427]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 }
[1325]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
[1452]109 return reader;
110}
[1325]111
[1452]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
[1325]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;
[1452]166 reader = 0x0;
[1325]167 }
168 }
169
[1452]170 return reader;
[1325]171}
172
173//--------------------------------------------------------------- getPKSreader
174
[1452]175// Search a list of directories for a Parkes Multibeam dataset and open an
[1325]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{
[1452]193 PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
194 iDir, format);
[1325]195
[1452]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;
[1427]203 }
204 }
205
[1452]206 return reader;
[1427]207}
Note: See TracBrowser for help on using the repository browser.