[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>
|
---|
[2579] | 45 | #include <string.h>
|
---|
[1325] | 46 |
|
---|
| 47 | //--------------------------------------------------------------- getPKSreader
|
---|
| 48 |
|
---|
| 49 | // Return an appropriate PKSreader for a Parkes Multibeam dataset.
|
---|
| 50 |
|
---|
| 51 | PKSreader* getPKSreader(
|
---|
| 52 | const String name,
|
---|
| 53 | const Int retry,
|
---|
| 54 | const Int interpolate,
|
---|
[1757] | 55 | String &format)
|
---|
[1325] | 56 | {
|
---|
| 57 | // Check accessibility of the input.
|
---|
| 58 | File inFile(name);
|
---|
| 59 | if (!inFile.exists()) {
|
---|
| 60 | format = "DATASET NOT FOUND";
|
---|
[1757] | 61 | return 0x0;
|
---|
[1325] | 62 | }
|
---|
| 63 |
|
---|
| 64 | if (!inFile.isReadable()) {
|
---|
| 65 | format = "DATASET UNREADABLE";
|
---|
[1757] | 66 | return 0x0;
|
---|
[1325] | 67 | }
|
---|
| 68 |
|
---|
| 69 | // Determine the type of input.
|
---|
[1757] | 70 | PKSreader *reader = 0x0;
|
---|
[1325] | 71 | if (inFile.isRegular()) {
|
---|
| 72 | // Is it MBFITS or SDFITS?
|
---|
[1757] | 73 | if (strstr(name.chars(), ".sdfits")) {
|
---|
| 74 | // Looks like SDFITS, possibly gzip'd.
|
---|
[1325] | 75 | format = "SDFITS";
|
---|
| 76 | reader = new PKSFITSreader("SDFITS");
|
---|
| 77 |
|
---|
| 78 | } else {
|
---|
[1757] | 79 | RegularFileIO file(name);
|
---|
[2907] | 80 | //char buf[32];
|
---|
| 81 | char buf[80];
|
---|
| 82 | //file.read(30, buf, False);
|
---|
| 83 | file.read(80, buf, False);
|
---|
| 84 | //buf[30] = '\0';
|
---|
| 85 | //if (String(buf) == "SIMPLE = T") {
|
---|
| 86 | if (String(buf).contains("SIMPLE = T")) {
|
---|
| 87 | //file.seek(560);
|
---|
| 88 | //file.read(26, buf, False);
|
---|
| 89 | //buf[26] = '\0' ;
|
---|
| 90 | Int nbread=1;
|
---|
| 91 | while (nbread) {
|
---|
| 92 | nbread=file.read(80, buf, False);
|
---|
| 93 | //if ( String(buf) == "ORIGIN = 'NRAO Green Bank" ) {
|
---|
| 94 | if ( String(buf).contains("ORIGIN = 'NRAO Green Bank" )) {
|
---|
| 95 | // Looks like GBT SDFITS
|
---|
| 96 | format = "GBTFITS" ;
|
---|
| 97 | reader = new PKSFITSreader("GBTFITS") ;
|
---|
| 98 | break;
|
---|
| 99 | }
|
---|
| 100 | else {
|
---|
| 101 | if ( String(buf).find("END ")==0 ) {
|
---|
| 102 | // Looks like SDFITS.
|
---|
| 103 | format = "SDFITS";
|
---|
| 104 | reader = new PKSFITSreader("SDFITS");
|
---|
| 105 | break;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }//while loop
|
---|
[1757] | 109 | } else {
|
---|
| 110 | // Assume it's MBFITS.
|
---|
| 111 | format = "MBFITS";
|
---|
| 112 | reader = new PKSFITSreader("MBFITS", retry, interpolate);
|
---|
| 113 | }
|
---|
[1325] | 114 | }
|
---|
| 115 |
|
---|
| 116 | } else if (inFile.isDirectory()) {
|
---|
[1883] | 117 | Bool isMS = ( (File(name+"/table.info").exists())
|
---|
| 118 | && File(name+"/table.dat").exists() );
|
---|
| 119 | if (isMS) {
|
---|
| 120 | RegularFileIO ifs(name+"/table.info") ;
|
---|
| 121 | char buf[128] ;
|
---|
| 122 | ifs.read(sizeof(buf),buf,False) ;
|
---|
| 123 | if ( strstr( buf, "Measurement Set" ) == NULL )
|
---|
| 124 | isMS = False ;
|
---|
| 125 | }
|
---|
| 126 | //if (File(name + "/DATA_DESCRIPTION").exists()) {
|
---|
| 127 | if (isMS) {
|
---|
[1325] | 128 | // MS version 2.
|
---|
| 129 | #ifdef NOPKSMS
|
---|
| 130 | format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
|
---|
| 131 | #else
|
---|
| 132 | format = "MS2";
|
---|
| 133 | reader = new PKSMS2reader();
|
---|
| 134 | #endif
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | } else {
|
---|
| 138 | format = "UNRECOGNIZED INPUT FORMAT";
|
---|
| 139 | }
|
---|
[1757] | 140 | return reader;
|
---|
| 141 | }
|
---|
[1325] | 142 |
|
---|
[1757] | 143 | //--------------------------------------------------------------- getPKSreader
|
---|
[1325] | 144 |
|
---|
[1757] | 145 | // Search a list of directories for a Parkes Multibeam dataset and return an
|
---|
| 146 |
|
---|
| 147 | PKSreader* getPKSreader(
|
---|
| 148 | const String name,
|
---|
| 149 | const Vector<String> directories,
|
---|
| 150 | const Int retry,
|
---|
| 151 | const Int interpolate,
|
---|
| 152 | Int &iDir,
|
---|
| 153 | String &format)
|
---|
| 154 | {
|
---|
| 155 | PKSreader *reader = 0x0;
|
---|
| 156 |
|
---|
| 157 | iDir = -1;
|
---|
| 158 | Int nDir = directories.nelements();
|
---|
| 159 | for (Int i = 0; i < nDir; i++) {
|
---|
| 160 | String inName = directories(i) + "/" + name;
|
---|
| 161 | reader = getPKSreader(inName, retry, interpolate, format);
|
---|
| 162 | if (reader) {
|
---|
| 163 | iDir = i;
|
---|
| 164 | break;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | return reader;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | //--------------------------------------------------------------- getPKSreader
|
---|
| 172 |
|
---|
| 173 | // Open an appropriate PKSreader for a Parkes Multibeam dataset.
|
---|
| 174 |
|
---|
| 175 | PKSreader* getPKSreader(
|
---|
| 176 | const String name,
|
---|
| 177 | const String antenna,
|
---|
| 178 | const Int retry,
|
---|
| 179 | const Int interpolate,
|
---|
| 180 | String &format,
|
---|
| 181 | Vector<Bool> &beams,
|
---|
| 182 | Vector<Bool> &IFs,
|
---|
| 183 | Vector<uInt> &nChan,
|
---|
| 184 | Vector<uInt> &nPol,
|
---|
| 185 | Vector<Bool> &haveXPol,
|
---|
| 186 | Bool &haveBase,
|
---|
| 187 | Bool &haveSpectra)
|
---|
| 188 | {
|
---|
| 189 | PKSreader *reader = getPKSreader(name, retry, interpolate, format);
|
---|
| 190 |
|
---|
[1325] | 191 | // Try to open it.
|
---|
| 192 | if (reader) {
|
---|
[1757] | 193 | if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
|
---|
| 194 | haveBase, haveSpectra)) {
|
---|
[1325] | 195 | format += " OPEN ERROR";
|
---|
| 196 | delete reader;
|
---|
[1757] | 197 | reader = 0x0;
|
---|
[1325] | 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[1757] | 201 | return reader;
|
---|
[1325] | 202 | }
|
---|
| 203 |
|
---|
| 204 | //--------------------------------------------------------------- getPKSreader
|
---|
| 205 |
|
---|
| 206 | // Search a list of directories for a Parkes Multibeam dataset and return an
|
---|
| 207 | // appropriate PKSreader for it.
|
---|
| 208 | PKSreader* getPKSreader(
|
---|
| 209 | const String name,
|
---|
[1757] | 210 | const String antenna,
|
---|
[1325] | 211 | const Vector<String> directories,
|
---|
| 212 | const Int retry,
|
---|
| 213 | const Int interpolate,
|
---|
| 214 | Int &iDir,
|
---|
| 215 | String &format,
|
---|
| 216 | Vector<Bool> &beams,
|
---|
| 217 | Vector<Bool> &IFs,
|
---|
| 218 | Vector<uInt> &nChan,
|
---|
| 219 | Vector<uInt> &nPol,
|
---|
| 220 | Vector<Bool> &haveXPol,
|
---|
| 221 | Bool &haveBase,
|
---|
| 222 | Bool &haveSpectra)
|
---|
| 223 | {
|
---|
[1757] | 224 | PKSreader *reader = getPKSreader(name, directories, retry, interpolate,
|
---|
| 225 | iDir, format);
|
---|
| 226 |
|
---|
| 227 | // Try to open it.
|
---|
| 228 | if (reader) {
|
---|
| 229 | if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol,
|
---|
| 230 | haveBase, haveSpectra)) {
|
---|
| 231 | format += " OPEN ERROR";
|
---|
| 232 | delete reader;
|
---|
| 233 | reader = 0x0;
|
---|
[1325] | 234 | }
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[1757] | 237 | return reader;
|
---|
[1325] | 238 | }
|
---|