Line data Source code
1 : //# VLASpectralLineRecord.cc: 2 : //# Copyright (C) 1999,2000,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: casa-feedback@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/VLASpectralLineRecord.h> 29 : #include <casacore/casa/Arrays/Vector.h> 30 : #include <casacore/casa/BasicMath/Math.h> 31 : #include <casacore/casa/Exceptions/Error.h> 32 : #include <casacore/casa/Utilities/Assert.h> 33 : 34 : #include <iomanip> 35 : 36 0 : VLASpectralLineRecord::VLASpectralLineRecord() 37 : :VLABaselineRecord(), 38 0 : itsNchan(0) 39 : { 40 0 : } 41 : 42 2029 : VLASpectralLineRecord:: 43 2029 : VLASpectralLineRecord(ByteSource& record, uInt offset, uInt nChan) 44 : :VLABaselineRecord(record, offset), 45 2029 : itsNchan(nChan) 46 : { 47 2029 : DebugAssert(itsNchan != 0, AipsError); 48 2029 : } 49 : 50 4058 : VLASpectralLineRecord::~VLASpectralLineRecord() { 51 4058 : } 52 : 53 520933 : void VLASpectralLineRecord:: 54 : attach(ByteSource& record, uInt offset, uInt nChan) { 55 520933 : VLABaselineRecord::attach(record, offset); 56 520933 : DebugAssert(nChan != 0, AipsError); 57 520933 : itsNchan = nChan; 58 520933 : } 59 : 60 0 : Vector<Complex> VLASpectralLineRecord::data() const { 61 0 : const uInt trueChan = itsNchan-1; 62 0 : Vector<Complex> v(trueChan); 63 0 : data(v); 64 0 : return v; 65 0 : } 66 : 67 522962 : void VLASpectralLineRecord::data(Array<Complex>& values) const { 68 522962 : const uInt trueChan = itsNchan-1; 69 522962 : if (values.nelements() == 0) { 70 0 : values.resize(IPosition(1,trueChan)); 71 : } else { 72 522962 : DebugAssert(values.nelements() == trueChan, AipsError); 73 : } 74 : 75 522962 : const Float fscale = scale(); 76 522962 : const Int64 where = itsOffset + 2*((itsNchan+15)/16 + 4); 77 522962 : itsRecord.seek(where); 78 : Bool isACopy; 79 522962 : Complex* dataPtr = values.getStorage(isACopy); 80 522962 : Complex* curDataPtr = dataPtr + trueChan; 81 522962 : uInt n = 2*trueChan; 82 522962 : Short *idata = new Short[n]; 83 522962 : itsRecord.read(n, idata); 84 : // #if defined(AIPS_DEBUG) 85 : // check on max idata value >= 16384 seems to be wrong, data identified with max value of 0 that otherwise fills OK 86 : // Short max = 0; 87 : // #endif 88 66939136 : while (n > 0) { 89 66416174 : n--; 90 66416174 : curDataPtr--; 91 : // #if defined(AIPS_DEBUG) 92 : // Short absData = abs(idata[n]); 93 : // if (absData > max) max = absData; 94 : // #endif 95 66416174 : Float tmpval = Float(idata[n])/fscale; 96 66416174 : n--; 97 : // #if defined(AIPS_DEBUG) 98 : // absData = abs(idata[n]); 99 : // if (absData > max) max = absData; 100 : // #endif 101 66416174 : *curDataPtr = Complex (Float(idata[n])/fscale, tmpval); 102 : } 103 522962 : DebugAssert(curDataPtr == dataPtr, AipsError); 104 522962 : values.putStorage(dataPtr, isACopy); 105 : // #if defined(AIPS_DEBUG) 106 : // AlwaysAssert(max >= 16384, AipsError); 107 : // #endif 108 522962 : delete [] idata; 109 522962 : } 110 : 111 0 : Vector<Bool> VLASpectralLineRecord::flags() const { 112 0 : const uInt trueChan = itsNchan-1; 113 0 : Vector<Bool> flags(trueChan, false); 114 : // Bool isACopy; 115 : // Bool* dataPtr = flags.getStorage(isACopy); 116 : // const Int64 where = itsOffset; 117 : // itsRecord.seek(where); 118 : // itsRecord.read(itsNchan, dataPtr); 119 : // flags.putStorage(dataPtr, isACopy); 120 : // // const uInt n = 2*((itsNchan+15)/16 + 2); 121 : // // uChar bytes[n]; 122 : // // itsRecord.seek(itsOffset); 123 : // // itsRecord.read(n, bytes); 124 : // // cout << "Header bytes from a spectral line record. [" << setbase(16); 125 : // // for (uInt i = 0; i < n; i++) { 126 : // // cout << Int(bytes[i]) << ":"; 127 : // // } 128 : // // cout << "]" << setbase(10) << endl; 129 0 : return flags; 130 : } 131 : 132 522962 : uInt VLASpectralLineRecord::scale() const { 133 522962 : const uInt offset = 2*((itsNchan+15)/16); 134 522962 : return VLABaselineRecord::scale(offset); 135 : } 136 : 137 0 : uInt VLASpectralLineRecord::ant1() const { 138 0 : const uInt offset = 2*((itsNchan+15)/16); 139 0 : return VLABaselineRecord::ant1(offset + 2u); 140 : } 141 : 142 0 : uInt VLASpectralLineRecord::ant2() const { 143 0 : const uInt offset = 2*((itsNchan+15)/16); 144 0 : return VLABaselineRecord::ant2(offset + 2u); 145 : } 146 : 147 520933 : VLABaselineRecord::Type VLASpectralLineRecord::type() const { 148 520933 : return VLABaselineRecord::SPECTRALLINE; 149 : } 150 : // Local Variables: 151 : // compile-command: "gmake VLASpectralLineRecord" 152 : // End: