casacore
Loading...
Searching...
No Matches
Measure.h
Go to the documentation of this file.
1//# Measure.h: Physical quantities within reference frame
2//# Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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_MEASURE_H
27#define MEASURES_MEASURE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/iosfwd.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37class String;
38class Unit;
39class MeasValue;
40class MRBase;
41template <class T> class Quantum;
42
43// <summary>
44// Physical quantities within reference frame
45// </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 module="Measures">Measures module</linkto> description
54// <li> <linkto class=Quantum>Quantum</linkto> dimensioned values
55// <li> <linkto class=MeasValue>MeasValue</linkto> internal measure values
56// <li> <linkto class=MeasRef>MeasRef</linkto> class to specify reference
57// frame
58// <li> <linkto class=MeasConvert>MeasConvert</linkto> class, doing actual conversions
59// of a measure from one reference frame to another
60// <li> Some classes if you really want to understand details:
61// <ul>
62// <li> <linkto class=MeasBase>MeasBase</linkto> class, the immediate
63// parent of all specific Measures
64// <li> <linkto class=MCBase>MCBase</linkto> class, the base class
65// for all specific conversion routines (like
66// <linkto class=MCEpoch>MCEpoch</linkto>).
67// <li> <linkto class=MeasData>MeasData</linkto> class, containing a set
68// of generally usable constants, and all program data necessary for
69// conversions.
70// </ul>
71// <li> <linkto class=MeasTable>MeasTab;e</linkto> class, containing
72// the interface for external Tables (like leap-seconds, IERS data,
73// JPL data).
74// </prerequisite>
75//
76// <etymology>
77// </etymology>
78//
79// <synopsis>
80// Measure forms the abstract base class for physical quantities within
81// a reference frame. Examples of derived classes are:
82// <ul>
83// <li> <linkto class=MEpoch>MEpoch</linkto>: a moment in time
84// <li> <linkto class=MDirection>MDirection</linkto>: a direction in space
85// <li> <linkto class=MPosition>MPosition</linkto>: a position on Earth
86// <li> <linkto class=MFrequency>MFrequency</linkto>: wave characteristics
87// <li> <linkto class=MRadialVelocity>MRadialVelocity</linkto>: a space
88// radial velocity
89// <li> <linkto class=MDoppler>MDoppler</linkto>: a Doppler velocity
90// </ul>
91// Measure is the generic name for the more specific instances like, e.g.,
92// MEpoch, an instant in time.<br>
93// A Measure has both a value (specified in some value internal to the specific
94// Measure, in general called <em>MVMeasure</em> (e.g. MVEpoch)), see
95// <linkto class=MeasValue>MeasValue</linkto> for general details; and a
96// reference type and frame specifier (see
97// <linkto class=MeasRef>MeasRef</linkto> class).<br>
98// The <linkto class=MeasRef>MeasRef</linkto> specifies the reference type
99// of the value, e.g. TAI, UTC, LAST. In addition the
100// <linkto class=MeasRef>MeasRef</linkto> specifies a possible offset (e.g.
101// the beginning of the year, or today), and, if necessary, Measures necessary
102// for defining the absolute quantity (e.g. an
103// <linkto class=MPosition>MPosition</linkto> on Earth for LAST), using a
104// reference frame specifier (see
105// <linkto class=MeasFrame>MeasFrame</linkto> class).<br>
106// The <src>MeasRef</src> class is templated, but typedefs exist
107// (and should be used) to
108// easily specify the correct one, e.g. <src>MEpoch::Ref</src>.<br>
109// A Measure can be converted from one reference frame to another (e.g.
110// an MDirection can be converted from J2000 to apparent coordinates) by
111// setting up a measure specific conversion engine (see
112// <linkto class=MeasConvert>MeasConvert</linkto> class and below).
113// From an input
114// <src>MeasRef</src> frame and an output <src>MeasRef</src> frame it
115// constructs a conversion <em>functional</em>, that can be fed values (with
116// the <src>() operator</src>).<br>
117// Some conversions can, in addition to the main type (like TAI), specify
118// details to completely describe any conversion process (e.g. the type
119// of nutation calculation) by specifying
120// <linkto class=Aipsrc>Aipsrc</linkto> keyword/value pairs. <br>
121// <p>
122// Measures can in general be constructed from a <src>MeasRef</src> and a
123// value. The value can be expressed in the internally used units (e.g.
124// <linkto class=MVEpoch>MVEpoch</linkto> for <src>MEpoch</src>,
125// <linkto class=MVDirection>MVDirection</linkto> for <src>MDirection</src>), or
126// as a <src>Quantum</src>, i.e. a value with a dimension (e.g. (20,"km/s"))
127// (see <linkto class=Quantum>Quantum</linkto> class). The preferred way of
128// construction is by using the constructor:
129// <srcblock>
130// Measure(MVmeasure, Measure::Ref)
131// </srcblock>
132// where the reference can be omitted,
133// defaulting to <src>Measure::DEFAULT</src>), or in simple cases (not needing
134// additional frame information) be specified directly as a code (e.g.
135// <src>MEpoch::IAT</src>).<br>
136// <p>
137// The value of the <src>Measure</src> can be obtained by a variety of
138// <src>get</src> functions, returning in general internal or <src>Quantum</src>
139// values. The preferred way is a <src>getValue(void)</src>, which returns
140// the specific <src>MVmeasure</src> value, which can then be further formatted
141// using the appropiate <src>MVmeasure</src> get() functions.<br>
142// Special formatting (like hh:mm:ss.t, dd.mm.ss.t, yy/mm/dd etc)
143// are catered for in <em>conversion-type</em> classes like
144// <linkto class=MVAngle>MVAngle</linkto>,
145// <linkto class=MVTime>MVTime</linkto>.<br>
146// <p>
147// Conversion (within a Measure type) from one reference frame to another
148// is done by the <linkto class=MeasConvert>MeasConvert</linkto> class. The
149// class is templated, but has typedefs <src>Measure::Convert</src> (e.g.
150// MEpoch::Convert) for easy, and recommended, reference.<br>
151// The basic constructors for a
152// <src>Measure::Convert</src> are:
153// <srcblock>
154// // With a default Measure included
155// Measure::Convert(Measure val, Measure::Ref outref);
156// // With only input and output reference frames given
157// Mesaure::Convert( Measure::Ref inref, Measure::Ref outref);
158// </srcblock>
159// The <src>val</src>
160// is used as a <em>model</em> for subsequent input values into this
161// <em>conversion engine</em>, including possible units; the <src>outref</src>
162// specifies the output reference frame wanted. The constructor analyses the
163// conversion wanted, and sets up a vector of routine calls to be called
164// in sequence for the conversion. The actual conversion is done
165// by the <src>() operator</src>.<br>
166// To aid in using the raw measures, each class has also a Measure::MVType and
167// Measure::MCType defined. They denote respectively the Measure Value class
168// of the internal value, and the class with conversion routines.
169// <p>
170// <note role=tip> In the member description a number of <em>dummy</em> routines are
171// present. They are the only way I have found to get <em>cxx2html</em> to
172// get the belonging text properly present.
173// </note>
174// </synopsis>
175//
176// <example>
177// <srcblock>
178// #include <casacore/measures/Measures.h>
179// #include <casacore/casa/Measure/MEpoch.h>
180// // Example is only to show what can be done, not the easiest way
181// // Set up a simple reference (no offset or secondary Measures). It
182// // indicates that times are given in MJD TAI.
183// MEpoch::Ref reftai(MEpoch::TAI);
184// // Same, but indicating MJD UTC
185// MEpoch::Ref refutc(MEpoch::UTC);
186// // Set up an MEpoch (note that no reference is given. In that case a
187// // default is assumed (for MEpoch UTC). MJD2000 is a provided constant
188// // of the MJD at 2000.0
189// MEpoch UTCval(Quantity(MeasData::MJD2000, "d"), reftai);
190// // Set up, just for fun, an epoch, UTC for B1950.0:
191// MEpoch val1950(Quantity(MeasData::MJDB1950, "d"));
192// // and use it as an offset in a reference
193// MEpoch::Ref ref1950(MEpoch::TAI, val1950);
194// // An epoch for J2000 with an offset of B1950.0 will than be
195// MEpoch val20_50(Quantity(MeasData::MJD2000-MeasData::MJDB1950, "d"),
196// ref1950);
197// // Set up conversion from TAI(with values in days w.r.t. B1950.0) to UTC:
198// MEpoch::Convert tai_to_utc(val20_50, refutc);
199// // And convert a value (in this case the value in val20_50, the model)
200// // from TAI(relative to B1950.0) to 'absolute' UTC
201// MEpoch result = tai_to_utc();
202// // Show result
203// cout << "Result 1: " << result << endl;
204// // To convert 10 years since B1950.0
205// result = tai_to_utc(Quantity(10.,"a"));
206// cout << "Result 2: " << result << endl;
207// // To convert any value in years(the last used units of the model) since B1950.0
208// result = tai_to_utc(12.3);
209// cout << "Result 3: " << result << endl;
210// </srcblock>
211// Which generates the output:
212// <srcblock>
213// Result 1: Epoch: 51544::11:59:25.2154
214// Result 2: Epoch: 36934::10:09:42.1283
215// Result 3: Epoch: 37774::11:57:41.1085
216// </srcblock>
217// </example>
218//
219// <motivation>
220// To be able to specify a physical entity absolutely in any reference frame;
221// and to be able to convert from one frame to another. E.g. Local Sidereal
222// Time to Temps Atomic International. A templated version for the MeasRef
223// and MeasConvert was chosen to be able to check most arguments at
224// compile time.
225// </motivation>
226//
227// <todo asof='1997/04/15'>
228// <li> more Measures, e.g. MPlanet
229// <li> operators on Measures (e.g. MEpoch - MEpoch == MDuration)
230// </todo>
231
232class Measure {
233
234public:
235 //# Enumerations
236 // Each derived class should have a <src>Types</src> enumeration, specifying
237 // the recognised frame types. It is formatted as:
238 // <srcblock>
239 // enum Types {
240 // CODE1,
241 // CODE2,
242 // ...,
243 // N_Types, // Number of types
244 // SPEC1 = n, // Possible special manipulator code
245 // .....,
246 // SYNONYM1 = CODEn, // Probable synonyms
247 // ....,
248 // DEFAULT = CODEm};
249 // </srcblock>
250 // Dummy for cxx2html
251 enum Types {N_Types, DEFAULT = 0};
252
253 //# Typedefs
254 // Each Measure should have typedefs of the form:
255 // <srcblock>
256 // typedef MeasConvert<class a_Measure, class its_MV, its_MC> Convert;
257 // typedef MeasRef<class a_Measure> Ref;
258 // </srcblock>
259 // Dummy for cxx2html
260 typedef void* Convert;
261 //# Friends
262 // Each derived class should have:
263 // <srcblock>
264 // friend class MeasConvert<a_Measure, its_MV, its_MC>;
265 // </srcblock>
266 // Output a Measure
267 friend std::ostream &operator<<(std::ostream &os, const Measure &meas);
268
269 //# Constructors
270
271 //# Destructor
272 // Destructor
273 virtual ~Measure();
274
275 //# Operators
276
277 //# General Member Functions
278 // Each Measure should have the following set functions (with appropiate
279 // MVs and Ref):
280 // <srcblock>
281 // void set(const MVmeasure &dt);
282 // void set(const Measure::Ref &rf);
283 // void set(const MVmeasure &dt, const Measure::Ref &rf);
284 // </srcblock>
285 // <group>
286 virtual void set(const MeasValue &dt) = 0;
287 virtual Bool putValue(const Vector<Quantum<Double> > &in) = 0;
288 // </group>
289 // Set the offset in the reference (False if non-matching Measure)
290 virtual Bool setOffset(const Measure &in) = 0;
291 //
292 // Check the type of derived Measure entity (e.g. "Epoch")
293 virtual Bool areYou(const String &tp) const = 0;
294 // All should have:
295 // Assert that we are the correct Measure type
296 // <thrown>
297 // <li> AipsError if wrong Measure type
298 // </thrown>
299 // Each Measure should have:
300 // <src> static void assure(const Measure &in); </src>
301 // <group>
302 virtual void assured(const String &tp) const = 0;
303 // </group>
304 // Tell me your Measure type (e.g. "Epoch")
305 virtual const String &tellMe() const = 0;
306
307 // Each Measure should have the following static methods to give its
308 // name (e.g. Epoch) or reference type (e.g. UTC):<br>
309 // <srcblock>
310 // // Show the Measure type (e.g. "Direction")
311 // static const String &showMe();
312 // // Cast an integer to the appropriate reference type. Avaialable to provide
313 // // a safe cast in cases where Measure type is not explicitly known.
314 // static Measure::Types castType(uInt tp);
315 // // Show the reference type (e.g. MEpoch::showType(MEpoch::IAT) == "TAI")
316 // static const String &showType(uInt tp);
317 // static const String &showType(Measure::Types tp);
318 // </srcblock>
319 // <group>
320 virtual String getRefString() const = 0;
321 // </group>
322 // Tell me if you are a pure model (e.g. a planet)
323 virtual Bool isModel() const;
324 //
325 // Each derived class should have a string-to-code translation routine
326 // for the reference type. The routine returns False if unknown String (and
327 // a default mr), else an appropiate mr reference.
328 // <srcblock>
329 // Bool giveMe(Measure::Ref &mr, const String &in);
330 // static Bool getType(Measure::Types &tp, const String &in);
331 // </srcblock>
332 // <group>
333 // Dummy for cxx2html
334 void dummy_giveMe() const {}
335 // </group>
336 //
337 // Set the reference type to the specified String. False if illegal
338 // string, reference set to DEFAULT.
339 virtual Bool setRefString(const String &in) = 0;
340 // Get the default reference type
341 virtual const String &getDefaultType() const = 0;
342 // Get a list of all known reference codes. nall returns the number in list,
343 // nextra the number of specials (like planets) that should be at
344 // end of list). typ returns the list of corresponding types.
345 // All should have
346 // <srcblock>
347 // static const String* allMyTypes(Int &nall, Int &nextra,
348 // const uInt *&typ);
349 // </srcblock>
350 // <group>
351 virtual const String* allTypes(Int &nall, Int &nextra,
352 const uInt *&typ) const;
353 // </group>
354 //
355 // Check if all internal tables of types (both enum and String) are
356 // complete and correct. This function is called automatically if and when
357 // necessary.
358 // <thrown>
359 // <li> AipsError if a (programming) error in the types.
360 // </thrown>
361 // All should have
362 // <srcblock>
363 // static void checkMyTypes();
364 // </srcblock>
365 // <group>
366 virtual void checkTypes() const = 0;
367 // </group>
368 //
369 // A general string checking routine to be used in derived measures.
370 // Its arguments are the string to be converted (in), an array of
371 // strings to check against (tname), and its length (N_name). The check
372 // is case insensitive and mini-max. A return value less than N_name indicates
373 // success.
374 static uInt giveMe(const String &in, Int N_name,
375 const String tname[]);
376 // Each class should have a function to return its reference:
377 // <srcblock>
378 // Measure::Ref getRef() const;
379 // </srcblock>
380 // <group>
381 // Dummy for cxx2html
382 void dummy_getRef() const {}
383 // </group>
384 //
385 // Each derived class should be able to get its internal value and have:
386 // <srcblock>
387 // const MVmeasure &getValue() const;
388 // </srcblock>
389 // To get dimensioned data, each derived class should contain the
390 // appropiate one of:
391 // <srcblock>
392 // Quantity get(const Unit &unit) const;
393 // Quantum<Vector<Double> > get(const Unit &unit) const;
394 // </srcblock>
395 // <group>
396 void dummy_getValue() const {}
397 // </group>
398 //
399 //
400 // Get unit (only available if Measure generated from a Quantum, else "")
401 virtual const Unit &getUnit() const = 0;
402
403 // Get data pointer (used by MeasConvert)
404 virtual const MeasValue* getData() const = 0;
405
406 // Get general reference pointer
407 virtual MRBase *getRefPtr() const = 0;
408
409 // Print a Measure
410 virtual void print(std::ostream &os) const = 0;
411 // Create a copy
412 // <group>
413 virtual Measure *clone() const = 0;
414 // </group>
415protected:
416
417private:
418 //# Enumerations
419
420 //# Data
421 // Each class will have the following information:
422 // Actual data
423 // <srcblock>
424 // MVmeasure data;
425 // </srcblock>
426 // Reference frame data
427 // <srcblock>
428 // MeasRef<Measure> ref;
429 // </srcblock>
430 // Possible input units
431 // <srcblock>
432 // Unit unit;
433 // </srcblock>
434 // And maybe later (or somewhere else)
435 // <srcblock>
436 // MeasErr error;
437 // </srcblock>
438 // <group>
439 // Dummy for cxx2html
440 void dummy_data() const {}
441 // </group>
442 //
443 //# Member functions
444 // Clear the measure
445 virtual void clear() = 0;
446
447};
448
449//# Global functions
450// <summary> Global functions </summary>
451// <group name=Output>
452// Output declaration
453std::ostream &operator<<(std::ostream &os, const Measure &meas);
454// </group>
456
457} //# NAMESPACE CASACORE - END
458
459#endif
virtual const String & getDefaultType() const =0
Get the default reference type.
virtual Measure * clone() const =0
Create a copy.
virtual Bool setOffset(const Measure &in)=0
Set the offset in the reference (False if non-matching Measure)
void dummy_giveMe() const
Each derived class should have a string-to-code translation routine for the reference type.
Definition Measure.h:334
virtual ~Measure()
Destructor.
virtual const MeasValue * getData() const =0
Get data pointer (used by MeasConvert)
friend std::ostream & operator<<(std::ostream &os, const Measure &meas)
Each derived class should have:
void dummy_getValue() const
Each derived class should be able to get its internal value and have:
Definition Measure.h:396
virtual void print(std::ostream &os) const =0
Print a Measure.
void * Convert
Each Measure should have typedefs of the form:
Definition Measure.h:260
virtual Bool isModel() const
Tell me if you are a pure model (e.g.
void dummy_getRef() const
Each class should have a function to return its reference:
Definition Measure.h:382
virtual const String * allTypes(Int &nall, Int &nextra, const uInt *&typ) const
Get a list of all known reference codes.
virtual void set(const MeasValue &dt)=0
Each Measure should have the following set functions (with appropiate MVs and Ref):
virtual Bool setRefString(const String &in)=0
Set the reference type to the specified String.
virtual const String & tellMe() const =0
Tell me your Measure type (e.g.
virtual const Unit & getUnit() const =0
Get unit (only available if Measure generated from a Quantum, else "")
Types
Each derived class should have a Types enumeration, specifying the recognised frame types.
Definition Measure.h:251
virtual String getRefString() const =0
Each Measure should have the following static methods to give its name (e.g.
virtual void clear()=0
Clear the measure.
virtual Bool areYou(const String &tp) const =0
Check the type of derived Measure entity (e.g.
virtual void assured(const String &tp) const =0
All should have: Assert that we are the correct Measure type.
static uInt giveMe(const String &in, Int N_name, const String tname[])
A general string checking routine to be used in derived measures.
virtual MRBase * getRefPtr() const =0
Get general reference pointer.
void dummy_data() const
Each class will have the following information: Actual data.
Definition Measure.h:440
virtual Bool putValue(const Vector< Quantum< Double > > &in)=0
virtual void checkTypes() const =0
Check if all internal tables of types (both enum and String) are complete and correct.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
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
std::ostream & operator<<(std::ostream &os, const Measure &meas)
Output declaration.