[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 |
|
---|
| 50 | PKSreader* 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()) {
|
---|
[1883] | 104 | Bool isMS = ( (File(name+"/table.info").exists())
|
---|
| 105 | && File(name+"/table.dat").exists() );
|
---|
| 106 | if (isMS) {
|
---|
| 107 | RegularFileIO ifs(name+"/table.info") ;
|
---|
| 108 | char buf[128] ;
|
---|
| 109 | ifs.read(sizeof(buf),buf,False) ;
|
---|
| 110 | if ( strstr( buf, "Measurement Set" ) == NULL )
|
---|
| 111 | isMS = False ;
|
---|
| 112 | }
|
---|
| 113 | //if (File(name + "/DATA_DESCRIPTION").exists()) {
|
---|
| 114 | if (isMS) {
|
---|
[1325] | 115 | // MS version 2.
|
---|
| 116 | #ifdef NOPKSMS
|
---|
| 117 | format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
|
---|
| 118 | #else
|
---|
| 119 | format = "MS2";
|
---|
| 120 | reader = new PKSMS2reader();
|
---|
| 121 | #endif
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | } else {
|
---|
| 125 | format = "UNRECOGNIZED INPUT FORMAT";
|
---|
| 126 | }
|
---|
[1757] | 127 | return reader;
|
---|
| 128 | }
|
---|
[1325] | 129 |
|
---|
[1757] | 130 | //--------------------------------------------------------------- getPKSreader
|
---|
[1325] | 131 |
|
---|
[1757] | 132 | // Search a list of directories for a Parkes Multibeam dataset and return an
|
---|
| 133 |
|
---|
| 134 | PKSreader* getPKSreader(
|
---|
| 135 | const String name,
|
---|
| 136 | const Vector<String> directories,
|
---|
| 137 | const Int retry,
|
---|
| 138 | const Int interpolate,
|
---|
| 139 | Int &iDir,
|
---|
| 140 | String &format)
|
---|
| 141 | {
|
---|
| 142 | PKSreader *reader = 0x0;
|
---|
| 143 |
|
---|
| 144 | iDir = -1;
|
---|
| 145 | Int nDir = directories.nelements();
|
---|
| 146 | for (Int i = 0; i < nDir; i++) {
|
---|
| 147 | String inName = directories(i) + "/" + name;
|
---|
| 148 | reader = getPKSreader(inName, retry, interpolate, format);
|
---|
| 149 | if (reader) {
|
---|
| 150 | iDir = i;
|
---|
| 151 | break;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | return reader;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | //--------------------------------------------------------------- getPKSreader
|
---|
| 159 |
|
---|
| 160 | // Open an appropriate PKSreader for a Parkes Multibeam dataset.
|
---|
| 161 |
|
---|
| 162 | PKSreader* getPKSreader(
|
---|
| 163 | const String name,
|
---|
| 164 | const String antenna,
|
---|
| 165 | const Int retry,
|
---|
| 166 | const Int interpolate,
|
---|
| 167 | String &format,
|
---|
| 168 | Vector<Bool> &beams,
|
---|
| 169 | Vector<Bool> &IFs,
|
---|
| 170 | Vector<uInt> &nChan,
|
---|
| 171 | Vector<uInt> &nPol,
|
---|
| 172 | Vector<Bool> &haveXPol,
|
---|
| 173 | Bool &haveBase,
|
---|
| 174 | Bool &haveSpectra)
|
---|
| 175 | {
|
---|
| 176 | PKSreader *reader = getPKSreader(name, retry, interpolate, format);
|
---|
| 177 |
|
---|
[1325] | 178 | // Try to open it.
|
---|
| 179 | if (reader) {
|
---|
[1757] | 180 | if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
|
---|
| 181 | haveBase, haveSpectra)) {
|
---|
[1325] | 182 | format += " OPEN ERROR";
|
---|
| 183 | delete reader;
|
---|
[1757] | 184 | reader = 0x0;
|
---|
[1325] | 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[1757] | 188 | return reader;
|
---|
[1325] | 189 | }
|
---|
| 190 |
|
---|
| 191 | //--------------------------------------------------------------- getPKSreader
|
---|
| 192 |
|
---|
| 193 | // Search a list of directories for a Parkes Multibeam dataset and return an
|
---|
| 194 | // appropriate PKSreader for it.
|
---|
| 195 | PKSreader* getPKSreader(
|
---|
| 196 | const String name,
|
---|
[1757] | 197 | const String antenna,
|
---|
[1325] | 198 | const Vector<String> directories,
|
---|
| 199 | const Int retry,
|
---|
| 200 | const Int interpolate,
|
---|
| 201 | Int &iDir,
|
---|
| 202 | String &format,
|
---|
| 203 | Vector<Bool> &beams,
|
---|
| 204 | Vector<Bool> &IFs,
|
---|
| 205 | Vector<uInt> &nChan,
|
---|
| 206 | Vector<uInt> &nPol,
|
---|
| 207 | Vector<Bool> &haveXPol,
|
---|
| 208 | Bool &haveBase,
|
---|
| 209 | Bool &haveSpectra)
|
---|
| 210 | {
|
---|
[1757] | 211 | PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
|
---|
| 212 | iDir, format);
|
---|
| 213 |
|
---|
| 214 | // Try to open it.
|
---|
| 215 | if (reader) {
|
---|
| 216 | if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
|
---|
| 217 | haveBase, haveSpectra)) {
|
---|
| 218 | format += " OPEN ERROR";
|
---|
| 219 | delete reader;
|
---|
| 220 | reader = 0x0;
|
---|
[1325] | 221 | }
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[1757] | 224 | return reader;
|
---|
[1325] | 225 | }
|
---|