WCSLIB 8.3
Loading...
Searching...
No Matches
cel.h
Go to the documentation of this file.
1/*============================================================================
2 WCSLIB 8.3 - an implementation of the FITS WCS standard.
3 Copyright (C) 1995-2024, Mark Calabretta
4
5 This file is part of WCSLIB.
6
7 WCSLIB is free software: you can redistribute it and/or modify it under the
8 terms of the GNU Lesser General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or (at your option)
10 any later version.
11
12 WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with WCSLIB. If not, see http://www.gnu.org/licenses.
19
20 Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
21 http://www.atnf.csiro.au/people/Mark.Calabretta
22 $Id: cel.h,v 8.3 2024/05/08 16:02:37 mcalabre Exp $
23*=============================================================================
24*
25* WCSLIB 8.3 - C routines that implement the FITS World Coordinate System
26* (WCS) standard. Refer to the README file provided with WCSLIB for an
27* overview of the library.
28*
29*
30* Summary of the cel routines
31* ---------------------------
32* Routines in this suite implement the part of the FITS World Coordinate
33* System (WCS) standard that deals with celestial coordinates, as described in
34*
35= "Representations of world coordinates in FITS",
36= Greisen, E.W., & Calabretta, M.R. 2002, A&A, 395, 1061 (WCS Paper I)
37=
38= "Representations of celestial coordinates in FITS",
39= Calabretta, M.R., & Greisen, E.W. 2002, A&A, 395, 1077 (WCS Paper II)
40*
41* These routines define methods to be used for computing celestial world
42* coordinates from intermediate world coordinates (a linear transformation
43* of image pixel coordinates), and vice versa. They are based on the celprm
44* struct which contains all information needed for the computations. This
45* struct contains some elements that must be set by the user, and others that
46* are maintained by these routines, somewhat like a C++ class but with no
47* encapsulation.
48*
49* Routine celini() is provided to initialize the celprm struct with default
50* values, celfree() reclaims any memory that may have been allocated to store
51* an error message, celsize() computes its total size including allocated
52* memory, celenq() returns information about the state of the struct, and
53* celprt() prints its contents.
54*
55* celperr() prints the error message(s), if any, stored in a celprm struct and
56* the prjprm struct that it contains.
57*
58* A setup routine, celset(), computes intermediate values in the celprm struct
59* from parameters in it that were supplied by the user. The struct always
60* needs to be set up by celset() but it need not be called explicitly - refer
61* to the explanation of celprm::flag.
62*
63* celx2s() and cels2x() implement the WCS celestial coordinate
64* transformations. In fact, they are high level driver routines for the lower
65* level spherical coordinate rotation and projection routines described in
66* sph.h and prj.h.
67*
68*
69* celini() - Default constructor for the celprm struct
70* ----------------------------------------------------
71* celini() sets all members of a celprm struct to default values. It should
72* be used to initialize every celprm struct.
73*
74* PLEASE NOTE: If the celprm struct has already been initialized, then before
75* reinitializing, it celfree() should be used to free any memory that may have
76* been allocated to store an error message. A memory leak may otherwise
77* result.
78*
79* Returned:
80* cel struct celprm*
81* Celestial transformation parameters.
82*
83* Function return value:
84* int Status return value:
85* 0: Success.
86* 1: Null celprm pointer passed.
87*
88*
89* celfree() - Destructor for the celprm struct
90* --------------------------------------------
91* celfree() frees any memory that may have been allocated to store an error
92* message in the celprm struct.
93*
94* Given:
95* cel struct celprm*
96* Celestial transformation parameters.
97*
98* Function return value:
99* int Status return value:
100* 0: Success.
101* 1: Null celprm pointer passed.
102*
103*
104* celsize() - Compute the size of a celprm struct
105* -----------------------------------------------
106* celsize() computes the full size of a celprm struct, including allocated
107* memory.
108*
109* Given:
110* cel const struct celprm*
111* Celestial transformation parameters.
112*
113* If NULL, the base size of the struct and the allocated
114* size are both set to zero.
115*
116* Returned:
117* sizes int[2] The first element is the base size of the struct as
118* returned by sizeof(struct celprm). The second element
119* is the total allocated size, in bytes. This figure
120* includes memory allocated for the constituent struct,
121* celprm::err.
122*
123* It is not an error for the struct not to have been set
124* up via celset().
125*
126* Function return value:
127* int Status return value:
128* 0: Success.
129*
130*
131* celenq() - enquire about the state of a celprm struct
132* -----------------------------------------------------
133* celenq() may be used to obtain information about the state of a celprm
134* struct. The function returns a true/false answer for the enquiry asked.
135*
136* Given:
137* cel const struct celprm*
138* Celestial transformation parameters.
139*
140* enquiry int Enquiry according to the following parameters:
141* CELENQ_SET: the struct has been set up by celset().
142* CELENQ_BYP: the struct is in bypass mode, which
143* implies that it has been set up (see
144* celset()).
145*
146* Function return value:
147* int Enquiry result:
148* 0: No.
149* 1: Yes.
150*
151*
152* celprt() - Print routine for the celprm struct
153* ----------------------------------------------
154* celprt() prints the contents of a celprm struct using wcsprintf(). Mainly
155* intended for diagnostic purposes.
156*
157* Given:
158* cel const struct celprm*
159* Celestial transformation parameters.
160*
161* Function return value:
162* int Status return value:
163* 0: Success.
164* 1: Null celprm pointer passed.
165*
166*
167* celperr() - Print error messages from a celprm struct
168* -----------------------------------------------------
169* celperr() prints the error message(s), if any, stored in a celprm struct and
170* the prjprm struct that it contains. If there are no errors then nothing is
171* printed. It uses wcserr_prt(), q.v.
172*
173* Given:
174* cel const struct celprm*
175* Coordinate transformation parameters.
176*
177* prefix const char *
178* If non-NULL, each output line will be prefixed with
179* this string.
180*
181* Function return value:
182* int Status return value:
183* 0: Success.
184* 1: Null celprm pointer passed.
185*
186*
187* celset() - Setup routine for the celprm struct
188* ----------------------------------------------
189* celset() sets up a celprm struct according to information supplied within
190* it.
191*
192* Note that this routine need not be called directly; it will be invoked by
193* celx2s() and cels2x() if celprm::flag is anything other than a predefined
194* magic value.
195
196* celset() normally operates regardless of the value of celprm::flag; i.e.
197* even if a struct was previously set up it will be reset unconditionally.
198* However, a celprm struct may be put into "bypass" mode by invoking celset()
199* initially with celprm::flag == 1 (rather than 0). celset() will return
200* immediately if invoked on a struct in that state. To take a struct out of
201* bypass mode, simply reset celprm::flag to zero. See also celenq().
202*
203* Given and returned:
204* cel struct celprm*
205* Celestial transformation parameters.
206*
207* Function return value:
208* int Status return value:
209* 0: Success.
210* 1: Null celprm pointer passed.
211* 2: Invalid projection parameters.
212* 3: Invalid coordinate transformation parameters.
213* 4: Ill-conditioned coordinate transformation
214* parameters.
215*
216* For returns > 1, a detailed error message is set in
217* celprm::err if enabled, see wcserr_enable().
218*
219*
220* celx2s() - Pixel-to-world celestial transformation
221* --------------------------------------------------
222* celx2s() transforms (x,y) coordinates in the plane of projection to
223* celestial coordinates (lng,lat).
224*
225* Given and returned:
226* cel struct celprm*
227* Celestial transformation parameters.
228*
229* Given:
230* nx,ny int Vector lengths.
231*
232* sxy,sll int Vector strides.
233*
234* x,y const double[]
235* Projected coordinates in pseudo "degrees".
236*
237* Returned:
238* phi,theta double[] Longitude and latitude (phi,theta) in the native
239* coordinate system of the projection [deg].
240*
241* lng,lat double[] Celestial longitude and latitude (lng,lat) of the
242* projected point [deg].
243*
244* stat int[] Status return value for each vector element:
245* 0: Success.
246* 1: Invalid value of (x,y).
247*
248* Function return value:
249* int Status return value:
250* 0: Success.
251* 1: Null celprm pointer passed.
252* 2: Invalid projection parameters.
253* 3: Invalid coordinate transformation parameters.
254* 4: Ill-conditioned coordinate transformation
255* parameters.
256* 5: One or more of the (x,y) coordinates were
257* invalid, as indicated by the stat vector.
258*
259* For returns > 1, a detailed error message is set in
260* celprm::err if enabled, see wcserr_enable().
261*
262*
263* cels2x() - World-to-pixel celestial transformation
264* --------------------------------------------------
265* cels2x() transforms celestial coordinates (lng,lat) to (x,y) coordinates in
266* the plane of projection.
267*
268* Given and returned:
269* cel struct celprm*
270* Celestial transformation parameters.
271*
272* Given:
273* nlng,nlat int Vector lengths.
274*
275* sll,sxy int Vector strides.
276*
277* lng,lat const double[]
278* Celestial longitude and latitude (lng,lat) of the
279* projected point [deg].
280*
281* Returned:
282* phi,theta double[] Longitude and latitude (phi,theta) in the native
283* coordinate system of the projection [deg].
284*
285* x,y double[] Projected coordinates in pseudo "degrees".
286*
287* stat int[] Status return value for each vector element:
288* 0: Success.
289* 1: Invalid value of (lng,lat).
290*
291* Function return value:
292* int Status return value:
293* 0: Success.
294* 1: Null celprm pointer passed.
295* 2: Invalid projection parameters.
296* 3: Invalid coordinate transformation parameters.
297* 4: Ill-conditioned coordinate transformation
298* parameters.
299* 6: One or more of the (lng,lat) coordinates were
300* invalid, as indicated by the stat vector.
301*
302* For returns > 1, a detailed error message is set in
303* celprm::err if enabled, see wcserr_enable().
304*
305*
306* celprm struct - Celestial transformation parameters
307* ---------------------------------------------------
308* The celprm struct contains information required to transform celestial
309* coordinates. It consists of certain members that must be set by the user
310* ("given") and others that are set by the WCSLIB routines ("returned"). Some
311* of the latter are supplied for informational purposes and others are for
312* internal use only.
313*
314* Returned celprm struct members must not be modified by the user.
315*
316* int flag
317* (Given and returned) This flag must be set to zero (or 1, see celset())
318* whenever any of the following celprm struct members are set or changed:
319*
320* - celprm::offset,
321* - celprm::phi0,
322* - celprm::theta0,
323* - celprm::ref[4],
324* - celprm::prj:
325* - prjprm::code,
326* - prjprm::r0,
327* - prjprm::pv[],
328* - prjprm::phi0,
329* - prjprm::theta0.
330*
331* This signals the initialization routine, celset(), to recompute the
332* returned members of the celprm struct. celset() will reset flag to
333* indicate that this has been done.
334*
335* int offset
336* (Given) If true (non-zero), an offset will be applied to (x,y) to
337* force (x,y) = (0,0) at the fiducial point, (phi_0,theta_0).
338* Default is 0 (false).
339*
340* double phi0
341* (Given) The native longitude, phi_0 [deg], and ...
342*
343* double theta0
344* (Given) ... the native latitude, theta_0 [deg], of the fiducial point,
345* i.e. the point whose celestial coordinates are given in
346* celprm::ref[1:2]. If undefined (set to a magic value by prjini()) the
347* initialization routine, celset(), will set this to a projection-specific
348* default.
349*
350* double ref[4]
351* (Given) The first pair of values should be set to the celestial
352* longitude and latitude of the fiducial point [deg] - typically right
353* ascension and declination. These are given by the CRVALia keywords in
354* FITS.
355*
356* (Given and returned) The second pair of values are the native longitude,
357* phi_p [deg], and latitude, theta_p [deg], of the celestial pole (the
358* latter is the same as the celestial latitude of the native pole,
359* delta_p) and these are given by the FITS keywords LONPOLEa and LATPOLEa
360* (or by PVi_2a and PVi_3a attached to the longitude axis which take
361* precedence if defined).
362*
363* LONPOLEa defaults to phi_0 (see above) if the celestial latitude of the
364* fiducial point of the projection is greater than or equal to the native
365* latitude, otherwise phi_0 + 180 [deg]. (This is the condition for the
366* celestial latitude to increase in the same direction as the native
367* latitude at the fiducial point.) ref[2] may be set to UNDEFINED (from
368* wcsmath.h) or 999.0 to indicate that the correct default should be
369* substituted.
370*
371* theta_p, the native latitude of the celestial pole (or equally the
372* celestial latitude of the native pole, delta_p) is often determined
373* uniquely by CRVALia and LONPOLEa in which case LATPOLEa is ignored.
374* However, in some circumstances there are two valid solutions for theta_p
375* and LATPOLEa is used to choose between them. LATPOLEa is set in ref[3]
376* and the solution closest to this value is used to reset ref[3]. It is
377* therefore legitimate, for example, to set ref[3] to +90.0 to choose the
378* more northerly solution - the default if the LATPOLEa keyword is omitted
379* from the FITS header. For the special case where the fiducial point of
380* the projection is at native latitude zero, its celestial latitude is
381* zero, and LONPOLEa = +/- 90.0 then the celestial latitude of the native
382* pole is not determined by the first three reference values and LATPOLEa
383* specifies it completely.
384*
385* The returned value, celprm::latpreq, specifies how LATPOLEa was actually
386* used.
387*
388* struct prjprm prj
389* (Given and returned) Projection parameters described in the prologue to
390* prj.h.
391*
392* double euler[5]
393* (Returned) Euler angles and associated intermediaries derived from the
394* coordinate reference values. The first three values are the Z-, X-, and
395* Z'-Euler angles [deg], and the remaining two are the cosine and sine of
396* the X-Euler angle.
397*
398* int latpreq
399* (Returned) For informational purposes, this indicates how the LATPOLEa
400* keyword was used
401* - 0: Not required, theta_p (== delta_p) was determined uniquely by the
402* CRVALia and LONPOLEa keywords.
403* - 1: Required to select between two valid solutions of theta_p.
404* - 2: theta_p was specified solely by LATPOLEa.
405*
406* int isolat
407* (Returned) True if the spherical rotation preserves the magnitude of the
408* latitude, which occurs iff the axes of the native and celestial
409* coordinates are coincident. It signals an opportunity to cache
410* intermediate calculations common to all elements in a vector
411* computation.
412*
413* struct wcserr *err
414* (Returned) If enabled, when an error status is returned, this struct
415* contains detailed information about the error, see wcserr_enable().
416*
417* void *padding
418* (An unused variable inserted for alignment purposes only.)
419*
420* Global variable: const char *cel_errmsg[] - Status return messages
421* ------------------------------------------------------------------
422* Status messages to match the status value returned from each function.
423*
424*===========================================================================*/
425
426#ifndef WCSLIB_CEL
427#define WCSLIB_CEL
428
429#include "prj.h"
430
431#ifdef __cplusplus
432extern "C" {
433#endif
434
436 CELENQ_SET = 2, // celprm struct has been set up.
437 CELENQ_BYP = 4, // celprm struct is in bypass mode.
438};
439
440extern const char *cel_errmsg[];
441
443 CELERR_SUCCESS = 0, // Success.
444 CELERR_NULL_POINTER = 1, // Null celprm pointer passed.
445 CELERR_BAD_PARAM = 2, // Invalid projection parameters.
446 CELERR_BAD_COORD_TRANS = 3, // Invalid coordinate transformation
447 // parameters.
448 CELERR_ILL_COORD_TRANS = 4, // Ill-conditioned coordinated transformation
449 // parameters.
450 CELERR_BAD_PIX = 5, // One or more of the (x,y) coordinates were
451 // invalid.
452 CELERR_BAD_WORLD = 6 // One or more of the (lng,lat) coordinates
453 // were invalid.
455
456struct celprm {
457 // Initialization flag (see the prologue above).
458 //--------------------------------------------------------------------------
459 int flag; // Set to zero to force initialization.
460
461 // Parameters to be provided (see the prologue above).
462 //--------------------------------------------------------------------------
463 int offset; // Force (x,y) = (0,0) at (phi_0,theta_0).
464 double phi0, theta0; // Native coordinates of fiducial point.
465 double ref[4]; // Celestial coordinates of fiducial
466 // point and native coordinates of
467 // celestial pole.
468
469 struct prjprm prj; // Projection parameters (see prj.h).
470
471 // Information derived from the parameters supplied.
472 //--------------------------------------------------------------------------
473 double euler[5]; // Euler angles and functions thereof.
474 int latpreq; // LATPOLEa requirement.
475 int isolat; // True if |latitude| is preserved.
476
477 // Error handling
478 //--------------------------------------------------------------------------
479 struct wcserr *err;
480
481 // Private
482 //--------------------------------------------------------------------------
483 void *padding; // (Dummy inserted for alignment purposes.)
484};
485
486// Size of the celprm struct in int units, used by the Fortran wrappers.
487#define CELLEN (sizeof(struct celprm)/sizeof(int))
488
489
490int celini(struct celprm *cel);
491
492int celfree(struct celprm *cel);
493
494int celsize(const struct celprm *cel, int sizes[2]);
495
496int celenq(const struct celprm *cel, int enquiry);
497
498int celprt(const struct celprm *cel);
499
500int celperr(const struct celprm *cel, const char *prefix);
501
502int celset(struct celprm *cel);
503
504int celx2s(struct celprm *cel, int nx, int ny, int sxy, int sll,
505 const double x[], const double y[],
506 double phi[], double theta[], double lng[], double lat[],
507 int stat[]);
508
509int cels2x(struct celprm *cel, int nlng, int nlat, int sll, int sxy,
510 const double lng[], const double lat[],
511 double phi[], double theta[], double x[], double y[],
512 int stat[]);
513
514
515// Deprecated.
516#define celini_errmsg cel_errmsg
517#define celprt_errmsg cel_errmsg
518#define celset_errmsg cel_errmsg
519#define celx2s_errmsg cel_errmsg
520#define cels2x_errmsg cel_errmsg
521
522#ifdef __cplusplus
523}
524#endif
525
526#endif // WCSLIB_CEL
int celini(struct celprm *cel)
Default constructor for the celprm struct.
int celx2s(struct celprm *cel, int nx, int ny, int sxy, int sll, const double x[], const double y[], double phi[], double theta[], double lng[], double lat[], int stat[])
Pixel-to-world celestial transformation.
int celenq(const struct celprm *cel, int enquiry)
enquire about the state of a celprm struct.
const char * cel_errmsg[]
int celfree(struct celprm *cel)
Destructor for the celprm struct.
int cels2x(struct celprm *cel, int nlng, int nlat, int sll, int sxy, const double lng[], const double lat[], double phi[], double theta[], double x[], double y[], int stat[])
World-to-pixel celestial transformation.
int celperr(const struct celprm *cel, const char *prefix)
Print error messages from a celprm struct.
int celsize(const struct celprm *cel, int sizes[2])
Compute the size of a celprm struct.
celenq_enum
Definition cel.h:435
@ CELENQ_SET
Definition cel.h:436
@ CELENQ_BYP
Definition cel.h:437
int celset(struct celprm *cel)
Setup routine for the celprm struct.
cel_errmsg_enum
Definition cel.h:442
@ CELERR_BAD_PARAM
Definition cel.h:445
@ CELERR_BAD_COORD_TRANS
Definition cel.h:446
@ CELERR_BAD_PIX
Definition cel.h:450
@ CELERR_SUCCESS
Definition cel.h:443
@ CELERR_NULL_POINTER
Definition cel.h:444
@ CELERR_BAD_WORLD
Definition cel.h:452
@ CELERR_ILL_COORD_TRANS
Definition cel.h:448
int celprt(const struct celprm *cel)
Print routine for the celprm struct.
Celestial transformation parameters.
Definition cel.h:456
double theta0
Definition cel.h:464
struct wcserr * err
Definition cel.h:479
double ref[4]
Definition cel.h:465
int flag
Definition cel.h:459
int offset
Definition cel.h:463
int latpreq
Definition cel.h:474
int isolat
Definition cel.h:475
double euler[5]
Definition cel.h:473
double phi0
Definition cel.h:464
struct prjprm prj
Definition cel.h:469
void * padding
Definition cel.h:483
Projection parameters.
Definition prj.h:731
Error message handling.
Definition wcserr.h:243