Line data Source code
1 : //# VLABaselineRecord.cc: this defines VLABaselineRecord.cc 2 : //# Copyright (C) 1997,1998,1999,2001 3 : //# Associated Universities, Inc. Washington DC, USA. 4 : //# 5 : //# This library is free software; you can redistribute it and/or modify it 6 : //# under the terms of the GNU Library General Public License as published by 7 : //# the Free Software Foundation; either version 2 of the License, or (at your 8 : //# option) any later version. 9 : //# 10 : //# This library is distributed in the hope that it will be useful, but WITHOUT 11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 13 : //# License for more details. 14 : //# 15 : //# You should have received a copy of the GNU Library General Public License 16 : //# along with this library; if not, write to the Free Software Foundation, 17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 : //# 19 : //# Correspondence concerning AIPS++ should be addressed as follows: 20 : //# Internet email: aips2-request@nrao.edu. 21 : //# Postal address: AIPS++ Project Office 22 : //# National Radio Astronomy Observatory 23 : //# 520 Edgemont Road 24 : //# Charlottesville, VA 22903-2475 USA 25 : //# 26 : //# $Id$ 27 : 28 : #include <nrao/VLA/VLABaselineRecord.h> 29 : #include <casacore/casa/Arrays/Vector.h> 30 : #include <casacore/casa/Exceptions/Error.h> 31 : #include <casacore/casa/Utilities/Assert.h> 32 : #include <casacore/casa/BasicSL/String.h> 33 : #include <iomanip> 34 : 35 0 : VLABaselineRecord::VLABaselineRecord() 36 : :itsRecord(), 37 0 : itsOffset(0) 38 : { 39 0 : } 40 : 41 6943 : VLABaselineRecord::VLABaselineRecord(ByteSource& record, uInt offset) 42 : :itsRecord(record), 43 6943 : itsOffset(offset) 44 : { 45 6943 : DebugAssert(record.isReadable(), AipsError); 46 6943 : DebugAssert(record.isSeekable(), AipsError); 47 6943 : DebugAssert(offset != 0, AipsError); 48 6943 : } 49 : 50 6943 : VLABaselineRecord::~VLABaselineRecord() { 51 6943 : } 52 : 53 4546903 : void VLABaselineRecord::attach(ByteSource& record, uInt offset) { 54 4546903 : DebugAssert(record.isReadable(), AipsError); 55 4546903 : DebugAssert(record.isSeekable(), AipsError); 56 4546903 : itsRecord = record; 57 4546903 : DebugAssert(offset != 0, AipsError); 58 4546903 : itsOffset = offset; 59 4546903 : } 60 : 61 0 : Vector<Complex> VLABaselineRecord::data() const { 62 0 : Vector<Complex> v; 63 0 : data(v); 64 0 : return v; 65 : } 66 : 67 0 : String VLABaselineRecord::name(VLABaselineRecord::Type typeEnum) { 68 0 : switch (typeEnum) { 69 0 : case VLABaselineRecord::CONTINUUM: 70 0 : return "continuum"; 71 0 : case VLABaselineRecord::SPECTRALLINE: 72 0 : return "spectral line"; 73 0 : default: 74 0 : return "unknown"; 75 : }; 76 : } 77 : 78 0 : VLABaselineRecord::Type VLABaselineRecord::type(const String& typeName) { 79 0 : String canonicalCase(typeName); 80 0 : canonicalCase.downcase(); 81 : VLABaselineRecord::Type t; 82 0 : for (uInt i = 0; i < NUMBER_TYPES; i++) { 83 0 : t = (VLABaselineRecord::Type) i; 84 0 : if (canonicalCase.matches(VLABaselineRecord::name(t))) { 85 0 : return t; 86 : } 87 : } 88 0 : return VLABaselineRecord::UNKNOWN_TYPE; 89 : } 90 : 91 2623346 : uInt VLABaselineRecord::scale(uInt headerOffset) const { 92 2623346 : const Int64 where = itsOffset + headerOffset + 1; 93 2623346 : itsRecord.seek(where); 94 : Char exponent; 95 2623346 : itsRecord >> exponent; 96 : // The exponent can sometimes be negative (after April 9 1997) - Another 97 : // undocumented feature. 98 : // DebugAssert((exponent & 0x1F) == exponent, AipsError); 99 : // exponent &= 0x1F; 100 : // cout << "exponent: " << setbase(10) << Int(exponent) << endl; 101 : // DONT ASK WHERE THE 8 COMES FROM ITS **UNDOCUMENTED** EXCEPT IN THE SOURCE 102 : // CODE FOR THE AIPS TASK FILLM!!! 103 2623346 : uInt scale = 1 << (exponent+8); 104 2623346 : DebugAssert(scale != 0, AipsError); 105 2623346 : return scale; 106 : } 107 : 108 0 : uInt VLABaselineRecord::ant1(uInt headerOffset) const { 109 0 : const Int64 where = itsOffset + headerOffset; 110 0 : itsRecord.seek(where); 111 : uChar byte[2]; // read as two bytes to defeat byte swapping 112 0 : itsRecord.read(2, byte); 113 0 : byte[0] &= 0xe0; 114 0 : byte[0] >>= 5; 115 0 : byte[1] &= 0x03; 116 0 : byte[1] <<= 2; 117 0 : uInt ant1 = byte[1] | byte[0]; 118 0 : DebugAssert(ant1 < 32, AipsError); 119 0 : return ant1; 120 : } 121 : 122 0 : uInt VLABaselineRecord::ant2(uInt headerOffset) const { 123 0 : const Int64 where = itsOffset + headerOffset + 1; 124 0 : itsRecord.seek(where); 125 : uChar byte; 126 0 : itsRecord >> byte; 127 0 : uInt ant2 = byte & 0x1f; 128 0 : DebugAssert(ant2 < 32, AipsError); 129 0 : return ant2; 130 : } 131 : 132 : // Local Variables: 133 : // compile-command: "gmake VLABaselineRecord" 134 : // End: