source: trunk/src/STAsciiWriter.cpp@ 2528

Last change on this file since 2528 was 2335, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-3347 (ASAP Trac #245)

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: write out data as ASCII

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Commented out the line which is a description of the data.
(Just put '#' at the line 'x y0 yf0')

It enables to plot data on gnuplot without any changes in the file.


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
RevLine 
[1819]1
[198]2//#---------------------------------------------------------------------------
[988]3//# STAsciiWriter.cc: ASAP class to write out single dish spectra as FITS images
[198]4//#---------------------------------------------------------------------------
5//# Copyright (C) 2004
6//# ATNF
7//#
8//# This program is free software; you can redistribute it and/or modify it
9//# under the terms of the GNU General Public License as published by the Free
10//# Software Foundation; either version 2 of the License, or (at your option)
11//# any later version.
12//#
13//# This program is distributed in the hope that it will be useful, but
14//# WITHOUT ANY WARRANTY; without even the implied warranty of
15//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16//# Public License for more details.
17//#
18//# You should have received a copy of the GNU General Public License along
19//# with this program; if not, write to the Free Software Foundation, Inc.,
20//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
21//#
22//# Correspondence concerning this software should be addressed as follows:
23//# Internet email: Malte.Marquarding@csiro.au
24//# Postal address: Malte Marquarding,
25//# Australia Telescope National Facility,
26//# P.O. Box 76,
27//# Epping, NSW, 2121,
28//# AUSTRALIA
29//#
30//# $Id: STAsciiWriter.cpp 2335 2011-10-16 14:24:38Z TakeshiNakazato $
31//#---------------------------------------------------------------------------
32
33#include <casa/aips.h>
34#include <casa/Arrays/Array.h>
[988]35#include <casa/Arrays/Matrix.h>
[198]36#include <casa/Arrays/Vector.h>
37#include <casa/Arrays/VectorIter.h>
38#include <casa/Utilities/CountedPtr.h>
39#include <casa/Quanta/Quantum.h>
40#include <casa/Quanta/MVAngle.h>
[496]41#include <casa/Utilities/Assert.h>
[198]42
[209]43#include <casa/fstream.h>
[717]44#include <casa/sstream.h>
[988]45#include <casa/iomanip.h>
[209]46
[198]47#include <measures/Measures/MEpoch.h>
48
49#include <tables/Tables/Table.h>
[988]50#include <tables/Tables/TableIter.h>
51#include <tables/Tables/TableRecord.h>
52#include <casa/Containers/RecordField.h>
53#include <tables/Tables/TableRow.h>
[198]54#include <tables/Tables/ScalarColumn.h>
55#include <tables/Tables/ArrayColumn.h>
56
[988]57#include "STDefs.h"
58#include "STHeader.h"
59#include "Scantable.h"
60#include "STAsciiWriter.h"
[198]61
62using namespace casa;
63using namespace asap;
64
65
[988]66STAsciiWriter::STAsciiWriter()
[198]67{;}
68
[988]69STAsciiWriter::~STAsciiWriter()
[198]70{;}
71
72
[988]73Bool STAsciiWriter::write(const Scantable& stable, const String& fileName)
[198]74{
75
76// Get global Header from Table
77
[988]78 STHeader hdr = stable.getHeader();
[198]79
80// Column keywords
81
[988]82 Table tab = stable.table();
[198]83
84// Temps
85
86 const Unit RAD(String("rad"));
87
[496]88// Open and write header file
[198]89
[496]90 String rootName(fileName);
[1819]91
[988]92 Block<String> cols(4);
93 cols[0] = String("SCANNO");
94 cols[1] = String("CYCLENO");
95 cols[2] = String("BEAMNO");
96 cols[3] = String("IFNO");
97 TableIterator iter(tab, cols);
98 // Open data file
99 while ( !iter.pastEnd() ) {
100 Table t = iter.table();
101 ROTableRow row(t);
102 const TableRecord& rec = row.get(0);
103 String dirtype = stable.getDirectionRefString();
104 ostringstream onstr;
[1552]105
106 if (rootName.length()==0) {
107 rootName = String("ascii");
108 }
109 if (tab.nrow() > 1) {
110 if (stable.nscan() > 1)
111 onstr << "_SCAN" << rec.asuInt("SCANNO");
112 if (stable.ncycle(rec.asuInt("SCANNO")) > 1)
113 onstr << "_CYCLE" << rec.asuInt("CYCLENO");
114 if (stable.nbeam(rec.asuInt("SCANNO")) > 1)
115 onstr << "_BEAM" << rec.asuInt("BEAMNO");
116 if (stable.nif(rec.asuInt("SCANNO")) > 1)
117 onstr << "_IF" << rec.asuInt("IFNO");
118 }
119
[988]120 String fName = rootName + String(onstr) + String(".txt");
121 ofstream of(fName.chars(), ios::trunc);
[1295]122 int row0 = t.rowNumbers(tab)[0];
[988]123 MDirection mdir = stable.getDirection(row0);
124 of << setfill('#') << setw(70) << "" << setfill(' ') << endl;
125 addLine(of, "Name", rec.asString("SRCNAME"));
126 addLine(of, "Position", String(dirtype+ " "+formatDirection(mdir)));
127 addLine(of, "Time", stable.getTime(row0,true));
128 addLine(of, "Flux Unit", hdr.fluxunit);
129 addLine(of, "Pol Type", stable.getPolType());
130 addLine(of, "Abcissa", stable.getAbcissaLabel(row0));
131 addLine(of, "Beam No", rec.asuInt("BEAMNO"));
132 addLine(of, "IF No", rec.asuInt("IFNO"));
[1375]133 String wcs = stable.frequencies().print(rec.asuInt("FREQ_ID"), True);
134 addLine(of, "WCS", wcs);
[1819]135 std::vector<double> restfreqs= stable.molecules().getRestFrequency(rec.asuInt("MOLECULE_ID"));
136 int nf = restfreqs.size();
137 //addLine(of, "Rest Freq.",
138 // stable.molecules().getRestFrequency(rec.asuInt("MOLECULE_ID") ));
[2294]139 if ( nf > 0 ) {
140 addLine(of, "Rest Freq.", restfreqs[0]);
141 for ( int i=1; i<nf; ++i) {
142 addLine(of, " ", restfreqs[i]);
143 }
[1819]144 }
[2294]145 else {
146 addLine(of, "Rest Freq.", "NONE" );
147 }
[1819]148 ostringstream osflagrow;
149 for ( unsigned int i=0; i<t.nrow(); ++i) {
150 osflagrow << "Pol" << i << ":" << ((row.get(i).asuInt("FLAGROW") > 0) ? "True" : "False") << " ";
151 }
152 addLine(of, "Row_Flagged", String(osflagrow));
[988]153 of << setfill('#') << setw(70) << "" << setfill(' ') << endl;
[496]154
[2335]155 of << std::left << setw(16) << "#x";
[996]156 for ( unsigned int i=0; i<t.nrow(); ++i ) {
[994]157 ostringstream os,os1;
158 os << "y" << i;
159 os1 << "yf" << i;
160 of << setw(16) << String(os);
161 of << setw(7) << String(os1);
[988]162 }
163 of << endl;
164 std::vector<double> abc = stable.getAbcissa(row0);
165 ROArrayColumn<Float> specCol(t,"SPECTRA");
166 ROArrayColumn<uChar> flagCol(t,"FLAGTRA");
167 Matrix<Float> specs = specCol.getColumn();
168 Matrix<uChar> flags = flagCol.getColumn();
[996]169 for ( unsigned int i=0; i<specs.nrow(); ++i ) {
[988]170 of << setw(16) << setprecision(8) << abc[i] ;
[996]171 for ( unsigned int j=0; j<specs.ncolumn(); ++j ) {
[988]172 of << setw(16) << setprecision(8) << specs(i,j) ;
173 of << setw(7) << Int(flags(i,j));
[198]174 }
[988]175 of << endl;
176 }
177 of.close();
178 ostringstream oss;
179 oss << "Wrote " << fName;
180 pushLog(String(oss));
181 ++iter;
182 }
183 return True;
[198]184}
185
186
[988]187String STAsciiWriter::formatDirection(const MDirection& md) const
188{
189 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
190 Int prec = 7;
[198]191
[988]192 MVAngle mvLon(t[0]);
193 String sLon = mvLon.string(MVAngle::TIME,prec);
194 uInt tp = md.getRef().getType();
195 if (tp == MDirection::GALACTIC ||
196 tp == MDirection::SUPERGAL ) {
197 sLon = mvLon(0.0).string(MVAngle::ANGLE_CLEAN,prec);
198 }
199 MVAngle mvLat(t[1]);
200 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
201 return sLon + String(" ") + sLat;
202}
[717]203
[988]204template <class T>
205void STAsciiWriter::addLine(ostream& of, const String& lbl, const T& value)
206{
207 String label = lbl+String(": ");
208 of << std::right << "# " << setw(15) << label << std::left
209 << setw(52) << value << setw(0) << "#"<< endl;
[198]210}
Note: See TracBrowser for help on using the repository browser.