casacore
Loading...
Searching...
No Matches
casacore::MVAngle Class Reference

More...

#include <MVAngle.h>

Classes

class  Format
 Format structure. More...
 

Public Types

enum  formatTypes {
  ANGLE ,
  TIME ,
  CLEAN ,
  NO_D ,
  NO_DM ,
  DIG2 ,
  FITS ,
  LOCAL ,
  USE_SPACE ,
  ALPHA ,
  NO_H ,
  NO_HM ,
  ANGLE_CLEAN ,
  ANGLE_NO_D ,
  ANGLE_NO_DM ,
  ANGLE_CLEAN_NO_D ,
  ANGLE_CLEAN_NO_DM ,
  TIME_CLEAN ,
  TIME_NO_H ,
  TIME_NO_HM ,
  TIME_CLEAN_NO_H ,
  TIME_CLEAN_NO_HM ,
  MOD_MASK
}
 Format types. More...
 

Public Member Functions

 MVAngle ()
 Default constructor: generate a zero value.
 
 MVAngle (const MVAngle &other)
 Copy constructor.
 
MVAngleoperator= (const MVAngle &other)
 Copy assignment.
 
 MVAngle (Double d)
 Constructor from Double.
 
 MVAngle (const Quantity &other)
 Constructor from Quantum : value can be an angle or time.
 
 ~MVAngle ()
 Destructor.
 
 operator Double () const
 Conversion operator.
 
const MVAngleoperator() ()
 Normalisation between -180 and +180 degrees (-pi and +pi)
 
const MVAngleoperator() (Double norm)
 Normalisation between 2pi*norm and 2pi*norm + 2pi.
 
const MVAngleoperator() (const MVAngle &norm)
 Normalisation between norm-pi and norm+pi.
 
const MVAnglebinorm (Double norm)
 Normalisation between pi*norm and pi*norm + pi.
 
