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

Last change on this file since 1877 was 1868, checked in by Takeshi Nakazato, 14 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): atnf

Description: Describe your changes here...

Sync with code/atnf/implement/PKSIO


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