source: branches/alma/external/atnf/PKSIO/PKSSDwriter.cc@ 1553

Last change on this file since 1553 was 1453, checked in by TakTsutsumi, 16 years ago

New Development: No

JIRA Issue: No

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed: many

Test Programs: sd.scantable(), sd.scantable.save()

Put in Release Notes: N/A

Description: copied from current casapy code tree


File size: 9.7 KB
RevLine 
[1325]1//#---------------------------------------------------------------------------
2//# PKSSDwriter.cc: Class to write Parkes multibeam data to an SDFITS file.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2006
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
13//# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14//# or 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//#
[1393]28//# $Id$
[1325]29//#---------------------------------------------------------------------------
30
31#include <atnf/PKSIO/PKSMBrecord.h>
32#include <atnf/PKSIO/PKSSDwriter.h>
33
34#include <casa/Quanta/MVTime.h>
35
36
37//--------------------------------------------------- PKSSDwriter::PKSSDwriter
38
39// Default constructor.
40
41PKSSDwriter::PKSSDwriter()
42{
43}
44
45//-------------------------------------------------- PKSSDwriter::~PKSSDwriter
46
47// Destructor.
48
49PKSSDwriter::~PKSSDwriter()
50{
51 close();
52}
53
54//-------------------------------------------------------- PKSSDwriter::create
55
56// Create the SDFITS file and and write static data.
57
58Int PKSSDwriter::create(
59 const String sdName,
60 const String observer,
61 const String project,
62 const String antName,
63 const Vector<Double> antPosition,
64 const String obsMode,
65 const Float equinox,
66 const String dopplerFrame,
67 const Vector<uInt> nChan,
68 const Vector<uInt> nPol,
69 const Vector<Bool> haveXPol,
[1393]70 const Bool haveBase,
71 const String fluxUnit)
[1325]72{
73 double antPos[3];
74 antPos[0] = antPosition(0);
75 antPos[1] = antPosition(1);
76 antPos[2] = antPosition(2);
77
78 cNIF = nChan.nelements();
79 if (nPol.nelements() != cNIF || haveXPol.nelements() != cNIF) {
80 cerr << "PKSSDwriter::create: "
81 << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol."
82 << endl;
83 return 1;
84 }
85
86 cNChan.assign(nChan);
87 cNPol.assign(nPol);
88
89 cHaveXPol.resize(cNIF);
90 for (uInt iIF = 0; iIF < cNIF; iIF++) {
91 // Convert Bool -> uInt.
92 cHaveXPol(iIF) = haveXPol(iIF) ? 1 : 0;
93 }
94
95 cHaveBase = haveBase;
96
97 // Storage in the trivial cNChan, cNPol, and cHaveXPol arrays should always
98 // be contiguous so the pointer returned by getStorage() shouldn't need to
99 // be deleted via freeStorage() (i.e. deleteIt always returned False). This
100 // storage will, of course, be deleted when the PKSwriter object is deleted.
101 Bool deleteIt;
102 Int status = cSDwriter.create((char *)sdName.chars(),
103 (char *)observer.chars(), (char *)project.chars(),
104 (char *)antName.chars(), antPos, (char *)obsMode.chars(), equinox,
105 (char *)dopplerFrame.chars(), cNIF,
106 (int *)cNChan.getStorage(deleteIt),
107 (int *)cNPol.getStorage(deleteIt),
108 (int *)cHaveXPol.getStorage(deleteIt), (int)cHaveBase, 1);
109 if (status) {
110 cSDwriter.reportError();
111 cSDwriter.deleteFile();
112 close();
113 }
114
115 return status;
116}
117
118//--------------------------------------------------------- PKSSDwriter::write
119
120// Write the next data record.
121
122Int PKSSDwriter::write(
123 const Int scanNo,
124 const Int cycleNo,
125 const Double mjd,
126 const Double interval,
127 const String fieldName,
128 const String srcName,
129 const Vector<Double> srcDir,
130 const Vector<Double> srcPM,
131 const Double srcVel,
132 const String obsMode,
133 const Int IFno,
134 const Double refFreq,
135 const Double bandwidth,
136 const Double freqInc,
[1453]137 //const Double restFreq,
138 const Vector<Double> restFreq,
[1325]139 const Vector<Float> tcal,
140 const String tcalTime,
141 const Float azimuth,
142 const Float elevation,
143 const Float parAngle,
144 const Float focusAxi,
145 const Float focusTan,
146 const Float focusRot,
147 const Float temperature,
148 const Float pressure,
149 const Float humidity,
150 const Float windSpeed,
151 const Float windAz,
152 const Int refBeam,
153 const Int beamNo,
154 const Vector<Double> direction,
155 const Vector<Double> scanRate,
156 const Vector<Float> tsys,
157 const Vector<Float> sigma,
158 const Vector<Float> calFctr,
159 const Matrix<Float> baseLin,
160 const Matrix<Float> baseSub,
161 const Matrix<Float> &spectra,
162 const Matrix<uChar> &flagged,
163 const Complex xCalFctr,
164 const Vector<Complex> &xPol)
165{
166 // Do basic checks.
167 uInt iIF = IFno - 1;
168 if (IFno < 1 || Int(cNIF) < IFno) {
169 cerr << "PKSDwriter::write: "
170 << "Invalid IF number " << IFno
171 << " (maximum " << cNIF << ")." << endl;
172 return 1;
173 }
174
175 uInt nChan = spectra.nrow();
176 if (nChan != cNChan(iIF)) {
177 cerr << "PKSDwriter::write: "
178 << "Wrong number of channels for IF " << IFno << "," << endl
179 << " "
180 << "got " << nChan << " should be " << cNChan(iIF) << "." << endl;
181 return 1;
182 }
183
184 uInt nPol = spectra.ncolumn();
185 if (nPol != cNPol(iIF)) {
186 cerr << "PKSDwriter::write: "
187 << "Wrong number of polarizations for IF " << IFno << "," << endl
188 << " "
189 << "got " << nPol << " should be " << cNPol(iIF) << "." << endl;
190 return 1;
191 }
192
193 // Extract calendar information from mjd.
194 MVTime time(mjd);
195 Int year = time.year();
196 Int month = time.month();
197 Int day = time.monthday();
198
199 // Transfer data to a single-IF PKSMBrecord.
200 PKSMBrecord mbrec(1);
201
202 // Start with basic beam- and IF-independent bookkeeping information.
203 mbrec.scanNo = scanNo;
204 mbrec.cycleNo = cycleNo;
205
206 sprintf(mbrec.datobs, "%4.4d-%2.2d-%2.2d", year, month, day);
207 mbrec.utc = fmod(mjd, 1.0) * 86400.0;
208 mbrec.exposure = float(interval);
209
210 strncpy(mbrec.srcName, (char *)srcName.chars(), 17);
211 mbrec.srcRA = srcDir(0);
212 mbrec.srcDec = srcDir(1);
213
[1453]214 //mbrec.restFreq = restFreq;
215 mbrec.restFreq = restFreq(0);
[1325]216
217 strncpy(mbrec.obsType, (char *)obsMode.chars(), 16);
218
219 // Now beam-dependent parameters.
220 mbrec.beamNo = beamNo;
221 mbrec.ra = direction(0);
222 mbrec.dec = direction(1);
223 mbrec.raRate = scanRate(0);
224 mbrec.decRate = scanRate(1);
225
226 // Now IF-dependent parameters.
227 mbrec.nIF = 1;
228 mbrec.IFno[0] = IFno;
229 mbrec.nChan[0] = nChan;
230 mbrec.nPol[0] = nPol;
231
232 mbrec.fqRefPix[0] = (nChan/2) + 1;
233 mbrec.fqRefVal[0] = refFreq;
234 mbrec.fqDelt[0] = freqInc;
235
236 // Now the data itself.
237 for (uInt i = 0; i < tsys.nelements(); i++) {
238 mbrec.tsys[0][i] = tsys(i);
239 }
240
241 for (uInt ipol = 0; ipol < nPol; ipol++) {
242 mbrec.calfctr[0][ipol] = calFctr(ipol);
243 }
244
245 if (cHaveXPol(iIF)) {
246 mbrec.xcalfctr[0][0] = xCalFctr.real();
247 mbrec.xcalfctr[0][1] = xCalFctr.imag();
248 } else {
249 mbrec.xcalfctr[0][0] = 0.0f;
250 mbrec.xcalfctr[0][1] = 0.0f;
251 }
252
253 if (cHaveBase) {
254 mbrec.haveBase = 1;
255
256 for (uInt ipol = 0; ipol < nPol; ipol++) {
257 mbrec.baseLin[0][ipol][0] = baseLin(0,ipol);
258 mbrec.baseLin[0][ipol][1] = baseLin(1,ipol);
259
260 for (uInt j = 0; j < baseSub.nrow(); j++) {
261 mbrec.baseSub[0][ipol][j] = baseSub(j,ipol);
262 }
263 for (uInt j = baseSub.nrow(); j < 9; j++) {
264 mbrec.baseSub[0][ipol][j] = 0.0f;
265 }
266 }
267
268 } else {
269 mbrec.haveBase = 0;
270 }
271
272 Bool delSpectra = False;
273 const Float *specstor = spectra.getStorage(delSpectra);
274 mbrec.spectra[0] = (float *)specstor;
275
276 Bool delFlagged = False;
277 const uChar *flagstor = flagged.getStorage(delFlagged);
278 mbrec.flagged[0] = (unsigned char *)flagstor;
279
280 Bool delXPol = False;
281 const Complex *xpolstor;
282 if (cHaveXPol(iIF)) {
283 xpolstor = xPol.getStorage(delXPol);
284 } else {
285 xpolstor = 0;
286 }
287 mbrec.xpol[0] = (float *)xpolstor;
288
289 // Finish off with system calibration parameters.
290 mbrec.extraSysCal = 1;
291 mbrec.refBeam = refBeam;
292 for (uInt i = 0; i < tcal.nelements(); i++) {
293 mbrec.tcal[0][i] = tcal(i);
294 }
295 strncpy(mbrec.tcalTime, (char *)tcalTime.chars(), 16);
296 mbrec.azimuth = azimuth;
297 mbrec.elevation = elevation;
298 mbrec.parAngle = parAngle;
299 mbrec.focusAxi = focusAxi;
300 mbrec.focusTan = focusTan;
301 mbrec.focusRot = focusRot;
302 mbrec.temp = temperature;
303 mbrec.pressure = pressure;
304 mbrec.humidity = humidity;
305 mbrec.windSpeed = windSpeed;
306 mbrec.windAz = windAz;
307
308 Int status = cSDwriter.write(mbrec);
309 if (status) {
310 cSDwriter.reportError();
311 status = 1;
312 }
313
314 spectra.freeStorage(specstor, delSpectra);
315 flagged.freeStorage(flagstor, delFlagged);
316 xPol.freeStorage(xpolstor, delXPol);
317
318 return status;
319}
320
321//--------------------------------------------------------- PKSSDwriter::close
322
323// Close the SDFITS file.
324
325void PKSSDwriter::close()
326{
327 cSDwriter.close();
328}
Note: See TracBrowser for help on using the repository browser.