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: wcs_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 wcs routines 00052 * --------------------------- 00053 * These routines implement the FITS World Coordinate System (WCS) standard 00054 * which defines methods to be used for computing world coordinates from image 00055 * pixel coordinates, and vice versa. They are based on the wcsprm struct 00056 * which contains all information needed for the computations. The struct 00057 * contains some members that must be set by the user, and others that are 00058 * maintained by these routines, somewhat like a C++ class but with no 00059 * encapsulation. 00060 * 00061 * Three routines, wcsini(), wcssub(), and wcsfree() are provided to manage the 00062 * wcsprm struct and another, wcsprt(), to prints its contents. Refer to the 00063 * description of the wcsprm struct for an explanation of the anticipated usage 00064 * of these routines. wcscopy(), which does a deep copy of one wcsprm struct 00065 * to another, is defined as a preprocessor macro function that invokes 00066 * wcssub(). 00067 * 00068 * A setup routine, wcsset(), computes intermediate values in the wcsprm struct 00069 * from parameters in it that were supplied by the user. The struct always 00070 * needs to be set up by wcsset() but this need not be called explicitly - 00071 * refer to the explanation of wcsprm::flag. 00072 * 00073 * wcsp2s() and wcss2p() implement the WCS world coordinate transformations. 00074 * In fact, they are high level driver routines for the WCS linear, 00075 * logarithmic, celestial, spectral and tabular transformation routines 00076 * described in lin.h, log.h, cel.h, spc.h and tab.h. 00077 * 00078 * Given either the celestial longitude or latitude plus an element of the 00079 * pixel coordinate a hybrid routine, wcsmix(), iteratively solves for the 00080 * unknown elements. 00081 * 00082 * wcssptr() translates the spectral axis in a wcsprm struct. For example, a 00083 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa. 00084 * 00085 * Quadcube projections: 00086 * --------------------- 00087 * The quadcube projections (TSC, CSC, QSC) may be represented in FITS in 00088 * either of two ways: 00089 * 00090 * a: The six faces may be laid out in one plane and numbered as follows: 00091 * 00092 = 0 00093 = 00094 = 4 3 2 1 4 3 2 00095 = 00096 = 5 00097 * 00098 * Faces 2, 3 and 4 may appear on one side or the other (or both). The 00099 * world-to-pixel routines map faces 2, 3 and 4 to the left but the 00100 * pixel-to-world routines accept them on either side. 00101 * 00102 * b: The "COBE" convention in which the six faces are stored in a 00103 * three-dimensional structure using a CUBEFACE axis indexed from 00104 * 0 to 5 as above. 00105 * 00106 * These routines support both methods; wcsset() determines which is being 00107 * used by the presence or absence of a CUBEFACE axis in ctype[]. wcsp2s() 00108 * and wcss2p() translate the CUBEFACE axis representation to the single 00109 * plane representation understood by the lower-level WCSLIB projection 00110 * routines. 00111 * 00112 * 00113 * wcsini() - Default constructor for the wcsprm struct 00114 * ---------------------------------------------------- 00115 * wcsini() optionally allocates memory for arrays in a wcsprm struct and sets 00116 * all members of the struct to default values. Memory is allocated for up to 00117 * NPVMAX PVi_ma keywords or NPSMAX PSi_ma keywords per WCS representation. 00118 * These may be changed via wcsnpv() and wcsnps() before wcsini() is called. 00119 * 00120 * PLEASE NOTE: every wcsprm struct should be initialized by wcsini(), possibly 00121 * repeatedly. On the first invokation, and only the first invokation, 00122 * wcsprm::flag must be set to -1 to initialize memory management, regardless 00123 * of whether wcsini() will actually be used to allocate memory. 00124 * 00125 * Given: 00126 * alloc int If true, allocate memory unconditionally for the 00127 * crpix, etc. arrays. 00128 * 00129 * If false, it is assumed that pointers to these arrays 00130 * have been set by the user except if they are null 00131 * pointers in which case memory will be allocated for 00132 * them regardless. (In other words, setting alloc true 00133 * saves having to initalize these pointers to zero.) 00134 * 00135 * naxis int The number of world coordinate axes. This is used to 00136 * determine the length of the various wcsprm vectors and 00137 * matrices and therefore the amount of memory to 00138 * allocate for them. 00139 * 00140 * Given and returned: 00141 * wcs struct wcsprm* 00142 * Coordinate transformation parameters. 00143 * 00144 * Note that, in order to initialize memory management, 00145 * wcsprm::flag should be set to -1 when wcs is 00146 * initialized for the first time (memory leaks may 00147 * result if it had already been initialized). 00148 * 00149 * Function return value: 00150 * int Status return value: 00151 * 0: Success. 00152 * 1: Null wcsprm pointer passed. 00153 * 2: Memory allocation failed. 00154 * 00155 * 00156 * wcsnpv() - Memory allocation for PVi_ma 00157 * --------------------------------------- 00158 * wcsnpv() changes the value of NPVMAX (default 64). This global variable 00159 * controls the number of PVi_ma keywords that wcsini() should allocate space 00160 * for. 00161 * 00162 * PLEASE NOTE: This function is not thread-safe. 00163 * 00164 * Given: 00165 * n int Value of NPVMAX; ignored if < 0. 00166 * 00167 * Function return value: 00168 * int Current value of NPVMAX. 00169 * 00170 * 00171 * wcsnps() - Memory allocation for PSi_ma 00172 * --------------------------------------- 00173 * wcsnps() changes the values of NPSMAX (default 8). This global variable 00174 * controls the number of PSi_ma keywords that wcsini() should allocate space 00175 * for. 00176 * 00177 * PLEASE NOTE: This function is not thread-safe. 00178 * 00179 * Given: 00180 * n int Value of NPSMAX; ignored if < 0. 00181 * 00182 * Function return value: 00183 * int Current value of NPSMAX. 00184 * 00185 * 00186 * wcssub() - Subimage extraction routine for the wcsprm struct 00187 * ------------------------------------------------------------ 00188 * wcssub() extracts the coordinate description for a subimage from a wcsprm 00189 * struct. It does a deep copy, using wcsini() to allocate memory for its 00190 * arrays if required. Only the "information to be provided" part of the 00191 * struct is extracted; a call to wcsset() is required to set up the remainder. 00192 * 00193 * The world coordinate system of the subimage must be separable in the sense 00194 * that the world coordinates at any point in the subimage must depend only on 00195 * the pixel coordinates of the axes extracted. In practice, this means that 00196 * the PCi_ja matrix of the original image must not contain non-zero 00197 * off-diagonal terms that associate any of the subimage axes with any of the 00198 * non-subimage axes. 00199 * 00200 * Note that while the required elements of the tabprm array are extracted, the 00201 * wtbarr array is not. (Thus it is not appropriate to call wcssub() after 00202 * wcstab() but before filling the tabprm structs - refer to wcshdr.h.) 00203 * 00204 * Given: 00205 * alloc int If true, allocate memory for the crpix, etc. arrays in 00206 * the destination. Otherwise, it is assumed that 00207 * pointers to these arrays have been set by the user 00208 * except if they are null pointers in which case memory 00209 * will be allocated for them regardless. 00210 * 00211 * wcssrc const struct wcsprm* 00212 * Struct to extract from. 00213 * 00214 * Given and returned: 00215 * nsub int* 00216 * axes int[] Vector of length *nsub containing the image axis 00217 * numbers (1-relative) to extract. Order is 00218 * significant; axes[0] is the axis number of the input 00219 * image that corresponds to the first axis in the 00220 * subimage, etc. 00221 * 00222 * nsub (the pointer) may be set to zero, and so also may 00223 * nsub, to indicate the number of axes in the input 00224 * image; the number of axes will be returned if 00225 * nsub != 0. axes itself (the pointer) may be set to 00226 * zero to indicate the first *nsub axes in their 00227 * original order. 00228 * 00229 * Set both nsub and axes to zero to do a deep copy of 00230 * one wcsprm struct to another. 00231 * 00232 * Subimage extraction by coordinate axis type may be 00233 * done by setting the elements of axes[] to the 00234 * following special preprocessor macro values: 00235 * 00236 * WCSSUB_LONGITUDE: Celestial longitude. 00237 * WCSSUB_LATITUDE: Celestial latitude. 00238 * WCSSUB_CUBEFACE: Quadcube CUBEFACE axis. 00239 * WCSSUB_SPECTRAL: Spectral axis. 00240 * WCSSUB_STOKES: Stokes axis. 00241 * 00242 * Refer to the notes (below) for further usage examples. 00243 * 00244 * On return, *nsub will contain the number of axes in 00245 * the subimage; this may be zero if there were no axes 00246 * of the required type(s) (in which case no memory will 00247 * be allocated). axes[] will contain the axis numbers 00248 * that were extracted. The vector length must be 00249 * sufficient to contain all axis numbers. No checks are 00250 * performed to verify that the coordinate axes are 00251 * consistent, this is done by wcsset(). 00252 * 00253 * wcsdst struct wcsprm* 00254 * Struct describing the subimage. wcsprm::flag should 00255 * be set to -1 if wcsdst was not previously initialized 00256 * (memory leaks may result if it was previously 00257 * initialized). 00258 * 00259 * Function return value: 00260 * int Status return value: 00261 * 0: Success. 00262 * 1: Null wcsprm pointer passed. 00263 * 2: Memory allocation failed. 00264 * 12: Invalid subimage specification. 00265 * 13: Non-separable subimage coordinate system. 00266 * 00267 * Notes: 00268 * Combinations of subimage axes of particular types may be extracted in the 00269 * same order as they occur in the input image by combining preprocessor 00270 * codes, for example 00271 * 00272 = *nsub = 1; 00273 = axes[0] = WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_SPECTRAL; 00274 * 00275 * would extract the longitude, latitude, and spectral axes in the same order 00276 * as the input image. If one of each were present, *nsub = 3 would be 00277 * returned. 00278 * 00279 * For convenience, WCSSUB_CELESTIAL is defined as the combination 00280 * WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_CUBEFACE. 00281 * 00282 * The codes may also be negated to extract all but the types specified, for 00283 * example 00284 * 00285 = *nsub = 4; 00286 = axes[0] = WCSSUB_LONGITUDE; 00287 = axes[1] = WCSSUB_LATITUDE; 00288 = axes[2] = WCSSUB_CUBEFACE; 00289 = axes[3] = -(WCSSUB_SPECTRAL | WCSSUB_STOKES); 00290 * 00291 * The last of these specifies all axis types other than spectral or Stokes. 00292 * Extraction is done in the order specified by axes[] a longitude axis (if 00293 * present) would be extracted first (via axes[0]) and not subsequently (via 00294 * axes[3]). Likewise for the latitude and cubeface axes in this example. 00295 * 00296 * From the foregoing, it is apparent that the value of *nsub returned may be 00297 * less than or greater than that given. However, it will never exceed the 00298 * number of axes in the input image. 00299 * 00300 * 00301 * wcscopy() macro - Copy routine for the wcsprm struct 00302 * ---------------------------------------------------- 00303 * wcscopy() does a deep copy of one wcsprm struct to another. As of 00304 * WCSLIB 3.6, it is implemented as a preprocessor macro that invokes 00305 * wcssub() with the nsub and axes pointers both set to zero. 00306 * 00307 * 00308 * wcsfree() - Destructor for the wcsprm struct 00309 * -------------------------------------------- 00310 * wcsfree() frees memory allocated for the wcsprm arrays by wcsini() and/or 00311 * wcsset(). wcsini() records the memory it allocates and wcsfree() will only 00312 * attempt to free this. 00313 * 00314 * PLEASE NOTE: wcsfree() must not be invoked on a wcsprm struct that was not 00315 * initialized by wcsini(). 00316 * 00317 * Returned: 00318 * wcs struct wcsprm* 00319 * Coordinate transformation parameters. 00320 * 00321 * Function return value: 00322 * int Status return value: 00323 * 0: Success. 00324 * 1: Null wcsprm pointer passed. 00325 * 00326 * 00327 * wcsprt() - Print routine for the wcsprm struct 00328 * ---------------------------------------------- 00329 * wcsprt() prints the contents of a wcsprm struct. 00330 * 00331 * Given: 00332 * wcs const struct wcsprm* 00333 * Coordinate transformation parameters. 00334 * 00335 * Function return value: 00336 * int Status return value: 00337 * 0: Success. 00338 * 1: Null wcsprm pointer passed. 00339 * 00340 * 00341 * wcsset() - Setup routine for the wcsprm struct 00342 * ---------------------------------------------- 00343 * wcsset() sets up a wcsprm struct according to information supplied within 00344 * it (refer to the description of the wcsprm struct). 00345 * 00346 * wcsset() recognizes the NCP projection and converts it to the equivalent SIN 00347 * projection and it also recognizes GLS as a synonym for SFL. It does alias 00348 * translation for the AIPS spectral types ('FREQ-LSR', 'FELO-HEL', etc.) but 00349 * without changing the input header keywords. 00350 * 00351 * Note that this routine need not be called directly; it will be invoked by 00352 * wcsp2s() and wcss2p() if the wcsprm::flag is anything other than a 00353 * predefined magic value. 00354 * 00355 * Given and returned: 00356 * wcs struct wcsprm* 00357 * Coordinate transformation parameters. 00358 * 00359 * Function return value: 00360 * int Status return value: 00361 * 0: Success. 00362 * 1: Null wcsprm pointer passed. 00363 * 2: Memory allocation failed. 00364 * 3: Linear transformation matrix is singular. 00365 * 4: Inconsistent or unrecognized coordinate axis 00366 * types. 00367 * 5: Invalid parameter value. 00368 * 6: Invalid coordinate transformation parameters. 00369 * 7: Ill-conditioned coordinate transformation 00370 * parameters. 00371 * 00372 * 00373 * wcsp2s() - Pixel-to-world transformation 00374 * ---------------------------------------- 00375 * wcsp2s() transforms pixel coordinates to world coordinates. 00376 * 00377 * Given and returned: 00378 * wcs struct wcsprm* 00379 * Coordinate transformation parameters. 00380 * 00381 * Given: 00382 * ncoord, 00383 * nelem int The number of coordinates, each of vector length 00384 * nelem but containing wcs.naxis coordinate elements. 00385 * Thus nelem must equal or exceed the value of the 00386 * NAXIS keyword unless ncoord == 1, in which case nelem 00387 * is not used. 00388 * pixcrd const double[ncoord][nelem] 00389 * Array of pixel coordinates. 00390 * 00391 * Returned: 00392 * imgcrd double[ncoord][nelem] 00393 * Array of intermediate world coordinates. For 00394 * celestial axes, imgcrd[][wcs.lng] and 00395 * imgcrd[][wcs.lat] are the projected x-, and 00396 * y-coordinates in pseudo "degrees". For spectral 00397 * axes, imgcrd[][wcs.spec] is the intermediate spectral 00398 * coordinate, in SI units. 00399 * 00400 * phi,theta double[ncoord] 00401 * Longitude and latitude in the native coordinate system 00402 * of the projection [deg]. 00403 * 00404 * world double[ncoord][nelem] 00405 * Array of world coordinates. For celestial axes, 00406 * world[][wcs.lng] and world[][wcs.lat] are the 00407 * celestial longitude and latitude [deg]. For 00408 * spectral axes, imgcrd[][wcs.spec] is the intermediate 00409 * spectral coordinate, in SI units. 00410 * 00411 * stat int[ncoord] 00412 * Status return value for each coordinate: 00413 * 0: Success. 00414 * 1+: A bit mask indicating invalid pixel coordinate 00415 * element(s). 00416 * 00417 * Function return value: 00418 * int Status return value: 00419 * 0: Success. 00420 * 1: Null wcsprm pointer passed. 00421 * 2: Memory allocation failed. 00422 * 3: Linear transformation matrix is singular. 00423 * 4: Inconsistent or unrecognized coordinate axis 00424 * types. 00425 * 5: Invalid parameter value. 00426 * 6: Invalid coordinate transformation parameters. 00427 * 7: Ill-conditioned coordinate transformation 00428 * parameters. 00429 * 8: One or more of the pixel coordinates were 00430 * invalid, as indicated by the stat vector. 00431 * 00432 * 00433 * wcss2p() - World-to-pixel transformation 00434 * ---------------------------------------- 00435 * wcss2p() transforms world coordinates to pixel coordinates. 00436 * 00437 * Given and returned: 00438 * wcs struct wcsprm* 00439 * Coordinate transformation parameters. 00440 * 00441 * Given: 00442 * ncoord, 00443 * nelem int The number of coordinates, each of vector length nelem 00444 * but containing wcs.naxis coordinate elements. Thus 00445 * nelem must equal or exceed the value of the NAXIS 00446 * keyword unless ncoord == 1, in which case nelem is not 00447 * used. 00448 * world const double[ncoord][nelem] 00449 * Array of world coordinates. For celestial axes, 00450 * world[][wcs.lng] and world[][wcs.lat] are the 00451 * celestial longitude and latitude [deg]. For spectral 00452 * axes, world[][wcs.spec] is the spectral coordinate, in 00453 * SI units. 00454 * 00455 * Returned: 00456 * phi,theta double[ncoord] 00457 * Longitude and latitude in the native coordinate 00458 * system of the projection [deg]. 00459 * 00460 * imgcrd double[ncoord][nelem] 00461 * Array of intermediate world coordinates. For 00462 * celestial axes, imgcrd[][wcs.lng] and 00463 * imgcrd[][wcs.lat] are the projected x-, and 00464 * y-coordinates in pseudo "degrees". For quadcube 00465 * projections with a CUBEFACE axis the face number is 00466 * also returned in imgcrd[][wcs.cubeface]. For 00467 * spectral axes, imgcrd[][wcs.spec] is the intermediate 00468 * spectral coordinate, in SI units. 00469 * 00470 * pixcrd double[ncoord][nelem] 00471 * Array of pixel coordinates. 00472 * 00473 * stat int[ncoord] 00474 * Status return value for each coordinate: 00475 * 0: Success. 00476 * 1+: A bit mask indicating invalid world coordinate 00477 * element(s). 00478 * 00479 * Function return value: 00480 * int Status return value: 00481 * 0: Success. 00482 * 1: Null wcsprm pointer passed. 00483 * 2: Memory allocation failed. 00484 * 3: Linear transformation matrix is singular. 00485 * 4: Inconsistent or unrecognized coordinate axis 00486 * types. 00487 * 5: Invalid parameter value. 00488 * 6: Invalid coordinate transformation parameters. 00489 * 7: Ill-conditioned coordinate transformation 00490 * parameters. 00491 * 9: One or more of the world coordinates were 00492 * invalid, as indicated by the stat vector. 00493 * 00494 * 00495 * wcsmix() - Hybrid coordinate transformation 00496 * ------------------------------------------- 00497 * wcsmix(), given either the celestial longitude or latitude plus an element 00498 * of the pixel coordinate, solves for the remaining elements by iterating on 00499 * the unknown celestial coordinate element using wcss2p(). Refer also to the 00500 * notes below. 00501 * 00502 * Given and returned: 00503 * wcs struct wcsprm* 00504 * Indices for the celestial coordinates obtained 00505 * by parsing the wcsprm::ctype[]. 00506 * 00507 * Given: 00508 * mixpix int Which element of the pixel coordinate is given. 00509 * mixcel int Which element of the celestial coordinate is given: 00510 * 1: Celestial longitude is given in 00511 * world[wcs.lng], latitude returned in 00512 * world[wcs.lat]. 00513 * 2: Celestial latitude is given in 00514 * world[wcs.lat], longitude returned in 00515 * world[wcs.lng]. 00516 * 00517 * vspan const double[2] 00518 * Solution interval for the celestial coordinate [deg]. 00519 * The ordering of the two limits is irrelevant. 00520 * Longitude ranges may be specified with any convenient 00521 * normalization, for example [-120,+120] is the same as 00522 * [240,480], except that the solution will be returned 00523 * with the same normalization, i.e. lie within the 00524 * interval specified. 00525 * 00526 * vstep const double 00527 * Step size for solution search [deg]. If zero, a 00528 * sensible, although perhaps non-optimal default will be 00529 * used. 00530 * 00531 * viter int If a solution is not found then the step size will be 00532 * halved and the search recommenced. viter controls how 00533 * many times the step size is halved. The allowed range 00534 * is 5 - 10. 00535 * 00536 * Given and returned: 00537 * world double[naxis] 00538 * World coordinate elements. world[wcs.lng] and 00539 * world[wcs.lat] are the celestial longitude and 00540 * latitude [deg]. Which is given and which returned 00541 * depends on the value of mixcel. All other elements 00542 * are given. 00543 * 00544 * Returned: 00545 * phi,theta double[naxis] 00546 * Longitude and latitude in the native coordinate 00547 * system of the projection [deg]. 00548 * 00549 * imgcrd double[naxis] 00550 * Image coordinate elements. imgcrd[wcs.lng] and 00551 * imgcrd[wcs.lat] are the projected x-, and 00552 * y-coordinates in pseudo "degrees". 00553 * 00554 * Given and returned: 00555 * pixcrd double[naxis] 00556 * Pixel coordinate. The element indicated by mixpix is 00557 * given and the remaining elements are returned. 00558 * 00559 * Function return value: 00560 * int Status return value: 00561 * 0: Success. 00562 * 1: Null wcsprm pointer passed. 00563 * 2: Memory allocation failed. 00564 * 3: Linear transformation matrix is singular. 00565 * 4: Inconsistent or unrecognized coordinate axis 00566 * types. 00567 * 5: Invalid parameter value. 00568 * 6: Invalid coordinate transformation parameters. 00569 * 7: Ill-conditioned coordinate transformation 00570 * parameters. 00571 * 10: Invalid world coordinate. 00572 * 11: No solution found in the specified interval. 00573 * 00574 * Notes: 00575 * Initially the specified solution interval is checked to see if it's a 00576 * "crossing" interval. If it isn't, a search is made for a crossing 00577 * solution by iterating on the unknown celestial coordinate starting at the 00578 * upper limit of the solution interval and decrementing by the specified 00579 * step size. A crossing is indicated if the trial value of the pixel 00580 * coordinate steps through the value specified. If a crossing interval is 00581 * found then the solution is determined by a modified form of "regula falsi" 00582 * division of the crossing interval. If no crossing interval was found 00583 * within the specified solution interval then a search is made for a 00584 * "non-crossing" solution as may arise from a point of tangency. The 00585 * process is complicated by having to make allowance for the discontinuities 00586 * that occur in all map projections. 00587 * 00588 * Once one solution has been determined others may be found by subsequent 00589 * invokations of wcsmix() with suitably restricted solution intervals. 00590 * 00591 * Note the circumstance that arises when the solution point lies at a native 00592 * pole of a projection in which the pole is represented as a finite curve, 00593 * for example the zenithals and conics. In such cases two or more valid 00594 * solutions may exist but wcsmix() only ever returns one. 00595 * 00596 * Because of its generality wcsmix() is very compute-intensive. For 00597 * compute-limited applications more efficient special-case solvers could be 00598 * written for simple projections, for example non-oblique cylindrical 00599 * projections. 00600 * 00601 * 00602 * wcssptr() - Spectral axis translation 00603 * ------------------------------------- 00604 * wcssptr() translates the spectral axis in a wcsprm struct. For example, a 00605 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa. 00606 * 00607 * Given and returned: 00608 * wcs struct wcsprm* 00609 * Coordinate transformation parameters. 00610 * i int* Index of the spectral axis (0-relative). If given < 0 00611 * it will be set to the first spectral axis identified 00612 * from the ctype[] keyvalues in the wcsprm struct. 00613 * ctype char[9] Required spectral CTYPEia. Wildcarding may be used as 00614 * for the ctypeS2 argument to spctrn() as described in 00615 * the prologue of spc.h, i.e. if the final three 00616 * characters are specified as "???", or if just the 00617 * eighth character is specified as '?', the correct 00618 * algorithm code will be substituted and returned. 00619 * 00620 * Function return value: 00621 * int Status return value: 00622 * 0: Success. 00623 * 1: Null wcsprm pointer passed. 00624 * 2: Memory allocation failed. 00625 * 3: Linear transformation matrix is singular. 00626 * 4: Inconsistent or unrecognized coordinate axis 00627 * types. 00628 * 5: Invalid parameter value. 00629 * 6: Invalid coordinate transformation parameters. 00630 * 7: Ill-conditioned coordinate transformation 00631 * parameters. 00632 * 12: Invalid subimage specification (no spectral 00633 * axis). 00634 * 00635 * 00636 * wcsprm struct - Coordinate transformation parameters 00637 * ---------------------------------------------------- 00638 * The wcsprm struct contains information required to transform world 00639 * coordinates. It consists of certain members that must be set by the user 00640 * ("given") and others that are set by the WCSLIB routines ("returned"). 00641 * Some of the former are not actually required for transforming coordinates. 00642 * These are described as "auxiliary"; the struct simply provides a place to 00643 * store them, though they may be used by wcshdo() in constructing a FITS 00644 * header from a wcsprm struct. Some of the returned values are supplied for 00645 * informational purposes and others are for internal use only as indicated. 00646 * 00647 * In practice, it is expected that a WCS parser would scan the FITS header to 00648 * determine the number of coordinate axes. It would then use wcsini() to 00649 * allocate memory for arrays in the wcsprm struct and set default values. 00650 * Then as it reread the header and identified each WCS keyrecord it would load 00651 * the value into the relevant wcsprm array element. This is essentially what 00652 * wcspih() does - refer to the prologue of wcshdr.h. As the final step, 00653 * wcsset() is invoked, either directly or indirectly, to set the derived 00654 * members of the wcsprm struct. wcsset() strips off trailing blanks in all 00655 * string members and null-fills the character array. 00656 * 00657 * int flag 00658 * (Given and returned) This flag must be set to zero whenever any of the 00659 * following wcsprm struct members are set or changed: 00660 * 00661 * - wcsprm::naxis (q.v., not normally set by the user), 00662 * - wcsprm::crpix, 00663 * - wcsprm::pc, 00664 * - wcsprm::cdelt, 00665 * - wcsprm::crval, 00666 * - wcsprm::cunit, 00667 * - wcsprm::ctype, 00668 * - wcsprm::lonpole, 00669 * - wcsprm::latpole, 00670 * - wcsprm::restfrq, 00671 * - wcsprm::restwav, 00672 * - wcsprm::npv, 00673 * - wcsprm::pv, 00674 * - wcsprm::nps, 00675 * - wcsprm::ps, 00676 * - wcsprm::cd, 00677 * - wcsprm::crota, 00678 * - wcsprm::altlin. 00679 * 00680 * This signals the initialization routine, wcsset(), to recompute the 00681 * returned members of the celprm struct. celset() will reset flag to 00682 * indicate that this has been done. 00683 * 00684 * PLEASE NOTE: flag should be set to -1 when wcsini() is called for the 00685 * first time for a particular wcsprm struct in order to initialize memory 00686 * management. It must ONLY be used on the first initialization otherwise 00687 * memory leaks may result. 00688 * 00689 * int naxis 00690 * (Given or returned) Number of pixel and world coordinate elements. 00691 * 00692 * If wcsini() is used to initialize the linprm struct (as would normally 00693 * be the case) then it will set naxis from the value passed to it as a 00694 * function argument. The user should not subsequently modify it. 00695 * 00696 * double *crpix 00697 * (Given) Address of the first element of an array of double containing 00698 * the coordinate reference pixel, CRPIXja. 00699 * 00700 * double *pc 00701 * (Given) Address of the first element of the PCi_ja (pixel coordinate) 00702 * transformation matrix. The expected order is 00703 * 00704 = struct wcsprm wcs; 00705 = wcs.pc = {PC1_1, PC1_2, PC2_1, PC2_2}; 00706 * 00707 * This may be constructed conveniently from a 2-D array via 00708 * 00709 = double m[2][2] = {{PC1_1, PC1_2}, 00710 = {PC2_1, PC2_2}}; 00711 * 00712 * which is equivalent to 00713 * 00714 = double m[2][2]; 00715 = m[0][0] = PC1_1; 00716 = m[0][1] = PC1_2; 00717 = m[1][0] = PC2_1; 00718 = m[1][1] = PC2_2; 00719 * 00720 * The storage order for this 2-D array is the same as for the 1-D array, 00721 * whence 00722 * 00723 = wcs.pc = *m; 00724 * 00725 * would be legitimate. 00726 * 00727 * double *cdelt 00728 * (Given) Address of the first element of an array of double containing 00729 * the coordinate increments, CDELTia. 00730 * 00731 * double *crval 00732 * (Given) Address of the first element of an array of double containing 00733 * the coordinate reference values, CRVALia. 00734 * 00735 * char (*cunit)[72] 00736 * (Given) Address of the first element of an array of char[72] containing 00737 * the CUNITia keyvalues which define the units of measurement of the 00738 * CRVALia, CDELTia, and CDi_ja keywords. 00739 * 00740 * As CUNITia is an optional header keyword, cunit[][72] may be left blank 00741 * but otherwise is expected to contain a standard units specification as 00742 * defined by WCS Paper I. Utility function wcsutrn(), described in 00743 * wcsunits.h, is available to translate commonly used non-standard units 00744 * specifications but this must be done as a separate step before invoking 00745 * wcsset(). 00746 * 00747 * For celestial axes, if cunit[][72] is not blank, wcsset() uses 00748 * wcsunits() to parse it and scale cdelt[], crval[], and cd[][*] to 00749 * degrees. It then resets cunit[][72] to "deg". 00750 * 00751 * For spectral axes, if cunit[][72] is not blank, wcsset() uses wcsunits() 00752 * to parse it and scale cdelt[], crval[], and cd[][*] to SI units. It 00753 * then resets cunit[][72] accordingly. 00754 * 00755 * wcsset() ignores cunit[][72] for other coordinate types; cunit[][72] may 00756 * be used to label coordinate values. 00757 * 00758 * These variables accomodate the longest allowed string-valued FITS 00759 * keyword, being limited to 68 characters, plus the null-terminating 00760 * character. 00761 * 00762 * char (*ctype)[72] 00763 * (Given) Address of the first element of an array of char[72] containing 00764 * the coordinate axis types, CTYPEia. 00765 * 00766 * The ctype[][72] keyword values must be in upper case and there must be 00767 * zero or one pair of matched celestial axis types, and zero or one 00768 * spectral axis. The ctype[][72] strings should be padded with blanks on 00769 * the right and null-terminated so that they are at least eight characters 00770 * in length. 00771 * 00772 * These variables accomodate the longest allowed string-valued FITS 00773 * keyword, being limited to 68 characters, plus the null-terminating 00774 * character. 00775 * 00776 * double lonpole 00777 * (Given and returned) The native longitude of the celestial pole, phi_p, 00778 * given by LONPOLEa [deg] or by PVi_2a [deg] attached to the longitude 00779 * axis which takes precedence if defined, and ... 00780 * double latpole 00781 * (Given and returned) ... the native latitude of the celestial pole, 00782 * theta_p, given by LATPOLEa [deg] or by PVi_3a [deg] attached to the 00783 * longitude axis which takes precedence if defined. 00784 * 00785 * lonpole and latpole may be left to default to values set by wcsini() 00786 * (see celprm::ref), but in any case they will be reset by wcsset() to 00787 * the values actually used. Note therefore that if the wcsprm struct is 00788 * reused without resetting them, whether directly or via wcsini(), they 00789 * will no longer have their default values. 00790 * 00791 * double restfrq 00792 * (Given) The rest frequency [Hz], and/or ... 00793 * double restwav 00794 * (Given) ... the rest wavelength in vacuuo [m], only one of which need be 00795 * given, the other should be set to zero. 00796 * 00797 * int npv 00798 * (Given) The number of entries in the wcsprm::pv[] array. 00799 * 00800 * int npvmax 00801 * (Given or returned) The length of the wcsprm::pv[] array. 00802 * 00803 * npvmax will be set by wcsini() if it allocates memory for wcsprm::pv[], 00804 * otherwise it must be set by the user. See also wcsnpv(). 00805 * 00806 * struct pvcard *pv 00807 * (Given or returned) Address of the first element of an array of length 00808 * npvmax of pvcard structs. Set by wcsini() if it allocates memory for 00809 * pv[], otherwise it must be set by the user. See also wcsnpv(). 00810 * 00811 * As a FITS header parser encounters each PVi_ma keyword it should load it 00812 * into a pvcard struct in the array and increment npv. wcsset() 00813 * interprets these as required. 00814 * 00815 * Note that, if they were not given, wcsset() resets the entries for 00816 * PVi_1a, PVi_2a, PVi_3a, and PVi_4a for longitude axis i to match 00817 * (phi_0,theta_0), the native longitude and latitude of the reference 00818 * point given by LONPOLEa and LATPOLEa. 00819 * 00820 * int nps 00821 * (Given) The number of entries in the wcsprm::ps[] array. 00822 * 00823 * int npsmax 00824 * (Given or returned) The length of the wcsprm::ps[] array. 00825 * 00826 * npsmax will be set by wcsini() if it allocates memory for wcsprm::ps[], 00827 * otherwise it must be set by the user. See also wcsnps(). 00828 * 00829 * struct pscard *ps 00830 * (Given or returned) Address of the first element of an array of length 00831 * npsmax of pscard structs. Set by wcsini() if it allocates memory for 00832 * ps[], otherwise it must be set by the user. See also wcsnps(). 00833 * 00834 * As a FITS header parser encounters each PSi_ma keyword it should load it 00835 * into a pscard struct in the array and increment nps. wcsset() 00836 * interprets these as required (currently no PSi_ma keyvalues are 00837 * recognized). 00838 * 00839 * double *cd 00840 * (Given) For historical compatibility, the wcsprm struct supports two 00841 * alternate specifications of the linear transformation matrix, those 00842 * associated with the CDi_ja keywords, and ... 00843 * double *crota 00844 * (Given) ... those associated with the CROTAia keywords. Although these 00845 * may not formally co-exist with PCi_ja, the approach taken here is simply 00846 * to ignore them if given in conjunction with PCi_ja. 00847 * 00848 * int altlin 00849 * (Given) altlin is a bit flag that denotes which of the PCi_ja, CDi_ja 00850 * and CROTAia keywords are present in the header: 00851 * 00852 * - Bit 0: PCi_ja is present. 00853 * 00854 * - Bit 1: CDi_ja is present. 00855 * 00856 * Matrix elements in the IRAF convention are 00857 * equivalent to the product CDi_ja = CDELTia * PCi_ja, but the 00858 * defaults differ from that of the PCi_ja matrix. If one or more 00859 * CDi_ja keywords are present then all unspecified CDi_ja default to 00860 * zero. If no CDi_ja (or CROTAia) keywords are present, then the 00861 * header is assumed to be in PCi_ja form whether or not any PCi_ja 00862 * keywords are present since this results in an interpretation of 00863 * CDELTia consistent with the original FITS specification. 00864 * 00865 * While CDi_ja may not formally co-exist with PCi_ja, it may co-exist 00866 * with CDELTia and CROTAia which are to be ignored. 00867 * 00868 * - Bit 2: CROTAia is present. 00869 * 00870 * In the AIPS convention, CROTAia may only be 00871 * associated with the latitude axis of a celestial axis pair. It 00872 * specifies a rotation in the image plane that is applied AFTER the 00873 * CDELTia; any other CROTAia keywords are ignored. 00874 * 00875 * CROTAia may not formally co-exist with PCi_ja. 00876 * 00877 * CROTAia and CDELTia may formally co-exist with CDi_ja but if so are to 00878 * be ignored. 00879 * 00880 * CDi_ja and CROTAia keywords, if found, are to be stored in the 00881 * wcsprm::cd and wcsprm::crota arrays which are dimensioned similarly to 00882 * wcsprm::pc and wcsprm::cdelt. FITS 00883 * header parsers should use the following procedure: 00884 * 00885 * - Whenever a PCi_ja keyword is encountered: altlin |= 1; 00886 * 00887 * - Whenever a CDi_ja keyword is encountered: altlin |= 2; 00888 * 00889 * - Whenever a CROTAia keyword is encountered: altlin |= 4; 00890 * 00891 * If none of these bits are set the PCi_ja representation results, i.e. 00892 * wcsprm::pc and wcsprm::cdelt will be used as given. 00893 * 00894 * These alternate specifications of the linear transformation matrix are 00895 * translated immediately to PCi_ja by wcsset() and are invisible to the 00896 * lower-level WCSLIB routines. In particular, wcsset() resets 00897 * wcsprm::cdelt to unity if CDi_ja is present (and no PCi_ja). 00898 * 00899 * If CROTAia are present but none is associated with the latitude axis 00900 * (and no PCi_ja or CDi_ja), then wcsset() reverts to a unity PCi_ja 00901 * matrix. 00902 * 00903 * int padding 00904 * (An unused variable inserted for alignment purposes only.) 00905 * 00906 * char alt[4] 00907 * (Given, auxiliary) Character code for alternate coordinate descriptions 00908 * (i.e. the 'a' in keyword names such as CTYPEia). This is blank for the 00909 * primary coordinate description, or one of the 26 upper-case letters, 00910 * A-Z. 00911 * 00912 * An array of four characters is provided for alignment purposes, only the 00913 * first is used. 00914 * 00915 * int colnum 00916 * (Given, auxiliary) Where the coordinate representation is associated 00917 * with an image-array column in a FITS binary table, this variable may be 00918 * used to record the relevant column number. 00919 * 00920 * It should be set to zero for an image header or pixel list. 00921 * 00922 * int *colax 00923 * (Given, auxiliary) Address of the first element of an array of int 00924 * recording the column numbers for each axis in a pixel list. 00925 * 00926 * The array elements should be set to zero for an image header or image 00927 * array in a binary table. 00928 * 00929 * char (*cname)[72] 00930 * (Given, auxiliary) The address of the first element of an array of 00931 * char[72] containing the coordinate axis names, CNAMEia. 00932 * 00933 * These variables accomodate the longest allowed string-valued FITS 00934 * keyword, being limited to 68 characters, plus the null-terminating 00935 * character. 00936 * 00937 * double *crder 00938 * (Given, auxiliary) Address of the first element of an array of double 00939 * recording the random error in the coordinate value, CRDERia. 00940 * double *csyer 00941 * (Given, auxiliary) Address of the first element of an array of double 00942 * recording the systematic error in the coordinate value, CSYERia. 00943 * 00944 * char dateavg[72] 00945 * (Given, auxiliary) The date of a representative mid-point of the 00946 * observation in ISO format, yyyy-mm-ddThh:mm:ss. 00947 * char dateobs[72] 00948 * (Given, auxiliary) The date of the start of the observation unless 00949 * otherwise explained in the comment field of the DATE-OBS keyword, in 00950 * ISO format, yyyy-mm-ddThh:mm:ss. 00951 * 00952 * double equinox 00953 * (Given, auxiliary) The equinox associated with dynamical equatorial or 00954 * ecliptic coordinate systems, EQUINOXa (or EPOCH in older headers). Not 00955 * applicable to ICRS equatorial or ecliptic coordinates. 00956 * 00957 * double mjdavg 00958 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-AVG, 00959 * corresponding to DATE-AVG. 00960 * double mjdobs 00961 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-OBS, 00962 * corresponding to DATE-OBS. 00963 * 00964 * double obsgeo[3] 00965 * (Given, auxiliary) Location of the observer in a standard terrestrial 00966 * reference frame, OBSGEO-X, OBSGEO-Y, OBSGEO-Z [m]. 00967 * 00968 * char radesys[72] 00969 * (Given, auxiliary) The equatorial or ecliptic coordinate system type, 00970 * RADESYSa. 00971 * 00972 * char specsys[72] 00973 * (Given, auxiliary) Spectral reference frame (standard of rest), 00974 * SPECSYSa, and ... 00975 * char ssysobs[72] 00976 * (Given, auxiliary) ... the actual frame in which there is no 00977 * differential variation in the spectral coordinate across the 00978 * field-of-view, SSYSOBSa. 00979 * double velosys 00980 * (Given, auxiliary) The relative radial velocity [m/s] between the 00981 * observer and the selected standard of rest in the direction of the 00982 * celestial reference coordinate, VELOSYSa. 00983 * 00984 * double zsource 00985 * (Given, auxiliary) The redshift, ZSOURCEa, of the source, and ... 00986 * char ssyssrc[72] 00987 * (Given, auxiliary) ... the spectral reference frame (standard of rest) 00988 * in which this was measured, SSYSSRCa. 00989 * 00990 * double velangl 00991 * (Given, auxiliary) The angle [deg] that should be used to decompose an 00992 * observed velocity into radial and transverse components. 00993 * 00994 * char wcsname[72] 00995 * (Given, auxiliary) The name given to the coordinate representation, 00996 * WCSNAMEa. This variable accomodates the longest allowed string-valued 00997 * FITS keyword, being limited to 68 characters, plus the null-terminating 00998 * character. 00999 * 01000 * int ntab 01001 * (Given) See wcsprm::tab. 01002 * 01003 * int nwtb 01004 * (Given) See wcsprm::wtb. 01005 * 01006 * struct tabprm *tab 01007 * (Given) Address of the first element of an array of ntab tabprm structs 01008 * for which memory has been allocated. These are used to store tabular 01009 * transformation parameters. 01010 * 01011 * Although technically wcsprm::ntab and tab are "given", they will 01012 * normally be set by invoking wcstab(), whether directly or indirectly. 01013 * 01014 * The tabprm structs contain some members that must be supplied and others 01015 * that are derived. The information to be supplied comes primarily from 01016 * arrays stored in one or more FITS binary table extensions. These 01017 * arrays, referred to here as "wcstab arrays", are themselves located by 01018 * parameters stored in the FITS image header. 01019 * 01020 * struct wtbarr *wtb 01021 * (Given) Address of the first element of an array of nwtb wtbarr structs 01022 * for which memory has been allocated. These are used in extracting 01023 * wcstab arrays from a FITS binary table. 01024 * 01025 * Although technically wcsprm::nwtb and wtb are "given", they will 01026 * normally be set by invoking wcstab(), whether directly or indirectly. 01027 * 01028 * int *types 01029 * (Returned) Address of the first element of an array of int containing a 01030 * four-digit type code for each axis. 01031 * 01032 * - First digit (i.e. 1000s): 01033 * - 0: Non-specific coordinate type. 01034 * - 1: Stokes coordinate. 01035 * - 2: Celestial coordinate (including CUBEFACE). 01036 * - 3: Spectral coordinate. 01037 * 01038 * - Second digit (i.e. 100s): 01039 * - 0: Linear axis. 01040 * - 1: Quantized axis (STOKES, CUBEFACE). 01041 * - 2: Non-linear celestial axis. 01042 * - 3: Non-linear spectral axis. 01043 * - 4: Logarithmic axis. 01044 * - 5: Tabular axis. 01045 * 01046 * - Third digit (i.e. 10s): 01047 * - 0: Group number, e.g. lookup table number, being an index into the 01048 * tabprm array (see above). 01049 * 01050 * - The fourth digit is used as a qualifier depending on the axis type. 01051 * 01052 * - For celestial axes: 01053 * - 0: Longitude coordinate. 01054 * - 1: Latitude coordinate. 01055 * - 2: CUBEFACE number. 01056 * 01057 * - For lookup tables: the axis number in a multidimensional table. 01058 * 01059 * CTYPEia in "4-3" form with unrecognized algorithm code will have its 01060 * type set to -1 and generate an error. 01061 * 01062 * char lngtyp[8] 01063 * (Returned) Four-character WCS celestial longitude and ... 01064 * char lattyp[8] 01065 * (Returned) ... latitude axis types. e.g. "RA", "DEC", "GLON", "GLAT", 01066 * etc. extracted from 'RA--', 'DEC-', 'GLON', 'GLAT', etc. in the first 01067 * four characters of CTYPEia but with trailing dashes removed. (Declared 01068 * as char[8] for alignment reasons.) 01069 * 01070 * int lng 01071 * (Returned) Index for the longitude coordinate, and ... 01072 * int lat 01073 * (Returned) ... index for the latitude coordinate, and ... 01074 * int spec 01075 * (Returned) ... index for the spectral coordinate in the imgcrd[][] and 01076 * world[][] arrays in the API of wcsp2s(), wcss2p() and wcsmix(). 01077 * 01078 * These may also serve as indices into the pixcrd[][] array provided that 01079 * the PCi_ja matrix does not transpose axes. 01080 * 01081 * int cubeface 01082 * (Returned) Index into the pixcrd[][] array for the CUBEFACE axis. This 01083 * is used for quadcube projections where the cube faces are stored on a 01084 * separate axis (see wcs.h). 01085 * 01086 * struct linprm lin 01087 * (Returned) Linear transformation parameters (usage is described in the 01088 * prologue to lin.h). 01089 * 01090 * struct celprm cel 01091 * (Returned) Celestial transformation parameters (usage is described in 01092 * the prologue to cel.h). 01093 * 01094 * struct spcprm spc 01095 * (Returned) Spectral transformation parameters (usage is described in the 01096 * prologue to spc.h). 01097 * 01098 * int m_flag 01099 * (For internal use only.) 01100 * int m_naxis 01101 * (For internal use only.) 01102 * double *m_crpix 01103 * (For internal use only.) 01104 * double *m_pc 01105 * (For internal use only.) 01106 * double *m_cdelt 01107 * (For internal use only.) 01108 * double *m_crval 01109 * (For internal use only.) 01110 * char (*m_cunit)[72] 01111 * (For internal use only.) 01112 * char (*m_ctype)[72] 01113 * (For internal use only.) 01114 * struct pvcard *m_pv 01115 * (For internal use only.) 01116 * struct pscard *m_ps 01117 * (For internal use only.) 01118 * double *m_cd 01119 * (For internal use only.) 01120 * double *m_crota 01121 * (For internal use only.) 01122 * int *m_colax 01123 * (For internal use only.) 01124 * char (*m_cname)[72] 01125 * (For internal use only.) 01126 * double *m_crder 01127 * (For internal use only.) 01128 * double *m_csyer 01129 * (For internal use only.) 01130 * struct tabprm *m_tab 01131 * (For internal use only.) 01132 * struct wtbarr *m_wtb 01133 * (For internal use only.) 01134 * 01135 * 01136 * pscard struct - Store for PSi_ma keyrecords 01137 * ------------------------------------------- 01138 * The pscard struct is used to pass the parsed contents of PSi_ma keyrecords 01139 * to wcsset() via the wcsprm struct. 01140 * 01141 * All members of this struct are to be set by the user. 01142 * 01143 * int i 01144 * (Given) Axis number (1-relative), as in the FITS PSi_ma keyword. 01145 * 01146 * int m 01147 * (Given) Parameter number (non-negative), as in the FITS PSi_ma keyword. 01148 * 01149 * char value[72] 01150 * (Given) Parameter value. 01151 * 01152 * 01153 * pvcard struct - Store for PVi_ma keyrecords 01154 * ------------------------------------------- 01155 * The pvcard struct is used to pass the parsed contents of PVi_ma keyrecords 01156 * to wcsset() via the wcsprm struct. 01157 * 01158 * All members of this struct are to be set by the user. 01159 * 01160 * int i 01161 * (Given) Axis number (1-relative), as in the FITS PVi_ma keyword. 01162 * 01163 * int m 01164 * (Given) Parameter number (non-negative), as in the FITS PVi_ma keyword. 01165 * 01166 * double value 01167 * (Given) Parameter value. 01168 * 01169 * 01170 * wtbarr struct - Extraction of coordinate lookup tables from BINTABLE 01171 * -------------------------------------------------------------------- 01172 * Function wcstab(), which is invoked automatically by wcspih(), sets up an 01173 * array of wtbarr structs to assist in extracting coordinate lookup tables 01174 * from a binary table extension (BINTABLE) and copying them into the tabprm 01175 * structs stored in wcsprm. Refer to the usage notes for wcspih() and 01176 * wcstab() in wcshdr.h, and also the prologue to tab.h. 01177 * 01178 * For C++ usage, because of a name space conflict with the wtbarr typedef 01179 * defined in CFITSIO header fitsio.h, the wtbarr struct is renamed to wtbarr_s 01180 * by preprocessor macro substitution with scope limited to wcs.h itself. 01181 * 01182 * int i 01183 * (Given) Image axis number. 01184 * 01185 * int m 01186 * (Given) wcstab array axis number for index vectors. 01187 * 01188 * int kind 01189 * (Given) Character identifying the wcstab array type: 01190 * - c: coordinate array, 01191 * - i: index vector. 01192 * 01193 * char extnam[72] 01194 * (Given) EXTNAME identifying the binary table extension. 01195 * 01196 * int extver 01197 * (Given) EXTVER identifying the binary table extension. 01198 * 01199 * int extlev 01200 * (Given) EXTLEV identifying the binary table extension. 01201 * 01202 * char ttype[72] 01203 * (Given) TTYPEn identifying the column of the binary table that contains 01204 * the wcstab array. 01205 * 01206 * long row 01207 * (Given) Table row number. 01208 * 01209 * int ndim 01210 * (Given) Expected dimensionality of the wcstab array. 01211 * 01212 * int *dimlen 01213 * (Given) Address of the first element of an array of int of length ndim 01214 * into which the wcstab array axis lengths are to be written. 01215 * 01216 * double **arrayp 01217 * (Given) Pointer to an array of double which is to be allocated by the 01218 * user and into which the wcstab array is to be written. 01219 * 01220 * 01221 * Global variable: const char *wcs_errmsg[] - Status return messages 01222 * ------------------------------------------------------------------ 01223 * Error messages to match the status value returned from each function. 01224 * 01225 *===========================================================================*/ 01226 01227 #ifndef WCSLIB_WCS 01228 #define WCSLIB_WCS 01229 01230 #include "lin.h" 01231 #include "cel.h" 01232 #include "spc.h" 01233 #include "tab.h" 01234 01235 #ifdef __cplusplus 01236 extern "C" { 01237 #endif 01238 01239 #define WCSSUB_LONGITUDE 0x1001 01240 #define WCSSUB_LATITUDE 0x1002 01241 #define WCSSUB_CUBEFACE 0x1004 01242 #define WCSSUB_CELESTIAL 0x1007 01243 #define WCSSUB_SPECTRAL 0x1008 01244 #define WCSSUB_STOKES 0x1010 01245 01246 01247 extern const char *wcs_errmsg[]; 01248 01249 /* Struct used for storing PVi_ma keywords. */ 01250 struct pvcard { 01251 int i; /* Axis number, as in PVi_ma (1-relative). */ 01252 int m; /* Parameter number, ditto (0-relative). */ 01253 double value; /* Parameter value. */ 01254 }; 01255 01256 /* Struct used for storing PSi_ma keywords. */ 01257 struct pscard { 01258 int i; /* Axis number, as in PSi_ma (1-relative). */ 01259 int m; /* Parameter number, ditto (0-relative). */ 01260 char value[72]; /* Parameter value. */ 01261 }; 01262 01263 /* For extracting wcstab arrays. */ 01264 #ifdef __cplusplus 01265 #define wtbarr wtbarr_s /* See prologue above. */ 01266 #endif 01267 struct wtbarr { 01268 int i; /* Image axis number. */ 01269 int m; /* Array axis number for index vectors. */ 01270 int kind; /* wcstab array type. */ 01271 char extnam[72]; /* EXTNAME of binary table extension. */ 01272 int extver; /* EXTVER of binary table extension. */ 01273 int extlev; /* EXTLEV of binary table extension. */ 01274 char ttype[72]; /* TTYPEn of column containing the array. */ 01275 long row; /* Table row number. */ 01276 int ndim; /* Expected wcstab array dimensionality. */ 01277 int *dimlen; /* Where to write the array axis lengths. */ 01278 double **arrayp; /* Where to write the address of the array */ 01279 /* allocated to store the wcstab array. */ 01280 }; 01281 01282 01283 struct wcsprm { 01284 /* Initialization flag (see the prologue above). */ 01285 /*------------------------------------------------------------------------*/ 01286 int flag; /* Set to zero to force initialization. */ 01287 01288 /* FITS header keyvalues to be provided (see the prologue above). */ 01289 /*------------------------------------------------------------------------*/ 01290 int naxis; /* Number of axes (pixel and coordinate). */ 01291 double *crpix; /* CRPIXja keyvalues for each pixel axis. */ 01292 double *pc; /* PCi_ja linear transformation matrix. */ 01293 double *cdelt; /* CDELTia keyvalues for each coord axis. */ 01294 double *crval; /* CRVALia keyvalues for each coord axis. */ 01295 01296 char (*cunit)[72]; /* CUNITia keyvalues for each coord axis. */ 01297 char (*ctype)[72]; /* CTYPEia keyvalues for each coord axis. */ 01298 01299 double lonpole; /* LONPOLEa keyvalue. */ 01300 double latpole; /* LATPOLEa keyvalue. */ 01301 01302 double restfrq; /* RESTFRQa keyvalue. */ 01303 double restwav; /* RESTWAVa keyvalue. */ 01304 01305 int npv; /* Number of PVi_ma keywords, and the */ 01306 int npvmax; /* number for which space was allocated. */ 01307 struct pvcard *pv; /* PVi_ma keywords for each i and m. */ 01308 01309 int nps; /* Number of PSi_ma keywords, and the */ 01310 int npsmax; /* number for which space was allocated. */ 01311 struct pscard *ps; /* PSi_ma keywords for each i and m. */ 01312 01313 /* Alternative header keyvalues (see the prologue above). */ 01314 /*------------------------------------------------------------------------*/ 01315 double *cd; /* CDi_ja linear transformation matrix. */ 01316 double *crota; /* CROTAia keyvalues for each coord axis. */ 01317 int altlin; /* Alternative representations */ 01318 /* Bit 0: PCi_ja is present, */ 01319 /* Bit 1: CDi_ja is present, */ 01320 /* Bit 2: CROTAia is present. */ 01321 int padding; /* (Dummy inserted for alignment purposes.) */ 01322 01323 /* Auxiliary coordinate system information, not used by WCSLIB. */ 01324 char alt[4]; 01325 int colnum; 01326 int *colax; 01327 01328 char (*cname)[72]; 01329 double *crder; 01330 double *csyer; 01331 char dateavg[72]; 01332 char dateobs[72]; 01333 double equinox; 01334 double mjdavg; 01335 double mjdobs; 01336 double obsgeo[3]; 01337 char radesys[72]; 01338 char specsys[72]; 01339 char ssysobs[72]; 01340 double velosys; 01341 double zsource; 01342 char ssyssrc[72]; 01343 double velangl; 01344 char wcsname[72]; 01345 01346 /* Coordinate lookup tables (see the prologue above). */ 01347 /*------------------------------------------------------------------------*/ 01348 int ntab; /* Number of separate tables. */ 01349 int nwtb; /* Number of wtbarr structs. */ 01350 struct tabprm *tab; /* Tabular transformation parameters. */ 01351 struct wtbarr *wtb; /* Array of wtbarr structs. */ 01352 01353 /* Information derived from the FITS header keyvalues by wcsset(). */ 01354 /*------------------------------------------------------------------------*/ 01355 int *types; /* Coordinate type codes for each axis. */ 01356 char lngtyp[8], lattyp[8]; /* Celestial axis types, e.g. RA, DEC. */ 01357 int lng, lat, spec; /* Longitude, latitude and spectral axis */ 01358 /* indices (0-relative). */ 01359 int cubeface; /* True if there is a CUBEFACE axis. */ 01360 01361 struct linprm lin; /* Linear transformation parameters. */ 01362 struct celprm cel; /* Celestial transformation parameters. */ 01363 struct spcprm spc; /* Spectral transformation parameters. */ 01364 01365 int m_flag, m_naxis; /* The remainder are for memory management. */ 01366 double *m_crpix, *m_pc, *m_cdelt, *m_crval; 01367 char (*m_cunit)[72], (*m_ctype)[72]; 01368 struct pvcard *m_pv; 01369 struct pscard *m_ps; 01370 double *m_cd, *m_crota; 01371 int *m_colax; 01372 char (*m_cname)[72]; 01373 double *m_crder, *m_csyer; 01374 struct tabprm *m_tab; 01375 struct wtbarr *m_wtb; 01376 }; 01377 01378 /* Size of the wcsprm struct in int units, used by the Fortran wrappers. */ 01379 #define WCSLEN (sizeof(struct wcsprm)/sizeof(int)) 01380 01381 01382 int wcsnpv(int n); 01383 01384 int wcsnps(int n); 01385 01386 int wcsini(int alloc, int naxis, struct wcsprm *wcs); 01387 01388 int wcssub(int alloc, const struct wcsprm *wcssrc, int *nsub, int axes[], 01389 struct wcsprm *wcsdst); 01390 01391 int wcsfree(struct wcsprm *wcs); 01392 01393 int wcsprt(const struct wcsprm *wcs); 01394 01395 int wcsset(struct wcsprm *wcs); 01396 01397 int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[], 01398 double imgcrd[], double phi[], double theta[], double world[], 01399 int stat[]); 01400 01401 int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[], 01402 double phi[], double theta[], double imgcrd[], double pixcrd[], 01403 int stat[]); 01404 01405 int wcsmix(struct wcsprm *wcs, int mixpix, int mixcel, const double vspan[], 01406 double vstep, int viter, double world[], double phi[], 01407 double theta[], double imgcrd[], double pixcrd[]); 01408 01409 int wcssptr(struct wcsprm *wcs, int *i, char ctype[9]); 01410 01411 /* Defined mainly for backwards compatibility, use wcssub() instead. */ 01412 #define wcscopy(alloc, wcssrc, wcsdst) wcssub(alloc, wcssrc, 0, 0, wcsdst) 01413 01414 01415 /* Deprecated. */ 01416 #define wcsini_errmsg wcs_errmsg 01417 #define wcssub_errmsg wcs_errmsg 01418 #define wcscopy_errmsg wcs_errmsg 01419 #define wcsfree_errmsg wcs_errmsg 01420 #define wcsprt_errmsg wcs_errmsg 01421 #define wcsset_errmsg wcs_errmsg 01422 #define wcsp2s_errmsg wcs_errmsg 01423 #define wcss2p_errmsg wcs_errmsg 01424 #define wcsmix_errmsg wcs_errmsg 01425 01426 #ifdef __cplusplus 01427 #undef wtbarr 01428 } 01429 #endif 01430 01431 #endif /* WCSLIB_WCS */