MVAngle coAngle () const
 Make co-angle (e.g.
 
Double radian () const
 Get value in given unit.
 
Double degree () const
 
Double circle () const
 
Quantity get () const
 
Quantity get (const Unit &inunit) const
 
String string () const
 Output data
Warning: The first function below is thread-unsafe because it uses the result of the setFormat function which changes a static class member; The other functions are thread-safe because the format is directly given;

 
String string (MVAngle::formatTypes intyp, uInt inprec=0) const
 
String string (uInt intyp, uInt inprec) const
 
String string (uInt inprec) const
 
String string (const MVAngle::Format &form) const
 
void print (ostream &oss, const MVAngle::Format &form) const
 
void print (ostream &oss, const MVAngle::Format &form, Bool loc) const
 

Static Public Member Functions

static Bool unitString (UnitVal &uv, String &us, MUString &in)
 Check if String unit.
 
static Bool read (Quantity &res, const String &in, Bool chk=True)
 Make res angle Quantity from string in angle/time-like format.
 
static Bool read (Quantity &res, MUString &in, Bool chk=True)
 
static Bool read (Quantity &res, const String &in, Bool chk, Bool throwExcp)
 
static Bool read (Quantity &res, MUString &in, Bool chk, Bool throwExcp)
 
static Bool handleReadError (MUString &in, Bool throwExcp)
 Handle a read error.
 
static Format setFormat (MVAngle::formatTypes intyp, uInt inprec=0)
 Set default format
Warning: It is thread-unsafe to print using the setFormat functions because they change a static class member; The only thred-safe way to print a time is to use the print function above;

 
static Format setFormat (uInt intyp, uInt inprec)
 
static Format setFormat (uInt inprec=0)
 
static Format setFormat (const Format &form)
 
static Format getFormat ()
 Get default format.
 
static MVAngle::formatTypes giveMe (const String &in)
 Get code belonging to string.
 
static Double timeZone ()
 Get time zone offset (in days)
 

Private Attributes

Double val
 Value.
 

Static Private Attributes

static MVAngle::Format defaultFormat
 Default format.
 
static MVAngle::Format interimFormat
 Temporary format.
 
static Bool interimSet
 

Friends

ostream & operator<< (ostream &os, const MVAngle &meas)
 Output an angle.
 
istream & operator>> (istream &is, MVAngle &meas)
 Input an angle.
 
ostream & operator<< (ostream &os, const MVAngle::Format &form)
 Set a temporary format.
 

Detailed Description

Class to handle angle type conversions and I/O

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25
Test programs:
tMeasure

Prerequisite

Etymology

From Measure, Value and Angle

Synopsis

An MVAngle is a simple Double, to be used for angle conversions and I/O. It can be constructed from a Double (in which case radians are assumed), or from a Quantity (Quantum<Double>). Quantities must be in either angle or time units.
It has an automatic conversion to Double, so all standard mathematical operations can operate on it.
The class has a number of special member operations:

  • MVAngle operator() will normalise the angle between -180 and +180(inclusive) degrees and return the value
  • MVAngle operator(Double) will normalise the angle using the value specified (and return the value) in fractions of a circle (this was chosen rather than radians to make for easier and more precise programming) as a lower bound. I.e. (-0.5) will normalise between -180 and +180 degrees, (0.) between 0 and 360 degrees, (-0.25) between -90 and +270 degrees, (5.) between 1800 and 2160 dgrees.
  • MVAngle operator(MVAngle) will normalise (and return the normalised value) to within 180 degrees of the argument value. This is useful for making a range of angles contiguous.
  • MVAngle binorm(Double) will normalise the angle in steps of 180 degrees. using the value specified (and return the value) in fractions of 180 degrees (this was chosen rather than radians to make for easier and more precise programming) as a lower bound. I.e. (-0.5) will normalise between -90 and +90 degrees, (0.) between 0 and 180 degrees, (10.) between 1800 and 1980 dgrees.
  • Double radian() will return value in radians
  • Double degree() will return value in degrees
  • Double circle() will return value in fraction of circles
  • MVAngle coAngle() will return 90-angle (or rather pi/2 - angle), with (0) normalisation.
  • Quantity get() will return radians
  • Quantity get(Unit) will return in specified units (angle or time)

Output formatting is done with the << statement, with the following rules:

  • standard output is done in the following format: +ddd.mm.ss.tt with a floating sign. The number of digits presented will be based on the precision attached to the current stream
  • output can be formatted by using either the setFormat() method for global angle format setting, or the output of MVAngle::Format() data for a once off change (see later). Formats have a first argument which determines the type (default, if not given, MVAngle::ANGLE, other possibility MVAngle::TIME (as hh:mm:ss.tt..), the second the number of digits wanted (default stream precision), with a value:

    • <3 : ddd.. only
    • <5 : ddd.mm.
    • <7 : ddd.mm.ss
    • >6 : with precision-6 t's added

    comparable for time;
    Tip: The added periods are to enable input checking of the format; Look at the 'clean' types to bypass them;
    The output format can be modified with modifiers (specify as MVAngle::ANGLE | MVAngle::MOD (or + MVAngle::MOD)).
    Caution: For overloading/casting problems with some compilers, the use of modifiers necessitates either the presence of a precision (i;e; (A|B, prec)), or an explicit cast: ((MVAngle::formatTypes)(A|B)), or make use of the provided ANGLE[_CLEAN][_NO_D[M]] and TIME[_CLEAN][_NO_H[M]];

    The modifiers can be:

    • MVAngle::CLEAN to suppress leading or trailing periods (or colons for TIME), + and leading zeroes in degree field for angle representation will be replaced with a space. Note that the result can not be read automatically.
    • MVAngle::NO_D (or NO_H) to suppress the output of degrees (or hours): useful for offsets
    • MVAngle::NO_DM (or NO_HM), to suppress the degrees and minutes.
    • MVAngle::DIG2 to allow only 2 digits for degrees, or -12 - +12 range for hours
    • MVAngle::LOCAL to indicate local time to FITS formatting only
    • MVAngle::FITS to produce, if LOCAL set, the time zone (note that if local set here, as opposed to in MVTime) the angle is supposed to be in local time already).
    • MVAngle::ALPHA to use d (or h) and m instead of periods or colons.

    Output in formats like 20' can be done via the standard Quantum output (e.g. stream << angle.get("'") ).

  • Available formats:
    • MVAngle::ANGLE in +ddd.mm.ss.ttt format
    • MVAngle::TIME in hh:mm:ss.ttt format
    • MVAngle::[ANGLE|TIME]_CLEAN format without superfluous periods
    • MVAngle::[ANGLE|TIME][CLEAN]_NO[D|H][M] in format with leading zero fields left empty.
    • MVAngle::CLEAN modifier for suppressing superfluous periods
    • MVAngle::NO_[D|H][M] modifier to suppress first field(s)
    • MVAngle::DIG2 modifier to output in +dd.mm.ss.ttt format or in time format in range -12 to +12h

The default formatting can be overwritten by a MVAngle::setFormat(); statement; which returns an MVAngle::Format structure, that can be used in a subsequent one to reset to previous. The format set holds for all MVAngle output on all streams.
Temporary formats (i.e. for one MVAngle output only), can be set by outputting a format (i.e. stream << MVAngle::Format() <<... ).
Caution: A setFormat() will also reset any lingering temporary format; A setFormat(getFormat()) will reset without changing; Problems could arise in parallel processors;
Input can be read if the values are in any of the above (non-clean) output formats.
For other formatting practice, the output can be written to a String with the string() member function.
Note that using a temporary format is inherently thread-unsafe because the format is kept in a static variable. Another thread may overwrite the format just set. The only thread-safe way to format an MVTime is using a print or string that accepts a Format object.

Strings and input can be converted to an MVAngle (or Quantity) by Bool read(Quantity &out, const String &in) and istream >> MVAngle &. In the latter case the actual reading is done by the String read, which reads between white-spaces.
The following input formats (note no blanks allowed) are supported (+stands for an optional + or -; v for an unsigned integer; dv for a floating number. [] indicate optional values. Separating codes are case insensitive):

  • +[v].[v].[dv] – value in deg, arcmin, arcsec
  • +[v]D[v[M[dv]]] – value in deg, arcmin, arcsec
  • +[v]:[v[:[dv]]] – value in h, min, s
  • +[v]H[v[M[dv]]] – value in h, min, s
  • +[v]{D|H|:}[dv] – value in deg (or h), arcmin (or min)
  • +dv[unit string] – value in time or angle units. rad default

Examples of valid strings:

5::2.59 5h + 0min + 2.59 s
5..2.59 5deg + 0arcmin + 2.59arcsec
5.259 5.259 rad
5..259 5deg + 259arcsec
5.259a 5.259 * pi * 2 *365.25 rad (normalised)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)


