casacore
Loading...
Searching...
No Matches
MeasConvert.h
Go to the documentation of this file.
1//# MeasConvert.h: Conversion of Measures
2//# Copyright (C) 1995,1996,1997,1998,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#ifndef MEASURES_MEASCONVERT_H
27#define MEASURES_MEASCONVERT_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/Block.h>
32#include <casacore/measures/Measures/MConvertBase.h>
33#include <casacore/casa/Quanta/Quantum.h>
34#include <casacore/measures/Measures/Measure.h>
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class MCBase;
39class MeasVal;
40
41//# Typedefs
42
43//# Constants
44
45// <summary> Conversion of Measures </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
50// </reviewed>
51
52// <prerequisite>
53// <li> <linkto class=Measure>Measure</linkto> class
54// <li> <linkto class=MRBase>MeasRef</linkto> base class
55// <li> <linkto class=MConvertBase>MConvertBase</linkto> class
56// <li> <linkto class=Quantum>Quantum</linkto> class
57// </prerequisite>
58//
59// <etymology>
60// </etymology>
61//
62// <synopsis>
63// MeasConvert can convert a Measure to the same type of Measure in a
64// different reference frame. The MeasConvert is a templated class, but
65// has typedefs, which are strongly recommended to be used,
66// for the allowed conversions, like <src>MEpoch::Convert.</src><br>
67// The basic operation is to create a MeasConvert with either of:
68// <ul>
69// <li> MEpoch::Convert(MEpoch, MEpoch::Ref), where the
70// <linkto class=MEpoch>MEpoch</linkto> is a template for subsequent
71// conversions, i.e. it will remember the value (with its reference) and
72// the <linkto class=MeasRef>MeasRef</linkto> output reference.
73// <li> MEpoch::Convert(MEpoch) with a subsequent setOut(MEpoch::Ref)
74// <li> MEpoch::Convert(MEpoch::Ref in, MEpoch::Ref out) is a template for
75// conversions from the input reference to the output reference. The
76// 'template' model used is the default value for the Measure, with
77// no units.
78// <li> MEpoch::Convert(Unit, MEpoch::Ref in, MEpoch::Ref out) is a
79// template for
80// conversions from the input reference to the output reference. The
81// 'template' model used is the default value for the Measure, with
82// the default units as specified.
83// <li> MEpoch::Convert() with a setModel(MEpoch) and setOut().
84// </ul>
85// An empty MeasRef argument indicates no conversion will be attempted<br>.
86// The constructor, and set functions, analyse the 'template' Measure and the
87// output reference frame, and construct a pointer (in practice a list
88// of pointers to bypass the necessity of creating too many conversion
89// functions) to a conversion routine.
90//
91// An <src>isNOP()</src> function is available to test if the created
92// conversion engine is empty.
93//
94// Actual conversions are done with the () operator, which produces a new
95// MEpoch (or other appropiate Measure).<br>
96// Possible arguments are (MVEpoch is used here generic, and indicates the
97// internal format of a Measure; possibly, to make sure distinction between
98// values with and without units possible, even simple Measures will
99// have their own internal class format, e.g. MVDouble.
100// The possible arguments to the () conversion operator are (again Epoch
101// is used for the generic Measure):
102// <ul>
103// <li> (MEpoch, MEpoch::Ref): will create a new conversion method, and use
104// it to produce the result of converting the MEpoch to the specified
105// frame
106// <li> (MEpoch): will create a new conversion method from the
107// MEpoch to the MeasRef belonging to the MeasConvert
108// <li> (Quantity): will use the conversion chain deduced from the
109// MEpoch model in the definition of MeasConvert, and will convert the
110// Quantity
111// <li> (Quantum<Vector<Double> >) as previous
112// <li> (Double): will use the units (if present) as specified in the
113// MeasConvert object to construct the internal value
114// to be converted
115// <li> (Vector<Double> >): as previous
116// </ul>
117// Float versions will be produced if necessary.<br>
118// The conversion analyser expects that all Measure classes have a set
119// of routines to do the actual analysing and conversion.
120// (see <linkto class=MCBase>MCBase</linkto> class for how this is done in
121// practice).<br>
122// If the standard conversion is not sufficient, additional methods can be
123// added at the end of the list with the <src>addMethod()</src> member
124// function (for real pros).<br>
125// </synopsis>
126//
127// <example>
128// See <linkto class=Measure>Measure</linkto> for an example
129// </example>
130//
131// <motivation>
132// Conversion of Measures will in general be done on a series of values.
133// Separating the analysis of the calculations necessary for the conversion
134// from the actual conversion could speed up the process.
135// </motivation>
136//
137// <todo asof="1999/09/24">
138// </todo>
139
140template<class M> class MeasConvert : public MConvertBase {
141
142public:
143
144 //# Friends
145
146 //# Constructors
147 // <note role=tip> In the following constructors and other functions, all
148 // <em>MeasRef</em> can be replaced with simple <src>Measure::TYPE</src>
149 // where no offsets or frames are needed in the reference.</note>
150 // Construct an empty MeasConvert. It is not usable, unless a setModel, and
151 // probably a setOut has been done.
153 // Copy constructor
155 // Copy assignment
157
158 // Construct a conversion for the specified Measure and reference
159 // <group>
160 MeasConvert(const M &ep);
161 MeasConvert(const M &ep, const typename M::Ref &mr);
162 MeasConvert(const Measure &ep, const typename M::Ref &mr);
163 MeasConvert(const M &ep, typename M::Types mr);
164 MeasConvert(const Measure &ep, typename M::Types mr);
165 MeasConvert(const typename M::Ref &mrin, const typename M::Ref &mr);
166 MeasConvert(const typename M::Ref &mrin, typename M::Types mr);
167 MeasConvert(typename M::Types mrin, const typename M::Ref &mr);
168 MeasConvert(typename M::Types mrin, typename M::Types mr);
169 MeasConvert(const Unit &inunit, const typename M::Ref &mrin,
170 const typename M::Ref &mr);
171 MeasConvert(const Unit &inunit, const typename M::Ref &mrin,
172 typename M::Types mr);
173 MeasConvert(const Unit &inunit, typename M::Types mrin,
174 const typename M::Ref &mr);
175 MeasConvert(const Unit &inunit, typename M::Types mrin,
176 typename M::Types mr);
177 // </group>
178
179 //# Destructor
181
182 //# Operators
183 // The actual conversion operations
184 // <group>
185 // Convert model Measure to output frame
186 const M &operator()();
187 const M &operator()(Double val);
188 const M &operator()(const Vector<Double> &val);
189 const M &operator()(const Quantum<Double> &val);
190 const M &operator()(const Quantum<Vector<Double> > &val);
191 const M &operator()(const typename M::MVType &val);
192 const M &operator()(const MeasVal *val);
193 const M &operator()(const M &val);
194 const M &operator()(const M &val, const typename M::Ref &mr);
195 const M &operator()(const M &val, typename M::Types mr);
196 const M &operator()(const typename M::Ref &mr);
197 const M &operator()(typename M::Types mr);
198 // </group>
199
200 //# General Member Functions
201 // Set a new model for the conversion
202 virtual void setModel(const Measure &val);
203 // Set a new output reference
204 // <group>
205 void setOut(const typename M::Ref &mr);
206 void setOut(typename M::Types mr);
207 // </group>
208 // Set a new model and reference
209 // <group>
210 void set(const M &val, const typename M::Ref &mr);
211 void set(const M &val, typename M::Types mr);
212 // </group>
213 // Set a new model value only
214 virtual void set(const MeasValue &val);
215 // Set a new model unit only
216 virtual void set(const Unit &inunit);
217
218 // Add a method (Note: uInt should be an enum from the appropiate Measure)
219 virtual void addMethod(uInt method);
220 // Add the frame type (Note: tp should be an MeasFrame::FrameType)
221 virtual void addFrameType(uInt tp);
222 // Get number of methods
223 virtual Int nMethod() const;
224 // Get method
225 virtual uInt getMethod(uInt which) const;
226 // Is the conversion engine empty?
227 Bool isNOP() { return crout.nelements() == 0; }
228 // Print conversion engine
229 virtual void print(ostream &os) const;
230
231private:
232 //# Data
233 // The model template Measure
235 // The model unit to be used in conversions
237 // The output reference
238 typename M::Ref outref;
239 // The input offset
240 typename M::MVType *offin;
241 // The output offset
242 typename M::MVType *offout;
243 // Vector of conversion routines (length variable)
245 // Coded (with MeasFrame::FrameTypes) frames used in conversion
247 // Local conversion data
249 // Cyclic buffer for return values
250 // <group>
251 // Current pointer
253 M *result[4];
254 // </group>
255 // Local variables that can be used in conversion
256 // <group>
257 typename M::MVType *locres;
258 // </group>
259
260 //# Member functions
261 // Initialise pointers
262 void init();
263 // Copy a MeasConvert
264 void copy(const MeasConvert<M> &other);
265 // Clear self
266 void clear();
267 // Create the conversion routine chain
268 void create();
269 // Convert a value
270 // <group>
271 const typename M::MVType &convert();
272 const typename M::MVType &convert(const typename M::MVType &val);
273 // </group>
274};
275
276//# Global functions
277
278
279} //# NAMESPACE CASACORE - END
280
281#ifndef CASACORE_NO_AUTO_TEMPLATES
282#include <casacore/measures/Measures/MeasConvert.tcc>
283#endif //# CASACORE_NO_AUTO_TEMPLATES
284#endif
simple 1-D array
Definition Block.h:198
size_t nelements() const
The number of elements contained in this Block<T>.
Definition Block.h:609
virtual void addMethod(uInt method)
Add a method (Note: uInt should be an enum from the appropiate Measure)
virtual void print(ostream &os) const
Print conversion engine.
const M::MVType & convert(const typename M::MVType &val)
const M & operator()(Double val)
const M & operator()(const typename M::MVType &val)
MeasConvert(const Unit &inunit, typename M::Types mrin, const typename M::Ref &mr)
virtual uInt getMethod(uInt which) const
Get method.
Bool isNOP()
Is the conversion engine empty?
void set(const M &val, const typename M::Ref &mr)
Set a new model and reference.
const M & operator()(const Quantum< Double > &val)
MeasConvert(const M &ep, const typename M::Ref &mr)
virtual void set(const MeasValue &val)
Set a new model value only.
const M & operator()(const MeasVal *val)
M::MVType * offin
The input offset.
const M & operator()(typename M::Types mr)
void init()
Initialise pointers.
const M & operator()(const Vector< Double > &val)
void setOut(const typename M::Ref &mr)
Set a new output reference.
MeasConvert(const Unit &inunit, const typename M::Ref &mrin, const typename M::Ref &mr)
MeasConvert(const Unit &inunit, const typename M::Ref &mrin, typename M::Types mr)
MeasConvert(const Measure &ep, const typename M::Ref &mr)
M::MVType * offout
The output offset.
M::Ref outref
The output reference.
MeasConvert(const typename M::Ref &mrin, const typename M::Ref &mr)
MeasConvert()
Tip: In the following constructors and other functions, all MeasRef can be replaced with simple Measu...
virtual void addFrameType(uInt tp)
Add the frame type (Note: tp should be an MeasFrame::FrameType)
MeasConvert(const Unit &inunit, typename M::Types mrin, typename M::Types mr)
Unit unit
The model unit to be used in conversions.
const M & operator()(const M &val, typename M::Types mr)
MeasConvert(typename M::Types mrin, typename M::Types mr)
Int lres
Cyclic buffer for return values.
void setOut(typename M::Types mr)
void clear()
Clear self.
MeasConvert< M > & operator=(const MeasConvert< M > &other)
Copy assignment.
void copy(const MeasConvert< M > &other)
Copy a MeasConvert.
virtual void setModel(const Measure &val)
Set a new model for the conversion.
const M & operator()(const M &val)
MeasConvert(const typename M::Ref &mrin, typename M::Types mr)
uInt crtype
Coded (with MeasFrame::FrameTypes) frames used in conversion.
void set(const M &val, typename M::Types mr)
MeasConvert(const M &ep)
Construct a conversion for the specified Measure and reference.
const M & operator()(const Quantum< Vector< Double > > &val)
Block< uInt > crout
Vector of conversion routines (length variable)
MeasConvert(typename M::Types mrin, const typename M::Ref &mr)
Measure * model
The model template Measure.
MeasConvert(const Measure &ep, typename M::Types mr)
const M & operator()(const M &val, const typename M::Ref &mr)
virtual Int nMethod() const
Get number of methods.
const M::MVType & convert()
Convert a value.
void create()
Create the conversion routine chain.
MCBase * cvdat
Local conversion data.
MeasConvert(const MeasConvert< M > &other)
Copy constructor.
MeasConvert(const M &ep, typename M::Types mr)
M::MVType * locres
Local variables that can be used in conversion.
const M & operator()(const typename M::Ref &mr)
const M & operator()()
The actual conversion operations.
virtual void set(const Unit &inunit)
Set a new model unit only.
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53