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