Caution: In general the input will be read as a Quantity; Reading of Quantities will always try to read special formats (like MVAngle, MVTime) first; In that case problems could arise converting strings like 5d, 5::, 5hm, 5dm; In 'angle' mode they could have meant to be 5d0m, 5:0:, 5h0m, 5d0m, but they could have meant: days, min, hectometre, decimetre; In the same vain 5d2 could have meant 5d2m or 5 d2; To try to guess the general use, the following interpretation is made:

  • 5d, 5:: == 5deg, 5h0m; make float (like 5;d) to make it days/min
  • 5dm, 5hm == decimetre, hectometre; use 5d0m 5h0m for angle
  • 5d2, 5h2, 5:2 == 5d2m, 5h2m, 5:2:; use float 5 or explicit () for other interpretation


Example

See synopsis

Motivation

To be able to format angle-like values in user-required ways.

To Do

  • Use AipsrcData once moved to aips from trial

Definition at line 243 of file MVAngle.h.

Member Enumeration Documentation

◆ formatTypes

Format types.

Enumerator
ANGLE 
TIME 
CLEAN 
NO_D 
NO_DM 
DIG2 
FITS 
LOCAL 
USE_SPACE 
ALPHA 
NO_H 
NO_HM 
ANGLE_CLEAN 
ANGLE_NO_D 
ANGLE_NO_DM 
ANGLE_CLEAN_NO_D 
ANGLE_CLEAN_NO_DM 
TIME_CLEAN 
TIME_NO_H 
TIME_NO_HM 
TIME_CLEAN_NO_H 
TIME_CLEAN_NO_HM 
MOD_MASK 

Definition at line 249 of file MVAngle.h.

Constructor & Destructor Documentation

◆ MVAngle() [1/4]

casacore::MVAngle::MVAngle ( )

Default constructor: generate a zero value.

◆ MVAngle() [2/4]

casacore::MVAngle::MVAngle ( const MVAngle & other)

Copy constructor.

◆ MVAngle() [3/4]

casacore::MVAngle::MVAngle ( Double d)

Constructor from Double.

◆ MVAngle() [4/4]

casacore::MVAngle::MVAngle ( const Quantity & other)

Constructor from Quantum : value can be an angle or time.

Thrown Exceptions

◆ ~MVAngle()

casacore::MVAngle::~MVAngle ( )

Destructor.

Member Function Documentation

◆ binorm()

const MVAngle & casacore::MVAngle::binorm ( Double norm)

Normalisation between pi*norm and pi*norm + pi.

◆ circle()

Double casacore::MVAngle::circle ( ) const

◆ coAngle()

MVAngle casacore::MVAngle::coAngle ( ) const

Make co-angle (e.g.

zenith distance from elevation)

◆ degree()

Double casacore::MVAngle::degree ( ) const

◆ get() [1/2]

Quantity casacore::MVAngle::get ( ) const

◆ get() [2/2]

Quantity casacore::MVAngle::get ( const Unit & inunit) const

◆ getFormat()

static Format casacore::MVAngle::getFormat ( )
static

Get default format.

◆ giveMe()

static MVAngle::formatTypes casacore::MVAngle::giveMe ( const String & in)
static

