//#--------------------------------------------------------------------------- //# SDAsciiWriter.cc: ASAP class to write out single dish spectra as FITS images //#--------------------------------------------------------------------------- //# Copyright (C) 2004 //# ATNF //# //# This program is free software; you can redistribute it and/or modify it //# under the terms of the GNU General Public License as published by the Free //# Software Foundation; either version 2 of the License, or (at your option) //# any later version. //# //# This program is distributed in the hope that it will be useful, but //# WITHOUT ANY WARRANTY; without even the implied warranty of //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General //# Public License for more details. //# //# You should have received a copy of the GNU General Public License along //# with this program; if not, write to the Free Software Foundation, Inc., //# 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning this software should be addressed as follows: //# Internet email: Malte.Marquarding@csiro.au //# Postal address: Malte Marquarding, //# Australia Telescope National Facility, //# P.O. Box 76, //# Epping, NSW, 2121, //# AUSTRALIA //# //# $Id: SDAsciiWriter.cc 496 2005-02-22 00:21:13Z kil064 $ //#--------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "SDDefs.h" #include "SDContainer.h" #include "SDMemTable.h" #include "SDAsciiWriter.h" using namespace casa; using namespace asap; SDAsciiWriter::SDAsciiWriter() {;} SDAsciiWriter::~SDAsciiWriter() {;} Bool SDAsciiWriter::write(const SDMemTable& sdTable, const String& fileName, Bool toStokes) { // Get global Header from Table SDHeader header = sdTable.getSDHeader(); MEpoch::Ref timeRef(MEpoch::UTC); // Should be in header MDirection::Types dirRef(MDirection::J2000); // Should be in header // Column keywords Table tab = sdTable.table(); ROArrayColumn dir(tab, String("DIRECTION")); ROScalarColumn time(tab, "TIME"); ROArrayColumn freqid(tab, "FREQID"); ROScalarColumn src(tab, "SRCNAME"); // Temps Vector whichStokes(1,1); Array whichDir; Vector lonLat(2); IPosition posDir(2,0); const Unit RAD(String("rad")); // Open and write header file String rootName(fileName); if (rootName.length()==0) rootName = String("ascii"); { String fName = String(rootName) + String("_header.txt"); cout << "Writing header to " << fName << endl; ofstream of(fName.chars(), ios::trunc); std::string summary = sdTable.summary(true); of << summary; of.close(); } // Open data file String fName = rootName + String(".txt"); ofstream of(fName.chars(), ios::trunc); // Write header of << "row beam IF pol source longitude latitude time nchan spectrum mask" << endl; // Loop over rows const uInt nRows = sdTable.nRow(); for (uInt iRow=0; iRow& dataIn(sdTable.rowAsMaskedArray(iRow,toStokes)); const Array& values = dataIn.getArray(); const Array& mask = dataIn.getMask(); // Get abcissa std::vector abcissa = sdTable.getAbcissa(Int(iRow)); const uInt n = abcissa.size(); // Iterate through data in this row by spectra ReadOnlyVectorIterator itData(values, asap::ChanAxis); ReadOnlyVectorIterator itMask(mask, asap::ChanAxis); while (!itData.pastEnd()) { const IPosition& pos = itData.pos(); AlwaysAssert(itData.vector().nelements()==n,AipsError); // FreqID Vector iTmp; freqid.get(iRow, iTmp); // Direction dir.get(iRow, whichDir); posDir(0) = pos(asap::BeamAxis); posDir(1) = 0; lonLat[0] = whichDir(posDir); // posDir(0) = pos(asap::BeamAxis); posDir(1) = 1; lonLat[1] = whichDir(posDir); // Write preamble of << iRow << " " << pos(asap::BeamAxis) << " " << pos(asap::IFAxis) << " " << pos(asap::PolAxis) << " " << src(iRow) << " " << formatDirection(lonLat) << " " << sdTable.getTime(iRow,True) << " " << n << " "; // Write abcissa of.setf(ios::fixed, ios::floatfield); of.precision(4); for (uInt i=0; i& data = itData.vector(); const Vector& mask = itMask.vector(); for (uInt i=0; i& lonLat) { MVAngle x1(lonLat(0)); String s1 = x1.string(MVAngle::TIME, 12); // MVAngle x2(lonLat(1)); String s2 = x2.string(MVAngle::ANGLE, 12); // String ss = s1 + String(" ") + s2; return ss; }