source: trunk/src/SDContainer.cc@ 16

Last change on this file since 16 was 16, checked in by mmarquar, 20 years ago

Updated data container. Changed the axis order in the spectrum/flag arrays to [nBeam,nIF,nPol,nChan]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDContainer.cc: A container class for single dish integrations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# Malte Marquarding, ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31#include <aips/Tables/Table.h>
32#include <aips/Arrays/IPosition.h>
33#include <aips/Arrays/ArrayAccessor.h>
34#include <aips/Arrays/Matrix.h>
35
36#include "SDContainer.h"
37
38using namespace atnf_sd;
39
40SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nPol, uInt nChan)
41 : nBeam_(nBeam),
42 nIF_(nIF),
43 nPol_(nPol),
44 nChan_(nChan),
45 spectrum_(IPosition(4,nBeam,nIF,nPol,nChan)),
46 flags_(IPosition(4,nBeam,nIF,nPol,nChan)),
47 tsys_(IPosition(4,nBeam,nIF,nPol,nChan)) {
48 uChar x = 0;
49 flags_ = ~x;
50}
51
52SDContainer::SDContainer(IPosition shp)
53 : nBeam_(shp(0)),
54 nIF_(shp(1)),
55 nPol_(shp(2)),
56 nChan_(shp(3)),
57 spectrum_(shp),
58 flags_(shp),
59 tsys_(shp) {
60 uChar x = 0;
61 flags_ = ~x;
62}
63
64SDContainer::~SDContainer() {
65}
66
67Bool SDContainer::putSpectrum(const Array<Float>& spec) {
68 spectrum_ = spec;
69}
70Bool SDContainer::putFlags(const Array<uChar>& flag) {
71 flags_ = flag;
72}
73Bool SDContainer::putTsys(const Array<Float>& tsys) {
74 tsys_ = tsys;
75}
76
77Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
78 uInt whichBeam, uInt whichIF) {
79
80 ArrayAccessor<Float, Axis<0> > aa0(spectrum_);
81 aa0.reset(aa0.begin(whichBeam));
82 ArrayAccessor<Float, Axis<1> > aa1(aa0);
83 aa1.reset(aa1.begin(whichIF));
84
85 //Vector<Float> pols(nPol);
86 ArrayAccessor<Float, Axis<1> > j(spec);
87 IPosition shp0 = spectrum_.shape();
88 IPosition shp1 = spec.shape();
89 if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
90 cerr << "Arrays not conformant" << endl;
91 return False;
92 }
93 // assert dimensions are the same....
94 for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
95 ArrayAccessor<Float, Axis<0> > jj(j);
96 for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
97 (*ii) = (*jj);
98 jj++;
99 }
100 j++;
101 }
102 // unset flags for this spectrum, they might be set again by the
103 // setFlags method
104
105 IPosition shp = flags_.shape();
106 IPosition start(4,whichBeam,whichIF,0,0);
107 IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
108 Array<uChar> arr(flags_(start,end));
109 arr = uChar(0);
110}
111
112Bool SDContainer::setFlags(const Matrix<uChar>& flag,
113 uInt whichBeam, uInt whichIF) {
114
115 ArrayAccessor<uChar, Axis<0> > aa0(flags_);
116 aa0.reset(aa0.begin(whichBeam));
117 ArrayAccessor<uChar, Axis<1> > aa1(aa0);
118 aa1.reset(aa1.begin(whichIF));
119
120 ArrayAccessor<uChar, Axis<1> > j(flag);
121 IPosition shp0 = flags_.shape();
122 IPosition shp1 = flag.shape();
123 if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
124 cerr << "Arrays not conformant" << endl;
125 return False;
126 }
127
128 // assert dimensions are the same....
129 for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
130 ArrayAccessor<uChar, Axis<0> > jj(j);
131 for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
132 (*ii) = (*jj);
133 jj++;
134 }
135 j++;
136 }
137 return True;
138}
139
140Bool SDContainer::setTsys(const Vector<Float>& tsys,
141 uInt whichBeam, uInt whichIF) {
142 ArrayAccessor<Float, Axis<0> > aa0(tsys_);
143 aa0.reset(aa0.begin(whichBeam));
144 ArrayAccessor<Float, Axis<1> > aa1(aa0);
145 aa1.reset(aa1.begin(whichIF));
146 // assert dimensions are the same....
147 for (ArrayAccessor<Float, Axis<3> > i(aa1);i != i.end(); ++i) {
148 ArrayAccessor<Float, Axis<0> > j(tsys);
149 for (ArrayAccessor<Float, Axis<2> > ii(i);ii != ii.end(); ++ii) {
150 (*ii) = (*j);
151 j++;
152 }
153 }
154}
Note: See TracBrowser for help on using the repository browser.