00001 /*============================================================================ 00002 00003 WCSLIB 4.4 - an implementation of the FITS WCS standard. 00004 Copyright (C) 1995-2009, Mark Calabretta 00005 00006 This file is part of WCSLIB. 00007 00008 WCSLIB is free software: you can redistribute it and/or modify it under the 00009 terms of the GNU Lesser General Public License as published by the Free 00010 Software Foundation, either version 3 of the License, or (at your option) 00011 any later version. 00012 00013 WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY 00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00016 more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with WCSLIB. If not, see <http://www.gnu.org/licenses/>. 00020 00021 Correspondence concerning WCSLIB may be directed to: 00022 Internet email: mcalabre@atnf.csiro.au 00023 Postal address: Dr. Mark Calabretta 00024 Australia Telescope National Facility, CSIRO 00025 PO Box 76 00026 Epping NSW 1710 00027 AUSTRALIA 00028 00029 Author: Mark Calabretta, Australia Telescope National Facility 00030 http://www.atnf.csiro.au/~mcalabre/index.html 00031 $Id: wcsunits_8h-source.html,v 1.1 2009/09/14 20:25:25 irby Exp $ 00032 *============================================================================= 00033 * 00034 * WCSLIB 4.4 - C routines that implement the FITS World Coordinate System 00035 * (WCS) standard. Refer to 00036 * 00037 * "Representations of world coordinates in FITS", 00038 * Greisen, E.W., & Calabretta, M.R. 2002, A&A, 395, 1061 (Paper I) 00039 * 00040 * The Flexible Image Transport System (FITS), a data format widely used in 00041 * astronomy for data interchange and archive, is described in 00042 * 00043 * "Definition of The Flexible Image Transport System (FITS)", 00044 * Hanisch, R.J., Farris, A., Greisen, E.W., et al. 2001, A&A, 376, 359 00045 * 00046 * which formalizes NOST 100-2.0, a document produced by the NASA/Science 00047 * Office of Standards and Technology, see http://fits.gsfc.nasa.gov. 00048 * 00049 * Refer to the README file provided with WCSLIB for an overview of the 00050 * library. 00051 * 00052 * 00053 * Summary of the wcsunits routines 00054 * -------------------------------- 00055 * Routines in this suite deal with units specifications and conversions: 00056 * 00057 * - wcsunits(): given two unit specifications, derive the conversion from 00058 * one to the other. 00059 * 00060 * - wcsutrn(): translates certain commonly used but non-standard unit 00061 * strings. It is intended to be called before wcsulex() which only 00062 * handles standard FITS units specifications. 00063 * 00064 * - wcsulex(): parses a standard FITS units specification of arbitrary 00065 * complexity, deriving the conversion to canonical units. 00066 * 00067 * 00068 * wcsunits() - FITS units specification conversion 00069 * ------------------------------------------------ 00070 * wcsunits() derives the conversion from one system of units to another. 00071 * 00072 * Given: 00073 * have const char [] 00074 * FITS units specification to convert from (null- 00075 * terminated), with or without surrounding square 00076 * brackets (for inline specifications); text following 00077 * the closing bracket is ignored. 00078 * 00079 * want const char [] 00080 * FITS units specification to convert to (null- 00081 * terminated), with or without surrounding square 00082 * brackets (for inline specifications); text following 00083 * the closing bracket is ignored. 00084 * 00085 * Returned: 00086 * scale, 00087 * offset, 00088 * power double* Convert units using 00089 * 00090 = pow(scale*value + offset, power); 00091 00092 * Normally offset is zero except for log() or ln() 00093 * conversions, e.g. "log(MHz)" to "ln(Hz)". Likewise, 00094 * power is normally unity except for exp() conversions, 00095 * e.g. "exp(ms)" to "exp(/Hz)". Thus conversions 00096 * ordinarily consist of 00097 * 00098 = value *= scale; 00099 * 00100 * Function return value: 00101 * int Status return value: 00102 * 0: Success. 00103 * 1-9: Status return from wcsulex(). 00104 * 10: Non-conformant unit specifications. 00105 * 11: Non-conformant functions. 00106 * 00107 * scale is zeroed on return if an error occurs. 00108 * 00109 * 00110 * wcsutrn() - Translation of non-standard unit specifications 00111 * ----------------------------------------------------------- 00112 * wcsutrn() translates certain commonly used but non-standard unit strings, 00113 * e.g. "DEG", "MHZ", "KELVIN", that are not recognized by wcsulex(), refer to 00114 * the notes below for a full list. Compounds are also recognized, e.g. 00115 * "JY/BEAM" and "KM/SEC/SEC". Extraneous embedded blanks are removed. 00116 * 00117 * Given: 00118 * ctrl int Although "S" is commonly used to represent seconds, 00119 * its translation to "s" is potentially unsafe since the 00120 * standard recognizes "S" formally as Siemens, however 00121 * rarely that may be used. The same applies to "H" for 00122 * hours (Henry), and "D" for days (Debye). This 00123 * bit-flag controls what to do in such cases: 00124 * 1: Translate "S" to "s". 00125 * 2: Translate "H" to "h". 00126 * 4: Translate "D" to "d". 00127 * Thus ctrl == 0 doesn't do any unsafe translations, 00128 * whereas ctrl == 7 does all of them. 00129 * 00130 * Given and returned: 00131 * unitstr char [] Null-terminated character array containing the units 00132 * specification to be translated. 00133 * 00134 * Inline units specifications in the a FITS header 00135 * keycomment are also handled. If the first non-blank 00136 * character in unitstr is '[' then the unit string is 00137 * delimited by its matching ']'. Blanks preceding '[' 00138 * will be stripped off, but text following the closing 00139 * bracket will be preserved without modification. 00140 * 00141 * Function return value: 00142 * int Status return value: 00143 * -1: No change was made, other than stripping blanks 00144 * (not an error). 00145 * 0: Success. 00146 * 9: Internal parser error. 00147 * 12: Potentially unsafe translation, whether applied 00148 * or not (see notes). 00149 * 00150 * Notes: 00151 * Translation of non-standard unit specifications: apart from leading and 00152 * trailing blanks, a case-sensitive match is required for the aliases listed 00153 * below, in particular the only recognized aliases with metric prefixes are 00154 * "KM", "KHZ", "MHZ", and "GHZ". Potentially unsafe translations of "D", 00155 * "H", and "S", shown in parentheses, are optional. 00156 * 00157 = Unit Recognized aliases 00158 = ---- ------------------------------------------------------------- 00159 = Angstrom angstrom 00160 = arcmin arcmins, ARCMIN, ARCMINS 00161 = arcsec arcsecs, ARCSEC, ARCSECS 00162 = beam BEAM 00163 = byte Byte 00164 = d day, days, (D), DAY, DAYS 00165 = deg degree, degrees, DEG, DEGREE, DEGREES 00166 = GHz GHZ 00167 = h hr, (H), HR 00168 = Hz hz, HZ 00169 = kHz KHZ 00170 = Jy JY 00171 = K kelvin, kelvins, Kelvin, Kelvins, KELVIN, KELVINS 00172 = km KM 00173 = m metre, meter, metres, meters, M, METRE, METER, METRES, METERS 00174 = min MIN 00175 = MHz MHZ 00176 = Ohm ohm 00177 = Pa pascal, pascals, Pascal, Pascals, PASCAL, PASCALS 00178 = pixel pixels, PIXEL, PIXELS 00179 = rad radian, radians, RAD, RADIAN, RADIANS 00180 = s sec, second, seconds, (S), SEC, SECOND, SECONDS 00181 = V volt, volts, Volt, Volts, VOLT, VOLTS 00182 = yr year, years, YR, YEAR, YEARS 00183 * 00184 * The aliases "angstrom", "ohm", and "Byte" for (Angstrom, Ohm, and byte) 00185 * are recognized by wcsulex() itself as an unofficial extension of the 00186 * standard, but they are converted to the standard form here. 00187 * 00188 * 00189 * wcsulex() - FITS units specification parser 00190 * ------------------------------------------- 00191 * wcsulex() parses a standard FITS units specification of arbitrary 00192 * complexity, deriving the scale factor required to convert to canonical 00193 * units - basically SI with degrees and "dimensionless" additions such as 00194 * byte, pixel and count. 00195 * 00196 * Given: 00197 * unitstr const char [] 00198 * Null-terminated character array containing the units 00199 * specification, with or without surrounding square 00200 * brackets (for inline specifications); text following 00201 * the closing bracket is ignored. 00202 * 00203 * Returned: 00204 * func int* Special function type, see note 4: 00205 * 0: None 00206 * 1: log() ...base 10 00207 * 2: ln() ...base e 00208 * 3: exp() 00209 * 00210 * scale double* Scale factor for the unit specification; multiply a 00211 * value expressed in the given units by this factor to 00212 * convert it to canonical units. 00213 * 00214 * units double[WCSUNITS_NTYPE] 00215 * A units specification is decomposed into powers of 16 00216 * fundamental unit types: angle, mass, length, time, 00217 * count, pixel, etc. Preprocessor macro WCSUNITS_NTYPE 00218 * is defined to dimension this vector, and others such 00219 * WCSUNITS_PLANE_ANGLE, WCSUNITS_LENGTH, etc. to access 00220 * its elements. 00221 * 00222 * Corresponding character strings, wcsunits_types[] and 00223 * wcsunits_units[], are predefined to describe each 00224 * quantity and its canonical units. 00225 * 00226 * Function return value: 00227 * int Status return value: 00228 * 0: Success. 00229 * 1: Invalid numeric multiplier. 00230 * 2: Dangling binary operator. 00231 * 3: Invalid symbol in INITIAL context. 00232 * 4: Function in invalid context. 00233 * 5: Invalid symbol in EXPON context. 00234 * 6: Unbalanced bracket. 00235 * 7: Unbalanced parenthesis. 00236 * 8: Consecutive binary operators. 00237 * 9: Internal parser error. 00238 * 00239 * scale and units[] are zeroed on return if an error 00240 * occurs. 00241 * 00242 * Notes: 00243 * 1: wcsulex() is permissive in accepting whitespace in all contexts in a 00244 * units specification where it does not create ambiguity (e.g. not 00245 * between a metric prefix and a basic unit string), including in strings 00246 * like "log (m ** 2)" which is formally disallowed. 00247 * 00248 * 2: Supported extensions: 00249 * - "angstrom" (OGIP usage) is allowed in addition to "Angstrom". 00250 * - "ohm" (OGIP usage) is allowed in addition to "Ohm". 00251 * - "Byte" (common usage) is allowed in addition to "byte". 00252 * 00253 * 3: Table 6 of WCS Paper I lists eleven units for which metric prefixes are 00254 * allowed. However, in this implementation only prefixes greater than 00255 * unity are allowed for "a" (annum), "yr" (year), "pc" (parsec), "bit", 00256 * and "byte", and only prefixes less than unity are allowed for "mag" 00257 * (stellar magnitude). 00258 * 00259 * Metric prefix "P" (peta) is specifically forbidden for "a" (annum) to 00260 * avoid confusion with "Pa" (Pascal, not peta-annum). Note that metric 00261 * prefixes are specifically disallowed for "h" (hour) and "d" (day) so 00262 * that "ph" (photons) cannot be interpreted as pico-hours, nor "cd" 00263 * (candela) as centi-days. 00264 * 00265 * 4: Function types log(), ln() and exp() may only occur at the start of the 00266 * units specification. The scale and units[] returned for these refers 00267 * to the string inside the function "argument", e.g. to "MHz" in log(MHz) 00268 * for which a scale of 1e6 will be returned. 00269 * 00270 * 00271 * Global variable: const char *wcsunits_errmsg[] - Status return messages 00272 * ----------------------------------------------------------------------- 00273 * Error messages to match the status value returned from each function. 00274 * 00275 * 00276 * Global variable: const char *wcsunits_types[] - Names of physical quantities 00277 * ---------------------------------------------------------------------------- 00278 * Names for physical quantities to match the units vector returned by 00279 * wcsulex(): 00280 * - 0: plane angle 00281 * - 1: solid angle 00282 * - 2: charge 00283 * - 3: mole 00284 * - 4: temperature 00285 * - 5: luminous intensity 00286 * - 6: mass 00287 * - 7: length 00288 * - 8: time 00289 * - 9: beam 00290 * - 10: bin 00291 * - 11: bit 00292 * - 12: count 00293 * - 13: stellar magnitude 00294 * - 14: pixel 00295 * - 15: solar ratio 00296 * - 16: voxel 00297 * 00298 * 00299 * Global variable: const char *wcsunits_units[] - Names of units 00300 * -------------------------------------------------------------- 00301 * Names for the units (SI) to match the units vector returned by wcsulex(): 00302 * - 0: degree 00303 * - 1: steradian 00304 * - 2: Coulomb 00305 * - 3: mole 00306 * - 4: Kelvin 00307 * - 5: candela 00308 * - 6: kilogram 00309 * - 7: metre 00310 * - 8: second 00311 * 00312 * The remainder are dimensionless. 00313 *===========================================================================*/ 00314 00315 #ifndef WCSLIB_WCSUNITS 00316 #define WCSLIB_WCSUNITS 00317 00318 #ifdef __cplusplus 00319 extern "C" { 00320 #endif 00321 00322 00323 extern const char *wcsunits_errmsg[]; 00324 00325 extern const char *wcsunits_types[]; 00326 extern const char *wcsunits_units[]; 00327 00328 #define WCSUNITS_PLANE_ANGLE 0 00329 #define WCSUNITS_SOLID_ANGLE 1 00330 #define WCSUNITS_CHARGE 2 00331 #define WCSUNITS_MOLE 3 00332 #define WCSUNITS_TEMPERATURE 4 00333 #define WCSUNITS_LUMINTEN 5 00334 #define WCSUNITS_MASS 6 00335 #define WCSUNITS_LENGTH 7 00336 #define WCSUNITS_TIME 8 00337 #define WCSUNITS_BEAM 9 00338 #define WCSUNITS_BIN 10 00339 #define WCSUNITS_BIT 11 00340 #define WCSUNITS_COUNT 12 00341 #define WCSUNITS_MAGNITUDE 13 00342 #define WCSUNITS_PIXEL 14 00343 #define WCSUNITS_SOLRATIO 15 00344 #define WCSUNITS_VOXEL 16 00345 00346 #define WCSUNITS_NTYPE 17 00347 00348 00349 int wcsunits(const char have[], const char want[], double *scale, 00350 double *offset, double *power); 00351 00352 int wcsutrn(int ctrl, char unitstr[]); 00353 00354 int wcsulex(const char unitstr[], int *func, double *scale, double units[]); 00355 00356 00357 #ifdef __cplusplus 00358 } 00359 #endif 00360 00361 #endif /* WCSLIB_WCSUNITS */