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>
42class Quantum;
43
44// <summary>
45// Physical quantities within reference frame
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
51// </reviewed>
52
53// <prerequisite>
54// <li> <linkto module="Measures">Measures module</linkto> description
55// <li> <linkto class=Quantum>Quantum</linkto> dimensioned values
56// <li> <linkto class=MeasValue>MeasValue</linkto> internal measure values
57// <li> <linkto class=MeasRef>MeasRef</linkto> class to specify reference
58// frame
59// <li> <linkto class=MeasConvert>MeasConvert</linkto> class, doing actual conversions
60// of a measure from one reference frame to another
61// <li> Some classes if you really want to understand details:
62// <ul>
63// <li> <linkto class=MeasBase>MeasBase</linkto> class, the immediate
64// parent of all specific Measures
65// <li> <linkto class=MCBase>MCBase</linkto> class, the base class
66// for all specific conversion routines (like
67// <linkto class=MCEpoch>MCEpoch</linkto>).
68// <li> <linkto class=MeasData>MeasData</linkto> class, containing a set
69// of generally usable constants, and all program data necessary for
70// conversions.
71// </ul>
72// <li> <linkto class=MeasTable>MeasTab;e</linkto> class, containing
73// the interface for external Tables (like leap-seconds, IERS data,
74// JPL data).
75// </prerequisite>
76//
77// <etymology>
78// </etymology>
79//
80// <synopsis>
81// Measure forms the abstract base class for physical quantities within
82// a reference frame. Examples of derived classes are:
83// <ul>
84// <li> <linkto class=MEpoch>MEpoch</linkto>: a moment in time
85// <li> <linkto class=MDirection>MDirection</linkto>: a direction in space
86// <li> <linkto class=MPosition>MPosition</linkto>: a position on Earth
87// <li> <linkto class=MFrequency>MFrequency</linkto>: wave characteristics
88// <li> <linkto class=MRadialVelocity>MRadialVelocity</linkto>: a space
89// radial velocity
90// <li> <linkto class=MDoppler>MDoppler</linkto>: a Doppler velocity
91// </ul>
92// Measure is the generic name for the more specific instances like, e.g.,
93// MEpoch, an instant in time.<br>
94// A Measure has both a value (specified in some value internal to the specific
95// Measure, in general called <em>MVMeasure</em> (e.g. MVEpoch)), see
96// <linkto class=MeasValue>MeasValue</linkto> for general details; and a
97// reference type and frame specifier (see
98// <linkto class=MeasRef>MeasRef</linkto> class).<br>
99// The <linkto class=MeasRef>MeasRef</linkto> specifies the reference type
100// of the value, e.g. TAI, UTC, LAST. In addition the
101// <linkto class=MeasRef>MeasRef</linkto> specifies a possible offset (e.g.
102// the beginning of the year, or today), and, if necessary, Measures necessary
103// for defining the absolute quantity (e.g. an
104// <linkto class=MPosition>MPosition</linkto> on Earth for LAST), using a
105// reference frame specifier (see
106// <linkto class=MeasFrame>MeasFrame</linkto> class).<br>
107// The <src>MeasRef</src> class is templated, but typedefs exist
108// (and should be used) to
109// easily specify the correct one, e.g. <src>MEpoch::Ref</src>.<br>
110// A Measure can be converted from one reference frame to another (e.g.
111// an MDirection can be converted from J2000 to apparent coordinates) by
112// setting up a measure specific conversion engine (see
113// <linkto class=MeasConvert>MeasConvert</linkto> class and below).
114// From an input
115// <src>MeasRef</src> frame and an output <src>MeasRef</src> frame it
116// constructs a conversion <em>functional</em>, that can be fed values (with
117// the <src>() operator</src>).<br>
118// Some conversions can, in addition to the main type (like TAI), specify
119// details to completely describe any conversion process (e.g. the type
120// of nutation calculation) by specifying
121// <linkto class=Aipsrc>Aipsrc</linkto> keyword/value pairs. <br>
122// <p>
123// Measures can in general be constructed from a <src>MeasRef</src> and a
124// value. The value can be expressed in the internally used units (e.g.
125// <linkto class=MVEpoch>MVEpoch</linkto> for <src>MEpoch</src>,
126// <linkto class=MVDirection>MVDirection</linkto> for <src>MDirection</src>), or
127// as a <src>Quantum</src>, i.e. a value with a dimension (e.g. (20,"km/s"))
128// (see <linkto class=Quantum>Quantum</linkto> class). The preferred way of
129// construction is by using the constructor:
130// <srcblock>
131// Measure(MVmeasure, Measure::Ref)
132// </srcblock>
133// where the reference can be omitted,
134// defaulting to <src>Measure::DEFAULT</src>), or in simple cases (not needing
135// additional frame information) be specified directly as a code (e.g.
136// <src>MEpoch::IAT</src>).<br>
137// <p>
138// The value of the <src>Measure</src> can be obtained by a variety of
139// <src>get</src> functions, returning in general internal or <src>Quantum</src>
140// values. The preferred way is a <src>getValue(void)</src>, which returns
141// the specific <src>MVmeasure</src> value, which can then be further formatted
142// using the appropiate <src>MVmeasure</src> get() functions.<br>
143// Special formatting (like hh:mm:ss.t, dd.mm.ss.t, yy/mm/dd etc)
144// are catered for in <em>conversion-type</em> classes like
145// <linkto class=MVAngle>MVAngle</linkto>,
146// <linkto class=MVTime>MVTime</linkto>.<br>
147// <p>
148// Conversion (within a Measure type) from one reference frame to another
149// is done by the <linkto class=MeasConvert>MeasConvert</linkto> class. The
150// class is templated, but has typedefs <src>Measure::Convert</src> (e.g.
151// MEpoch::Convert) for easy, and recommended, reference.<br>
152// The basic constructors for a
153// <src>Measure::Convert</src> are:
154// <srcblock>
155// // With a default Measure included
156// Measure::Convert(Measure val, Measure::Ref outref);
157// // With only input and output reference frames given
158// Mesaure::Convert( Measure::Ref inref, Measure::Ref outref);
159// </srcblock>
160// The <src>val</src>
161// is used as a <em>model</em> for subsequent input values into this
162// <em>conversion engine</em>, including possible units; the <src>outref</src>
163// specifies the output reference frame wanted. The constructor analyses the
164// conversion wanted, and sets up a vector of routine calls to be called
165// in sequence for the conversion. The actual conversion is done
166// by the <src>() operator</src>.<br>
167// To aid in using the raw measures, each class has also a Measure::MVType and
168// Measure::MCType defined. They denote respectively the Measure Value class
169// of the internal value, and the class with conversion routines.
170// <p>
171// <note role=tip> In the member description a number of <em>dummy</em> routines are
172// present. They are the only way I have found to get <em>cxx2html</em> to
173// get the belonging text properly present.
174// </note>
175// </synopsis>
176//
177// <example>
178// <srcblock>
179// #include <casacore/measures/Measures.h>
180// #include <casacore/casa/Measure/MEpoch.h>
181// // Example is only to show what can be done, not the easiest way
182// // Set up a simple reference (no offset or secondary Measures). It
183// // indicates that times are given in MJD TAI.
184// MEpoch::Ref reftai(MEpoch::TAI);
185// // Same, but indicating MJD UTC
186// MEpoch::Ref refutc(MEpoch::UTC);
187// // Set up an MEpoch (note that no reference is given. In that case a
188// // default is assumed (for MEpoch UTC). MJD2000 is a provided constant
189// // of the MJD at 2000.0
190// MEpoch UTCval(Quantity(MeasData::MJD2000, "d"), reftai);
191// // Set up, just for fun, an epoch, UTC for B1950.0:
192// MEpoch val1950(Quantity(MeasData::MJDB1950, "d"));
193// // and use it as an offset in a reference
194// MEpoch::Ref ref1950(MEpoch::TAI, val1950);
195// // An epoch for J2000 with an offset of B1950.0 will than be
196// MEpoch val20_50(Quantity(MeasData::MJD2000-MeasData::MJDB1950, "d"),
197// ref1950);
198// // Set up conversion from TAI(with values in days w.r.t. B1950.0) to UTC:
199// MEpoch::Convert tai_to_utc(val20_50, refutc);
200// // And convert a value (in this case the value in val20_50, the model)
201// // from TAI(relative to B1950.0) to 'absolute' UTC
202// MEpoch result = tai_to_utc();
203// // Show result
204// cout << "Result 1: " << result << endl;
205// // To convert 10 years since B1950.0
206// result = tai_to_utc(Quantity(10.,"a"));
207// cout << "Result 2: " << result << endl;
208// // To convert any value in years(the last used units of the model) since B1950.0
209// result = tai_to_utc(12.3);
210// cout << "Result 3: " << result << endl;
211// </srcblock>
212// Which generates the output:
213// <srcblock>
214// Result 1: Epoch: 51544::11:59:25.2154
215// Result 2: Epoch: 36934::10:09:42.1283
216// Result 3: Epoch: 37774::11:57:41.1085
217// </srcblock>
218// </example>
219//
220// <motivation>
221// To be able to specify a physical entity absolutely in any reference frame;
222// and to be able to convert from one frame to another. E.g. Local Sidereal
223// Time to Temps Atomic International. A templated version for the MeasRef
224// and MeasConvert was chosen to be able to check most arguments at
225// compile time.
226// </motivation>
227//
228// <todo asof='1997/04/15'>
229// <li> more Measures, e.g. MPlanet
230// <li> operators on Measures (e.g. MEpoch - MEpoch == MDuration)
231// </todo>
232
233class Measure {
234 public:
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, const uInt *&typ) const;
352 // </group>
353 //
354 // Check if all internal tables of types (both enum and String) are
355 // complete and correct. This function is called automatically if and when
356 // necessary.
357 // <thrown>
358 // <li> AipsError if a (programming) error in the types.
359 // </thrown>
360 // All should have
361 // <srcblock>
362 // static void checkMyTypes();
363 // </srcblock>
364 // <group>
365 virtual void checkTypes() const = 0;
366 // </group>
367 //
368 // A general string checking routine to be used in derived measures.
369 // Its arguments are the string to be converted (in), an array of
370 // strings to check against (tname), and its length (N_name). The check
371 // is case insensitive and mini-max. A return value less than N_name indicates
372 // success.
373 static uInt giveMe(const String &in, Int N_name, const String tname[]);
374 // Each class should have a function to return its reference:
375 // <srcblock>
376 // Measure::Ref getRef() const;
377 // </srcblock>
378 // <group>
379 // Dummy for cxx2html
380 void dummy_getRef() const {}
381 // </group>
382 //
383 // Each derived class should be able to get its internal value and have:
384 // <srcblock>
385 // const MVmeasure &getValue() const;
386 // </srcblock>
387 // To get dimensioned data, each derived class should contain the
388 // appropiate one of:
389 // <srcblock>
390 // Quantity get(const Unit &unit) const;
391 // Quantum<Vector<Double> > get(const Unit &unit) const;
392 // </srcblock>
393 // <group>
394 void dummy_getValue() const {}
395 // </group>
396 //
397 //
398 // Get unit (only available if Measure generated from a Quantum, else "")
399 virtual const Unit &getUnit() const = 0;
400
401 // Get data pointer (used by MeasConvert)
402 virtual const MeasValue *getData() const = 0;
403
404 // Get general reference pointer
405 virtual MRBase *getRefPtr() const = 0;
406
407 // Print a Measure
408 virtual void print(std::ostream &os) const = 0;
409 // Create a copy
410 // <group>
411 virtual Measure *clone() const = 0;
412 // </group>
413 protected:
414 private:
415 // # Enumerations
416
417 // # Data
418 // Each class will have the following information:
419 // Actual data
420 // <srcblock>
421 // MVmeasure data;
422 // </srcblock>
423 // Reference frame data
424 // <srcblock>
425 // MeasRef<Measure> ref;
426 // </srcblock>
427 // Possible input units
428 // <srcblock>
429 // Unit unit;
430 // </srcblock>
431 // And maybe later (or somewhere else)
432 // <srcblock>
433 // MeasErr error;
434 // </srcblock>
435 // <group>
436 // Dummy for cxx2html
437 void dummy_data() const {}
438 // </group>
439 //
440 // # Member functions
441 // Clear the measure
442 virtual void clear() = 0;
443};
444
445// # Global functions
446// <summary> Global functions </summary>
447// <group name=Output>
448// Output declaration
449std::ostream &operator<<(std::ostream &os, const Measure &meas);
450// </group>
452} // namespace casacore
453
454#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:394
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:380
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:437
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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.