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: wcsfix_8h-source.html,v 1.1 2009/09/14 20:25:24 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 * "Representations of celestial coordinates in FITS", 00041 * Calabretta, M.R., & Greisen, E.W. 2002, A&A, 395, 1077 (Paper II) 00042 * 00043 * "Representations of spectral coordinates in FITS", 00044 * Greisen, E.W., Calabretta, M.R., Valdes, F.G., & Allen, S.L. 00045 * 2006, A&A, 446, 747 (Paper III) 00046 * 00047 * Refer to the README file provided with WCSLIB for an overview of the 00048 * library. 00049 * 00050 * 00051 * Summary of the wcsfix routines 00052 * ------------------------------ 00053 * Routines in this suite identify and translate various forms of non-standard 00054 * construct that are known to occur in FITS WCS headers. These range from the 00055 * translation of non-standard values for standard WCS keywords, to the repair 00056 * of malformed coordinate representations. 00057 * 00058 * Non-standard keyvalues: 00059 * ----------------------- 00060 * AIPS-convention celestial projection types, NCP and GLS, and spectral 00061 * types, 'FREQ-LSR', 'FELO-HEL', etc., set in CTYPEia are translated 00062 * on-the-fly by wcsset() but without modifying the relevant ctype[], pv[] or 00063 * specsys members of the wcsprm struct. That is, only the information 00064 * extracted from ctype[] is translated when wcsset() fills in wcsprm::cel 00065 * (celprm struct) or wcsprm::spc (spcprm struct). 00066 * 00067 * On the other hand, these routines do change the values of wcsprm::ctype[], 00068 * wcsprm::pv[], wcsprm::specsys and other wcsprm struct members as 00069 * appropriate to produce the same result as if the FITS header itself had 00070 * been translated. 00071 * 00072 * Auxiliary WCS header information not used directly by WCSLIB may also be 00073 * translated. For example, the older DATE-OBS date format (wcsprm::dateobs) 00074 * is recast to year-2000 standard form, and MJD-OBS (wcsprm::mjdobs) will be 00075 * deduced from it if not already set. 00076 * 00077 * Certain combinations of keyvalues that result in malformed coordinate 00078 * systems, as described in Sect. 7.3.4 of Paper I, may also be repaired. 00079 * These are handled by cylfix(). 00080 * 00081 * Non-standard keywords: 00082 * ---------------------- 00083 * The AIPS-convention CROTAn keywords are recognized as quasi-standard and 00084 * as such are accomodated by the wcsprm::crota[] and translated to 00085 * wcsprm::pc[][] by wcsset(). These are not dealt with here, nor are any 00086 * other non-standard keywords since these routines work only on the contents 00087 * of a wcsprm struct and do not deal with FITS headers per se. In 00088 * particular, they do not identify or translate CD00i00j, PC00i00j, PROJPn, 00089 * EPOCH, VELREF or VSOURCEa keywords; this may be done by the FITS WCS 00090 * header parser supplied with WCSLIB, refer to wcshdr.h. 00091 * 00092 * wcsfix() applies all of the corrections handled by the following specific 00093 * functions which may also be invoked separately: 00094 * 00095 * - cdfix(): Sets the diagonal element of the CDi_ja matrix to 1.0 if all 00096 * CDi_ja keywords associated with a particular axis are omitted. 00097 * 00098 * - datfix(): recast an older DATE-OBS date format in dateobs to year-2000 00099 * standard form and derive mjdobs from it if not already set. 00100 * Alternatively, if mjdobs is set and dateobs isn't, then derive dateobs 00101 * from it. 00102 * 00103 * - unitfix(): translate some commonly used but non-standard unit strings in 00104 * the CUNITia keyvalues, e.g. 'DEG' -> 'deg'. 00105 * 00106 * - celfix(): translate AIPS-convention celestial projection types, NCP and 00107 * GLS, in ctype[] as set from CTYPEia. 00108 * 00109 * - spcfix(): translate AIPS-convention spectral types, 'FREQ-LSR', 00110 * 'FELO-HEL', etc., in ctype[] as set from CTYPEia. 00111 * 00112 * - cylfix(): fixes WCS keyvalues for malformed cylindrical projections that 00113 * suffer from the problem described in Sect. 7.3.4 of Paper I. 00114 * 00115 * 00116 * wcsfix() - Translate a non-standard WCS struct 00117 * ---------------------------------------------- 00118 * wcsfix() applies all of the corrections handled separately by datfix(), 00119 * unitfix(), celfix(), spcfix() and cylfix(). 00120 * 00121 * Given: 00122 * ctrl int Do potentially unsafe translations of non-standard 00123 * unit strings as described in the usage notes to 00124 * wcsutrn(). 00125 * 00126 * naxis const int [] 00127 * Image axis lengths. If this array pointer is set to 00128 * zero then cylfix() will not be invoked. 00129 * 00130 * Given and returned: 00131 * wcs struct wcsprm* 00132 * Coordinate transformation parameters. 00133 * 00134 * Returned: 00135 * stat int [NWCSFIX] 00136 * Status returns from each of the functions. Use the 00137 * preprocessor macros NWCSFIX to dimension this vector 00138 * and CDFIX, DATFIX, UNITFIX, CELFIX, SPCFIX and CYLFIX 00139 * to access its elements. A status value of -2 is set 00140 * for functions that were not invoked. 00141 * 00142 * Function return value: 00143 * int Status return value: 00144 * 0: Success. 00145 * 1: One or more of the translation functions returned 00146 * an error. 00147 * 00148 * 00149 * cdfix() - Fix erroneously omitted CDi_ja keywords 00150 * ------------------------------------------------- 00151 * cdfix() sets the diagonal element of the CDi_ja matrix to unity if all 00152 * CDi_ja keywords associated with a given axis were omitted. According to 00153 * Paper I, if any CDi_ja keywords at all are given in a FITS header then those 00154 * not given default to zero. This results in a singular matrix with an 00155 * intersecting row and column of zeros. 00156 * 00157 * Given and returned: 00158 * wcs struct wcsprm* 00159 * Coordinate transformation parameters. 00160 * 00161 * Function return value: 00162 * int Status return value: 00163 * -1: No change required (not an error). 00164 * 0: Success. 00165 * 1: Null wcsprm pointer passed. 00166 * 00167 * 00168 * datfix() - Translate DATE-OBS and derive MJD-OBS or vice versa 00169 * -------------------------------------------------------------- 00170 * datfix() translates the old DATE-OBS date format set in wcsprm::dateobs to 00171 * year-2000 standard form (yyyy-mm-ddThh:mm:ss) and derives MJD-OBS from it if 00172 * not already set. Alternatively, if wcsprm::mjdobs is set and 00173 * wcsprm::dateobs isn't, then datfix() derives wcsprm::dateobs from it. If 00174 * both are set but disagree by more than half a day then status 5 is returned. 00175 * 00176 * Given and returned: 00177 * wcs struct wcsprm* 00178 * Coordinate transformation parameters. wcsprm::dateobs 00179 * and/or wcsprm::mjdobs may be changed. 00180 * 00181 * Function return value: 00182 * int Status return value: 00183 * -1: No change required (not an error). 00184 * 0: Success. 00185 * 1: Null wcsprm pointer passed. 00186 * 5: Invalid parameter value. 00187 * 00188 * Notes: 00189 * The MJD algorithms used by datfix() are from D.A. Hatcher, 1984, QJRAS, 00190 * 25, 53-55, as modified by P.T. Wallace for use in SLALIB subroutines CLDJ 00191 * and DJCL. 00192 * 00193 * 00194 * unitfix() - Correct aberrant CUNITia keyvalues 00195 * ---------------------------------------------- 00196 * unitfix() applies wcsutrn() to translate non-standard CUNITia keyvalues, 00197 * e.g. 'DEG' -> 'deg', also stripping off unnecessary whitespace. 00198 * 00199 * Given: 00200 * ctrl int Do potentially unsafe translations described in the 00201 * usage notes to wcsutrn(). 00202 * 00203 * Given and returned: 00204 * wcs struct wcsprm* 00205 * Coordinate transformation parameters. 00206 * 00207 * Function return value: 00208 * int Status return value: 00209 * -1: No change required (not an error). 00210 * 0: Success. 00211 * 1: Null wcsprm pointer passed. 00212 * 00213 * 00214 * celfix() - Translate AIPS-convention celestial projection types 00215 * --------------------------------------------------------------- 00216 * celfix() translates AIPS-convention celestial projection types, NCP and 00217 * GLS, set in the ctype[] member of the wcsprm struct. 00218 * 00219 * Two additional pv[] keyvalues are created when translating NCP. If the 00220 * pv[] array was initially allocated by wcsini() then the array will be 00221 * expanded if necessary. Otherwise, error 2 will be returned if two empty 00222 * slots are not already available for use. 00223 * 00224 * Given and returned: 00225 * wcs struct wcsprm* 00226 * Coordinate transformation parameters. wcsprm::ctype[] 00227 * and/or wcsprm::pv[] may be changed. 00228 * 00229 * Function return value: 00230 * int Status return value: 00231 * -1: No change required (not an error). 00232 * 0: Success. 00233 * 1: Null wcsprm pointer passed. 00234 * 2: Memory allocation failed. 00235 * 3: Linear transformation matrix is singular. 00236 * 4: Inconsistent or unrecognized coordinate axis 00237 * types. 00238 * 5: Invalid parameter value. 00239 * 6: Invalid coordinate transformation parameters. 00240 * 7: Ill-conditioned coordinate transformation 00241 * parameters. 00242 * 00243 * 00244 * spcfix() - Translate AIPS-convention spectral types 00245 * --------------------------------------------------- 00246 * spcfix() translates AIPS-convention spectral coordinate types, 00247 * '{FREQ,FELO,VELO}-{OBS,HEL,LSR}' (e.g. 'FREQ-LSR', 'FELO-HEL', 'VELO-OBS') 00248 * set in wcsprm::ctype[]. 00249 * 00250 * Given and returned: 00251 * wcs struct wcsprm* 00252 * Coordinate transformation parameters. wcsprm::ctype[] 00253 * and/or wcsprm::specsys may be changed. 00254 * 00255 * Function return value: 00256 * int Status return value: 00257 * -1: No change required (not an error). 00258 * 0: Success. 00259 * 1: Null wcsprm pointer passed. 00260 * 2: Memory allocation failed. 00261 * 3: Linear transformation matrix is singular. 00262 * 4: Inconsistent or unrecognized coordinate axis 00263 * types. 00264 * 5: Invalid parameter value. 00265 * 6: Invalid coordinate transformation parameters. 00266 * 7: Ill-conditioned coordinate transformation 00267 * parameters. 00268 * 00269 * 00270 * cylfix() - Fix malformed cylindrical projections 00271 * ------------------------------------------------ 00272 * cylfix() fixes WCS keyvalues for malformed cylindrical projections that 00273 * suffer from the problem described in Sect. 7.3.4 of Paper I. 00274 * 00275 * Given: 00276 * naxis const int [] 00277 * Image axis lengths. 00278 * 00279 * Given and returned: 00280 * wcs struct wcsprm* 00281 * Coordinate transformation parameters. 00282 * 00283 * Function return value: 00284 * int Status return value: 00285 * -1: No change required (not an error). 00286 * 0: Success. 00287 * 1: Null wcsprm pointer passed. 00288 * 2: Memory allocation failed. 00289 * 3: Linear transformation matrix is singular. 00290 * 4: Inconsistent or unrecognized coordinate axis 00291 * types. 00292 * 5: Invalid parameter value. 00293 * 6: Invalid coordinate transformation parameters. 00294 * 7: Ill-conditioned coordinate transformation 00295 * parameters. 00296 * 8: All of the corner pixel coordinates are 00297 * invalid. 00298 * 9: Could not determine reference pixel coordinate. 00299 * 10: Could not determine reference pixel value. 00300 * 00301 * 00302 * Global variable: const char *wcsfix_errmsg[] - Status return messages 00303 * --------------------------------------------------------------------- 00304 * Error messages to match the status value returned from each function. 00305 * 00306 *===========================================================================*/ 00307 00308 #ifndef WCSLIB_WCSFIX 00309 #define WCSLIB_WCSFIX 00310 00311 #include "wcs.h" 00312 00313 #ifdef __cplusplus 00314 extern "C" { 00315 #endif 00316 00317 #define CDFIX 0 00318 #define DATFIX 1 00319 #define UNITFIX 2 00320 #define CELFIX 3 00321 #define SPCFIX 4 00322 #define CYLFIX 5 00323 #define NWCSFIX 6 00324 00325 extern const char *wcsfix_errmsg[]; 00326 #define cylfix_errmsg wcsfix_errmsg 00327 00328 00329 int wcsfix(int ctrl, const int naxis[], struct wcsprm *wcs, int stat[]); 00330 00331 int cdfix(struct wcsprm *wcs); 00332 00333 int datfix(struct wcsprm *wcs); 00334 00335 int unitfix(int ctrl, struct wcsprm *wcs); 00336 00337 int celfix(struct wcsprm *wcs); 00338 00339 int spcfix(struct wcsprm *wcs); 00340 00341 int cylfix(const int naxis[], struct wcsprm *wcs); 00342 00343 00344 #ifdef __cplusplus 00345 } 00346 #endif 00347 00348 #endif /* WCSLIB_WCSFIX */