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

Last change on this file since 1876 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
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>
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,
[1757]54 String &format)
[1325]55{
56 // Check accessibility of the input.
57 File inFile(name);
58 if (!inFile.exists()) {
59 format = "DATASET NOT FOUND";
[1757]60 return 0x0;
[1325]61 }
62
63 if (!inFile.isReadable()) {
64 format = "DATASET UNREADABLE";
[1757]65 return 0x0;
[1325]66 }
67
68 // Determine the type of input.
[1757]69 PKSreader *reader = 0x0;
[1325]70 if (inFile.isRegular()) {
71 // Is it MBFITS or SDFITS?
[1757]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 {
[1757]78 RegularFileIO file(name);
79 char buf[32];
80 file.read(30, buf, False);
81 buf[30] = '\0';
82 if (String(buf) == "SIMPLE = T") {
[1868]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 }
[1757]96 } else {
97 // Assume it's MBFITS.
98 format = "MBFITS";
99 reader = new PKSFITSreader("MBFITS", retry, interpolate);
100 }
[1325]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 }
[1757]117 return reader;
118}
[1325]119
[1757]120//--------------------------------------------------------------- getPKSreader
[1325]121
[1757]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
[1325]168 // Try to open it.
169 if (reader) {
[1757]170 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
171 haveBase, haveSpectra)) {
[1325]172 format += " OPEN ERROR";
173 delete reader;
[1757]174 reader = 0x0;
[1325]175 }
176 }
177
[1757]178 return reader;
[1325]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,
[1757]187 const String antenna,
[1325]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{
[1757]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;
[1325]211 }
212 }
213
[1757]214 return reader;
[1325]215}
Note: See TracBrowser for help on using the repository browser.