WCSLIB: cel.h Source File

WCSLIB 5.17

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