WCSLIB 4.20
wcs.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  WCSLIB 4.20 - an implementation of the FITS WCS standard.
4  Copyright (C) 1995-2013, 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_8h_source.html,v 1.1 2014/02/12 21:11:37 irby Exp $
26 *=============================================================================
27 *
28 * WCSLIB 4.20 - 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 strict bounds checking
377 * -------------------------------------------------
378 * wcsbchk() is used to control strict bounds checking in the projection
379 * routines. Note that wcsset() always enables strict bounds checking.
380 * wcsbchk() will invoke 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 bounds checking for the
388 * sky-to-pixel (s2x) transformation for the AZP, SZP,
389 * TAN, SIN, ZPN, and COP projections.
390 *
391 * If bounds&2 then enable bounds checking for the
392 * pixel-to-sky transformation for the HPX and XPH
393 * projections.
394 *
395 * Zero it to disable all checking.
396 *
397 * Function return value:
398 * int Status return value:
399 * 0: Success.
400 * 1: Null wcsprm pointer passed.
401 *
402 *
403 * wcsset() - Setup routine for the wcsprm struct
404 * ----------------------------------------------
405 * wcsset() sets up a wcsprm struct according to information supplied within
406 * it (refer to the description of the wcsprm struct).
407 *
408 * wcsset() recognizes the NCP projection and converts it to the equivalent SIN
409 * projection and likewise translates GLS into SFL. It also translates the
410 * AIPS spectral types ('FREQ-LSR', 'FELO-HEL', etc.), possibly changing the
411 * input header keywords wcsprm::ctype and/or wcsprm::specsys if necessary.
412 *
413 * Note that this routine need not be called directly; it will be invoked by
414 * wcsp2s() and wcss2p() if the wcsprm::flag is anything other than a
415 * predefined magic value.
416 *
417 * Given and returned:
418 * wcs struct wcsprm*
419 * Coordinate transformation parameters.
420 *
421 * Function return value:
422 * int Status return value:
423 * 0: Success.
424 * 1: Null wcsprm pointer passed.
425 * 2: Memory allocation failed.
426 * 3: Linear transformation matrix is singular.
427 * 4: Inconsistent or unrecognized coordinate axis
428 * types.
429 * 5: Invalid parameter value.
430 * 6: Invalid coordinate transformation parameters.
431 * 7: Ill-conditioned coordinate transformation
432 * parameters.
433 *
434 * For returns > 1, a detailed error message is set in
435 * wcsprm::err if enabled, see wcserr_enable().
436 *
437 * Notes:
438 * wcsset() always enables strict bounds checking in the projection routines
439 * (via a call to prjini()). Use wcsbchk() to modify bounds-checking after
440 * wcsset() is invoked.
441 *
442 *
443 * wcsp2s() - Pixel-to-world transformation
444 * ----------------------------------------
445 * wcsp2s() transforms pixel coordinates to world coordinates.
446 *
447 * Given and returned:
448 * wcs struct wcsprm*
449 * Coordinate transformation parameters.
450 *
451 * Given:
452 * ncoord,
453 * nelem int The number of coordinates, each of vector length
454 * nelem but containing wcs.naxis coordinate elements.
455 * Thus nelem must equal or exceed the value of the
456 * NAXIS keyword unless ncoord == 1, in which case nelem
457 * is not used.
458 *
459 * pixcrd const double[ncoord][nelem]
460 * Array of pixel coordinates.
461 *
462 * Returned:
463 * imgcrd double[ncoord][nelem]
464 * Array of intermediate world coordinates. For
465 * celestial axes, imgcrd[][wcs.lng] and
466 * imgcrd[][wcs.lat] are the projected x-, and
467 * y-coordinates in pseudo "degrees". For spectral
468 * axes, imgcrd[][wcs.spec] is the intermediate spectral
469 * coordinate, in SI units.
470 *
471 * phi,theta double[ncoord]
472 * Longitude and latitude in the native coordinate system
473 * of the projection [deg].
474 *
475 * world double[ncoord][nelem]
476 * Array of world coordinates. For celestial axes,
477 * world[][wcs.lng] and world[][wcs.lat] are the
478 * celestial longitude and latitude [deg]. For
479 * spectral axes, imgcrd[][wcs.spec] is the intermediate
480 * spectral coordinate, in SI units.
481 *
482 * stat int[ncoord]
483 * Status return value for each coordinate:
484 * 0: Success.
485 * 1+: A bit mask indicating invalid pixel coordinate
486 * element(s).
487 *
488 * Function return value:
489 * int Status return value:
490 * 0: Success.
491 * 1: Null wcsprm pointer passed.
492 * 2: Memory allocation failed.
493 * 3: Linear transformation matrix is singular.
494 * 4: Inconsistent or unrecognized coordinate axis
495 * types.
496 * 5: Invalid parameter value.
497 * 6: Invalid coordinate transformation parameters.
498 * 7: Ill-conditioned coordinate transformation
499 * parameters.
500 * 8: One or more of the pixel coordinates were
501 * invalid, as indicated by the stat vector.
502 *
503 * For returns > 1, a detailed error message is set in
504 * wcsprm::err if enabled, see wcserr_enable().
505 *
506 *
507 * wcss2p() - World-to-pixel transformation
508 * ----------------------------------------
509 * wcss2p() transforms world coordinates to pixel coordinates.
510 *
511 * Given and returned:
512 * wcs struct wcsprm*
513 * Coordinate transformation parameters.
514 *
515 * Given:
516 * ncoord,
517 * nelem int The number of coordinates, each of vector length nelem
518 * but containing wcs.naxis coordinate elements. Thus
519 * nelem must equal or exceed the value of the NAXIS
520 * keyword unless ncoord == 1, in which case nelem is not
521 * used.
522 *
523 * world const double[ncoord][nelem]
524 * Array of world coordinates. For celestial axes,
525 * world[][wcs.lng] and world[][wcs.lat] are the
526 * celestial longitude and latitude [deg]. For spectral
527 * axes, world[][wcs.spec] is the spectral coordinate, in
528 * SI units.
529 *
530 * Returned:
531 * phi,theta double[ncoord]
532 * Longitude and latitude in the native coordinate
533 * system of the projection [deg].
534 *
535 * imgcrd double[ncoord][nelem]
536 * Array of intermediate world coordinates. For
537 * celestial axes, imgcrd[][wcs.lng] and
538 * imgcrd[][wcs.lat] are the projected x-, and
539 * y-coordinates in pseudo "degrees". For quadcube
540 * projections with a CUBEFACE axis the face number is
541 * also returned in imgcrd[][wcs.cubeface]. For
542 * spectral axes, imgcrd[][wcs.spec] is the intermediate
543 * spectral coordinate, in SI units.
544 *
545 * pixcrd double[ncoord][nelem]
546 * Array of pixel coordinates.
547 *
548 * stat int[ncoord]
549 * Status return value for each coordinate:
550 * 0: Success.
551 * 1+: A bit mask indicating invalid world coordinate
552 * element(s).
553 *
554 * Function return value:
555 * int Status return value:
556 * 0: Success.
557 * 1: Null wcsprm pointer passed.
558 * 2: Memory allocation failed.
559 * 3: Linear transformation matrix is singular.
560 * 4: Inconsistent or unrecognized coordinate axis
561 * types.
562 * 5: Invalid parameter value.
563 * 6: Invalid coordinate transformation parameters.
564 * 7: Ill-conditioned coordinate transformation
565 * parameters.
566 * 9: One or more of the world coordinates were
567 * invalid, as indicated by the stat vector.
568 *
569 * For returns > 1, a detailed error message is set in
570 * wcsprm::err if enabled, see wcserr_enable().
571 *
572 *
573 * wcsmix() - Hybrid coordinate transformation
574 * -------------------------------------------
575 * wcsmix(), given either the celestial longitude or latitude plus an element
576 * of the pixel coordinate, solves for the remaining elements by iterating on
577 * the unknown celestial coordinate element using wcss2p(). Refer also to the
578 * notes below.
579 *
580 * Given and returned:
581 * wcs struct wcsprm*
582 * Indices for the celestial coordinates obtained
583 * by parsing the wcsprm::ctype[].
584 *
585 * Given:
586 * mixpix int Which element of the pixel coordinate is given.
587 *
588 * mixcel int Which element of the celestial coordinate is given:
589 * 1: Celestial longitude is given in
590 * world[wcs.lng], latitude returned in
591 * world[wcs.lat].
592 * 2: Celestial latitude is given in
593 * world[wcs.lat], longitude returned in
594 * world[wcs.lng].
595 *
596 * vspan const double[2]
597 * Solution interval for the celestial coordinate [deg].
598 * The ordering of the two limits is irrelevant.
599 * Longitude ranges may be specified with any convenient
600 * normalization, for example [-120,+120] is the same as
601 * [240,480], except that the solution will be returned
602 * with the same normalization, i.e. lie within the
603 * interval specified.
604 *
605 * vstep const double
606 * Step size for solution search [deg]. If zero, a
607 * sensible, although perhaps non-optimal default will be
608 * used.
609 *
610 * viter int If a solution is not found then the step size will be
611 * halved and the search recommenced. viter controls how
612 * many times the step size is halved. The allowed range
613 * is 5 - 10.
614 *
615 * Given and returned:
616 * world double[naxis]
617 * World coordinate elements. world[wcs.lng] and
618 * world[wcs.lat] are the celestial longitude and
619 * latitude [deg]. Which is given and which returned
620 * depends on the value of mixcel. All other elements
621 * are given.
622 *
623 * Returned:
624 * phi,theta double[naxis]
625 * Longitude and latitude in the native coordinate
626 * system of the projection [deg].
627 *
628 * imgcrd double[naxis]
629 * Image coordinate elements. imgcrd[wcs.lng] and
630 * imgcrd[wcs.lat] are the projected x-, and
631 * y-coordinates in pseudo "degrees".
632 *
633 * Given and returned:
634 * pixcrd double[naxis]
635 * Pixel coordinate. The element indicated by mixpix is
636 * given and the remaining elements are returned.
637 *
638 * Function return value:
639 * int Status return value:
640 * 0: Success.
641 * 1: Null wcsprm pointer passed.
642 * 2: Memory allocation failed.
643 * 3: Linear transformation matrix is singular.
644 * 4: Inconsistent or unrecognized coordinate axis
645 * types.
646 * 5: Invalid parameter value.
647 * 6: Invalid coordinate transformation parameters.
648 * 7: Ill-conditioned coordinate transformation
649 * parameters.
650 * 10: Invalid world coordinate.
651 * 11: No solution found in the specified interval.
652 *
653 * For returns > 1, a detailed error message is set in
654 * wcsprm::err if enabled, see wcserr_enable().
655 *
656 * Notes:
657 * Initially the specified solution interval is checked to see if it's a
658 * "crossing" interval. If it isn't, a search is made for a crossing
659 * solution by iterating on the unknown celestial coordinate starting at the
660 * upper limit of the solution interval and decrementing by the specified
661 * step size. A crossing is indicated if the trial value of the pixel
662 * coordinate steps through the value specified. If a crossing interval is
663 * found then the solution is determined by a modified form of "regula falsi"
664 * division of the crossing interval. If no crossing interval was found
665 * within the specified solution interval then a search is made for a
666 * "non-crossing" solution as may arise from a point of tangency. The
667 * process is complicated by having to make allowance for the discontinuities
668 * that occur in all map projections.
669 *
670 * Once one solution has been determined others may be found by subsequent
671 * invokations of wcsmix() with suitably restricted solution intervals.
672 *
673 * Note the circumstance that arises when the solution point lies at a native
674 * pole of a projection in which the pole is represented as a finite curve,
675 * for example the zenithals and conics. In such cases two or more valid
676 * solutions may exist but wcsmix() only ever returns one.
677 *
678 * Because of its generality wcsmix() is very compute-intensive. For
679 * compute-limited applications more efficient special-case solvers could be
680 * written for simple projections, for example non-oblique cylindrical
681 * projections.
682 *
683 *
684 * wcssptr() - Spectral axis translation
685 * -------------------------------------
686 * wcssptr() translates the spectral axis in a wcsprm struct. For example, a
687 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa.
688 *
689 * Given and returned:
690 * wcs struct wcsprm*
691 * Coordinate transformation parameters.
692 *
693 * i int* Index of the spectral axis (0-relative). If given < 0
694 * it will be set to the first spectral axis identified
695 * from the ctype[] keyvalues in the wcsprm struct.
696 *
697 * ctype char[9] Desired spectral CTYPEia. Wildcarding may be used as
698 * for the ctypeS2 argument to spctrn() as described in
699 * the prologue of spc.h, i.e. if the final three
700 * characters are specified as "???", or if just the
701 * eighth character is specified as '?', the correct
702 * algorithm code will be substituted and returned.
703 *
704 * Function return value:
705 * int Status return value:
706 * 0: Success.
707 * 1: Null wcsprm pointer passed.
708 * 2: Memory allocation failed.
709 * 3: Linear transformation matrix is singular.
710 * 4: Inconsistent or unrecognized coordinate axis
711 * types.
712 * 5: Invalid parameter value.
713 * 6: Invalid coordinate transformation parameters.
714 * 7: Ill-conditioned coordinate transformation
715 * parameters.
716 * 12: Invalid subimage specification (no spectral
717 * axis).
718 *
719 * For returns > 1, a detailed error message is set in
720 * wcsprm::err if enabled, see wcserr_enable().
721 *
722 *
723 * wcsprm struct - Coordinate transformation parameters
724 * ----------------------------------------------------
725 * The wcsprm struct contains information required to transform world
726 * coordinates. It consists of certain members that must be set by the user
727 * ("given") and others that are set by the WCSLIB routines ("returned").
728 * Some of the former are not actually required for transforming coordinates.
729 * These are described as "auxiliary"; the struct simply provides a place to
730 * store them, though they may be used by wcshdo() in constructing a FITS
731 * header from a wcsprm struct. Some of the returned values are supplied for
732 * informational purposes and others are for internal use only as indicated.
733 *
734 * In practice, it is expected that a WCS parser would scan the FITS header to
735 * determine the number of coordinate axes. It would then use wcsini() to
736 * allocate memory for arrays in the wcsprm struct and set default values.
737 * Then as it reread the header and identified each WCS keyrecord it would load
738 * the value into the relevant wcsprm array element. This is essentially what
739 * wcspih() does - refer to the prologue of wcshdr.h. As the final step,
740 * wcsset() is invoked, either directly or indirectly, to set the derived
741 * members of the wcsprm struct. wcsset() strips off trailing blanks in all
742 * string members and null-fills the character array.
743 *
744 * int flag
745 * (Given and returned) This flag must be set to zero whenever any of the
746 * following wcsprm struct members are set or changed:
747 *
748 * - wcsprm::naxis (q.v., not normally set by the user),
749 * - wcsprm::crpix,
750 * - wcsprm::pc,
751 * - wcsprm::cdelt,
752 * - wcsprm::crval,
753 * - wcsprm::cunit,
754 * - wcsprm::ctype,
755 * - wcsprm::lonpole,
756 * - wcsprm::latpole,
757 * - wcsprm::restfrq,
758 * - wcsprm::restwav,
759 * - wcsprm::npv,
760 * - wcsprm::pv,
761 * - wcsprm::nps,
762 * - wcsprm::ps,
763 * - wcsprm::cd,
764 * - wcsprm::crota,
765 * - wcsprm::altlin.
766 *
767 * This signals the initialization routine, wcsset(), to recompute the
768 * returned members of the celprm struct. celset() will reset flag to
769 * indicate that this has been done.
770 *
771 * PLEASE NOTE: flag should be set to -1 when wcsini() is called for the
772 * first time for a particular wcsprm struct in order to initialize memory
773 * management. It must ONLY be used on the first initialization otherwise
774 * memory leaks may result.
775 *
776 * int naxis
777 * (Given or returned) Number of pixel and world coordinate elements.
778 *
779 * If wcsini() is used to initialize the linprm struct (as would normally
780 * be the case) then it will set naxis from the value passed to it as a
781 * function argument. The user should not subsequently modify it.
782 *
783 * double *crpix
784 * (Given) Address of the first element of an array of double containing
785 * the coordinate reference pixel, CRPIXja.
786 *
787 * double *pc
788 * (Given) Address of the first element of the PCi_ja (pixel coordinate)
789 * transformation matrix. The expected order is
790 *
791 = struct wcsprm wcs;
792 = wcs.pc = {PC1_1, PC1_2, PC2_1, PC2_2};
793 *
794 * This may be constructed conveniently from a 2-D array via
795 *
796 = double m[2][2] = {{PC1_1, PC1_2},
797 = {PC2_1, PC2_2}};
798 *
799 * which is equivalent to
800 *
801 = double m[2][2];
802 = m[0][0] = PC1_1;
803 = m[0][1] = PC1_2;
804 = m[1][0] = PC2_1;
805 = m[1][1] = PC2_2;
806 *
807 * The storage order for this 2-D array is the same as for the 1-D array,
808 * whence
809 *
810 = wcs.pc = *m;
811 *
812 * would be legitimate.
813 *
814 * double *cdelt
815 * (Given) Address of the first element of an array of double containing
816 * the coordinate increments, CDELTia.
817 *
818 * double *crval
819 * (Given) Address of the first element of an array of double containing
820 * the coordinate reference values, CRVALia.
821 *
822 * char (*cunit)[72]
823 * (Given) Address of the first element of an array of char[72] containing
824 * the CUNITia keyvalues which define the units of measurement of the
825 * CRVALia, CDELTia, and CDi_ja keywords.
826 *
827 * As CUNITia is an optional header keyword, cunit[][72] may be left blank
828 * but otherwise is expected to contain a standard units specification as
829 * defined by WCS Paper I. Utility function wcsutrn(), described in
830 * wcsunits.h, is available to translate commonly used non-standard units
831 * specifications but this must be done as a separate step before invoking
832 * wcsset().
833 *
834 * For celestial axes, if cunit[][72] is not blank, wcsset() uses
835 * wcsunits() to parse it and scale cdelt[], crval[], and cd[][*] to
836 * degrees. It then resets cunit[][72] to "deg".
837 *
838 * For spectral axes, if cunit[][72] is not blank, wcsset() uses wcsunits()
839 * to parse it and scale cdelt[], crval[], and cd[][*] to SI units. It
840 * then resets cunit[][72] accordingly.
841 *
842 * wcsset() ignores cunit[][72] for other coordinate types; cunit[][72] may
843 * be used to label coordinate values.
844 *
845 * These variables accomodate the longest allowed string-valued FITS
846 * keyword, being limited to 68 characters, plus the null-terminating
847 * character.
848 *
849 * char (*ctype)[72]
850 * (Given) Address of the first element of an array of char[72] containing
851 * the coordinate axis types, CTYPEia.
852 *
853 * The ctype[][72] keyword values must be in upper case and there must be
854 * zero or one pair of matched celestial axis types, and zero or one
855 * spectral axis. The ctype[][72] strings should be padded with blanks on
856 * the right and null-terminated so that they are at least eight characters
857 * in length.
858 *
859 * These variables accomodate the longest allowed string-valued FITS
860 * keyword, being limited to 68 characters, plus the null-terminating
861 * character.
862 *
863 * double lonpole
864 * (Given and returned) The native longitude of the celestial pole, phi_p,
865 * given by LONPOLEa [deg] or by PVi_2a [deg] attached to the longitude
866 * axis which takes precedence if defined, and ...
867 * double latpole
868 * (Given and returned) ... the native latitude of the celestial pole,
869 * theta_p, given by LATPOLEa [deg] or by PVi_3a [deg] attached to the
870 * longitude axis which takes precedence if defined.
871 *
872 * lonpole and latpole may be left to default to values set by wcsini()
873 * (see celprm::ref), but in any case they will be reset by wcsset() to
874 * the values actually used. Note therefore that if the wcsprm struct is
875 * reused without resetting them, whether directly or via wcsini(), they
876 * will no longer have their default values.
877 *
878 * double restfrq
879 * (Given) The rest frequency [Hz], and/or ...
880 * double restwav
881 * (Given) ... the rest wavelength in vacuo [m], only one of which need be
882 * given, the other should be set to zero.
883 *
884 * int npv
885 * (Given) The number of entries in the wcsprm::pv[] array.
886 *
887 * int npvmax
888 * (Given or returned) The length of the wcsprm::pv[] array.
889 *
890 * npvmax will be set by wcsini() if it allocates memory for wcsprm::pv[],
891 * otherwise it must be set by the user. See also wcsnpv().
892 *
893 * struct pvcard *pv
894 * (Given or returned) Address of the first element of an array of length
895 * npvmax of pvcard structs. Set by wcsini() if it allocates memory for
896 * pv[], otherwise it must be set by the user. See also wcsnpv().
897 *
898 * As a FITS header parser encounters each PVi_ma keyword it should load it
899 * into a pvcard struct in the array and increment npv. wcsset()
900 * interprets these as required.
901 *
902 * Note that, if they were not given, wcsset() resets the entries for
903 * PVi_1a, PVi_2a, PVi_3a, and PVi_4a for longitude axis i to match
904 * phi_0 and theta_0 (the native longitude and latitude of the reference
905 * point), LONPOLEa and LATPOLEa respectively.
906 *
907 * int nps
908 * (Given) The number of entries in the wcsprm::ps[] array.
909 *
910 * int npsmax
911 * (Given or returned) The length of the wcsprm::ps[] array.
912 *
913 * npsmax will be set by wcsini() if it allocates memory for wcsprm::ps[],
914 * otherwise it must be set by the user. See also wcsnps().
915 *
916 * struct pscard *ps
917 * (Given or returned) Address of the first element of an array of length
918 * npsmax of pscard structs. Set by wcsini() if it allocates memory for
919 * ps[], otherwise it must be set by the user. See also wcsnps().
920 *
921 * As a FITS header parser encounters each PSi_ma keyword it should load it
922 * into a pscard struct in the array and increment nps. wcsset()
923 * interprets these as required (currently no PSi_ma keyvalues are
924 * recognized).
925 *
926 * double *cd
927 * (Given) For historical compatibility, the wcsprm struct supports two
928 * alternate specifications of the linear transformation matrix, those
929 * associated with the CDi_ja keywords, and ...
930 * double *crota
931 * (Given) ... those associated with the CROTAia keywords. Although these
932 * may not formally co-exist with PCi_ja, the approach taken here is simply
933 * to ignore them if given in conjunction with PCi_ja.
934 *
935 * int altlin
936 * (Given) altlin is a bit flag that denotes which of the PCi_ja, CDi_ja
937 * and CROTAia keywords are present in the header:
938 *
939 * - Bit 0: PCi_ja is present.
940 *
941 * - Bit 1: CDi_ja is present.
942 *
943 * Matrix elements in the IRAF convention are
944 * equivalent to the product CDi_ja = CDELTia * PCi_ja, but the
945 * defaults differ from that of the PCi_ja matrix. If one or more
946 * CDi_ja keywords are present then all unspecified CDi_ja default to
947 * zero. If no CDi_ja (or CROTAia) keywords are present, then the
948 * header is assumed to be in PCi_ja form whether or not any PCi_ja
949 * keywords are present since this results in an interpretation of
950 * CDELTia consistent with the original FITS specification.
951 *
952 * While CDi_ja may not formally co-exist with PCi_ja, it may co-exist
953 * with CDELTia and CROTAia which are to be ignored.
954 *
955 * - Bit 2: CROTAia is present.
956 *
957 * In the AIPS convention, CROTAia may only be
958 * associated with the latitude axis of a celestial axis pair. It
959 * specifies a rotation in the image plane that is applied AFTER the
960 * CDELTia; any other CROTAia keywords are ignored.
961 *
962 * CROTAia may not formally co-exist with PCi_ja.
963 *
964 * CROTAia and CDELTia may formally co-exist with CDi_ja but if so are to
965 * be ignored.
966 *
967 * CDi_ja and CROTAia keywords, if found, are to be stored in the
968 * wcsprm::cd and wcsprm::crota arrays which are dimensioned similarly to
969 * wcsprm::pc and wcsprm::cdelt. FITS
970 * header parsers should use the following procedure:
971 *
972 * - Whenever a PCi_ja keyword is encountered: altlin |= 1;
973 *
974 * - Whenever a CDi_ja keyword is encountered: altlin |= 2;
975 *
976 * - Whenever a CROTAia keyword is encountered: altlin |= 4;
977 *
978 * If none of these bits are set the PCi_ja representation results, i.e.
979 * wcsprm::pc and wcsprm::cdelt will be used as given.
980 *
981 * These alternate specifications of the linear transformation matrix are
982 * translated immediately to PCi_ja by wcsset() and are invisible to the
983 * lower-level WCSLIB routines. In particular, wcsset() resets
984 * wcsprm::cdelt to unity if CDi_ja is present (and no PCi_ja).
985 *
986 * If CROTAia are present but none is associated with the latitude axis
987 * (and no PCi_ja or CDi_ja), then wcsset() reverts to a unity PCi_ja
988 * matrix.
989 *
990 * int velref
991 * (Given) AIPS velocity code VELREF, refer to spcaips().
992 *
993 * char alt[4]
994 * (Given, auxiliary) Character code for alternate coordinate descriptions
995 * (i.e. the 'a' in keyword names such as CTYPEia). This is blank for the
996 * primary coordinate description, or one of the 26 upper-case letters,
997 * A-Z.
998 *
999 * An array of four characters is provided for alignment purposes, only the
1000 * first is used.
1001 *
1002 * int colnum
1003 * (Given, auxiliary) Where the coordinate representation is associated
1004 * with an image-array column in a FITS binary table, this variable may be
1005 * used to record the relevant column number.
1006 *
1007 * It should be set to zero for an image header or pixel list.
1008 *
1009 * int *colax
1010 * (Given, auxiliary) Address of the first element of an array of int
1011 * recording the column numbers for each axis in a pixel list.
1012 *
1013 * The array elements should be set to zero for an image header or image
1014 * array in a binary table.
1015 *
1016 * char (*cname)[72]
1017 * (Given, auxiliary) The address of the first element of an array of
1018 * char[72] containing the coordinate axis names, CNAMEia.
1019 *
1020 * These variables accomodate the longest allowed string-valued FITS
1021 * keyword, being limited to 68 characters, plus the null-terminating
1022 * character.
1023 *
1024 * double *crder
1025 * (Given, auxiliary) Address of the first element of an array of double
1026 * recording the random error in the coordinate value, CRDERia.
1027 * double *csyer
1028 * (Given, auxiliary) Address of the first element of an array of double
1029 * recording the systematic error in the coordinate value, CSYERia.
1030 *
1031 * char dateavg[72]
1032 * (Given, auxiliary) The date of a representative mid-point of the
1033 * observation in ISO format, yyyy-mm-ddThh:mm:ss.
1034 * char dateobs[72]
1035 * (Given, auxiliary) The date of the start of the observation unless
1036 * otherwise explained in the comment field of the DATE-OBS keyword, in
1037 * ISO format, yyyy-mm-ddThh:mm:ss.
1038 *
1039 * double equinox
1040 * (Given, auxiliary) The equinox associated with dynamical equatorial or
1041 * ecliptic coordinate systems, EQUINOXa (or EPOCH in older headers). Not
1042 * applicable to ICRS equatorial or ecliptic coordinates.
1043 *
1044 * double mjdavg
1045 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-AVG,
1046 * corresponding to DATE-AVG.
1047 * double mjdobs
1048 * (Given, auxiliary) Modified Julian Date (MJD = JD - 2400000.5), MJD-OBS,
1049 * corresponding to DATE-OBS.
1050 *
1051 * double obsgeo[3]
1052 * (Given, auxiliary) Location of the observer in a standard terrestrial
1053 * reference frame, OBSGEO-X, OBSGEO-Y, OBSGEO-Z [m].
1054 *
1055 * char radesys[72]
1056 * (Given, auxiliary) The equatorial or ecliptic coordinate system type,
1057 * RADESYSa.
1058 *
1059 * char specsys[72]
1060 * (Given, auxiliary) Spectral reference frame (standard of rest),
1061 * SPECSYSa, and ...
1062 * char ssysobs[72]
1063 * (Given, auxiliary) ... the actual frame in which there is no
1064 * differential variation in the spectral coordinate across the
1065 * field-of-view, SSYSOBSa.
1066 * double velosys
1067 * (Given, auxiliary) The relative radial velocity [m/s] between the
1068 * observer and the selected standard of rest in the direction of the
1069 * celestial reference coordinate, VELOSYSa.
1070 *
1071 * double zsource
1072 * (Given, auxiliary) The redshift, ZSOURCEa, of the source, and ...
1073 * char ssyssrc[72]
1074 * (Given, auxiliary) ... the spectral reference frame (standard of rest)
1075 * in which this was measured, SSYSSRCa.
1076 *
1077 * double velangl
1078 * (Given, auxiliary) The angle [deg] that should be used to decompose an
1079 * observed velocity into radial and transverse components.
1080 *
1081 * char wcsname[72]
1082 * (Given, auxiliary) The name given to the coordinate representation,
1083 * WCSNAMEa. This variable accomodates the longest allowed string-valued
1084 * FITS keyword, being limited to 68 characters, plus the null-terminating
1085 * character.
1086 *
1087 * int ntab
1088 * (Given) See wcsprm::tab.
1089 *
1090 * int nwtb
1091 * (Given) See wcsprm::wtb.
1092 *
1093 * struct tabprm *tab
1094 * (Given) Address of the first element of an array of ntab tabprm structs
1095 * for which memory has been allocated. These are used to store tabular
1096 * transformation parameters.
1097 *
1098 * Although technically wcsprm::ntab and tab are "given", they will
1099 * normally be set by invoking wcstab(), whether directly or indirectly.
1100 *
1101 * The tabprm structs contain some members that must be supplied and others
1102 * that are derived. The information to be supplied comes primarily from
1103 * arrays stored in one or more FITS binary table extensions. These
1104 * arrays, referred to here as "wcstab arrays", are themselves located by
1105 * parameters stored in the FITS image header.
1106 *
1107 * struct wtbarr *wtb
1108 * (Given) Address of the first element of an array of nwtb wtbarr structs
1109 * for which memory has been allocated. These are used in extracting
1110 * wcstab arrays from a FITS binary table.
1111 *
1112 * Although technically wcsprm::nwtb and wtb are "given", they will
1113 * normally be set by invoking wcstab(), whether directly or indirectly.
1114 *
1115 * char lngtyp[8]
1116 * (Returned) Four-character WCS celestial longitude and ...
1117 * char lattyp[8]
1118 * (Returned) ... latitude axis types. e.g. "RA", "DEC", "GLON", "GLAT",
1119 * etc. extracted from 'RA--', 'DEC-', 'GLON', 'GLAT', etc. in the first
1120 * four characters of CTYPEia but with trailing dashes removed. (Declared
1121 * as char[8] for alignment reasons.)
1122 *
1123 * int lng
1124 * (Returned) Index for the longitude coordinate, and ...
1125 * int lat
1126 * (Returned) ... index for the latitude coordinate, and ...
1127 * int spec
1128 * (Returned) ... index for the spectral coordinate in the imgcrd[][] and
1129 * world[][] arrays in the API of wcsp2s(), wcss2p() and wcsmix().
1130 *
1131 * These may also serve as indices into the pixcrd[][] array provided that
1132 * the PCi_ja matrix does not transpose axes.
1133 *
1134 * int cubeface
1135 * (Returned) Index into the pixcrd[][] array for the CUBEFACE axis. This
1136 * is used for quadcube projections where the cube faces are stored on a
1137 * separate axis (see wcs.h).
1138 *
1139 * int *types
1140 * (Returned) Address of the first element of an array of int containing a
1141 * four-digit type code for each axis.
1142 *
1143 * - First digit (i.e. 1000s):
1144 * - 0: Non-specific coordinate type.
1145 * - 1: Stokes coordinate.
1146 * - 2: Celestial coordinate (including CUBEFACE).
1147 * - 3: Spectral coordinate.
1148 *
1149 * - Second digit (i.e. 100s):
1150 * - 0: Linear axis.
1151 * - 1: Quantized axis (STOKES, CUBEFACE).
1152 * - 2: Non-linear celestial axis.
1153 * - 3: Non-linear spectral axis.
1154 * - 4: Logarithmic axis.
1155 * - 5: Tabular axis.
1156 *
1157 * - Third digit (i.e. 10s):
1158 * - 0: Group number, e.g. lookup table number, being an index into the
1159 * tabprm array (see above).
1160 *
1161 * - The fourth digit is used as a qualifier depending on the axis type.
1162 *
1163 * - For celestial axes:
1164 * - 0: Longitude coordinate.
1165 * - 1: Latitude coordinate.
1166 * - 2: CUBEFACE number.
1167 *
1168 * - For lookup tables: the axis number in a multidimensional table.
1169 *
1170 * CTYPEia in "4-3" form with unrecognized algorithm code will have its
1171 * type set to -1 and generate an error.
1172 *
1173 * void *padding
1174 * (An unused variable inserted for alignment purposes only.)
1175 *
1176 * struct linprm lin
1177 * (Returned) Linear transformation parameters (usage is described in the
1178 * prologue to lin.h).
1179 *
1180 * struct celprm cel
1181 * (Returned) Celestial transformation parameters (usage is described in
1182 * the prologue to cel.h).
1183 *
1184 * struct spcprm spc
1185 * (Returned) Spectral transformation parameters (usage is described in the
1186 * prologue to spc.h).
1187 *
1188 * struct wcserr *err
1189 * (Returned) If enabled, when an error status is returned this struct
1190 * contains detailed information about the error, see wcserr_enable().
1191 *
1192 * void *m_padding
1193 * (For internal use only.)
1194 * int m_flag
1195 * (For internal use only.)
1196 * int m_naxis
1197 * (For internal use only.)
1198 * double *m_crpix
1199 * (For internal use only.)
1200 * double *m_pc
1201 * (For internal use only.)
1202 * double *m_cdelt
1203 * (For internal use only.)
1204 * double *m_crval
1205 * (For internal use only.)
1206 * char (*m_cunit)[72]
1207 * (For internal use only.)
1208 * char (*m_ctype)[72]
1209 * (For internal use only.)
1210 * struct pvcard *m_pv
1211 * (For internal use only.)
1212 * struct pscard *m_ps
1213 * (For internal use only.)
1214 * double *m_cd
1215 * (For internal use only.)
1216 * double *m_crota
1217 * (For internal use only.)
1218 * int *m_colax
1219 * (For internal use only.)
1220 * char (*m_cname)[72]
1221 * (For internal use only.)
1222 * double *m_crder
1223 * (For internal use only.)
1224 * double *m_csyer
1225 * (For internal use only.)
1226 * struct tabprm *m_tab
1227 * (For internal use only.)
1228 * struct wtbarr *m_wtb
1229 * (For internal use only.)
1230 *
1231 *
1232 * pscard struct - Store for PSi_ma keyrecords
1233 * -------------------------------------------
1234 * The pscard struct is used to pass the parsed contents of PSi_ma keyrecords
1235 * to wcsset() via the wcsprm struct.
1236 *
1237 * All members of this struct are to be set by the user.
1238 *
1239 * int i
1240 * (Given) Axis number (1-relative), as in the FITS PSi_ma keyword.
1241 *
1242 * int m
1243 * (Given) Parameter number (non-negative), as in the FITS PSi_ma keyword.
1244 *
1245 * char value[72]
1246 * (Given) Parameter value.
1247 *
1248 *
1249 * pvcard struct - Store for PVi_ma keyrecords
1250 * -------------------------------------------
1251 * The pvcard struct is used to pass the parsed contents of PVi_ma keyrecords
1252 * to wcsset() via the wcsprm struct.
1253 *
1254 * All members of this struct are to be set by the user.
1255 *
1256 * int i
1257 * (Given) Axis number (1-relative), as in the FITS PVi_ma keyword. If
1258 * i == 0, wcsset() will replace it with the latitude axis number.
1259 *
1260 * int m
1261 * (Given) Parameter number (non-negative), as in the FITS PVi_ma keyword.
1262 *
1263 * double value
1264 * (Given) Parameter value.
1265 *
1266 *
1267 * wtbarr struct - Extraction of coordinate lookup tables from BINTABLE
1268 * --------------------------------------------------------------------
1269 * Function wcstab(), which is invoked automatically by wcspih(), sets up an
1270 * array of wtbarr structs to assist in extracting coordinate lookup tables
1271 * from a binary table extension (BINTABLE) and copying them into the tabprm
1272 * structs stored in wcsprm. Refer to the usage notes for wcspih() and
1273 * wcstab() in wcshdr.h, and also the prologue to tab.h.
1274 *
1275 * For C++ usage, because of a name space conflict with the wtbarr typedef
1276 * defined in CFITSIO header fitsio.h, the wtbarr struct is renamed to wtbarr_s
1277 * by preprocessor macro substitution with scope limited to wcs.h itself.
1278 *
1279 * int i
1280 * (Given) Image axis number.
1281 *
1282 * int m
1283 * (Given) wcstab array axis number for index vectors.
1284 *
1285 * int kind
1286 * (Given) Character identifying the wcstab array type:
1287 * - c: coordinate array,
1288 * - i: index vector.
1289 *
1290 * char extnam[72]
1291 * (Given) EXTNAME identifying the binary table extension.
1292 *
1293 * int extver
1294 * (Given) EXTVER identifying the binary table extension.
1295 *
1296 * int extlev
1297 * (Given) EXTLEV identifying the binary table extension.
1298 *
1299 * char ttype[72]
1300 * (Given) TTYPEn identifying the column of the binary table that contains
1301 * the wcstab array.
1302 *
1303 * long row
1304 * (Given) Table row number.
1305 *
1306 * int ndim
1307 * (Given) Expected dimensionality of the wcstab array.
1308 *
1309 * int *dimlen
1310 * (Given) Address of the first element of an array of int of length ndim
1311 * into which the wcstab array axis lengths are to be written.
1312 *
1313 * double **arrayp
1314 * (Given) Pointer to an array of double which is to be allocated by the
1315 * user and into which the wcstab array is to be written.
1316 *
1317 *
1318 * Global variable: const char *wcs_errmsg[] - Status return messages
1319 * ------------------------------------------------------------------
1320 * Error messages to match the status value returned from each function.
1321 *
1322 *===========================================================================*/
1323 
1324 #ifndef WCSLIB_WCS
1325 #define WCSLIB_WCS
1326 
1327 #include "lin.h"
1328 #include "cel.h"
1329 #include "spc.h"
1330 #include "tab.h"
1331 #include "wcserr.h"
1332 
1333 #ifdef __cplusplus
1334 extern "C" {
1335 #endif
1336 
1337 #define WCSSUB_LONGITUDE 0x1001
1338 #define WCSSUB_LATITUDE 0x1002
1339 #define WCSSUB_CUBEFACE 0x1004
1340 #define WCSSUB_CELESTIAL 0x1007
1341 #define WCSSUB_SPECTRAL 0x1008
1342 #define WCSSUB_STOKES 0x1010
1343 
1344 
1345 extern const char *wcs_errmsg[];
1346 
1348  WCSERR_SUCCESS = 0, /* Success. */
1349  WCSERR_NULL_POINTER = 1, /* Null wcsprm pointer passed. */
1350  WCSERR_MEMORY = 2, /* Memory allocation failed. */
1351  WCSERR_SINGULAR_MTX = 3, /* Linear transformation matrix is
1352  singular. */
1353  WCSERR_BAD_CTYPE = 4, /* Inconsistent or unrecognized coordinate
1354  axis types. */
1355  WCSERR_BAD_PARAM = 5, /* Invalid parameter value. */
1356  WCSERR_BAD_COORD_TRANS = 6, /* Invalid coordinate transformation
1357  parameters. */
1358  WCSERR_ILL_COORD_TRANS = 7, /* Ill-conditioned coordinate transformation
1359  parameters. */
1360  WCSERR_BAD_PIX = 8, /* One or more of the pixel coordinates were
1361  invalid. */
1362  WCSERR_BAD_WORLD = 9, /* One or more of the world coordinates were
1363  invalid. */
1364  WCSERR_BAD_WORLD_COORD = 10, /* Invalid world coordinate. */
1365  WCSERR_NO_SOLUTION = 11, /* No solution found in the specified
1366  interval. */
1367  WCSERR_BAD_SUBIMAGE = 12, /* Invalid subimage specification. */
1368  WCSERR_NON_SEPARABLE = 13 /* Non-separable subimage coordinate
1369  system. */
1370 };
1371 
1372 
1373 /* Struct used for storing PVi_ma keywords. */
1374 struct pvcard {
1375  int i; /* Axis number, as in PVi_ma (1-relative). */
1376  int m; /* Parameter number, ditto (0-relative). */
1377  double value; /* Parameter value. */
1378 };
1379 
1380 /* Struct used for storing PSi_ma keywords. */
1381 struct pscard {
1382  int i; /* Axis number, as in PSi_ma (1-relative). */
1383  int m; /* Parameter number, ditto (0-relative). */
1384  char value[72]; /* Parameter value. */
1385 };
1386 
1387  /* For extracting wcstab arrays. Matches */
1388  /* the wtbarr typedef defined in CFITSIO */
1389  /* header fitsio.h. */
1390 #ifdef __cplusplus
1391 #define wtbarr wtbarr_s /* See prologue above. */
1392 #endif
1393 struct wtbarr {
1394  int i; /* Image axis number. */
1395  int m; /* Array axis number for index vectors. */
1396  int kind; /* wcstab array type. */
1397  char extnam[72]; /* EXTNAME of binary table extension. */
1398  int extver; /* EXTVER of binary table extension. */
1399  int extlev; /* EXTLEV of binary table extension. */
1400  char ttype[72]; /* TTYPEn of column containing the array. */
1401  long row; /* Table row number. */
1402  int ndim; /* Expected wcstab array dimensionality. */
1403  int *dimlen; /* Where to write the array axis lengths. */
1404  double **arrayp; /* Where to write the address of the array */
1405  /* allocated to store the wcstab array. */
1406 };
1407 
1408 
1409 struct wcsprm {
1410  /* Initialization flag (see the prologue above). */
1411  /*------------------------------------------------------------------------*/
1412  int flag; /* Set to zero to force initialization. */
1413 
1414  /* FITS header keyvalues to be provided (see the prologue above). */
1415  /*------------------------------------------------------------------------*/
1416  int naxis; /* Number of axes (pixel and coordinate). */
1417  double *crpix; /* CRPIXja keyvalues for each pixel axis. */
1418  double *pc; /* PCi_ja linear transformation matrix. */
1419  double *cdelt; /* CDELTia keyvalues for each coord axis. */
1420  double *crval; /* CRVALia keyvalues for each coord axis. */
1421 
1422  char (*cunit)[72]; /* CUNITia keyvalues for each coord axis. */
1423  char (*ctype)[72]; /* CTYPEia keyvalues for each coord axis. */
1424 
1425  double lonpole; /* LONPOLEa keyvalue. */
1426  double latpole; /* LATPOLEa keyvalue. */
1427 
1428  double restfrq; /* RESTFRQa keyvalue. */
1429  double restwav; /* RESTWAVa keyvalue. */
1430 
1431  int npv; /* Number of PVi_ma keywords, and the */
1432  int npvmax; /* number for which space was allocated. */
1433  struct pvcard *pv; /* PVi_ma keywords for each i and m. */
1434 
1435  int nps; /* Number of PSi_ma keywords, and the */
1436  int npsmax; /* number for which space was allocated. */
1437  struct pscard *ps; /* PSi_ma keywords for each i and m. */
1438 
1439  /* Alternative header keyvalues (see the prologue above). */
1440  /*------------------------------------------------------------------------*/
1441  double *cd; /* CDi_ja linear transformation matrix. */
1442  double *crota; /* CROTAia keyvalues for each coord axis. */
1443  int altlin; /* Alternative representations */
1444  /* Bit 0: PCi_ja is present, */
1445  /* Bit 1: CDi_ja is present, */
1446  /* Bit 2: CROTAia is present. */
1447  int velref; /* AIPS velocity code, VELREF. */
1448 
1449  /* Auxiliary coordinate system information, not used by WCSLIB. */
1450  char alt[4];
1451  int colnum;
1452  int *colax;
1453 
1454  char (*cname)[72];
1455  double *crder;
1456  double *csyer;
1457  char dateavg[72];
1458  char dateobs[72];
1459  double equinox;
1460  double mjdavg;
1461  double mjdobs;
1462  double obsgeo[3];
1463  char radesys[72];
1464  char specsys[72];
1465  char ssysobs[72];
1466  double velosys;
1467  double zsource;
1468  char ssyssrc[72];
1469  double velangl;
1470  char wcsname[72];
1471 
1472  /* Coordinate lookup tables (see the prologue above). */
1473  /*------------------------------------------------------------------------*/
1474  int ntab; /* Number of separate tables. */
1475  int nwtb; /* Number of wtbarr structs. */
1476  struct tabprm *tab; /* Tabular transformation parameters. */
1477  struct wtbarr *wtb; /* Array of wtbarr structs. */
1478 
1479  /* Information derived from the FITS header keyvalues by wcsset(). */
1480  /*------------------------------------------------------------------------*/
1481  char lngtyp[8], lattyp[8]; /* Celestial axis types, e.g. RA, DEC. */
1482  int lng, lat, spec; /* Longitude, latitude and spectral axis */
1483  /* indices (0-relative). */
1484  int cubeface; /* True if there is a CUBEFACE axis. */
1485  int *types; /* Coordinate type codes for each axis. */
1486  void *padding; /* (Dummy inserted for alignment purposes.) */
1487 
1488  struct linprm lin; /* Linear transformation parameters. */
1489  struct celprm cel; /* Celestial transformation parameters. */
1490  struct spcprm spc; /* Spectral transformation parameters. */
1491 
1492  /* Error handling */
1493  /*------------------------------------------------------------------------*/
1494  struct wcserr *err;
1495 
1496  /* Private - the remainder are for memory management. */
1497  /*------------------------------------------------------------------------*/
1498  void *m_padding;
1500  double *m_crpix, *m_pc, *m_cdelt, *m_crval;
1501  char (*m_cunit)[72], (*m_ctype)[72];
1502  struct pvcard *m_pv;
1503  struct pscard *m_ps;
1504  double *m_cd, *m_crota;
1505  int *m_colax;
1506  char (*m_cname)[72];
1507  double *m_crder, *m_csyer;
1508  struct tabprm *m_tab;
1509  struct wtbarr *m_wtb;
1510 };
1511 
1512 /* Size of the wcsprm struct in int units, used by the Fortran wrappers. */
1513 #define WCSLEN (sizeof(struct wcsprm)/sizeof(int))
1514 
1515 
1516 int wcsnpv(int n);
1517 
1518 int wcsnps(int n);
1519 
1520 int wcsini(int alloc, int naxis, struct wcsprm *wcs);
1521 
1522 int wcssub(int alloc, const struct wcsprm *wcssrc, int *nsub, int axes[],
1523  struct wcsprm *wcsdst);
1524 
1525 int wcsfree(struct wcsprm *wcs);
1526 
1527 int wcsprt(const struct wcsprm *wcs);
1528 
1529 int wcsperr(const struct wcsprm *wcs, const char *prefix);
1530 
1531 int wcsbchk(struct wcsprm *wcs, int bounds);
1532 
1533 int wcsset(struct wcsprm *wcs);
1534 
1535 int wcsp2s(struct wcsprm *wcs, int ncoord, int nelem, const double pixcrd[],
1536  double imgcrd[], double phi[], double theta[], double world[],
1537  int stat[]);
1538 
1539 int wcss2p(struct wcsprm *wcs, int ncoord, int nelem, const double world[],
1540  double phi[], double theta[], double imgcrd[], double pixcrd[],
1541  int stat[]);
1542 
1543 int wcsmix(struct wcsprm *wcs, int mixpix, int mixcel, const double vspan[],
1544  double vstep, int viter, double world[], double phi[],
1545  double theta[], double imgcrd[], double pixcrd[]);
1546 
1547 int wcssptr(struct wcsprm *wcs, int *i, char ctype[9]);
1548 
1549 /* Defined mainly for backwards compatibility, use wcssub() instead. */
1550 #define wcscopy(alloc, wcssrc, wcsdst) wcssub(alloc, wcssrc, 0x0, 0x0, wcsdst)
1551 
1552 
1553 /* Deprecated. */
1554 #define wcsini_errmsg wcs_errmsg
1555 #define wcssub_errmsg wcs_errmsg
1556 #define wcscopy_errmsg wcs_errmsg
1557 #define wcsfree_errmsg wcs_errmsg
1558 #define wcsprt_errmsg wcs_errmsg
1559 #define wcsset_errmsg wcs_errmsg
1560 #define wcsp2s_errmsg wcs_errmsg
1561 #define wcss2p_errmsg wcs_errmsg
1562 #define wcsmix_errmsg wcs_errmsg
1563 
1564 #ifdef __cplusplus
1565 #undef wtbarr
1566 }
1567 #endif
1568 
1569 #endif /* WCSLIB_WCS */