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