WCSLIB 4.21
wcs.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  WCSLIB 4.21 - an implementation of the FITS WCS standard.
4  Copyright (C) 1995-2014, Mark Calabretta
5 
6  This file is part of WCSLIB.
7 
8  WCSLIB is free software: you can redistribute it and/or modify it under the
9  terms of the GNU Lesser General Public License as published by the Free
10  Software Foundation, either version 3 of the License, or (at your option)
11  any later version.
12 
13  WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16  more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with WCSLIB. If not, see http://www.gnu.org/licenses.
20 
21  Direct correspondence concerning WCSLIB to mark@calabretta.id.au
22 
23  Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
24  http://www.atnf.csiro.au/people/Mark.Calabretta
25  $Id: wcs.h,v 4.21 2014/03/24 05:12:27 mcalabre Exp $
26 *=============================================================================
27 *
28 * WCSLIB 4.21 - C routines that implement the FITS World Coordinate System
29 * (WCS) standard. Refer to
30 *
31 * "Representations of world coordinates in FITS",
32 * Greisen, E.W., & Calabretta, M.R. 2002, A&A, 395, 1061 (Paper I)
33 *
34 * "Representations of celestial coordinates in FITS",
35 * Calabretta, M.R., & Greisen, E.W. 2002, A&A, 395, 1077 (Paper II)
36 *
37 * "Representations of spectral coordinates in FITS",
38 * Greisen, E.W., Calabretta, M.R., Valdes, F.G., & Allen, S.L.
39 * 2006, A&A, 446, 747 (Paper III)
40 *
41 * Refer to the README file provided with WCSLIB for an overview of the
42 * library.
43 *
44 *
45 * Summary of the wcs routines
46 * ---------------------------
47 * These routines implement the FITS World Coordinate System (WCS) standard
48 * which defines methods to be used for computing world coordinates from image
49 * pixel coordinates, and vice versa. They are based on the wcsprm struct
50 * which contains all information needed for the computations. The struct
51 * contains some members that must be set by the user, and others that are
52 * maintained by these routines, somewhat like a C++ class but with no
53 * encapsulation.
54 *
55 * Three routines, wcsini(), wcssub(), and wcsfree() are provided to manage the
56 * wcsprm struct and another, wcsprt(), to prints its contents. Refer to the
57 * description of the wcsprm struct for an explanation of the anticipated usage
58 * of these routines. wcscopy(), which does a deep copy of one wcsprm struct
59 * to another, is defined as a preprocessor macro function that invokes
60 * wcssub().
61 *
62 * wcsperr() prints the error message(s) (if any) stored in a wcsprm struct,
63 * and the linprm, celprm, prjprm, spcprm, and tabprm structs that it contains.
64 *
65 * A setup routine, wcsset(), computes intermediate values in the wcsprm struct
66 * from parameters in it that were supplied by the user. The struct always
67 * needs to be set up by wcsset() but this need not be called explicitly -
68 * refer to the explanation of wcsprm::flag.
69 *
70 * wcsp2s() and wcss2p() implement the WCS world coordinate transformations.
71 * In fact, they are high level driver routines for the WCS linear,
72 * logarithmic, celestial, spectral and tabular transformation routines
73 * described in lin.h, log.h, cel.h, spc.h and tab.h.
74 *
75 * Given either the celestial longitude or latitude plus an element of the
76 * pixel coordinate a hybrid routine, wcsmix(), iteratively solves for the
77 * unknown elements.
78 *
79 * wcssptr() translates the spectral axis in a wcsprm struct. For example, a
80 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa.
81 *
82 * Quadcube projections:
83 * ---------------------
84 * The quadcube projections (TSC, CSC, QSC) may be represented in FITS in
85 * either of two ways:
86 *
87 * a: The six faces may be laid out in one plane and numbered as follows:
88 *
89 = 0
90 =
91 = 4 3 2 1 4 3 2
92 =
93 = 5
94 *
95 * Faces 2, 3 and 4 may appear on one side or the other (or both). The
96 * world-to-pixel routines map faces 2, 3 and 4 to the left but the
97 * pixel-to-world routines accept them on either side.
98 *
99 * b: The "COBE" convention in which the six faces are stored in a
100 * three-dimensional structure using a CUBEFACE axis indexed from
101 * 0 to 5 as above.
102 *
103 * These routines support both methods; wcsset() determines which is being
104 * used by the presence or absence of a CUBEFACE axis in ctype[]. wcsp2s()
105 * and wcss2p() translate the CUBEFACE axis representation to the single
106 * plane representation understood by the lower-level WCSLIB projection
107 * routines.
108 *
109 *
110 * wcsini() - Default constructor for the wcsprm struct
111 * ----------------------------------------------------
112 * wcsini() optionally allocates memory for arrays in a wcsprm struct and sets
113 * all members of the struct to default values. Memory is allocated for up to
114 * NPVMAX PVi_ma keywords or NPSMAX PSi_ma keywords per WCS representation.
115 * These may be changed via wcsnpv() and wcsnps() before wcsini() is called.
116 *
117 * PLEASE NOTE: every wcsprm struct should be initialized by wcsini(), possibly
118 * repeatedly. On the first invokation, and only the first invokation,
119 * wcsprm::flag must be set to -1 to initialize memory management, regardless
120 * of whether wcsini() will actually be used to allocate memory.
121 *
122 * Given:
123 * alloc int If true, allocate memory unconditionally for the
124 * crpix, etc. arrays.
125 *
126 * If false, it is assumed that pointers to these arrays
127 * have been set by the user except if they are null
128 * pointers in which case memory will be allocated for
129 * them regardless. (In other words, setting alloc true
130 * saves having to initalize these pointers to zero.)
131 *
132 * naxis int The number of world coordinate axes. This is used to
133 * determine the length of the various wcsprm vectors and
134 * matrices and therefore the amount of memory to
135 * allocate for them.
136 *
137 * Given and returned:
138 * wcs struct wcsprm*
139 * Coordinate transformation parameters.
140 *
141 * Note that, in order to initialize memory management,
142 * wcsprm::flag should be set to -1 when wcs is
143 * initialized for the first time (memory leaks may
144 * result if it had already been initialized).
145 *
146 * Function return value:
147 * int Status return value:
148 * 0: Success.
149 * 1: Null wcsprm pointer passed.
150 * 2: Memory allocation failed.
151 *
152 * For returns > 1, a detailed error message is set in
153 * wcsprm::err if enabled, see wcserr_enable().
154 *
155 *
156 * wcsnpv() - Memory allocation for PVi_ma
157 * ---------------------------------------
158 * wcsnpv() changes the value of NPVMAX (default 64). This global variable
159 * controls the number of PVi_ma keywords that wcsini() should allocate space
160 * for.
161 *
162 * PLEASE NOTE: This function is not thread-safe.
163 *
164 * Given:
165 * n int Value of NPVMAX; ignored if < 0.
166 *
167 * Function return value:
168 * int Current value of NPVMAX.
169 *
170 *
171 * wcsnps() - Memory allocation for PSi_ma
172 * ---------------------------------------
173 * wcsnps() changes the values of NPSMAX (default 8). This global variable
174 * controls the number of PSi_ma keywords that wcsini() should allocate space
175 * for.
176 *
177 * PLEASE NOTE: This function is not thread-safe.
178 *
179 * Given:
180 * n int Value of NPSMAX; ignored if < 0.
181 *
182 * Function return value:
183 * int Current value of NPSMAX.
184 *
185 *
186 * wcssub() - Subimage extraction routine for the wcsprm struct
187 * ------------------------------------------------------------
188 * wcssub() extracts the coordinate description for a subimage from a wcsprm
189 * struct. It does a deep copy, using wcsini() to allocate memory for its
190 * arrays if required. Only the "information to be provided" part of the
191 * struct is extracted; a call to wcsset() is required to set up the remainder.
192 *
193 * The world coordinate system of the subimage must be separable in the sense
194 * that the world coordinates at any point in the subimage must depend only on
195 * the pixel coordinates of the axes extracted. In practice, this means that
196 * the PCi_ja matrix of the original image must not contain non-zero
197 * off-diagonal terms that associate any of the subimage axes with any of the
198 * non-subimage axes.
199 *
200 * Note that while the required elements of the tabprm array are extracted, the
201 * wtbarr array is not. (Thus it is not appropriate to call wcssub() after
202 * wcstab() but before filling the tabprm structs - refer to wcshdr.h.)
203 *
204 * wcssub() can also add axes to a wcsprm struct. The new axes will be created
205 * using the defaults set by wcsini() which produce a simple, unnamed, linear
206 * axis with world coordinate equal to the pixel coordinate. These default
207 * values can be changed afterwards, before invoking wcsset().
208 *
209 * Given:
210 * alloc int If true, allocate memory for the crpix, etc. arrays in
211 * the destination. Otherwise, it is assumed that
212 * pointers to these arrays have been set by the user
213 * except if they are null pointers in which case memory
214 * will be allocated for them regardless.
215 *
216 * wcssrc const struct wcsprm*
217 * Struct to extract from.
218 *
219 * Given and returned:
220 * nsub int*
221 * axes int[] Vector of length *nsub containing the image axis
222 * numbers (1-relative) to extract. Order is
223 * significant; axes[0] is the axis number of the input
224 * image that corresponds to the first axis in the
225 * subimage, etc.
226 *
227 * Use an axis number of 0 to create a new axis using
228 * the defaults set by wcsini(). They can be changed
229 * later.
230 *
231 * nsub (the pointer) may be set to zero, and so also may
232 * *nsub, which is interpreted to mean all axes in the
233 * input image; the number of axes will be returned if
234 * nsub != 0x0. axes itself (the pointer) may be set to
235 * zero to indicate the first *nsub axes in their
236 * original order.
237 *
238 * Set both nsub (or *nsub) and axes to zero to do a deep
239 * copy of one wcsprm struct to another.
240 *
241 * Subimage extraction by coordinate axis type may be
242 * done by setting the elements of axes[] to the
243 * following special preprocessor macro values:
244 *
245 * WCSSUB_LONGITUDE: Celestial longitude.
246 * WCSSUB_LATITUDE: Celestial latitude.
247 * WCSSUB_CUBEFACE: Quadcube CUBEFACE axis.
248 * WCSSUB_SPECTRAL: Spectral axis.
249 * WCSSUB_STOKES: Stokes axis.
250 *
251 * Refer to the notes (below) for further usage examples.
252 *
253 * On return, *nsub will be set to the number of axes in
254 * the subimage; this may be zero if there were no axes
255 * of the required type(s) (in which case no memory will
256 * be allocated). axes[] will contain the axis numbers
257 * that were extracted, or 0 for newly created axes. The
258 * vector length must be sufficient to contain all axis
259 * numbers. No checks are performed to verify that the
260 * coordinate axes are consistent, this is done by
261 * wcsset().
262 *
263 * wcsdst struct wcsprm*
264 * Struct describing the subimage. wcsprm::flag should
265 * be set to -1 if wcsdst was not previously initialized
266 * (memory leaks may result if it was previously
267 * initialized).
268 *
269 * Function return value:
270 * int Status return value:
271 * 0: Success.
272 * 1: Null wcsprm pointer passed.
273 * 2: Memory allocation failed.
274 * 12: Invalid subimage specification.
275 * 13: Non-separable subimage coordinate system.
276 *
277 * For returns > 1, a detailed error message is set in
278 * wcsprm::err if enabled, see wcserr_enable().
279 *
280 * Notes:
281 * Combinations of subimage axes of particular types may be extracted in the
282 * same order as they occur in the input image by combining preprocessor
283 * codes, for example
284 *
285 = *nsub = 1;
286 = axes[0] = WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_SPECTRAL;
287 *
288 * would extract the longitude, latitude, and spectral axes in the same order
289 * as the input image. If one of each were present, *nsub = 3 would be
290 * returned.
291 *
292 * For convenience, WCSSUB_CELESTIAL is defined as the combination
293 * WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_CUBEFACE.
294 *
295 * The codes may also be negated to extract all but the types specified, for
296 * example
297 *
298 = *nsub = 4;
299 = axes[0] = WCSSUB_LONGITUDE;
300 = axes[1] = WCSSUB_LATITUDE;
301 = axes[2] = WCSSUB_CUBEFACE;
302 = axes[3] = -(WCSSUB_SPECTRAL | WCSSUB_STOKES);
303 *
304 * The last of these specifies all axis types other than spectral or Stokes.
305 * Extraction is done in the order specified by axes[] a longitude axis (if
306 * present) would be extracted first (via axes[0]) and not subsequently (via
307 * axes[3]). Likewise for the latitude and cubeface axes in this example.
308 *
309 * From the foregoing, it is apparent that the value of *nsub returned may be
310 * less than or greater than that given. However, it will never exceed the
311 * number of axes in the input image (plus the number of newly-created axes
312 * if any were specified on input).
313 *
314 *
315 * wcscopy() macro - Copy routine for the wcsprm struct
316 * ----------------------------------------------------
317 * wcscopy() does a deep copy of one wcsprm struct to another. As of
318 * WCSLIB 3.6, it is implemented as a preprocessor macro that invokes
319 * wcssub() with the nsub and axes pointers both set to zero.
320 *
321 *
322 * wcsfree() - Destructor for the wcsprm struct
323 * --------------------------------------------
324 * wcsfree() frees memory allocated for the wcsprm arrays by wcsini() and/or
325 * wcsset(). wcsini() records the memory it allocates and wcsfree() will only
326 * attempt to free this.
327 *
328 * PLEASE NOTE: wcsfree() must not be invoked on a wcsprm struct that was not
329 * initialized by wcsini().
330 *
331 * Returned:
332 * wcs struct wcsprm*
333 * Coordinate transformation parameters.
334 *
335 * Function return value:
336 * int Status return value:
337 * 0: Success.
338 * 1: Null wcsprm pointer passed.
339 *
340 *
341 * wcsprt() - Print routine for the wcsprm struct
342 * ----------------------------------------------
343 * wcsprt() prints the contents of a wcsprm struct using wcsprintf(). Mainly
344 * intended for diagnostic purposes.
345 *
346 * Given:
347 * wcs const struct wcsprm*
348 * Coordinate transformation parameters.
349 *
350 * Function return value:
351 * int Status return value:
352 * 0: Success.
353 * 1: Null wcsprm pointer passed.
354 *
355 *
356 * wcsperr() - Print error messages from a wcsprm struct
357 * -----------------------------------------------------
358 * wcsperr() prints the error message(s), if any, stored in a wcsprm struct,
359 * and the linprm, celprm, prjprm, spcprm, and tabprm structs that it contains.
360 * If there are no errors then nothing is printed. It uses wcserr_prt(), q.v.
361 *
362 * Given:
363 * wcs const struct wcsprm*
364 * Coordinate transformation parameters.
365 *
366 * prefix const char *
367 * If non-NULL, each output line will be prefixed with
368 * this string.
369 *
370 * Function return value:
371 * int Status return value:
372 * 0: Success.
373 * 1: Null wcsprm pointer passed.
374 *
375 *
376 * wcsbchk() - Enable/disable bounds checking
377 * ------------------------------------------
378 * wcsbchk() is used to control bounds checking in the projection routines.
379 * Note that wcsset() always enables bounds checking. wcsbchk() will invoke
380 * wcsset() on the wcsprm struct beforehand if necessary.
381 *
382 * Given and returned:
383 * wcs struct wcsprm*
384 * Coordinate transformation parameters.
385 *
386 * Given:
387 * bounds int If bounds&1 then enable strict bounds checking for the
388 * spherical-to-Cartesian (s2x) transformation for the
389 * AZP, SZP, TAN, SIN, ZPN, and COP projections.
390 *
391 * If bounds&2 then enable strict bounds checking for the
392 * Cartesian-to-spherical (x2s) transformation for the
393 * HPX and XPH projections.
394 *
395 * If bounds&4 then enable bounds checking on the native
396 * coordinates returned by the Cartesian-to-spherical
397 * (x2s) transformations using prjchk().
398 *
399 * Zero it to disable all checking.
400 *
401 * Function return value:
402 * int Status return value:
403 * 0: Success.
404 * 1: Null wcsprm pointer passed.
405 *
406 *
407 * wcsset() - Setup routine for the wcsprm struct
408 * ----------------------------------------------
409 * wcsset() sets up a wcsprm struct according to information supplied within
410 * it (refer to the description of the wcsprm struct).
411 *
412 * wcsset() recognizes the NCP projection and converts it to the equivalent SIN
413 * projection and likewise translates GLS into SFL. It also translates the
414 * AIPS spectral types ('FREQ-LSR', 'FELO-HEL', etc.), possibly changing the
415 * input header keywords wcsprm::ctype and/or wcsprm::specsys if necessary.
416 *
417 * Note that this routine need not be called directly; it will be invoked by
418 * wcsp2s() and wcss2p() if the wcsprm::flag is anything other than a
419 * predefined magic value.
420 *
421 * Given and returned:
422 * wcs struct wcsprm*
423 * Coordinate transformation parameters.
424 *
425 * Function return value:
426 * int Status return value:
427 * 0: Success.
428 * 1: Null wcsprm pointer passed.
429 * 2: Memory allocation failed.
430 * 3: Linear transformation matrix is singular.
431 * 4: Inconsistent or unrecognized coordinate axis
432 * types.
433 * 5: Invalid parameter value.
434 * 6: Invalid coordinate transformation parameters.
435 * 7: Ill-conditioned coordinate transformation
436 * parameters.
437 *
438 * For returns > 1, a detailed error message is set in
439 * wcsprm::err if enabled, see wcserr_enable().
440 *
441 * Notes:
442 * wcsset() always enables strict bounds checking in the projection routines
443 * (via a call to prjini()). Use wcsbchk() to modify bounds-checking after
444 * wcsset() is invoked.
445 *
446 *
447 * wcsp2s() - Pixel-to-world transformation
448 * ----------------------------------------
449 * wcsp2s() transforms pixel coordinates to world coordinates.
450 *
451 * Given and returned:
452 * wcs struct wcsprm*
453 * Coordinate transformation parameters.
454 *
455 * Given:
456 * ncoord,
457 * nelem int The number of coordinates, each of vector length
458 * nelem but containing wcs.naxis coordinate elements.
459 * Thus nelem must equal or exceed the value of the
460 * NAXIS keyword unless ncoord == 1, in which case nelem
461 * is not used.
462 *
463 * pixcrd const double[ncoord][nelem]
464 * Array of pixel coordinates.
465 *
466 * Returned:
467 * imgcrd double[ncoord][nelem]
468 * Array of intermediate world coordinates. For
469 * celestial axes, imgcrd[][wcs.lng] and
470 * imgcrd[][wcs.lat] are the projected x-, and
471 * y-coordinates in pseudo "degrees". For spectral
472 * axes, imgcrd[][wcs.spec] is the intermediate spectral
473 * coordinate, in SI units.
474 *
475 * phi,theta double[ncoord]
476 * Longitude and latitude in the native coordinate system
477 * of the projection [deg].
478 *
479 * world double[ncoord][nelem]
480 * Array of world coordinates. For celestial axes,
481 * world[][wcs.lng] and world[][wcs.lat] are the
482 * celestial longitude and latitude [deg]. For
483 * spectral axes, imgcrd[][wcs.spec] is the intermediate
484 * spectral coordinate, in SI units.
485 *
486 * stat int[ncoord]
487 * Status return value for each coordinate:
488 * 0: Success.
489 * 1+: A bit mask indicating invalid pixel coordinate
490 * element(s).
491 *
492 * Function return value:
493 * int Status return value:
494 * 0: Success.
495 * 1: Null wcsprm pointer passed.
496 * 2: Memory allocation failed.
497 * 3: Linear transformation matrix is singular.
498 * 4: Inconsistent or unrecognized coordinate axis
499 * types.
500 * 5: Invalid parameter value.
501 * 6: Invalid coordinate transformation parameters.
502 * 7: Ill-conditioned coordinate transformation
503 * parameters.
504 * 8: One or more of the pixel coordinates were
505 * invalid, as indicated by the stat vector.
506 *
507 * For returns > 1, a detailed error message is set in
508 * wcsprm::err if enabled, see wcserr_enable().
509 *
510 *
511 * wcss2p() - World-to-pixel transformation
512 * ----------------------------------------
513 * wcss2p() transforms world coordinates to pixel coordinates.
514 *
515 * Given and returned:
516 * wcs struct wcsprm*
517 * Coordinate transformation parameters.
518 *
519 * Given:
520 * ncoord,
521 * nelem int The number of coordinates, each of vector length nelem
522 * but containing wcs.naxis coordinate elements. Thus
523 * nelem must equal or exceed the value of the NAXIS
524 * keyword unless ncoord == 1, in which case nelem is not
525 * used.
526 *
527 * world const double[ncoord][nelem]
528 * Array of world coordinates. For celestial axes,
529 * world[][wcs.lng] and world[][wcs.lat] are the
530 * celestial longitude and latitude [deg]. For spectral
531 * axes, world[][wcs.spec] is the spectral coordinate, in
532 * SI units.
533 *
534 * Returned:
535 * phi,theta double[ncoord]
536 * Longitude and latitude in the native coordinate
537 * system of the projection [deg].
538 *
539 * imgcrd double[ncoord][nelem]
540 * Array of intermediate world coordinates. For
541 * celestial axes, imgcrd[][wcs.lng] and
542 * imgcrd[][wcs.lat] are the projected x-, and
543 * y-coordinates in pseudo "degrees". For quadcube
544 * projections with a CUBEFACE axis the face number is
545 * also returned in imgcrd[][wcs.cubeface]. For
546 * spectral axes, imgcrd[][wcs.spec] is the intermediate
547 * spectral coordinate, in SI units.
548 *
549 * pixcrd double[ncoord][nelem]
550 * Array of pixel coordinates.
551 *
552 * stat int[ncoord]
553 * Status return value for each coordinate:
554 * 0: Success.
555 * 1+: A bit mask indicating invalid world coordinate
556 * element(s).
557 *
558 * Function return value:
559 * int Status return value:
560 * 0: Success.
561 * 1: Null wcsprm pointer passed.
562 * 2: Memory allocation failed.
563 * 3: Linear transformation matrix is singular.
564 * 4: Inconsistent or unrecognized coordinate axis
565 * types.
566 * 5: Invalid parameter value.
567 * 6: Invalid coordinate transformation parameters.
568 * 7: Ill-conditioned coordinate transformation
569 * parameters.
570 * 9: One or more of the world coordinates were
571 * invalid, as indicated by the stat vector.
572 *
573 * For returns > 1, a detailed error message is set in
574 * wcsprm::err if enabled, see wcserr_enable().
575 *
576 *
577 * wcsmix() - Hybrid coordinate transformation
578 * -------------------------------------------
579 * wcsmix(), given either the celestial longitude or latitude plus an element
580 * of the pixel coordinate, solves for the remaining elements by iterating on
581 * the unknown celestial coordinate element using wcss2p(). Refer also to the
582 * notes below.
583 *
584 * Given and returned:
585 * wcs struct wcsprm*
586 * Indices for the celestial coordinates obtained
587 * by parsing the wcsprm::ctype[].
588 *
589 * Given:
590 * mixpix int Which element of the pixel coordinate is given.
591 *
592 * mixcel int Which element of the celestial coordinate is given:
593 * 1: Celestial longitude is given in
594 * world[wcs.lng], latitude returned in
595 * world[wcs.lat].
596 * 2: Celestial latitude is given in
597 * world[wcs.lat], longitude returned in
598 * world[wcs.lng].
599 *
600 * vspan const double[2]
601 * Solution interval for the celestial coordinate [deg].
602 * The ordering of the two limits is irrelevant.
603 * Longitude ranges may be specified with any convenient
604 * normalization, for example [-120,+120] is the same as
605 * [240,480], except that the solution will be returned
606 * with the same normalization, i.e. lie within the
607 * interval specified.
608 *
609 * vstep const double
610 * Step size for solution search [deg]. If zero, a
611 * sensible, although perhaps non-optimal default will be
612 * used.
613 *
614 * viter int If a solution is not found then the step size will be
615 * halved and the search recommenced. viter controls how
616 * many times the step size is halved. The allowed range
617 * is 5 - 10.
618 *
619 * Given and returned:
620 * world double[naxis]
621 * World coordinate elements. world[wcs.lng] and
622 * world[wcs.lat] are the celestial longitude and
623 * latitude [deg]. Which is given and which returned
624 * depends on the value of mixcel. All other elements
625 * are given.
626 *
627 * Returned:
628 * phi,theta double[naxis]
629 * Longitude and latitude in the native coordinate
630 * system of the projection [deg].
631 *
632 * imgcrd double[naxis]
633 * Image coordinate elements. imgcrd[wcs.lng] and
634 * imgcrd[wcs.lat] are the projected x-, and
635 * y-coordinates in pseudo "degrees".
636 *
637 * Given and returned:
638 * pixcrd double[naxis]
639 * Pixel coordinate. The element indicated by mixpix is
640 * given and the remaining elements are returned.
641 *
642 * Function return value:
643 * int Status return value:
644 * 0: Success.
645 * 1: Null wcsprm pointer passed.
646 * 2: Memory allocation failed.
647 * 3: Linear transformation matrix is singular.
648 * 4: Inconsistent or unrecognized coordinate axis
649 * types.
650 * 5: Invalid parameter value.
651 * 6: Invalid coordinate transformation parameters.
652 * 7: Ill-conditioned coordinate transformation
653 * parameters.
654 * 10: Invalid world coordinate.
655 * 11: No solution found in the specified interval.
656 *
657 * For returns > 1, a detailed error message is set in
658 * wcsprm::err if enabled, see wcserr_enable().
659 *
660 * Notes:
661 * Initially the specified solution interval is checked to see if it's a
662 * "crossing" interval. If it isn't, a search is made for a crossing
663 * solution by iterating on the unknown celestial coordinate starting at the
664 * upper limit of the solution interval and decrementing by the specified
665 * step size. A crossing is indicated if the trial value of the pixel
666 * coordinate steps through the value specified. If a crossing interval is
667 * found then the solution is determined by a modified form of "regula falsi"
668 * division of the crossing interval. If no crossing interval was found
669 * within the specified solution interval then a search is made for a
670 * "non-crossing" solution as may arise from a point of tangency. The
671 * process is complicated by having to make allowance for the discontinuities
672 * that occur in all map projections.
673 *
674 * Once one solution has been determined others may be found by subsequent
675 * invokations of wcsmix() with suitably restricted solution intervals.
676 *
677 * Note the circumstance that arises when the solution point lies at a native
678 * pole of a projection in which the pole is represented as a finite curve,
679 * for example the zenithals and conics. In such cases two or more valid
680 * solutions may exist but wcsmix() only ever returns one.
681 *
682 * Because of its generality wcsmix() is very compute-intensive. For
683 * compute-limited applications more efficient special-case solvers could be
684 * written for simple projections, for example non-oblique cylindrical
685 * projections.
686 *
687 *
688 * wcssptr() - Spectral axis translation
689 * -------------------------------------
690 * wcssptr() translates the spectral axis in a wcsprm struct. For example, a
691 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa.
692 *
693 * Given and returned:
694 * wcs struct wcsprm*
695 * Coordinate transformation parameters.
696 *
697 * i int* Index of the spectral axis (0-relative). If given < 0
698 * it will be set to the first spectral axis identified
699 * from the ctype[] keyvalues in the wcsprm struct.
700 *
701 * ctype char[9] Desired spectral CTYPEia. Wildcarding may be used as
702 * for the ctypeS2 argument to spctrn() as described in
703 * the prologue of spc.h, i.e. if the final three
704 * characters are specified as "???", or if just the
705 * eighth character is specified as '?', the correct
706 * algorithm code will be substituted and returned.
707 *
708 * Function return value:
709 * int Status return value:
710 * 0: Success.
711 * 1: Null wcsprm pointer passed.
712 * 2: Memory allocation failed.
713 * 3: Linear transformation matrix is singular.
714 * 4: Inconsistent or unrecognized coordinate axis
715 * types.
716 * 5: Invalid parameter value.
717 * 6: Invalid coordinate transformation parameters.
718 * 7: Ill-conditioned coordinate transformation
719 * parameters.
720 * 12: Invalid subimage specification (no spectral
721 * axis).
722 *
723 * For returns > 1, a detailed error message is set in
724 * wcsprm::err if enabled, see wcserr_enable().
725 *
726 *
727 * wcsprm struct - Coordinate transformation parameters
728 * ----------------------------------------------------
729 * The wcsprm struct contains information required to transform world
730 * coordinates. It consists of certain members that must be set by the user
731 * ("given") and others that are set by the WCSLIB routines ("returned").
732 * Some of the former are not actually required for transforming coordinates.
733 * These are described as "auxiliary"; the struct simply provides a place to
734 * store them, though they may be used by wcshdo() in constructing a FITS
735 * header from a wcsprm struct. Some of the returned values are supplied for
736 * informational purposes and others are for internal use only as indicated.
737 *
738 * In practice, it is expected that a WCS parser would scan the FITS header to
739 * determine the number of coordinate axes. It would then use wcsini() to
740 * allocate memory for arrays in the wcsprm struct and set default values.
741 * Then as it reread the header and identified each WCS keyrecord it would load
742 * the value into the relevant wcsprm array element. This is essentially what
743 * wcspih() does - refer to the prologue of wcshdr.h. As the final step,
744 * wcsset() is invoked, either directly or indirectly, to set the derived
745 * members of the wcsprm struct. wcsset() strips off trailing blanks in all
746 * string members and null-fills the character array.
747 *
748 * int flag
749 * (Given and returned) This flag must be set to zero whenever any of the
750 * following wcsprm struct members are set or changed:
751 *
752 * - wcsprm::naxis (q.v., not normally set by the user),
753 * - wcsprm::crpix,
754 * - wcsprm::pc,
755 * - wcsprm::cdelt,
756 * - wcsprm::crval,
757 * - wcsprm::cunit,
758 * - wcsprm::ctype,
759 * - wcsprm::lonpole,
760 * - wcsprm::latpole,
761 * - wcsprm::restfrq,
762 * - wcsprm::restwav,
763 * - wcsprm::npv,
764 * - wcsprm::pv,
765 * - wcsprm::nps,
766 * - wcsprm::ps,
767 * - wcsprm::cd,
768 * - wcsprm::crota,
769 * - wcsprm::altlin.
770 *
771 * This signals the initialization routine, wcsset(), to recompute the
772 * returned members of the celprm struct. celset() will reset flag to
773 * indicate that this has been done.
774 *
775 * PLEASE NOTE: flag should be set to -1 when wcsini() is called for the
776 * first time for a particular wcsprm struct in order to initialize memory
777 * management. It must ONLY be used on the first initialization otherwise
778 * memory leaks may result.
779 *
780 * int naxis
781 * (Given or returned) Number of pixel and world coordinate elements.
782 *
783 * If wcsini() is used to initialize the linprm struct (as would normally
784 * be the case) then it will set naxis from the value passed to it as a
785 * function argument. The user should not subsequently modify it.
786 *
787 * double *crpix
788 * (Given) Address of the first element of an array of double containing
789 * the coordinate reference pixel, CRPIXja.
790 *
791 * double *pc
792 * (Given) Address of the first element of the PCi_ja (pixel coordinate)
793 * transformation matrix. The expected order is
794 *
795 = struct wcsprm wcs;
796 = wcs.pc = {PC1_1, PC1_2, PC2_1, PC2_2};
797 *
798 * This may be constructed conveniently from a 2-D array via
799 *
800 = double m[2][2] = {{PC1_1, PC1_2},
801 = {PC2_1, PC2_2}};
802 *
803 * which is equivalent to
804 *
805 = double m[2][2];
806 = m[0][0] = PC1_1;
807 = m[0][1] = PC1_2;
808 = m[1][0] = PC2_1;
809 = m[1][1] = PC2_2;
810 *
811 * The storage order for this 2-D array is the same as for the 1-D array,
812 * whence
813 *
814 = wcs.pc = *m;
815 *
816 * would be legitimate.
817 *
818 * double *cdelt
819 * (Given) Address of the first element of an array of double containing
820 * the coordinate increments, CDELTia.
821 *
822 * double *crval
823 * (Given) Address of the first element of an array of double containing
824 * the coordinate reference values, CRVALia.
825 *
826 * char (*cunit)[72]
827 * (Given) Address of the first element of an array of char[72] containing
828 * the CUNITia keyvalues which define the units of measurement of the
829 * CRVALia, CDELTia, and CDi_ja keywords.
830 *
831 * As CUNITia is an optional header keyword, cunit[][72] may be left blank
832 * but otherwise is expected to contain a standard units specification as
833 * defined by WCS Paper I. Utility function wcsutrn(), described in
834 * wcsunits.h, is available to translate commonly used non-standard units
835 * specifications but this must be done as a separate step before invoking
836 * wcsset().
837 *
838 * For celestial axes, if cunit[][72] is not blank, wcsset() uses
839 * wcsunits() to parse it and scale cdelt[], crval[], and cd[][*] to
840 * degrees. It then resets cunit[][72] to "deg".
841 *
842 * For spectral axes, if cunit[][72] is not blank, wcsset() uses wcsunits()
843 * to parse it and scale cdelt[], crval[], and cd[][*] to SI units. It
844 * then resets cunit[][72] accordingly.
845 *
846 * wcsset() ignores cunit[][72] for other coordinate types; cunit[][72] may
847 * be used to label coordinate values.
848 *
849 * These variables accomodate the longest allowed string-valued FITS
850 * keyword, being limited to 68 characters, plus the null-terminating
851 * character.
852 *
853 * char (*ctype)[72]
854 * (Given) Address of the first element of an array of char[72] containing
855 * the coordinate axis types, CTYPEia.
856 *
857 * The ctype[][72] keyword values must be in upper case and there must be
858 * zero or one pair of matched celestial axis types, and zero or one
859 * spectral axis. The ctype[][72] strings should be padded with blanks on
860 * the right and null-terminated so that they are at least eight characters
861 * in length.
862 *
863 * These variables accomodate the longest allowed string-valued FITS
864 * keyword, being limited to 68 characters, plus the null-terminating
865 * character.
866 *
867 * double lonpole
868 * (Given and returned) The native longitude of the celestial pole, phi_p,
869 * given by LONPOLEa [deg] or by PVi_2a [deg] attached to the longitude
870 * axis which takes precedence if defined, and ...
871 * double latpole
872 * (Given and returned) ... the native latitude of the celestial pole,
873 * theta_p, given by LATPOLEa [deg] or by PVi_3a [deg] attached to the
874 * longitude axis which takes precedence if defined.
875 *
876 * lonpole and latpole may be left to default to values set by wcsini()
877 * (see celprm::ref), but in any case they will be reset by wcsset() to
878 * the values actually used. Note therefore that if the wcsprm struct is
879 * reused without resetting them, whether directly or via wcsini(), they
880 * will no longer have their default values.
881 *
882 * double restfrq
883 * (Given) The rest frequency [Hz], and/or ...
884 * double restwav
885 * (Given) ... the rest wavelength in vacuo [m], only one of which need be
886 * given, the other should be set to zero.
887 *
888 * int npv
889 * (Given) The number of entries in the wcsprm::pv[] array.
890 *
891 * int npvmax
892 * (Given or returned) The length of the wcsprm::pv[] array.
893 *
894 * npvmax will be set by wcsini() if it allocates memory for wcsprm::pv[],
895 * otherwise it must be set by the user. See also wcsnpv().
896 *
897 * struct pvcard *pv
898 * (Given or returned) Address of the first element of an array of length
899 * npvmax of pvcard structs. Set by wcsini() if it allocates memory for
900 * pv[], otherwise it must be set by the user. See also wcsnpv().
901 *
902 * As a FITS header parser encounters each PVi_ma keyword it should load it
903 * into a pvcard struct in the array and increment npv. wcsset()
904 * interprets these as required.
905 *
906 * Note that, if they were not given, wcsset() resets the entries for
907 * PVi_1a, PVi_2a, PVi_3a, and PVi_4a for longitude axis i to match
908 * phi_0 and theta_0 (the native longitude and latitude of the reference
909 * point), LONPOLEa and LATPOLEa respectively.
910 *
911 * int nps
912 * (Given) The number of entries in the wcsprm::ps[] array.
913 *
914 * int npsmax
915 * (Given or returned) The length of the wcsprm::ps[] array.
916 *
917 * npsmax will be set by wcsini() if it allocates memory for wcsprm::ps[],
918 * otherwise it must be set by the user. See also wcsnps().
919 *
920 * struct pscard *ps
921 * (Given or returned) Address of the first element of an array of length
922 * npsmax of pscard structs. Set by wcsini() if it allocates memory for
923 * ps[], otherwise it must be set by the user. See also wcsnps().
924 *
925 * As a FITS header parser encounters each PSi_ma keyword it should load it
926 * into a pscard struct in the array and increment nps. wcsset()
927 * interprets these as required (currently no PSi_ma keyvalues are
928 * recognized).
929 *
930 * double *cd
931 * (Given) For historical compatibility, the wcsprm struct supports two
932 * alternate specifications of the linear transformation matrix, those
933 * associated with the CDi_ja keywords, and ...
934 * double *crota
935 * (Given) ... those associated with the CROTAia keywords. Although these
936 * may not formally co-exist with PCi_ja, the approach taken here is simply
937 * to ignore them if given in conjunction with PCi_ja.
938 *
939 * int altlin
940 * (Given) altlin is a bit flag that denotes which of the PCi_ja, CDi_ja
941 * and CROTAia keywords are present in the header:
942 *
943 * - Bit 0: PCi_ja is present.
944 *
945 * - Bit 1: CDi_ja is present.
946 *
947 * Matrix elements in the IRAF convention are
948 * equivalent to the product CDi_ja = CDELTia * PCi_ja, but the
949 * defaults differ from that of the PCi_ja matrix. If one or more
950 * CDi_ja keywords are present then all unspecified CDi_ja default to
951 * zero. If no CDi_ja (or CROTAia) keywords are present, then the
952 * header is assumed to be in PCi_ja form whether or not any PCi_ja
953 * keywords are present since this results in an interpretation of
954 * CDELTia consistent with the original FITS specification.
955 *
956 * While CDi_ja may not formally co-exist with PCi_ja, it may co-exist
957 * with CDELTia and CROTAia which are to be ignored.
958 *
959 * - Bit 2: CROTAia is present.
960 *
961 * In the AIPS convention, CROTAia may only be
962 * associated with the latitude axis of a celestial axis pair. It
963 * specifies a rotation in the image plane that is applied AFTER the
964 * CDELTia; any other CROTAia keywords are ignored.
965 *
966 * CROTAia may not formally co-exist with PCi_ja.
967 *
968 * CROTAia and CDELTia may formally co-exist with CDi_ja but if so are to
969 * be ignored.
970 *
971 * CDi_ja and CROTAia keywords, if found, are to be stored in the
972 * wcsprm::cd and wcsprm::crota arrays which are dimensioned similarly to
973 * wcsprm::pc and wcsprm::cdelt. FITS
974 * header parsers should use the following procedure:
975 *
976 * - Whenever a PCi_ja keyword is encountered: altlin |= 1;
977 *
978 * - Whenever a CDi_ja keyword is encountered: altlin |= 2;
979 *
980 * - Whenever a CROTAia keyword is encountered: altlin |= 4;
981 *
982 * If none of these bits are set the PCi_ja representation results, i.e.
983 * wcsprm::pc and wcsprm::cdelt will be used as given.
984 *
985 * These alternate specifications of the linear transformation matrix are
986 * translated immediately to PCi_ja by wcsset() and are invisible to the
987 * lower-level WCSLIB routines. In particular, wcsset() resets
988 * wcsprm::cdelt to unity if CDi_ja is present (and no PCi_ja).
989 *
990 * If CROTAia are present but none is associated with the latitude axis
991 * (and no PCi_ja or CDi_ja), then wcsset() reverts to a unity PCi_ja
992 * matrix.
993 *
994 * int velref
995 * (Given) AIPS velocity code VELREF, refer to spcaips().
996 *
997 * char alt[4]
998 * (Given, auxiliary) Character code for alternate coordinate descriptions
999 * (i.e. the 'a' in keyword names such as CTYPEia). This is blank for the
1000 * primary coordinate description, or one of the 26 upper-case letters,
1001 * A-Z.
1002 *
1003 * An array of four characters is provided for alignment purposes, only the
1004 * first is used.
1005 *
1006 * int colnum
1007 * (Given, auxiliary) Where the coordinate representation is associated
1008 * with an image-array column in a FITS binary table, this variable may be
1009 * used to record the relevant column number.
1010 *
1011 * It should be set to zero for an image header or pixel list.
1012 *
1013 * int *colax
1014 * (Given, auxiliary) Address of the first element of an array of int
1015 * recording the column numbers for each axis in a pixel list.
1016 *
1017 * The array elements should be set to zero for an image header or image
1018 * array in a binary table.
1019 *
1020 * char (*cname)[72]
1021 * (Given, auxiliary) The address of the first element of an array of
1022 * char[72] containing the coordinate axis names, CNAMEia.
1023 *
1024 * These variables accomodate the longest allowed string-valued FITS
1025 * keyword, being limited to 68 characters, plus the null-terminating
1026 * character.
1027 *
1028 * double *crder
1029 * (Given, auxiliary) Address of the first element of an array of double
1030 * recording the random error in the coordinate value, CRDERia.
1031 * double *csyer
1032 * (Given, auxiliary) Address of the first element of an array of double
1033 * recording the systematic error in the coordinate value, CSYERia.
1034 *
1035 * char dateavg[72]
1036 * (Given, auxiliary) The date of a representative mid-point of the
1037 * observation in ISO format, yyyy-mm-ddThh:mm:ss.
1038 * char dateobs[72]
1039 * (Given, auxiliary) The date of the start of the observation unless
1040 * otherwise explained in the comment field of the DATE-OBS keyword, in
1041 * ISO format, yyyy-mm-ddThh:mm:ss.
1042 *
1043 * double equinox
1044 * (Given, auxiliary) The equinox associated with dynamical equatorial or
1045 * ecliptic coordinate systems, EQUINOXa (or EPOCH in older headers). Not
1046 * applicable to ICRS equatorial or ecliptic coordinates.
1047 *
1048 * double mjdavg
1049 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-AVG,
1050 * corresponding to DATE-AVG.
1051 * double mjdobs
1052 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-OBS,
1053 * corresponding to DATE-OBS.
1054 *
1055 * double obsgeo[3]
1056 * (Given, auxiliary) Location of the observer in a standard terrestrial
1057 * reference frame, OBSGEO-X, OBSGEO-Y, OBSGEO-Z [m].
1058 *
1059 * char radesys[72]
1060 * (Given, auxiliary) The equatorial or ecliptic coordinate system type,
1061 * RADESYSa.
1062 *
1063 * char specsys[72]
1064 * (Given, auxiliary) Spectral reference frame (standard of rest),
1065 * SPECSYSa, and ...
1066 * char ssysobs[72]
1067 * (Given, auxiliary) ... the actual frame in which there is no
1068 * differential variation in the spectral coordinate across the
1069 * field-of-view, SSYSOBSa.
1070 * double velosys
1071 * (Given, auxiliary) The relative radial velocity [m/s] between the
1072 * observer and the selected standard of rest in the direction of the
1073 * celestial reference coordinate, VELOSYSa.
1074 *
1075 * double zsource
1076 * (Given, auxiliary) The redshift, ZSOURCEa, of the source, and ...
1077 * char ssyssrc[72]
1078 * (Given, auxiliary) ... the spectral reference frame (standard of rest)
1079 * in which this was measured, SSYSSRCa.
1080 *
1081 * double velangl
1082 * (Given, auxiliary) The angle [deg] that should be used to decompose an
1083 * observed velocity into radial and transverse components.
1084 *
1085 * char wcsname[72]
1086 * (Given, auxiliary) The name given to the coordinate representation,
1087 * WCSNAMEa. This variable accomodates the longest allowed string-valued
1088 * FITS keyword, being limited to 68 characters, plus the null-terminating
1089 * character.
1090 *
1091 * int ntab
1092 * (Given) See wcsprm::tab.
1093 *
1094 * int nwtb
1095 * (Given) See wcsprm::wtb.
1096 *
1097 * struct tabprm *tab
1098 * (Given) Address of the first element of an array of ntab tabprm structs
1099 * for which memory has been allocated. These are used to store tabular
1100 * transformation parameters.
1101 *
1102 * Although technically wcsprm::ntab and tab are "given", they will
1103 * normally be set by invoking wcstab(), whether directly or indirectly.
1104 *
1105 * The tabprm structs contain some members that must be supplied and others
1106 * that are derived. The information to be supplied comes primarily from
1107 * arrays stored in one or more FITS binary table extensions. These
1108 * arrays, referred to here as "wcstab arrays", are themselves located by
1109 * parameters stored in the FITS image header.
1110 *
1111 * struct wtbarr *wtb
1112 * (Given) Address of the first element of an array of nwtb wtbarr structs
1113 * for which memory has been allocated. These are used in extracting
1114 * wcstab arrays from a FITS binary table.
1115 *
1116 * Although technically wcsprm::nwtb and wtb are "given", they will
1117 * normally be set by invoking wcstab(), whether directly or indirectly.
1118 *
1119 * char lngtyp[8]
1120 * (Returned) Four-character WCS celestial longitude and ...
1121 * char lattyp[8]
1122 * (Returned) ... latitude axis types. e.g. "RA", "DEC", "GLON", "GLAT",
1123 * etc. extracted from 'RA--', 'DEC-', 'GLON', 'GLAT', etc. in the first
1124 * four characters of CTYPEia but with trailing dashes removed. (Declared
1125 * as char[8] for alignment reasons.)
1126 *
1127 * int lng
1128 * (Returned) Index for the longitude coordinate, and ...
1129 * int lat
1130 * (Returned) ... index for the latitude coordinate, and ...
1131 * int spec
1132 * (Returned) ... index for the spectral coordinate in the imgcrd[][] and
1133 * world[][] arrays in the API of wcsp2s(), wcss2p() and wcsmix().
1134 *
1135 * These may also serve as indices into the pixcrd[][] array provided that
1136 * the PCi_ja matrix does not transpose axes.
1137 *
1138 * int cubeface
1139 * (Returned) Index into the pixcrd[][] array for the CUBEFACE axis. This
1140 * is used for quadcube projections where the cube faces are stored on a
1141 * separate axis (see wcs.h).
1142 *
1143 * int *types
1144 * (Returned) Address of the first element of an array of int containing a
1145 * four-digit type code for each axis.
1146 *
1147 * - First digit (i.e. 1000s):
1148 * - 0: Non-specific coordinate type.
1149 * - 1: Stokes coordinate.
1150 * - 2: Celestial coordinate (including CUBEFACE).
1151 * - 3: Spectral coordinate.
1152 *
1153 * - Second digit (i.e. 100s):
1154 * - 0: Linear axis.
1155 * - 1: Quantized axis (STOKES, CUBEFACE).
1156 * - 2: Non-linear celestial axis.
1157 * - 3: Non-linear spectral axis.
1158 * - 4: Logarithmic axis.
1159 * - 5: Tabular axis.
1160 *
1161 * - Third digit (i.e. 10s):
1162 * - 0: Group number, e.g. lookup table number, being an index into the
1163 * tabprm array (see above).
1164 *
1165 * - The fourth digit is used as a qualifier depending on the axis type.
1166 *
1167 * - For celestial axes:
1168 * - 0: Longitude coordinate.
1169 * - 1: Latitude coordinate.
1170 * - 2: CUBEFACE number.
1171 *
1172 * - For lookup tables: the axis number in a multidimensional table.
1173 *
1174 * CTYPEia in "4-3" form with unrecognized algorithm code will have its
1175 * type set to -1 and generate an error.
1176 *
1177 * void *padding
1178 * (An unused variable inserted for alignment purposes only.)
1179 *
1180 * struct linprm lin
1181 * (Returned) Linear transformation parameters (usage is described in the
1182 * prologue to lin.h).
1183 *
1184 * struct celprm cel
1185 * (Returned) Celestial transformation parameters (usage is described in
1186 * the prologue to cel.h).
1187 *
1188 * struct spcprm spc
1189 * (Returned) Spectral transformation parameters (usage is described in the
1190 * prologue to spc.h).
1191 *
1192 * struct wcserr *err
1193 * (Returned) If enabled, when an error status is returned this struct
1194 * contains detailed information about the error, see wcserr_enable().
1195 *
1196 * void *m_padding
1197 * (For internal use only.)
1198 * int m_flag
1199 * (For internal use only.)
1200 * int m_naxis
1201 * (For internal use only.)
1202 * double *m_crpix
1203 * (For internal use only.)
1204 * double *m_pc
1205 * (For internal use only.)
1206 * double *m_cdelt
1207 * (For internal use only.)
1208 * double *m_crval
1209 * (For internal use only.)
1210 * char (*m_cunit)[72]
1211 * (For internal use only.)
1212 * char (*m_ctype)[72]
1213 * (For internal use only.)
1214 * struct pvcard *m_pv
1215 * (For internal use only.)
1216 * struct pscard *m_ps
1217 * (For internal use only.)
1218 * double *m_cd
1219 * (For internal use only.)
1220 * double *m_crota
1221 * (For internal use only.)
1222 * int *m_colax
1223 * (For internal use only.)
1224 * char (*m_cname)[72]
1225 * (For internal use only.)
1226 * double *m_crder
1227 * (For internal use only.)
1228 * double *m_csyer
1229 * (For internal use only.)
1230 * struct tabprm *m_tab
1231 * (For internal use only.)
1232 * struct wtbarr *m_wtb
1233 * (For internal use only.)
1234 *
1235 *
1236 * pscard struct - Store for PSi_ma keyrecords
1237 * -------------------------------------------
1238 * The pscard struct is used to pass the parsed contents of PSi_ma keyrecords
1239 * to wcsset() via the wcsprm struct.
1240 *
1241 * All members of this struct are to be set by the user.
1242 *
1243 * int i
1244 * (Given) Axis number (1-relative), as in the FITS PSi_ma keyword.
1245 *
1246 * int m
1247 * (Given) Parameter number (non-negative), as in the FITS PSi_ma keyword.
1248 *
1249 * char value[72]
1250 * (Given) Parameter value.
1251 *
1252 *
1253 * pvcard struct - Store for PVi_ma keyrecords
1254 * -------------------------------------------
1255 * The pvcard struct is used to pass the parsed contents of PVi_ma keyrecords
1256 * to wcsset() via the wcsprm struct.
1257 *
1258 * All members of this struct are to be set by the user.
1259 *
1260 * int i
1261 * (Given) Axis number (1-relative), as in the FITS PVi_ma keyword. If
1262 * i == 0, wcsset() will replace it with the latitude axis number.
1263 *
1264 * int m
1265 * (Given) Parameter number (non-negative), as in the FITS PVi_ma keyword.
1266 *
1267 * double value
1268 * (Given) Parameter value.
1269 *
1270 *
1271 * wtbarr struct - Extraction of coordinate lookup tables from BINTABLE
1272 * --------------------------------------------------------------------
1273 * Function wcstab(), which is invoked automatically by wcspih(), sets up an
1274 * array of wtbarr structs to assist in extracting coordinate lookup tables
1275 * from a binary table extension (BINTABLE) and copying them into the tabprm
1276 * structs stored in wcsprm. Refer to the usage notes for wcspih() and
1277 * wcstab() in wcshdr.h, and also the prologue to tab.h.
1278 *
1279 * For C++ usage, because of a name space conflict with the wtbarr typedef
1280 * defined in CFITSIO header fitsio.h, the wtbarr struct is renamed to wtbarr_s
1281 * by preprocessor macro substitution with scope limited to wcs.h itself.
1282 *
1283 * int i
1284 * (Given) Image axis number.
1285 *
1286 * int m
1287 * (Given) wcstab array axis number for index vectors.
1288 *
1289 * int kind
1290 * (Given) Character identifying the wcstab array type:
1291 * - c: coordinate array,
1292 * - i: index vector.
1293 *
1294 * char extnam[72]
1295 * (Given) EXTNAME identifying the binary table extension.
1296 *
1297 * int extver
1298 * (Given) EXTVER identifying the binary table extension.
1299 *
1300 * int extlev
1301 * (Given) EXTLEV identifying the binary table extension.
1302 *
1303 * char ttype[72]
1304 * (Given) TTYPEn identifying the column of the binary table that contains
1305 * the wcstab array.
1306 *
1307 * long row
1308 * (Given) Table row number.
1309 *
1310 * int ndim
1311 * (Given) Expected dimensionality of the wcstab array.
1312 *
1313 * int *dimlen
1314 * (Given) Address of the first element of an array of int of length ndim
1315 * into which the wcstab array axis lengths are to be written.
1316 *
1317 * double **arrayp
1318 * (Given) Pointer to an array of double which is to be allocated by the
1319 * user and into which the wcstab array is to be written.
1320 *
1321 *
1322 * Global variable: const char *wcs_errmsg[] - Status return messages
1323 * ------------------------------------------------------------------
1324 * Error messages to match the status value returned from each function.
1325 *
1326 *===========================================================================*/
1327 
1328 #ifndef WCSLIB_WCS
1329 #define WCSLIB_WCS
1330 
1331 #include "lin.h"
1332 #include "cel.h"
1333 #include "spc.h"
1334 #include "tab.h"
1335 #include "wcserr.h"
1336 
1337 #ifdef __cplusplus
1338 extern "C" {
1339 #endif
1340 
1341 #define WCSSUB_LONGITUDE 0x1001
1342 #define WCSSUB_LATITUDE 0x1002
1343 #define WCSSUB_CUBEFACE 0x1004
1344 #define WCSSUB_CELESTIAL 0x1007
1345 #define WCSSUB_SPECTRAL 0x1008
1346 #define WCSSUB_STOKES 0x1010
1347 
1348 
1349 extern const char *wcs_errmsg[];
1350 
1352  WCSERR_SUCCESS = 0, /* Success. */
1353  WCSERR_NULL_POINTER = 1, /* Null wcsprm pointer passed. */
1354  WCSERR_MEMORY = 2, /* Memory allocation failed. */
1355  WCSERR_SINGULAR_MTX = 3, /* Linear transformation matrix is
1356  singular. */
1357  WCSERR_BAD_CTYPE = 4, /* Inconsistent or unrecognized coordinate
1358  axis types. */
1359  WCSERR_BAD_PARAM = 5, /* Invalid parameter value. */
1360  WCSERR_BAD_COORD_TRANS = 6, /* Invalid coordinate transformation
1361  parameters. */
1362  WCSERR_ILL_COORD_TRANS = 7, /* Ill-conditioned coordinate transformation
1363  parameters. */
1364  WCSERR_BAD_PIX = 8, /* One or more of the pixel coordinates were
1365  invalid. */
1366  WCSERR_BAD_WORLD = 9, /* One or more of the world coordinates were
1367  invalid. */
1368  WCSERR_BAD_WORLD_COORD = 10, /* Invalid world coordinate. */
1369  WCSERR_NO_SOLUTION = 11, /* No solution found in the specified
1370  interval. */
1371  WCSERR_BAD_SUBIMAGE = 12, /* Invalid subimage specification. */
1372  WCSERR_NON_SEPARABLE = 13 /* Non-separable subimage coordinate
1373  system. */
1374 };
1375 
1376 
1377 /* Struct used for storing PVi_ma keywords. */
1378 struct pvcard {
1379  int i; /* Axis number, as in PVi_ma (1-relative). */
1380  int m; /* Parameter number, ditto (0-relative). */
1381  double value; /* Parameter value. */
1382 };
1383 
1384 /* Struct used for storing PSi_ma keywords. */
1385 struct pscard {
1386  int i; /* Axis number, as in PSi_ma (1-relative). */
1387  int m; /* Parameter number, ditto (0-relative). */
1388  char value[72]; /* Parameter value. */
1389 };
1390 
1391  /* For extracting wcstab arrays. Matches */
1392  /* the wtbarr typedef defined in CFITSIO */
1393  /* header fitsio.h. */
1394 #ifdef __cplusplus
1395 #define wtbarr wtbarr_s /* See prologue above. */
1396 #endif
1397 struct wtbarr {
1398  int i; /* Image axis number. */
1399  int m; /* Array axis number for index vectors. */
1400  int kind; /* wcstab array type. */
1401  char extnam[72]; /* EXTNAME of binary table extension. */
1402  int extver; /* EXTVER of binary table extension. */
1403  int extlev; /* EXTLEV of binary table extension. */
1404  char ttype[72]; /* TTYPEn of column containing the array. */
1405  long row; /* Table row number. */
1406  int ndim; /* Expected wcstab array dimensionality. */
1407  int *dimlen; /* Where to write the array axis lengths. */
1408  double **arrayp; /* Where to write the address of the array */
1409  /* allocated to store the wcstab array. */
1410 };
1411 
1412 
1413 struct wcsprm {
1414  /* Initialization flag (see the prologue above). */
1415  /*------------------------------------------------------------------------*/
1416  int flag; /* Set to zero to force initialization. */
1417 
1418  /* FITS header keyvalues to be provided (see the prologue above). */
1419  /*------------------------------------------------------------------------*/
1420  int naxis; /* Number of axes (pixel and coordinate). */
1421  double *crpix; /* CRPIXja keyvalues for each pixel axis. */
1422  double *pc; /* PCi_ja linear transformation matrix. */
1423  double *cdelt; /* CDELTia keyvalues for each coord axis. */
1424  double *crval; /* CRVALia keyvalues for each coord axis. */
1425 
1426  char (*cunit)[72]; /* CUNITia keyvalues for each coord axis. */
1427  char (*ctype)[72]; /* CTYPEia keyvalues for each coord axis. */
1428 
1429  double lonpole; /* LONPOLEa keyvalue. */
1430  double latpole; /* LATPOLEa keyvalue. */
1431 
1432  double restfrq; /* RESTFRQa keyvalue. */
1433  double restwav; /* RESTWAVa keyvalue. */
1434 
1435  int npv; /* Number of PVi_ma keywords, and the */
1436  int npvmax; /* number for which space was allocated. */
1437  struct pvcard *pv; /* PVi_ma keywords for each i and m. */
1438 
1439  int nps; /* Number of PSi_ma keywords, and the */
1440  int npsmax; /* number for which space was allocated. */
1441  struct pscard *ps; /* PSi_ma keywords for each i and m. */
1442 
1443  /* Alternative header keyvalues (see the prologue above). */
1444  /*------------------------------------------------------------------------*/
1445  double *cd; /* CDi_ja linear transformation matrix. */
1446  double *crota; /* CROTAia keyvalues for each coord axis. */
1447  int altlin; /* Alternative representations */
1448  /* Bit 0: PCi_ja is present, */
1449  /* Bit 1: CDi_ja is present, */
1450  /* Bit 2: CROTAia is present. */
1451  int velref; /* AIPS velocity code, VELREF. */
1452 
1453  /* Auxiliary coordinate system information, not used by WCSLIB. */
1454  char alt[4];
1455  int colnum;
1456  int *colax;
1457 
1458  char (*cname)[72];
1459  double *crder;
1460  double *csyer;
1461  char dateavg[72];
1462  char dateobs[72];
1463  double equinox;
1464  double mjdavg;
1465  double mjdobs;
1466  double obsgeo[3];
1467  char radesys[72];
1468  char specsys[72];
1469  char ssysobs[72];
1470  double velosys;
1471  double zsource;
1472  char ssyssrc[72];
1473  double velangl;
1474  char wcsname[72];
1475 
1476  /* Coordinate lookup tables (see the prologue above). */
1477  /*------------------------------------------------------------------------*/
1478  int ntab; /* Number of separate tables. */
1479  int nwtb; /* Number of wtbarr structs. */
1480  struct tabprm *tab; /* Tabular transformation parameters. */
1481  struct wtbarr *wtb; /* Array of wtbarr structs. */
1482 
1483  /* Information derived from the FITS header keyvalues by wcsset(). */
1484  /*------------------------------------------------------------------------*/
1485  char lngtyp[8], lattyp[8]; /* Celestial axis types, e.g. RA, DEC. */
1486  int lng, lat, spec; /* Longitude, latitude and spectral axis */
1487  /* indices (0-relative). */
1488  int cubeface; /* True if there is a CUBEFACE axis. */
1489  int *types; /* Coordinate type codes for each axis. */
1490  void *padding; /* (Dummy inserted for alignment purposes.) */
1491 
1492  struct linprm lin; /* Linear transformation parameters. */
1493  struct celprm cel; /* Celestial transformation parameters. */
1494  struct spcprm spc; /* Spectral transformation parameters. */
1495 
1496  /* Error handling */
1497  /*------------------------------------------------------------------------*/
1498  struct wcserr *err;
1499 
1500  /* Private - the remainder are for memory management. */
1501  /*------------------------------------------------------------------------*/
1502  void *m_padding;
1504  double *m_crpix, *m_pc, *m_cdelt, *m_crval;
1505  char (*m_cunit)[72], (*m_ctype)[72];
1506  struct pvcard *m_pv;
1507  struct pscard *m_ps;
1508  double *m_cd, *m_crota;
1509  int *m_colax;
1510  char (*m_cname)[72];
1511  double *m_crder, *m_csyer;
1512  struct tabprm *m_tab;
1513  struct wtbarr *m_wtb;
1514 };
1515 
1516 /* Size of the wcsprm struct in int units, used by the Fortran wrappers. */
1517 #define WCSLEN (sizeof(struct wcsprm)/sizeof(int))
1518 
1519 
1520 int wcsnpv(int n);
1521 
1522 int wcsnps(int n);
1523 
1524 int wcsini(int alloc, int naxis, struct wcsprm *wcs);
1525 
1526 int wcssub(int alloc, const struct wcsprm *wcssrc, int *nsub, int axes[],
1527  struct wcsprm *wcsdst);
1528 
1529 int wcsfree(struct wcsprm *wcs);
1530 
1531 int wcsprt(const struct wcsprm *wcs);
1532 
1533 int wcsperr(const struct wcsprm *wcs, const char *prefix);
1534 
1535 int wcsbchk(struct wcsprm *wcs, int bounds);
1536 
1537 int wcsset(struct wcsprm *wcs);
1538 
1539 int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[],
1540  double imgcrd[], double phi[], double theta[], double world[],
1541  int stat[]);
1542 
1543 int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[],
1544  double phi[], double theta[], double imgcrd[], double pixcrd[],
1545  int stat[]);
1546 
1547 int wcsmix(struct wcsprm *wcs, int mixpix, int mixcel, const double vspan[],
1548  double vstep, int viter, double world[], double phi[],
1549  double theta[], double imgcrd[], double pixcrd[]);
1550 
1551 int wcssptr(struct wcsprm *wcs, int *i, char ctype[9]);
1552 
1553 /* Defined mainly for backwards compatibility, use wcssub() instead. */
1554 #define wcscopy(alloc, wcssrc, wcsdst) wcssub(alloc, wcssrc, 0x0, 0x0, wcsdst)
1555 
1556 
1557 /* Deprecated. */
1558 #define wcsini_errmsg wcs_errmsg
1559 #define wcssub_errmsg wcs_errmsg
1560 #define wcscopy_errmsg wcs_errmsg
1561 #define wcsfree_errmsg wcs_errmsg
1562 #define wcsprt_errmsg wcs_errmsg
1563 #define wcsset_errmsg wcs_errmsg
1564 #define wcsp2s_errmsg wcs_errmsg
1565 #define wcss2p_errmsg wcs_errmsg
1566 #define wcsmix_errmsg wcs_errmsg
1567 
1568 #ifdef __cplusplus
1569 #undef wtbarr
1570 }
1571 #endif
1572 
1573 #endif /* WCSLIB_WCS */