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

Last change on this file since 1427 was 1427, checked in by Malte Marquarding, 16 years ago

sync with livedata/implement/atnf

File size: 7.7 KB
Line 
1//#---------------------------------------------------------------------------
2//# PKSreader.cc: Class to read Parkes multibeam data.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2008
5//# Associated Universities, Inc. Washington DC, USA.
6//#
7//# This library is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU Library General Public License as published by
9//# the Free Software Foundation; either version 2 of the License, or (at your
10//# option) any later version.
11//#
12//# This library is distributed in the hope that it will be useful, but WITHOUT
13//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
15//# License for more details.
16//#
17//# You should have received a copy of the GNU Library General Public License
18//# along with this library; if not, write to the Free Software Foundation,
19//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning AIPS++ should be addressed as follows:
22//#        Internet email: aips2-request@nrao.edu.
23//#        Postal address: AIPS++ Project Office
24//#                        National Radio Astronomy Observatory
25//#                        520 Edgemont Road
26//#                        Charlottesville, VA 22903-2475 USA
27//#
28//# $Id: PKSreader.cc,v 19.6 2008-06-26 01:54:08 cal103 Exp $
29//#---------------------------------------------------------------------------
30//# Original: 2000/08/23, Mark Calabretta, ATNF
31//#---------------------------------------------------------------------------
32
33#include <atnf/PKSIO/PKSreader.h>
34#include <atnf/PKSIO/PKSFITSreader.h>
35
36#ifndef NOPKSMS
37#include <atnf/PKSIO/PKSMS2reader.h>
38#endif
39
40#include <casa/IO/RegularFileIO.h>
41#include <casa/OS/File.h>
42
43
44//--------------------------------------------------------------- getPKSreader
45
46// Return an appropriate PKSreader for a Parkes Multibeam dataset.
47
48PKSreader* getPKSreader(
49        const String name,
50        const Int retry,
51        const Int interpolate,
52        String &format,
53        Vector<Bool> &beams,
54        Vector<Bool> &IFs,
55        Vector<uInt> &nChan,
56        Vector<uInt> &nPol,
57        Vector<Bool> &haveXPol,
58        Bool   &haveBase,
59        Bool   &haveSpectra)
60{
61  // Check accessibility of the input.
62  File inFile(name);
63  if (!inFile.exists()) {
64    format = "DATASET NOT FOUND";
65    return 0;
66  }
67
68  if (!inFile.isReadable()) {
69    format = "DATASET UNREADABLE";
70    return 0;
71  }
72
73  // Determine the type of input.
74  PKSreader *reader = 0;
75  if (inFile.isRegular()) {
76    // Is it MBFITS or SDFITS?
77    if (strstr(name.chars(), ".sdfits")) {
78      // Looks like SDFITS, possibly gzip'd.
79      format = "SDFITS";
80      reader = new PKSFITSreader("SDFITS");
81
82    } else {
83      RegularFileIO file(name);
84      char buf[32];
85      file.read(30, buf, False);
86      buf[30] = '\0';
87      if (String(buf) == "SIMPLE  =                    T") {
88        // Looks like SDFITS.
89        format = "SDFITS";
90        reader = new PKSFITSreader("SDFITS");
91
92      } else {
93        // Assume it's MBFITS.
94        format = "MBFITS";
95        reader = new PKSFITSreader("MBFITS", retry, interpolate);
96      }
97    }
98
99  } else if (inFile.isDirectory()) {
100    if (File(name + "/DATA_DESCRIPTION").exists()) {
101      // MS version 2.
102      #ifdef NOPKSMS
103      format = "MS2 INPUT FORMAT IS NO LONGER SUPPORTED";
104      #else
105      format = "MS2";
106      reader = new PKSMS2reader();
107      #endif
108    }
109
110  } else {
111    format = "UNRECOGNIZED INPUT FORMAT";
112  }
113
114
115  // Try to open it.
116  if (reader) {
117    if (reader->open(name, beams, IFs, nChan, nPol, haveXPol, haveBase,
118                     haveSpectra)) {
119      format += " OPEN ERROR";
120      delete reader;
121    } else {
122      return reader;
123    }
124  }
125
126  return 0;
127}
128
129
130//--------------------------------------------------------------- getPKSreader
131
132// Search a list of directories for a Parkes Multibeam dataset and return an
133// appropriate PKSreader for it.
134
135PKSreader* getPKSreader(
136        const String name,
137        const Vector<String> directories,
138        const Int retry,
139        const Int interpolate,
140        Int    &iDir,
141        String &format,
142        Vector<Bool> &beams,
143        Vector<Bool> &IFs,
144        Vector<uInt> &nChan,
145        Vector<uInt> &nPol,
146        Vector<Bool> &haveXPol,
147        Bool   &haveBase,
148        Bool   &haveSpectra)
149{
150  Int nDir = directories.nelements();
151  for (iDir = 0; iDir < nDir; iDir++) {
152    String inName = directories(iDir) + "/" + name;
153    PKSreader *reader = getPKSreader(inName, retry, interpolate, format,
154                                     beams, IFs, nChan, nPol, haveXPol,
155                                     haveBase, haveSpectra);
156    if (reader != 0) {
157      return reader;
158    }
159  }
160
161  iDir = -1;
162  return 0;
163}
164
165
166//-------------------------------------------------------- PKSFITSreader::read
167
168// Read the next data record.
169
170Int PKSreader::read(
171        Int             &scanNo,
172        Int             &cycleNo,
173        Double          &mjd,
174        Double          &interval,
175        String          &fieldName,
176        String          &srcName,
177        Vector<Double>  &srcDir,
178        Vector<Double>  &srcPM,
179        Double          &srcVel,
180        String          &obsType,
181        Int             &IFno,
182        Double          &refFreq,
183        Double          &bandwidth,
184        Double          &freqInc,
185        Double          &restFreq,
186        Vector<Float>   &tcal,
187        String          &tcalTime,
188        Float           &azimuth,
189        Float           &elevation,
190        Float           &parAngle,
191        Float           &focusAxi,
192        Float           &focusTan,
193        Float           &focusRot,
194        Float           &temperature,
195        Float           &pressure,
196        Float           &humidity,
197        Float           &windSpeed,
198        Float           &windAz,
199        Int             &refBeam,
200        Int             &beamNo,
201        Vector<Double>  &direction,
202        Vector<Double>  &scanRate,
203        Vector<Float>   &tsys,
204        Vector<Float>   &sigma,
205        Vector<Float>   &calFctr,
206        Matrix<Float>   &baseLin,
207        Matrix<Float>   &baseSub,
208        Matrix<Float>   &spectra,
209        Matrix<uChar>   &flagged,
210        Complex         &xCalFctr,
211        Vector<Complex> &xPol)
212{
213  Int status;
214  MBrecord MBrec;
215
216  if ((status = read(MBrec))) {
217    if (status != -1) {
218      status = 1;
219    }
220
221    return status;
222  }
223
224  scanNo      = MBrec.scanNo;
225  cycleNo     = MBrec.cycleNo;
226  mjd         = MBrec.mjd;
227  interval    = MBrec.interval;
228  fieldName   = MBrec.fieldName;
229  srcName     = MBrec.srcName;
230  srcDir      = MBrec.srcDir;
231  srcPM       = MBrec.srcPM;
232  srcVel      = MBrec.srcVel;
233  obsType     = MBrec.obsType;
234  IFno        = MBrec.IFno;
235  refFreq     = MBrec.refFreq;
236  bandwidth   = MBrec.bandwidth;
237  freqInc     = MBrec.freqInc;
238  restFreq    = MBrec.restFreq;
239  tcal        = MBrec.tcal;
240  tcalTime    = MBrec.tcalTime;
241  azimuth     = MBrec.azimuth;
242  elevation   = MBrec.elevation;
243  parAngle    = MBrec.parAngle;
244  focusAxi    = MBrec.focusAxi;
245  focusTan    = MBrec.focusTan;
246  focusRot    = MBrec.focusRot;
247  temperature = MBrec.temperature;
248  pressure    = MBrec.pressure;
249  humidity    = MBrec.humidity;
250  windSpeed   = MBrec.windSpeed;
251  windAz      = MBrec.windAz;
252  refBeam     = MBrec.refBeam;
253  beamNo      = MBrec.beamNo;
254  direction   = MBrec.direction;
255  scanRate    = MBrec.scanRate;
256  tsys        = MBrec.tsys;
257  sigma       = MBrec.sigma;
258  calFctr     = MBrec.calFctr;
259  baseLin     = MBrec.baseLin;
260  baseSub     = MBrec.baseSub;
261  spectra     = MBrec.spectra;
262  flagged     = MBrec.flagged;
263  xCalFctr    = MBrec.xCalFctr;
264  xPol        = MBrec.xPol;
265
266  return 0;
267}
Note: See TracBrowser for help on using the repository browser.