Get code belonging to string.

0 if not known

◆ handleReadError()

static Bool casacore::MVAngle::handleReadError ( MUString & in,
Bool throwExcp )
static

Handle a read error.

An exception is thrown if indicated so. Otherwise in.pop() is called and False is returned.

◆ operator Double()

casacore::MVAngle::operator Double ( ) const

Conversion operator.

◆ operator()() [1/3]

const MVAngle & casacore::MVAngle::operator() ( )

Normalisation between -180 and +180 degrees (-pi and +pi)

◆ operator()() [2/3]

const MVAngle & casacore::MVAngle::operator() ( const MVAngle & norm)

Normalisation between norm-pi and norm+pi.

◆ operator()() [3/3]

const MVAngle & casacore::MVAngle::operator() ( Double norm)

Normalisation between 2pi*norm and 2pi*norm + 2pi.

◆ operator=()

MVAngle & casacore::MVAngle::operator= ( const MVAngle & other)

Copy assignment.

◆ print() [1/2]

void casacore::MVAngle::print ( ostream & oss,
const MVAngle::Format & form ) const

◆ print() [2/2]

void casacore::MVAngle::print ( ostream & oss,
const MVAngle::Format & form,
Bool loc ) const

◆ radian()

Double casacore::MVAngle::radian ( ) const

Get value in given unit.

◆ read() [1/4]

static Bool casacore::MVAngle::read ( Quantity & res,
const String & in,
Bool chk,
Bool throwExcp )
static

◆ read() [2/4]

static Bool casacore::MVAngle::read ( Quantity & res,
const String & in,
Bool chk = True )
static

Make res angle Quantity from string in angle/time-like format.

In the case of String input, also quantities are recognised. chk=True means that the entire string should be consumed. throwExcp=True means that an exception is thrown in case of an error.

◆ read() [3/4]

static Bool casacore::MVAngle::read ( Quantity & res,
MUString & in,
Bool chk,
Bool throwExcp )
static

◆ read() [4/4]

static Bool casacore::MVAngle::read ( Quantity & res,
MUString & in,
Bool chk = True )
static

◆ setFormat() [1/4]

static Format casacore::MVAngle::setFormat ( const Format & form)
static

◆ setFormat() [2/4]

static Format casacore::MVAngle::setFormat ( MVAngle::formatTypes intyp,
uInt inprec = 0 )
static

Set default format
Warning: It is thread-unsafe to print using the setFormat functions because they change a static class member; The only thred-safe way to print a time is to use the print function above;

◆ setFormat() [3/4]

static Format casacore::MVAngle::setFormat ( uInt inprec = 0)
static

◆ setFormat() [4/4]

static Format casacore::MVAngle::setFormat ( uInt intyp,
uInt inprec )
static

◆ string() [1/5]

String casacore::MVAngle::string ( ) const

Output data
Warning: The first function below is thread-unsafe because it uses the result of the setFormat function which changes a static class member; The other functions are thread-safe because the format is directly given;

◆ string() [2/5]

String casacore::MVAngle::string ( const MVAngle::Format & form) const

◆ string() [3/5]

String casacore::MVAngle::string ( MVAngle::formatTypes intyp,
uInt inprec = 0 ) const

◆ string() [4/5]

String casacore::MVAngle::string ( uInt inprec) const

◆ string() [5/5]

String casacore::MVAngle::string ( uInt intyp,
uInt inprec ) const

◆ timeZone()

static Double casacore::MVAngle::timeZone ( )
static

Get time zone offset (in days)

◆ unitString()

static Bool casacore::MVAngle::unitString ( UnitVal & uv,
String & us,
MUString & in )
static

Check if String unit.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

ostream & operator<< ( ostream & os,
const MVAngle & meas )
friend

Output an angle.

◆ operator<< [2/2]

ostream & operator<< ( ostream & os,
const MVAngle::Format & form )
friend

Set a temporary format.

◆ operator>>

istream & operator>> ( istream & is,
MVAngle & meas )
friend

Input an angle.

Member Data Documentation

◆ defaultFormat

MVAngle::Format casacore::MVAngle::defaultFormat
staticprivate

Default format.

Definition at line 398 of file MVAngle.h.

◆ interimFormat

MVAngle::Format casacore::MVAngle::interimFormat
staticprivate

Temporary format.

Definition at line 401 of file MVAngle.h.

◆ interimSet

Bool casacore::MVAngle::interimSet
staticprivate

Definition at line 402 of file MVAngle.h.

◆ val

Double casacore::MVAngle::val
private

Value.

Definition at line 396 of file MVAngle.h.


The documentation for this class was generated from the following file: