wcs.h

Go to the documentation of this file.
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.h,v 4.4.1.1 2009/08/10 08:52:49 cal103 Exp cal103 $
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: Invalid pixel coordinate.
00415 *
00416 * Function return value:
00417 *             int       Status return value:
00418 *                         0: Success.
00419 *                         1: Null wcsprm pointer passed.
00420 *                         2: Memory allocation failed.
00421 *                         3: Linear transformation matrix is singular.
00422 *                         4: Inconsistent or unrecognized coordinate axis
00423 *                            types.
00424 *                         5: Invalid parameter value.
00425 *                         6: Invalid coordinate transformation parameters.
00426 *                         7: Ill-conditioned coordinate transformation
00427 *                            parameters.
00428 *                         8: One or more of the pixel coordinates were
00429 *                            invalid, as indicated by the stat vector.
00430 *
00431 *
00432 * wcss2p() - World-to-pixel transformation
00433 * ----------------------------------------
00434 * wcss2p() transforms world coordinates to pixel coordinates.
00435 *
00436 * Given and returned:
00437 *   wcs       struct wcsprm*
00438 *                       Coordinate transformation parameters.
00439 *
00440 * Given:
00441 *   ncoord,
00442 *   nelem     int       The number of coordinates, each of vector length nelem
00443 *                       but containing wcs.naxis coordinate elements.  Thus
00444 *                       nelem must equal or exceed the value of the NAXIS
00445 *                       keyword unless ncoord == 1, in which case nelem is not
00446 *                       used.
00447 *   world     const double[ncoord][nelem]
00448 *                       Array of world coordinates.  For celestial axes,
00449 *                       world[][wcs.lng] and world[][wcs.lat] are the
00450 *                       celestial longitude and latitude [deg]. For spectral
00451 *                       axes, world[][wcs.spec] is the spectral coordinate, in
00452 *                       SI units.
00453 *
00454 * Returned:
00455 *   phi,theta double[ncoord]
00456 *                       Longitude and latitude in the native coordinate
00457 *                       system of the projection [deg].
00458 *
00459 *   imgcrd    double[ncoord][nelem]
00460 *                       Array of intermediate world coordinates.  For
00461 *                       celestial axes, imgcrd[][wcs.lng] and
00462 *                       imgcrd[][wcs.lat] are the projected x-, and
00463 *                       y-coordinates in pseudo "degrees".  For quadcube
00464 *                       projections with a CUBEFACE axis the face number is
00465 *                       also returned in imgcrd[][wcs.cubeface].  For
00466 *                       spectral axes, imgcrd[][wcs.spec] is the intermediate
00467 *                       spectral coordinate, in SI units.
00468 *
00469 *   pixcrd    double[ncoord][nelem]
00470 *                       Array of pixel coordinates.
00471 *
00472 *   stat      int[ncoord]
00473 *                       Status return value for each coordinate:
00474 *                         0: Success.
00475 *                         1: Invalid world coordinate.
00476 *
00477 * Function return value:
00478 *             int       Status return value:
00479 *                         0: Success.
00480 *                         1: Null wcsprm pointer passed.
00481 *                         2: Memory allocation failed.
00482 *                         3: Linear transformation matrix is singular.
00483 *                         4: Inconsistent or unrecognized coordinate axis
00484 *                            types.
00485 *                         5: Invalid parameter value.
00486 *                         6: Invalid coordinate transformation parameters.
00487 *                         7: Ill-conditioned coordinate transformation
00488 *                            parameters.
00489 *                         9: One or more of the world coordinates were
00490 *                            invalid, as indicated by the stat vector.
00491 *
00492 *
00493 * wcsmix() - Hybrid coordinate transformation
00494 * -------------------------------------------
00495 * wcsmix(), given either the celestial longitude or latitude plus an element
00496 * of the pixel coordinate, solves for the remaining elements by iterating on
00497 * the unknown celestial coordinate element using wcss2p().  Refer also to the
00498 * notes below.
00499 *
00500 * Given and returned:
00501 *   wcs       struct wcsprm*
00502 *                       Indices for the celestial coordinates obtained
00503 *                       by parsing the wcsprm::ctype[].
00504 *
00505 * Given:
00506 *   mixpix    int       Which element of the pixel coordinate is given.
00507 *   mixcel    int       Which element of the celestial coordinate is given:
00508 *                         1: Celestial longitude is given in
00509 *                            world[wcs.lng], latitude returned in
00510 *                            world[wcs.lat].
00511 *                         2: Celestial latitude is given in
00512 *                            world[wcs.lat], longitude returned in
00513 *                            world[wcs.lng].
00514 *
00515 *   vspan     const double[2]
00516 *                       Solution interval for the celestial coordinate [deg].
00517 *                       The ordering of the two limits is irrelevant.
00518 *                       Longitude ranges may be specified with any convenient
00519 *                       normalization, for example [-120,+120] is the same as
00520 *                       [240,480], except that the solution will be returned
00521 *                       with the same normalization, i.e. lie within the
00522 *                       interval specified.
00523 *
00524 *   vstep     const double
00525 *                       Step size for solution search [deg].  If zero, a
00526 *                       sensible, although perhaps non-optimal default will be
00527 *                       used.
00528 *
00529 *   viter     int       If a solution is not found then the step size will be
00530 *                       halved and the search recommenced.  viter controls how
00531 *                       many times the step size is halved.  The allowed range
00532 *                       is 5 - 10.
00533 *
00534 * Given and returned:
00535 *   world     double[naxis]
00536 *                       World coordinate elements.  world[wcs.lng] and
00537 *                       world[wcs.lat] are the celestial longitude and
00538 *                       latitude [deg].  Which is given and which returned
00539 *                       depends on the value of mixcel.  All other elements
00540 *                       are given.
00541 *
00542 * Returned:
00543 *   phi,theta double[naxis]
00544 *                       Longitude and latitude in the native coordinate
00545 *                       system of the projection [deg].
00546 *
00547 *   imgcrd    double[naxis]
00548 *                       Image coordinate elements.  imgcrd[wcs.lng] and
00549 *                       imgcrd[wcs.lat] are the projected x-, and
00550 *                       y-coordinates in pseudo "degrees".
00551 *
00552 * Given and returned:
00553 *   pixcrd    double[naxis]
00554 *                       Pixel coordinate.  The element indicated by mixpix is
00555 *                       given and the remaining elements are returned.
00556 *
00557 * Function return value:
00558 *             int       Status return value:
00559 *                          0: Success.
00560 *                          1: Null wcsprm pointer passed.
00561 *                          2: Memory allocation failed.
00562 *                          3: Linear transformation matrix is singular.
00563 *                          4: Inconsistent or unrecognized coordinate axis
00564 *                             types.
00565 *                          5: Invalid parameter value.
00566 *                          6: Invalid coordinate transformation parameters.
00567 *                          7: Ill-conditioned coordinate transformation
00568 *                             parameters.
00569 *                         10: Invalid world coordinate.
00570 *                         11: No solution found in the specified interval.
00571 *
00572 * Notes:
00573 *   Initially the specified solution interval is checked to see if it's a
00574 *   "crossing" interval.  If it isn't, a search is made for a crossing
00575 *   solution by iterating on the unknown celestial coordinate starting at the
00576 *   upper limit of the solution interval and decrementing by the specified
00577 *   step size.  A crossing is indicated if the trial value of the pixel
00578 *   coordinate steps through the value specified.  If a crossing interval is
00579 *   found then the solution is determined by a modified form of "regula falsi"
00580 *   division of the crossing interval.  If no crossing interval was found
00581 *   within the specified solution interval then a search is made for a
00582 *   "non-crossing" solution as may arise from a point of tangency.  The
00583 *   process is complicated by having to make allowance for the discontinuities
00584 *   that occur in all map projections.
00585 *
00586 *   Once one solution has been determined others may be found by subsequent
00587 *   invokations of wcsmix() with suitably restricted solution intervals.
00588 *
00589 *   Note the circumstance that arises when the solution point lies at a native
00590 *   pole of a projection in which the pole is represented as a finite curve,
00591 *   for example the zenithals and conics.  In such cases two or more valid
00592 *   solutions may exist but wcsmix() only ever returns one.
00593 *
00594 *   Because of its generality wcsmix() is very compute-intensive.  For
00595 *   compute-limited applications more efficient special-case solvers could be
00596 *   written for simple projections, for example non-oblique cylindrical
00597 *   projections.
00598 *
00599 *
00600 * wcssptr() - Spectral axis translation
00601 * -------------------------------------
00602 * wcssptr() translates the spectral axis in a wcsprm struct.  For example, a
00603 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa.
00604 *
00605 * Given and returned:
00606 *   wcs       struct wcsprm*
00607 *                       Coordinate transformation parameters.
00608 *   i         int*      Index of the spectral axis (0-relative).  If given < 0
00609 *                       it will be set to the first spectral axis identified
00610 *                       from the ctype[] keyvalues in the wcsprm struct.
00611 *   ctype     char[9]   Required spectral CTYPEia.  Wildcarding may be used as
00612 *                       for the ctypeS2 argument to spctrn() as described in
00613 *                       the prologue of spc.h, i.e. if the final three
00614 *                       characters are specified as "???", or if just the
00615 *                       eighth character is specified as '?', the correct
00616 *                       algorithm code will be substituted and returned.
00617 *
00618 * Function return value:
00619 *             int       Status return value:
00620 *                          0: Success.
00621 *                          1: Null wcsprm pointer passed.
00622 *                          2: Memory allocation failed.
00623 *                          3: Linear transformation matrix is singular.
00624 *                          4: Inconsistent or unrecognized coordinate axis
00625 *                             types.
00626 *                          5: Invalid parameter value.
00627 *                          6: Invalid coordinate transformation parameters.
00628 *                          7: Ill-conditioned coordinate transformation
00629 *                             parameters.
00630 *                         12: Invalid subimage specification (no spectral
00631 *                             axis).
00632 *
00633 *
00634 * wcsprm struct - Coordinate transformation parameters
00635 * ----------------------------------------------------
00636 * The wcsprm struct contains information required to transform world
00637 * coordinates.  It consists of certain members that must be set by the user
00638 * ("given") and others that are set by the WCSLIB routines ("returned").
00639 * Some of the former are not actually required for transforming coordinates.
00640 * These are described as "auxiliary"; the struct simply provides a place to
00641 * store them, though they may be used by wcshdo() in constructing a FITS
00642 * header from a wcsprm struct.  Some of the returned values are supplied for
00643 * informational purposes and others are for internal use only as indicated.
00644 *
00645 * In practice, it is expected that a WCS parser would scan the FITS header to
00646 * determine the number of coordinate axes.  It would then use wcsini() to
00647 * allocate memory for arrays in the wcsprm struct and set default values.
00648 * Then as it reread the header and identified each WCS keyrecord it would load
00649 * the value into the relevant wcsprm array element.  This is essentially what
00650 * wcspih() does - refer to the prologue of wcshdr.h.  As the final step,
00651 * wcsset() is invoked, either directly or indirectly, to set the derived
00652 * members of the wcsprm struct.  wcsset() strips off trailing blanks in all
00653 * string members and null-fills the character array.
00654 *
00655 *   int flag
00656 *     (Given and returned) This flag must be set to zero whenever any of the
00657 *     following wcsprm struct members are set or changed:
00658 *
00659 *       - wcsprm::naxis (q.v., not normally set by the user),
00660 *       - wcsprm::crpix,
00661 *       - wcsprm::pc,
00662 *       - wcsprm::cdelt,
00663 *       - wcsprm::crval,
00664 *       - wcsprm::cunit,
00665 *       - wcsprm::ctype,
00666 *       - wcsprm::lonpole,
00667 *       - wcsprm::latpole,
00668 *       - wcsprm::restfrq,
00669 *       - wcsprm::restwav,
00670 *       - wcsprm::npv,
00671 *       - wcsprm::pv,
00672 *       - wcsprm::nps,
00673 *       - wcsprm::ps,
00674 *       - wcsprm::cd,
00675 *       - wcsprm::crota,
00676 *       - wcsprm::altlin.
00677 *
00678 *     This signals the initialization routine, wcsset(), to recompute the
00679 *     returned members of the celprm struct.  celset() will reset flag to
00680 *     indicate that this has been done.
00681 *
00682 *     PLEASE NOTE: flag should be set to -1 when wcsini() is called for the
00683 *     first time for a particular wcsprm struct in order to initialize memory
00684 *     management.  It must ONLY be used on the first initialization otherwise
00685 *     memory leaks may result.
00686 *
00687 *   int naxis
00688 *     (Given or returned) Number of pixel and world coordinate elements.
00689 *
00690 *     If wcsini() is used to initialize the linprm struct (as would normally
00691 *     be the case) then it will set naxis from the value passed to it as a
00692 *     function argument.  The user should not subsequently modify it.
00693 *
00694 *   double *crpix
00695 *     (Given) Address of the first element of an array of double containing
00696 *     the coordinate reference pixel, CRPIXja.
00697 *
00698 *   double *pc
00699 *     (Given) Address of the first element of the PCi_ja (pixel coordinate)
00700 *     transformation matrix.  The expected order is
00701 *
00702 =       struct wcsprm wcs;
00703 =       wcs.pc = {PC1_1, PC1_2, PC2_1, PC2_2};
00704 *
00705 *     This may be constructed conveniently from a 2-D array via
00706 *
00707 =       double m[2][2] = {{PC1_1, PC1_2},
00708 =                         {PC2_1, PC2_2}};
00709 *
00710 *     which is equivalent to
00711 *
00712 =       double m[2][2];
00713 =       m[0][0] = PC1_1;
00714 =       m[0][1] = PC1_2;
00715 =       m[1][0] = PC2_1;
00716 =       m[1][1] = PC2_2;
00717 *
00718 *     The storage order for this 2-D array is the same as for the 1-D array,
00719 *     whence
00720 *
00721 =       wcs.pc = *m;
00722 *
00723 *     would be legitimate.
00724 *
00725 *   double *cdelt
00726 *     (Given) Address of the first element of an array of double containing
00727 *     the coordinate increments, CDELTia.
00728 *
00729 *   double *crval
00730 *     (Given) Address of the first element of an array of double containing
00731 *     the coordinate reference values, CRVALia.
00732 *
00733 *   char (*cunit)[72]
00734 *     (Given) Address of the first element of an array of char[72] containing
00735 *     the CUNITia keyvalues which define the units of measurement of the
00736 *     CRVALia, CDELTia, and CDi_ja keywords.
00737 *
00738 *     As CUNITia is an optional header keyword, cunit[][72] may be left blank
00739 *     but otherwise is expected to contain a standard units specification as
00740 *     defined by WCS Paper I.  Utility function wcsutrn(), described in
00741 *     wcsunits.h, is available to translate commonly used non-standard units
00742 *     specifications but this must be done as a separate step before invoking
00743 *     wcsset().
00744 *
00745 *     For celestial axes, if cunit[][72] is not blank, wcsset() uses
00746 *     wcsunits() to parse it and scale cdelt[], crval[], and cd[][*] to
00747 *     degrees.  It then resets cunit[][72] to "deg".
00748 *
00749 *     For spectral axes, if cunit[][72] is not blank, wcsset() uses wcsunits()
00750 *     to parse it and scale cdelt[], crval[], and cd[][*] to SI units.  It
00751 *     then resets cunit[][72] accordingly.
00752 *
00753 *     wcsset() ignores cunit[][72] for other coordinate types; cunit[][72] may
00754 *     be used to label coordinate values.
00755 *
00756 *     These variables accomodate the longest allowed string-valued FITS
00757 *     keyword, being limited to 68 characters, plus the null-terminating
00758 *     character.
00759 *
00760 *   char (*ctype)[72]
00761 *     (Given) Address of the first element of an array of char[72] containing
00762 *     the coordinate axis types, CTYPEia.
00763 *
00764 *     The ctype[][72] keyword values must be in upper case and there must be
00765 *     zero or one pair of matched celestial axis types, and zero or one
00766 *     spectral axis.  The ctype[][72] strings should be padded with blanks on
00767 *     the right and null-terminated so that they are at least eight characters
00768 *     in length.
00769 *
00770 *     These variables accomodate the longest allowed string-valued FITS
00771 *     keyword, being limited to 68 characters, plus the null-terminating
00772 *     character.
00773 *
00774 *   double lonpole
00775 *     (Given and returned) The native longitude of the celestial pole, phi_p,
00776 *     given by LONPOLEa [deg] or by PVi_2a [deg] attached to the longitude
00777 *     axis which takes precedence if defined, and ...
00778 *   double latpole
00779 *     (Given and returned) ... the native latitude of the celestial pole,
00780 *     theta_p, given by LATPOLEa [deg] or by PVi_3a [deg] attached to the
00781 *     longitude axis which takes precedence if defined.
00782 *
00783 *     lonpole and latpole may be left to default to values set by wcsini()
00784 *     (see celprm::ref), but in any case they will be reset by wcsset() to
00785 *     the values actually used.  Note therefore that if the wcsprm struct is
00786 *     reused without resetting them, whether directly or via wcsini(), they
00787 *     will no longer have their default values.
00788 *
00789 *   double restfrq
00790 *     (Given) The rest frequency [Hz], and/or ...
00791 *   double restwav
00792 *     (Given) ... the rest wavelength in vacuuo [m], only one of which need be
00793 *     given, the other should be set to zero.
00794 *
00795 *   int npv
00796 *     (Given) The number of entries in the wcsprm::pv[] array.
00797 *
00798 *   int npvmax
00799 *     (Given or returned) The length of the wcsprm::pv[] array.
00800 *
00801 *     npvmax will be set by wcsini() if it allocates memory for wcsprm::pv[],
00802 *     otherwise it must be set by the user.  See also wcsnpv().
00803 *
00804 *   struct pvcard *pv
00805 *     (Given or returned) Address of the first element of an array of length
00806 *     npvmax of pvcard structs.  Set by wcsini() if it allocates memory for
00807 *     pv[], otherwise it must be set by the user.  See also wcsnpv().
00808 *
00809 *     As a FITS header parser encounters each PVi_ma keyword it should load it
00810 *     into a pvcard struct in the array and increment npv.  wcsset()
00811 *     interprets these as required.
00812 *
00813 *     Note that, if they were not given, wcsset() resets the entries for
00814 *     PVi_1a, PVi_2a, PVi_3a, and PVi_4a for longitude axis i to match
00815 *     (phi_0,theta_0), the native longitude and latitude of the reference
00816 *     point given by LONPOLEa and LATPOLEa.
00817 *
00818 *   int nps
00819 *     (Given) The number of entries in the wcsprm::ps[] array.
00820 *
00821 *   int npsmax
00822 *     (Given or returned) The length of the wcsprm::ps[] array.
00823 *
00824 *     npsmax will be set by wcsini() if it allocates memory for wcsprm::ps[],
00825 *     otherwise it must be set by the user.  See also wcsnps().
00826 *
00827 *   struct pscard *ps
00828 *     (Given or returned) Address of the first element of an array of length
00829 *     npsmax of pscard structs.  Set by wcsini() if it allocates memory for
00830 *     ps[], otherwise it must be set by the user.  See also wcsnps().
00831 *
00832 *     As a FITS header parser encounters each PSi_ma keyword it should load it
00833 *     into a pscard struct in the array and increment nps.  wcsset()
00834 *     interprets these as required (currently no PSi_ma keyvalues are
00835 *     recognized).
00836 *
00837 *   double *cd
00838 *     (Given) For historical compatibility, the wcsprm struct supports two
00839 *     alternate specifications of the linear transformation matrix, those
00840 *     associated with the CDi_ja keywords, and ...
00841 *   double *crota
00842 *     (Given) ... those associated with the CROTAia keywords.  Although these
00843 *     may not formally co-exist with PCi_ja, the approach taken here is simply
00844 *     to ignore them if given in conjunction with PCi_ja.
00845 *
00846 *   int altlin
00847 *     (Given) altlin is a bit flag that denotes which of the PCi_ja, CDi_ja
00848 *     and CROTAia keywords are present in the header:
00849 *
00850 *     - Bit 0: PCi_ja is present.
00851 *
00852 *     - Bit 1: CDi_ja is present.
00853 *
00854 *       Matrix elements in the IRAF convention are
00855 *       equivalent to the product CDi_ja = CDELTia * PCi_ja, but the
00856 *       defaults differ from that of the PCi_ja matrix.  If one or more
00857 *       CDi_ja keywords are present then all unspecified CDi_ja default to
00858 *       zero.  If no CDi_ja (or CROTAia) keywords are present, then the
00859 *       header is assumed to be in PCi_ja form whether or not any PCi_ja
00860 *       keywords are present since this results in an interpretation of
00861 *       CDELTia consistent with the original FITS specification.
00862 *
00863 *       While CDi_ja may not formally co-exist with PCi_ja, it may co-exist
00864 *       with CDELTia and CROTAia which are to be ignored.
00865 *
00866 *     - Bit 2: CROTAia is present.
00867 *
00868 *       In the AIPS convention, CROTAia may only be
00869 *       associated with the latitude axis of a celestial axis pair.  It
00870 *       specifies a rotation in the image plane that is applied AFTER the
00871 *       CDELTia; any other CROTAia keywords are ignored.
00872 *
00873 *       CROTAia may not formally co-exist with PCi_ja.
00874 *
00875 *       CROTAia and CDELTia may formally co-exist with CDi_ja but if so are to
00876 *       be ignored.
00877 *
00878 *     CDi_ja and CROTAia keywords, if found, are to be stored in the
00879 *     wcsprm::cd and wcsprm::crota arrays which are dimensioned similarly to
00880 *     wcsprm::pc and wcsprm::cdelt.  FITS
00881 *     header parsers should use the following procedure:
00882 *
00883 *     - Whenever a PCi_ja  keyword is encountered: altlin |= 1;
00884 *
00885 *     - Whenever a CDi_ja  keyword is encountered: altlin |= 2;
00886 *
00887 *     - Whenever a CROTAia keyword is encountered: altlin |= 4;
00888 *
00889 *     If none of these bits are set the PCi_ja representation results, i.e.
00890 *     wcsprm::pc and wcsprm::cdelt will be used as given.
00891 *
00892 *     These alternate specifications of the linear transformation matrix are
00893 *     translated immediately to PCi_ja by wcsset() and are invisible to the
00894 *     lower-level WCSLIB routines.  In particular, wcsset() resets
00895 *     wcsprm::cdelt to unity if CDi_ja is present (and no PCi_ja).
00896 *
00897 *     If CROTAia are present but none is associated with the latitude axis
00898 *     (and no PCi_ja or CDi_ja), then wcsset() reverts to a unity PCi_ja
00899 *     matrix.
00900 *
00901 *   int padding
00902 *     (An unused variable inserted for alignment purposes only.)
00903 *
00904 *   char alt[4]
00905 *     (Given, auxiliary) Character code for alternate coordinate descriptions
00906 *     (i.e. the 'a' in keyword names such as CTYPEia).  This is blank for the
00907 *     primary coordinate description, or one of the 26 upper-case letters,
00908 *     A-Z.
00909 *
00910 *     An array of four characters is provided for alignment purposes, only the
00911 *     first is used.
00912 *
00913 *   int colnum
00914 *     (Given, auxiliary) Where the coordinate representation is associated
00915 *     with an image-array column in a FITS binary table, this variable may be
00916 *     used to record the relevant column number.
00917 *
00918 *     It should be set to zero for an image header or pixel list.
00919 *
00920 *   int *colax
00921 *     (Given, auxiliary) Address of the first element of an array of int
00922 *     recording the column numbers for each axis in a pixel list.
00923 *
00924 *     The array elements should be set to zero for an image header or image
00925 *     array in a binary table.
00926 *
00927 *   char (*cname)[72]
00928 *     (Given, auxiliary) The address of the first element of an array of
00929 *     char[72] containing the coordinate axis names, CNAMEia.
00930 *
00931 *     These variables accomodate the longest allowed string-valued FITS
00932 *     keyword, being limited to 68 characters, plus the null-terminating
00933 *     character.
00934 *
00935 *   double *crder
00936 *     (Given, auxiliary) Address of the first element of an array of double
00937 *     recording the random error in the coordinate value, CRDERia.
00938 *   double *csyer
00939 *     (Given, auxiliary) Address of the first element of an array of double
00940 *     recording the systematic error in the coordinate value, CSYERia.
00941 *
00942 *   char dateavg[72]
00943 *     (Given, auxiliary) The date of a representative mid-point of the
00944 *     observation in ISO format, yyyy-mm-ddThh:mm:ss.
00945 *   char dateobs[72]
00946 *     (Given, auxiliary) The date of the start of the observation unless
00947 *     otherwise explained in the comment field of the DATE-OBS keyword, in
00948 *     ISO format, yyyy-mm-ddThh:mm:ss.
00949 *
00950 *   double equinox
00951 *     (Given, auxiliary) The equinox associated with dynamical equatorial or
00952 *     ecliptic coordinate systems, EQUINOXa (or EPOCH in older headers).  Not
00953 *     applicable to ICRS equatorial or ecliptic coordinates.
00954 *
00955 *   double mjdavg
00956 *     (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-AVG,
00957 *     corresponding to DATE-AVG.
00958 *   double mjdobs
00959 *     (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-OBS,
00960 *     corresponding to DATE-OBS.
00961 *
00962 *   double obsgeo[3]
00963 *     (Given, auxiliary) Location of the observer in a standard terrestrial
00964 *     reference frame, OBSGEO-X, OBSGEO-Y, OBSGEO-Z [m].
00965 *
00966 *   char radesys[72]
00967 *     (Given, auxiliary) The equatorial or ecliptic coordinate system type,
00968 *     RADESYSa.
00969 *
00970 *   char specsys[72]
00971 *     (Given, auxiliary) Spectral reference frame (standard of rest),
00972 *     SPECSYSa, and ...
00973 *   char ssysobs[72]
00974 *     (Given, auxiliary) ... the actual frame in which there is no
00975 *     differential variation in the spectral coordinate across the
00976 *     field-of-view, SSYSOBSa.
00977 *   double velosys
00978 *     (Given, auxiliary) The relative radial velocity [m/s] between the
00979 *     observer and the selected standard of rest in the direction of the
00980 *     celestial reference coordinate, VELOSYSa.
00981 *
00982 *   double zsource
00983 *     (Given, auxiliary) The redshift, ZSOURCEa, of the source, and ...
00984 *   char ssyssrc[72]
00985 *     (Given, auxiliary) ... the spectral reference frame (standard of rest)
00986 *     in which this was measured, SSYSSRCa.
00987 *
00988 *   double velangl
00989 *     (Given, auxiliary) The angle [deg] that should be used to decompose an
00990 *     observed velocity into radial and transverse components.
00991 *
00992 *   char wcsname[72]
00993 *     (Given, auxiliary) The name given to the coordinate representation,
00994 *     WCSNAMEa.  This variable accomodates the longest allowed string-valued
00995 *     FITS keyword, being limited to 68 characters, plus the null-terminating
00996 *     character.
00997 *
00998 *   int ntab
00999 *     (Given) See wcsprm::tab.
01000 *
01001 *   int nwtb
01002 *     (Given) See wcsprm::wtb.
01003 *
01004 *   struct tabprm *tab
01005 *     (Given) Address of the first element of an array of ntab tabprm structs
01006 *     for which memory has been allocated.  These are used to store tabular
01007 *     transformation parameters.
01008 *
01009 *     Although technically wcsprm::ntab and tab are "given", they will
01010 *     normally be set by invoking wcstab(), whether directly or indirectly.
01011 *
01012 *     The tabprm structs contain some members that must be supplied and others
01013 *     that are derived.  The information to be supplied comes primarily from
01014 *     arrays stored in one or more FITS binary table extensions.  These
01015 *     arrays, referred to here as "wcstab arrays", are themselves located by
01016 *     parameters stored in the FITS image header.
01017 *
01018 *   struct wtbarr *wtb
01019 *     (Given) Address of the first element of an array of nwtb wtbarr structs
01020 *     for which memory has been allocated.  These are used in extracting
01021 *     wcstab arrays from a FITS binary table.
01022 *
01023 *     Although technically wcsprm::nwtb and wtb are "given", they will
01024 *     normally be set by invoking wcstab(), whether directly or indirectly.
01025 *
01026 *   int *types
01027 *     (Returned) Address of the first element of an array of int containing a
01028 *     four-digit type code for each axis.
01029 *
01030 *     - First digit (i.e. 1000s):
01031 *       - 0: Non-specific coordinate type.
01032 *       - 1: Stokes coordinate.
01033 *       - 2: Celestial coordinate (including CUBEFACE).
01034 *       - 3: Spectral coordinate.
01035 *
01036 *     - Second digit (i.e. 100s):
01037 *       - 0: Linear axis.
01038 *       - 1: Quantized axis (STOKES, CUBEFACE).
01039 *       - 2: Non-linear celestial axis.
01040 *       - 3: Non-linear spectral axis.
01041 *       - 4: Logarithmic axis.
01042 *       - 5: Tabular axis.
01043 *
01044 *     - Third digit (i.e. 10s):
01045 *       - 0: Group number, e.g. lookup table number, being an index into the
01046 *            tabprm array (see above).
01047 *
01048 *     - The fourth digit is used as a qualifier depending on the axis type.
01049 *
01050 *       - For celestial axes:
01051 *         - 0: Longitude coordinate.
01052 *         - 1: Latitude coordinate.
01053 *         - 2: CUBEFACE number.
01054 *
01055 *       - For lookup tables: the axis number in a multidimensional table.
01056 *
01057 *     CTYPEia in "4-3" form with unrecognized algorithm code will have its
01058 *     type set to -1 and generate an error.
01059 *
01060 *   char lngtyp[8]
01061 *     (Returned) Four-character WCS celestial longitude and ...
01062 *   char lattyp[8]
01063 *     (Returned) ... latitude axis types. e.g. "RA", "DEC", "GLON", "GLAT",
01064 *     etc. extracted from 'RA--', 'DEC-', 'GLON', 'GLAT', etc. in the first
01065 *     four characters of CTYPEia but with trailing dashes removed.  (Declared
01066 *     as char[8] for alignment reasons.)
01067 *
01068 *   int lng
01069 *     (Returned) Index for the longitude coordinate, and ...
01070 *   int lat
01071 *     (Returned) ... index for the latitude coordinate, and ...
01072 *   int spec
01073 *     (Returned) ... index for the spectral coordinate in the imgcrd[][] and
01074 *     world[][] arrays in the API of wcsp2s(), wcss2p() and wcsmix().
01075 *
01076 *     These may also serve as indices into the pixcrd[][] array provided that
01077 *     the PCi_ja matrix does not transpose axes.
01078 *
01079 *   int cubeface
01080 *     (Returned) Index into the pixcrd[][] array for the CUBEFACE axis.  This
01081 *     is used for quadcube projections where the cube faces are stored on a
01082 *     separate axis (see wcs.h).
01083 *
01084 *   struct linprm lin
01085 *     (Returned) Linear transformation parameters (usage is described in the
01086 *     prologue to lin.h).
01087 *
01088 *   struct celprm cel
01089 *     (Returned) Celestial transformation parameters (usage is described in
01090 *     the prologue to cel.h).
01091 *
01092 *   struct spcprm spc
01093 *     (Returned) Spectral transformation parameters (usage is described in the
01094 *     prologue to spc.h).
01095 *
01096 *   int m_flag
01097 *     (For internal use only.)
01098 *   int m_naxis
01099 *     (For internal use only.)
01100 *   double *m_crpix
01101 *     (For internal use only.)
01102 *   double *m_pc
01103 *     (For internal use only.)
01104 *   double *m_cdelt
01105 *     (For internal use only.)
01106 *   double *m_crval
01107 *     (For internal use only.)
01108 *   char (*m_cunit)[72]
01109 *     (For internal use only.)
01110 *   char (*m_ctype)[72]
01111 *     (For internal use only.)
01112 *   struct pvcard *m_pv
01113 *     (For internal use only.)
01114 *   struct pscard *m_ps
01115 *     (For internal use only.)
01116 *   double *m_cd
01117 *     (For internal use only.)
01118 *   double *m_crota
01119 *     (For internal use only.)
01120 *   int *m_colax
01121 *     (For internal use only.)
01122 *   char (*m_cname)[72]
01123 *     (For internal use only.)
01124 *   double *m_crder
01125 *     (For internal use only.)
01126 *   double *m_csyer
01127 *     (For internal use only.)
01128 *   struct tabprm *m_tab
01129 *     (For internal use only.)
01130 *   struct wtbarr *m_wtb
01131 *     (For internal use only.)
01132 *
01133 *
01134 * pscard struct - Store for PSi_ma keyrecords
01135 * -------------------------------------------
01136 * The pscard struct is used to pass the parsed contents of PSi_ma keyrecords
01137 * to wcsset() via the wcsprm struct.
01138 *
01139 * All members of this struct are to be set by the user.
01140 *
01141 *   int i
01142 *     (Given) Axis number (1-relative), as in the FITS PSi_ma keyword.
01143 *
01144 *   int m
01145 *     (Given) Parameter number (non-negative), as in the FITS PSi_ma keyword.
01146 *
01147 *   char value[72]
01148 *     (Given) Parameter value.
01149 *
01150 *
01151 * pvcard struct - Store for PVi_ma keyrecords
01152 * -------------------------------------------
01153 * The pvcard struct is used to pass the parsed contents of PVi_ma keyrecords
01154 * to wcsset() via the wcsprm struct.
01155 *
01156 * All members of this struct are to be set by the user.
01157 *
01158 *   int i
01159 *     (Given) Axis number (1-relative), as in the FITS PVi_ma keyword.
01160 *
01161 *   int m
01162 *     (Given) Parameter number (non-negative), as in the FITS PVi_ma keyword.
01163 *
01164 *   double value
01165 *     (Given) Parameter value.
01166 *
01167 *
01168 * wtbarr struct - Extraction of coordinate lookup tables from BINTABLE
01169 * --------------------------------------------------------------------
01170 * Function wcstab(), which is invoked automatically by wcspih(), sets up an
01171 * array of wtbarr structs to assist in extracting coordinate lookup tables
01172 * from a binary table extension (BINTABLE) and copying them into the tabprm
01173 * structs stored in wcsprm.  Refer to the usage notes for wcspih() and
01174 * wcstab() in wcshdr.h, and also the prologue to tab.h.
01175 *
01176 * For C++ usage, because of a name space conflict with the wtbarr typedef
01177 * defined in CFITSIO header fitsio.h, the wtbarr struct is renamed to wtbarr_s
01178 * by preprocessor macro substitution with scope limited to wcs.h itself.
01179 *
01180 *   int i
01181 *     (Given) Image axis number.
01182 *
01183 *   int m
01184 *     (Given) wcstab array axis number for index vectors.
01185 *
01186 *   int kind
01187 *     (Given) Character identifying the wcstab array type:
01188 *       - c: coordinate array,
01189 *       - i: index vector.
01190 *
01191 *   char extnam[72]
01192 *     (Given) EXTNAME identifying the binary table extension.
01193 *
01194 *   int extver
01195 *     (Given) EXTVER identifying the binary table extension.
01196 *
01197 *   int extlev
01198 *     (Given) EXTLEV identifying the binary table extension.
01199 *
01200 *   char ttype[72]
01201 *     (Given) TTYPEn identifying the column of the binary table that contains
01202 *     the wcstab array.
01203 *
01204 *   long row
01205 *     (Given) Table row number.
01206 *
01207 *   int ndim
01208 *     (Given) Expected dimensionality of the wcstab array.
01209 *
01210 *   int *dimlen
01211 *     (Given) Address of the first element of an array of int of length ndim
01212 *     into which the wcstab array axis lengths are to be written.
01213 *
01214 *   double **arrayp
01215 *     (Given) Pointer to an array of double which is to be allocated by the
01216 *     user and into which the wcstab array is to be written.
01217 *
01218 *
01219 * Global variable: const char *wcs_errmsg[] - Status return messages
01220 * ------------------------------------------------------------------
01221 * Error messages to match the status value returned from each function.
01222 *
01223 *===========================================================================*/
01224 
01225 #ifndef WCSLIB_WCS
01226 #define WCSLIB_WCS
01227 
01228 #include "lin.h"
01229 #include "cel.h"
01230 #include "spc.h"
01231 #include "tab.h"
01232 
01233 #ifdef __cplusplus
01234 extern "C" {
01235 #endif
01236 
01237 #define WCSSUB_LONGITUDE 0x1001
01238 #define WCSSUB_LATITUDE  0x1002
01239 #define WCSSUB_CUBEFACE  0x1004
01240 #define WCSSUB_CELESTIAL 0x1007
01241 #define WCSSUB_SPECTRAL  0x1008
01242 #define WCSSUB_STOKES    0x1010
01243 
01244 
01245 extern const char *wcs_errmsg[];
01246 
01247 /* Struct used for storing PVi_ma keywords. */
01248 struct pvcard {
01249   int i;                        /* Axis number, as in PVi_ma (1-relative).  */
01250   int m;                        /* Parameter number, ditto  (0-relative).   */
01251   double value;                 /* Parameter value.                         */
01252 };
01253 
01254 /* Struct used for storing PSi_ma keywords. */
01255 struct pscard {
01256   int i;                        /* Axis number, as in PSi_ma (1-relative).  */
01257   int m;                        /* Parameter number, ditto  (0-relative).   */
01258   char value[72];               /* Parameter value.                         */
01259 };
01260 
01261                                 /* For extracting wcstab arrays.            */
01262 #ifdef __cplusplus
01263 #define wtbarr wtbarr_s         /* See prologue above.                      */
01264 #endif
01265 struct wtbarr {
01266   int  i;                       /* Image axis number.                       */
01267   int  m;                       /* Array axis number for index vectors.     */
01268   int  kind;                    /* wcstab array type.                       */
01269   char extnam[72];              /* EXTNAME of binary table extension.       */
01270   int  extver;                  /* EXTVER  of binary table extension.       */
01271   int  extlev;                  /* EXTLEV  of binary table extension.       */
01272   char ttype[72];               /* TTYPEn of column containing the array.   */
01273   long row;                     /* Table row number.                        */
01274   int  ndim;                    /* Expected wcstab array dimensionality.    */
01275   int  *dimlen;                 /* Where to write the array axis lengths.   */
01276   double **arrayp;              /* Where to write the address of the array  */
01277                                 /* allocated to store the wcstab array.     */
01278 };
01279 
01280 
01281 struct wcsprm {
01282   /* Initialization flag (see the prologue above).                          */
01283   /*------------------------------------------------------------------------*/
01284   int    flag;                  /* Set to zero to force initialization.     */
01285 
01286   /* FITS header keyvalues to be provided (see the prologue above).         */
01287   /*------------------------------------------------------------------------*/
01288   int    naxis;                 /* Number of axes (pixel and coordinate).   */
01289   double *crpix;                /* CRPIXja keyvalues for each pixel axis.   */
01290   double *pc;                   /* PCi_ja  linear transformation matrix.    */
01291   double *cdelt;                /* CDELTia keyvalues for each coord axis.   */
01292   double *crval;                /* CRVALia keyvalues for each coord axis.   */
01293 
01294   char   (*cunit)[72];          /* CUNITia keyvalues for each coord axis.   */
01295   char   (*ctype)[72];          /* CTYPEia keyvalues for each coord axis.   */
01296 
01297   double lonpole;               /* LONPOLEa keyvalue.                       */
01298   double latpole;               /* LATPOLEa keyvalue.                       */
01299 
01300   double restfrq;               /* RESTFRQa keyvalue.                       */
01301   double restwav;               /* RESTWAVa keyvalue.                       */
01302 
01303   int    npv;                   /* Number of PVi_ma keywords, and the       */
01304   int    npvmax;                /* number for which space was allocated.    */
01305   struct pvcard *pv;            /* PVi_ma keywords for each i and m.        */
01306 
01307   int    nps;                   /* Number of PSi_ma keywords, and the       */
01308   int    npsmax;                /* number for which space was allocated.    */
01309   struct pscard *ps;            /* PSi_ma keywords for each i and m.        */
01310 
01311   /* Alternative header keyvalues (see the prologue above).                 */
01312   /*------------------------------------------------------------------------*/
01313   double *cd;                   /* CDi_ja linear transformation matrix.     */
01314   double *crota;                /* CROTAia keyvalues for each coord axis.   */
01315   int    altlin;                /* Alternative representations              */
01316                                 /*   Bit 0: PCi_ja  is present,             */
01317                                 /*   Bit 1: CDi_ja  is present,             */
01318                                 /*   Bit 2: CROTAia is present.             */
01319   int    padding;               /* (Dummy inserted for alignment purposes.) */
01320 
01321   /* Auxiliary coordinate system information, not used by WCSLIB.           */
01322   char   alt[4];
01323   int    colnum;
01324   int    *colax;
01325 
01326   char   (*cname)[72];
01327   double *crder;
01328   double *csyer;
01329   char   dateavg[72];
01330   char   dateobs[72];
01331   double equinox;
01332   double mjdavg;
01333   double mjdobs;
01334   double obsgeo[3];
01335   char   radesys[72];
01336   char   specsys[72];
01337   char   ssysobs[72];
01338   double velosys;
01339   double zsource;
01340   char   ssyssrc[72];
01341   double velangl;
01342   char   wcsname[72];
01343 
01344   /* Coordinate lookup tables (see the prologue above).                     */
01345   /*------------------------------------------------------------------------*/
01346   int    ntab;                  /* Number of separate tables.               */
01347   int    nwtb;                  /* Number of wtbarr structs.                */
01348   struct tabprm *tab;           /* Tabular transformation parameters.       */
01349   struct wtbarr *wtb;           /* Array of wtbarr structs.                 */
01350 
01351   /* Information derived from the FITS header keyvalues by wcsset().        */
01352   /*------------------------------------------------------------------------*/
01353   int    *types;                /* Coordinate type codes for each axis.     */
01354   char   lngtyp[8], lattyp[8];  /* Celestial axis types, e.g. RA, DEC.      */
01355   int    lng, lat, spec;        /* Longitude, latitude and spectral axis    */
01356                                 /* indices (0-relative).                    */
01357   int    cubeface;              /* True if there is a CUBEFACE axis.        */
01358 
01359   struct linprm lin;            /* Linear    transformation parameters.     */
01360   struct celprm cel;            /* Celestial transformation parameters.     */
01361   struct spcprm spc;            /* Spectral  transformation parameters.     */
01362 
01363   int    m_flag, m_naxis;       /* The remainder are for memory management. */
01364   double *m_crpix, *m_pc, *m_cdelt, *m_crval;
01365   char  (*m_cunit)[72], (*m_ctype)[72];
01366   struct pvcard *m_pv;
01367   struct pscard *m_ps;
01368   double *m_cd, *m_crota;
01369   int    *m_colax;
01370   char  (*m_cname)[72];
01371   double *m_crder, *m_csyer;
01372   struct tabprm *m_tab;
01373   struct wtbarr *m_wtb;
01374 };
01375 
01376 /* Size of the wcsprm struct in int units, used by the Fortran wrappers. */
01377 #define WCSLEN (sizeof(struct wcsprm)/sizeof(int))
01378 
01379 
01380 int wcsnpv(int n);
01381 
01382 int wcsnps(int n);
01383 
01384 int wcsini(int alloc, int naxis, struct wcsprm *wcs);
01385 
01386 int wcssub(int alloc, const struct wcsprm *wcssrc, int *nsub, int axes[],
01387            struct wcsprm *wcsdst);
01388 
01389 int wcsfree(struct wcsprm *wcs);
01390 
01391 int wcsprt(const struct wcsprm *wcs);
01392 
01393 int wcsset(struct wcsprm *wcs);
01394 
01395 int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[],
01396            double imgcrd[], double phi[], double theta[], double world[],
01397            int stat[]);
01398 
01399 int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[],
01400            double phi[], double theta[], double imgcrd[], double pixcrd[],
01401            int stat[]);
01402 
01403 int wcsmix(struct wcsprm *wcs, int mixpix, int mixcel, const double vspan[],
01404            double vstep, int viter, double world[], double phi[],
01405            double theta[], double imgcrd[], double pixcrd[]);
01406 
01407 int wcssptr(struct wcsprm *wcs, int *i, char ctype[9]);
01408 
01409 /* Defined mainly for backwards compatibility, use wcssub() instead. */
01410 #define wcscopy(alloc, wcssrc, wcsdst) wcssub(alloc, wcssrc, 0, 0, wcsdst)
01411 
01412 
01413 /* Deprecated. */
01414 #define wcsini_errmsg wcs_errmsg
01415 #define wcssub_errmsg wcs_errmsg
01416 #define wcscopy_errmsg wcs_errmsg
01417 #define wcsfree_errmsg wcs_errmsg
01418 #define wcsprt_errmsg wcs_errmsg
01419 #define wcsset_errmsg wcs_errmsg
01420 #define wcsp2s_errmsg wcs_errmsg
01421 #define wcss2p_errmsg wcs_errmsg
01422 #define wcsmix_errmsg wcs_errmsg
01423 
01424 #ifdef __cplusplus
01425 #undef wtbarr
01426 }
01427 #endif
01428 
01429 #endif /* WCSLIB_WCS */

Generated on Tue Aug 11 10:36:36 2009 for WCSLIB 4.4 by  doxygen 1.5.1