WCSLIB  5.6
dis.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  WCSLIB 5.6 - an implementation of the FITS WCS standard.
4  Copyright (C) 1995-2015, 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: dis.h,v 5.6 2015/06/14 07:11:24 mcalabre Exp $
26 *=============================================================================
27 *
28 * WCSLIB 5.6 - 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 dis routines
34 * ---------------------------
35 * Routines in this suite implement extensions to the FITS World Coordinate
36 * System (WCS) standard proposed by
37 *
38 = "Representations of distortions in FITS world coordinate systems",
39 = Calabretta, M.R. et al. (WCS Paper IV, draft dated 2004/04/22),
40 = available from http://www.atnf.csiro.au/people/Mark.Calabretta
41 *
42 * In brief, a distortion function may occupy one of two positions in the WCS
43 * algorithm chain. Prior distortions precede the linear transformation
44 * matrix, whether it be PCi_ja or CDi_ja, and sequent distortions follow it.
45 * Paper IV defines FITS keywords used to specify parameters for predefined
46 * distortion functions. The following are used for prior distortions:
47 *
48 = CPDISja ...(string-valued, identifies the distortion function)
49 = DPja ...(record-valued, parameters)
50 = CPERRja ...(floating-valued, maximum value)
51 *
52 * Their counterparts for sequent distortions are CQDISia, DQia, and CQERRia.
53 * An additional floating-valued keyword, DVERRa, records the maximum value of
54 * the combined distortions.
55 *
56 * DPja and DQia are "record-valued". Syntactically, the keyvalues are
57 * standard FITS strings, but they are to be interpreted in a special way.
58 * The general form is
59 *
60 = DPja = '<field-specifier>: <float>'
61 *
62 * where the field-specifier consists of a sequence of fields separated by
63 * periods, and the ': ' between the field-specifier and the floating-point
64 * value is part of the record syntax. For example:
65 *
66 = DP1 = 'AXIS.1: 1'
67 *
68 * Certain field-specifiers are defined for all distortion functions, while
69 * others are defined only for particular distortions. Refer to Paper IV for
70 * further details. wcspih() parses all distortion keywords and loads them
71 * into a disprm struct for analysis by disset() which knows (or possibly does
72 * not know) how to interpret them. Of the Paper IV distortion functions, only
73 * the general Polynomial distortion is currently implemented here.
74 *
75 * The TPV "projection":
76 * ---------------------
77 * The distortion function component of the TPV celestial "projection" is also
78 * supported. The TPV projection, originally proposed in a draft of WCS Paper
79 * II, consists of a TAN projection with sequent polynomial distortion, the
80 * coefficients of which are encoded in PVi_ma keyrecords. Full details may be
81 * found at the registry of FITS conventions:
82 *
83 = http://fits.gsfc.nasa.gov/registry/tpvwcs/tpv.html
84 *
85 * Internally, wcsset() changes TPV to a TAN projection, translates the PVi_ma
86 * keywords to DQia and loads them into a disprm struct. These DQia keyrecords
87 * have the form
88 *
89 = DQia = 'TPV.m: <value>'
90 *
91 * where i, a, m, and the value for each DQia match each PVi_ma. Consequently,
92 * WCSLIB would handle a FITS header containing these keywords, along with
93 * CQDISja = 'TPV' and a few other required keywords.
94 *
95 * Simple Imaging Polynomial (SIP):
96 * --------------------------------
97 * These routines also support the Simple Imaging Polynomial (SIP), which arose
98 * as an application of an early draft of Paper IV. It is described in detail
99 * in
100 *
101 = http://fits.gsfc.nasa.gov/registry/sip.html
102 *
103 * SIP, which is defined only as a prior distortion for 2D celestial images,
104 * has the interesting feature that it records an approximation to the inverse
105 * polynomial distortion function. This is used by disx2p() to provide an
106 * initial estimate for its more precise iterative inversion. The
107 * special-purpose keywords used by SIP are parsed and translated by wcspih()
108 * as follows:
109 *
110 = A_p_q = <value> -> DP1 = 'SIP.FWD.p_q: <value>'
111 = AP_p_q = <value> -> DP1 = 'SIP.REV.p_q: <value>'
112 = B_p_q = <value> -> DP2 = 'SIP.FWD.p_q: <value>'
113 = BP_p_q = <value> -> DP2 = 'SIP.REV.p_q: <value>'
114 = A_DMAX = <value> -> DPERR1 = <value>
115 = B_DMAX = <value> -> DPERR2 = <value>
116 *
117 * SIP's A_ORDER and B_ORDER keywords are not used. WCSLIB would recognise a
118 * FITS header containing the above keywords, along with CPDISja = 'SIP' and a
119 * few other required keywords.
120 *
121 * Template Polynomial Distortion (TPD):
122 * -------------------------------------
123 * The "Template Polynomial Distortion" (TPD) is a superset of the TPV and SIP
124 * polynomial distortions that also supports 1D usage and inversions. Like TPV
125 * and SIP, the form of the polynomial is fixed (the "template") and only the
126 * coefficients for the required terms are set non-zero. TPD generalizes TPV
127 * in going to 9th degree, and SIP by accomodating TPV's linear and radial
128 * terms. Within WCSLIB, both TPV and SIP are implemented as special cases of
129 * TPD. Indeed, TPD was developed precisely for that purpose. Moreover, the
130 * general Polynomial distortion is translated and implemented internally as
131 * TPD whenever possible.
132 *
133 * However, WCSLIB also recognizes 'TPD' as a distortion function in its own
134 * right (i.e. a recognized value of CPDISja or CQDISia), for use as both prior
135 * and sequent distortions. Its DPja and DQia keyrecords have the form
136 *
137 = DPja = 'TPD.FWD.m: <value>'
138 = DPja = 'TPD.REV.m: <value>'
139 *
140 * for the forward and reverse distortion functions.
141 *
142 * In typical applications, TPD is considerably faster than the general
143 * Polynomial distortion, though nowhere near as powerful. As TPD has a finite
144 * and not too large number of possible terms (60), the coefficients for each
145 * can be stored (by disset()) in a fixed location in the disprm::dparm[]
146 * array. A large part of the speedup then arises from evaluating the
147 * polynomial using Horner's scheme.
148 *
149 * Separate implementations for polynomials of each degree, and conditionals
150 * for 1D polynomials and 2D polynomials with and without the radial variable,
151 * ensure that unused terms mostly do not impose a significant computational
152 * overhead.
153 *
154 * The TPD terms are as follows
155 *
156 = 0: 1 4: xx 12: xxxx 24: xxxxxx 40: xxxxxxxx
157 = 5: xy 13: xxxy 25: xxxxxy 41: xxxxxxxy
158 = 1: x 6: yy 14: xxyy 26: xxxxyy 42: xxxxxxyy
159 = 2: y 15: xyyy 27: xxxyyy 43: xxxxxyyy
160 = 3: r 7: xxx 16: yyyy 28: xxyyyy 44: xxxxyyyy
161 = 8: xxy 29: xyyyyy 45: xxxyyyyy
162 = 9: xyy 17: xxxxx 30: yyyyyy 46: xxyyyyyy
163 = 10: yyy 18: xxxxy 47: xyyyyyyy
164 = 11: rrr 19: xxxyy 31: xxxxxxx 48: yyyyyyyy
165 = 20: xxyyy 32: xxxxxxy
166 = 21: xyyyy 33: xxxxxyy 49: xxxxxxxxx
167 = 22: yyyyy 34: xxxxyyy 50: xxxxxxxxy
168 = 23: rrrrr 35: xxxyyyy 51: xxxxxxxyy
169 = 36: xxyyyyy 52: xxxxxxyyy
170 = 37: xyyyyyy 53: xxxxxyyyy
171 = 38: yyyyyyy 54: xxxxyyyyy
172 = 39: rrrrrrr 55: xxxyyyyyy
173 = 56: xxyyyyyyy
174 = 57: xyyyyyyyy
175 = 58: yyyyyyyyy
176 = 59: rrrrrrrrr
177 *
178 * where r = sqrt(xx + yy). Note that even powers of r are excluded since they
179 * can be accomodated by powers of (xx + yy).
180 *
181 * TPV uses all terms up to 39. The m in its PVi_ma keywords translates
182 * directly to the TPD coefficient number.
183 *
184 * SIP uses all terms except for 0, 3, 11, 23, 39, and 59, with terms 1 and 2
185 * only used for the inverse. Its A_p_q, etc. keywords must be translated
186 * using a map.
187 *
188 * Summary of the dis routines:
189 * ----------------------------
190 * These routines apply the distortion functions defined by the extension to
191 * the FITS WCS standard proposed in Paper IV. They are based on the disprm
192 * struct which contains all information needed for the computations. The
193 * struct contains some members that must be set by the user, and others that
194 * are maintained by these routines, somewhat like a C++ class but with no
195 * encapsulation.
196 *
197 * disndp(), dpfill(), disini(), discpy(), and disfree() are provided to manage
198 * the disprm struct, and another, disprt(), prints its contents.
199 *
200 * A setup routine, disset(), computes intermediate values in the disprm struct
201 * from parameters in it that were supplied by the user. The struct always
202 * needs to be set up by disset(), though disset() need not be called
203 * explicitly - refer to the explanation of disprm::flag.
204 *
205 * disp2x() and disx2p() implement the WCS distortion functions, disp2x() using
206 * separate functions, such as dispoly() and tpd7(), to do the computation.
207 *
208 * An auxiliary routine, diswarp(), computes various measures of the distortion
209 * over a specified range of coordinates.
210 *
211 * PLEASE NOTE:
212 * Distortions are not currently handled by wcsbth(), wcssub(), wcscompare(),
213 * or wcshdo().
214 *
215 *
216 * disndp() - Memory allocation for DPja and DQia
217 * ----------------------------------------------
218 * disndp() changes the value of NDPMAX (default 256). This global variable
219 * controls the number of dpkey structs, for holding DPja or DQia keyvalues,
220 * that disini() should allocate space for.
221 *
222 * PLEASE NOTE: This function is not thread-safe.
223 *
224 * Given:
225 * n int Value of NDPMAX; ignored if < 0.
226 *
227 * Function return value:
228 * int Current value of NDPMAX.
229 *
230 *
231 * dpfill() - Fill the contents of a dpkey struct
232 * ----------------------------------------------
233 * dpfill() is a utility routine to aid in filling the contents of the dpkey
234 * struct. No checks are done on the validity of the inputs.
235 *
236 * WCS Paper IV specifies the syntax of a record-valued keyword as
237 *
238 = keyword = '<field-specifier>: <float>'
239 *
240 * However, some DPja and DQia record values, such as those of DPja.NAXES and
241 * DPja.AXIS.j, are intrinsically integer-valued. While FITS header parsers
242 * are not expected to know in advance which of DPja and DQia are integral and
243 * which are floating point, if the record's value parses as an integer (i.e.
244 * without decimal point or exponent), then preferably enter it into the dpkey
245 * struct as an integer. Either way, it doesn't matter as disset() accepts
246 * either data type for all record values.
247 *
248 * Given and returned:
249 * dp struct dpkey*
250 * Store for DPja and DQia keyvalues.
251 *
252 * Given:
253 * keyword const char *
254 * field const char *
255 * These arguments are concatenated with an intervening
256 * "." to construct the full record field name, i.e.
257 * including the keyword name, DPja or DQia (but
258 * excluding the colon delimiter which is NOT part of the
259 * name). Either may be given as a NULL pointer. Set
260 * both NULL to omit setting this component of the
261 * struct.
262 *
263 * j int Axis number (1-relative), i.e. the j in DPja or
264 * i in DQia. Can be given as 0, in which case the axis
265 * number will be obtained from the keyword component of
266 * the field name which must either have been given or
267 * preset.
268 *
269 * type int Data type of the record's value
270 * 0: Integer,
271 * 1: Floating point.
272 *
273 * ival int For type == 0, the integer value of the record.
274 *
275 * fval double For type == 1, the floating point value of the record.
276 *
277 * Function return value:
278 * int Status return value:
279 * 0: Success.
280 *
281 *
282 * disini() - Default constructor for the disprm struct
283 * ----------------------------------------------------
284 * disini() allocates memory for arrays in a disprm struct and sets all members
285 * of the struct to default values. Memory is allocated for up to NDPMAX DPja
286 * or DQia keywords per WCS representation. This may be changed via disndp()
287 * before disini() is called.
288 *
289 * PLEASE NOTE: every disprm struct must be initialized by disini(), possibly
290 * repeatedly. On the first invokation, and only the first invokation,
291 * disprm::flag must be set to -1 to initialize memory management, regardless
292 * of whether disini() will actually be used to allocate memory.
293 *
294 * Given:
295 * alloc int If true, allocate memory unconditionally for arrays in
296 * the disprm struct.
297 *
298 * If false, it is assumed that pointers to these arrays
299 * have been set by the user except if they are null
300 * pointers in which case memory will be allocated for
301 * them regardless. (In other words, setting alloc true
302 * saves having to initalize these pointers to zero.)
303 *
304 * naxis int The number of world coordinate axes, used to determine
305 * array sizes.
306 *
307 * Given and returned:
308 * dis struct disprm*
309 * Distortion function parameters. Note that, in order
310 * to initialize memory management disprm::flag must be
311 * set to -1 when dis is initialized for the first time
312 * (memory leaks may result if it had already been
313 * initialized).
314 *
315 * Function return value:
316 * int Status return value:
317 * 0: Success.
318 * 1: Null disprm pointer passed.
319 * 2: Memory allocation failed.
320 *
321 * For returns > 1, a detailed error message is set in
322 * disprm::err if enabled, see wcserr_enable().
323 *
324 *
325 * discpy() - Copy routine for the disprm struct
326 * ---------------------------------------------
327 * discpy() does a deep copy of one disprm struct to another, using disini() to
328 * allocate memory unconditionally for its arrays if required. Only the
329 * "information to be provided" part of the struct is copied; a call to
330 * disset() is required to initialize the remainder.
331 *
332 * Given:
333 * alloc int If true, allocate memory unconditionally for arrays in
334 * the destination. Otherwise, it is assumed that
335 * pointers to these arrays have been set by the user
336 * except if they are null pointers in which case memory
337 * will be allocated for them regardless.
338 *
339 * dissrc const struct disprm*
340 * Struct to copy from.
341 *
342 * Given and returned:
343 * disdst struct disprm*
344 * Struct to copy to. disprm::flag should be set to -1
345 * if disdst was not previously initialized (memory leaks
346 * may result if it was previously initialized).
347 *
348 * Function return value:
349 * int Status return value:
350 * 0: Success.
351 * 1: Null disprm pointer passed.
352 * 2: Memory allocation failed.
353 *
354 * For returns > 1, a detailed error message is set in
355 * disprm::err if enabled, see wcserr_enable().
356 *
357 *
358 * disfree() - Destructor for the disprm struct
359 * --------------------------------------------
360 * disfree() frees memory allocated for the disprm arrays by disini().
361 * disini() keeps a record of the memory it allocates and disfree() will only
362 * attempt to free this.
363 *
364 * PLEASE NOTE: disfree() must not be invoked on a disprm struct that was not
365 * initialized by disini().
366 *
367 * Given:
368 * dis struct disprm*
369 * Distortion function parameters.
370 *
371 * Function return value:
372 * int Status return value:
373 * 0: Success.
374 * 1: Null disprm pointer passed.
375 *
376 *
377 * disprt() - Print routine for the disprm struct
378 * ----------------------------------------------
379 * disprt() prints the contents of a disprm struct using wcsprintf(). Mainly
380 * intended for diagnostic purposes.
381 *
382 * Given:
383 * dis const struct disprm*
384 * Distortion function parameters.
385 *
386 * Function return value:
387 * int Status return value:
388 * 0: Success.
389 * 1: Null disprm pointer passed.
390 *
391 *
392 * disset() - Setup routine for the disprm struct
393 * ----------------------------------------------
394 * disset(), sets up the disprm struct according to information supplied within
395 * it - refer to the explanation of disprm::flag.
396 *
397 * Note that this routine need not be called directly; it will be invoked by
398 * disp2x() and disx2p() if the disprm::flag is anything other than a
399 * predefined magic value.
400 *
401 * Given and returned:
402 * dis struct disprm*
403 * Distortion function parameters.
404 *
405 * Function return value:
406 * int Status return value:
407 * 0: Success.
408 * 1: Null disprm pointer passed.
409 * 2: Memory allocation failed.
410 * 3: Invalid parameter.
411 *
412 * For returns > 1, a detailed error message is set in
413 * disprm::err if enabled, see wcserr_enable().
414 *
415 *
416 * disp2x() - Apply distortion function
417 * ------------------------------------
418 * disp2x() applies the distortion functions. By definition, the distortion
419 * is in the pixel-to-world direction.
420 *
421 * Depending on the point in the algorithm chain at which it is invoked,
422 * disp2x() may transform pixel coordinates to corrected pixel coordinates, or
423 * intermediate pixel coordinates to corrected intermediate pixel coordinates,
424 * or image coordinates to corrected image coordinates.
425 *
426 *
427 * Given and returned:
428 * dis struct disprm*
429 * Distortion function parameters.
430 *
431 * Given:
432 * rawcrd const double[naxis]
433 * Array of coordinates.
434 *
435 * Returned:
436 * discrd double[naxis]
437 * Array of coordinates to which the distortion functions
438 * have been applied.
439 *
440 * Function return value:
441 * int Status return value:
442 * 0: Success.
443 * 1: Null disprm pointer passed.
444 * 2: Memory allocation failed.
445 * 3: Invalid parameter.
446 * 4: Distort error.
447 *
448 * For returns > 1, a detailed error message is set in
449 * disprm::err if enabled, see wcserr_enable().
450 *
451 *
452 * disx2p() - Apply de-distortion function
453 * ---------------------------------------
454 * disx2p() applies the inverse of the distortion functions. By definition,
455 * the de-distortion is in the world-to-pixel direction.
456 *
457 * Depending on the point in the algorithm chain at which it is invoked,
458 * disx2p() may transform corrected pixel coordinates to pixel coordinates, or
459 * corrected intermediate pixel coordinates to intermediate pixel coordinates,
460 * or corrected image coordinates to image coordinates.
461 *
462 * disx2p() iteratively solves for the inverse using disp2x(). It assumes
463 * that the distortion is small and the functions are well-behaved, being
464 * continuous and with continuous derivatives. Also that, to first order
465 * in the neighbourhood of the solution, discrd[j] ~= a + b*rawcrd[j], i.e.
466 * independent of rawcrd[i], where i != j. This is effectively equivalent to
467 * assuming that the distortion functions are separable to first order.
468 * Furthermore, a is assumed to be small, and b close to unity.
469 *
470 * If disprm::disx2p() is defined, then disx2p() uses it to provide an initial
471 * estimate for its more precise iterative inversion.
472 *
473 * Given and returned:
474 * dis struct disprm*
475 * Distortion function parameters.
476 *
477 * Given:
478 * discrd const double[naxis]
479 * Array of coordinates.
480 *
481 * Returned:
482 * rawcrd double[naxis]
483 * Array of coordinates to which the inverse distortion
484 * functions have been applied.
485 *
486 * Function return value:
487 * int Status return value:
488 * 0: Success.
489 * 1: Null disprm pointer passed.
490 * 2: Memory allocation failed.
491 * 3: Invalid parameter.
492 * 5: De-distort error.
493 *
494 * For returns > 1, a detailed error message is set in
495 * disprm::err if enabled, see wcserr_enable().
496 *
497 *
498 * diswarp() - Compute measures of distortion
499 * ------------------------------------------
500 * diswarp() computes various measures of the distortion over a specified range
501 * of coordinates.
502 *
503 * For prior distortions, the measures may be interpreted simply as an offset
504 * in pixel coordinates. For sequent distortions, the interpretation depends
505 * on the nature of the linear transformation matrix (PCi_ja or CDi_ja). If
506 * the latter introduces a scaling, then the measures will also be scaled.
507 * Note also that the image domain, which is rectangular in pixel coordinates,
508 * may be rotated, skewed, and/or stretched in intermediate pixel coordinates,
509 * and in general cannot be defined using pixblc[] and pixtrc[].
510 *
511 * PLEASE NOTE: the measures of total distortion may be essentially meaningless
512 * if there are multiple sequent distortions with different scaling.
513 *
514 * See also linwarp().
515 *
516 * Given and returned:
517 * dis struct disprm*
518 * Distortion function parameters.
519 *
520 * Given:
521 * pixblc const double[naxis]
522 * Start of the range of pixel coordinates (for prior
523 * distortions), or intermediate pixel coordinates (for
524 * sequent distortions). May be specified as a NULL
525 * pointer which is interpreted as (1,1,...).
526 *
527 * pixtrc const double[naxis]
528 * End of the range of pixel coordinates (prior) or
529 * intermediate pixel coordinates (sequent).
530 *
531 * pixsamp const double[naxis]
532 * If positive or zero, the increment on the particular
533 * axis, starting at pixblc[]. Zero is interpreted as a
534 * unit increment. pixsamp may also be specified as a
535 * NULL pointer which is interpreted as all zeroes, i.e.
536 * unit increments on all axes.
537 *
538 * If negative, the grid size on the particular axis (the
539 * absolute value being rounded to the nearest integer).
540 * For example, if pixsamp is (-128.0,-128.0,...) then
541 * each axis will be sampled at 128 points between
542 * pixblc[] and pixtrc[] inclusive. Use caution when
543 * using this option on non-square images.
544 *
545 * Returned:
546 * nsamp int* The number of pixel coordinates sampled.
547 *
548 * Can be specified as a NULL pointer if not required.
549 *
550 * maxdis double[naxis]
551 * For each individual distortion function, the
552 * maximum absolute value of the distortion.
553 *
554 * Can be specified as a NULL pointer if not required.
555 *
556 * maxtot double* For the combination of all distortion functions, the
557 * maximum absolute value of the distortion.
558 *
559 * Can be specified as a NULL pointer if not required.
560 *
561 * avgdis double[naxis]
562 * For each individual distortion function, the
563 * mean value of the distortion.
564 *
565 * Can be specified as a NULL pointer if not required.
566 *
567 * avgtot double* For the combination of all distortion functions, the
568 * mean value of the distortion.
569 *
570 * Can be specified as a NULL pointer if not required.
571 *
572 * rmsdis double[naxis]
573 * For each individual distortion function, the
574 * root mean square deviation of the distortion.
575 *
576 * Can be specified as a NULL pointer if not required.
577 *
578 * rmstot double* For the combination of all distortion functions, the
579 * root mean square deviation of the distortion.
580 *
581 * Can be specified as a NULL pointer if not required.
582 *
583 * Function return value:
584 * int Status return value:
585 * 0: Success.
586 * 1: Null disprm pointer passed.
587 * 2: Memory allocation failed.
588 * 3: Invalid parameter.
589 * 4: Distort error.
590 *
591 *
592 * disprm struct - Distortion parameters
593 * -------------------------------------
594 * The disprm struct contains all of the information required to apply a set of
595 * distortion functions. It consists of certain members that must be set by
596 * the user ("given") and others that are set by the WCSLIB routines
597 * ("returned"). While the addresses of the arrays themselves may be set by
598 * disini() if it (optionally) allocates memory, their contents must be set by
599 * the user.
600 *
601 * int flag
602 * (Given and returned) This flag must be set to zero whenever any of the
603 * following members of the disprm struct are set or modified:
604 *
605 * - disprm::naxis,
606 * - disprm::dtype,
607 * - disprm::ndp,
608 * - disprm::dp.
609 *
610 * This signals the initialization routine, disset(), to recompute the
611 * returned members of the disprm struct. disset() will reset flag to
612 * indicate that this has been done.
613 *
614 * PLEASE NOTE: flag must be set to -1 when disini() is called for the
615 * first time for a particular disprm struct in order to initialize memory
616 * management. It must ONLY be used on the first initialization otherwise
617 * memory leaks may result.
618 *
619 * int naxis
620 * (Given or returned) Number of pixel and world coordinate elements.
621 *
622 * If disini() is used to initialize the disprm struct (as would normally
623 * be the case) then it will set naxis from the value passed to it as a
624 * function argument. The user should not subsequently modify it.
625 *
626 * char (*dtype)[72]
627 * (Given) Pointer to the first element of an array of char[72] containing
628 * the name of the distortion function for each axis.
629 *
630 * int ndp
631 * (Given) The number of entries in the disprm::dp[] array.
632 *
633 * int ndpmax
634 * (Given) The length of the disprm::dp[] array.
635 *
636 * ndpmax will be set by disini() if it allocates memory for disprm::dp[],
637 * otherwise it must be set by the user. See also disndp().
638 *
639 * struct dpkey dp
640 * (Given) Address of the first element of an array of length ndpmax of
641 * dpkey structs.
642 *
643 * As a FITS header parser encounters each DPja or DQia keyword it should
644 * load it into a dpkey struct in the array and increment ndp. However,
645 * note that a single disprm struct must hold only DPja or DQia keyvalues,
646 * not both. disset() interprets them as required by the particular
647 * distortion function.
648 *
649 * double *maxdis
650 * (Given) Pointer to the first element of an array of double specifying
651 * the maximum absolute value of the distortion for each axis computed over
652 * the whole image.
653 *
654 * It is not necessary to reset the disprm struct (via disset()) when
655 * disprm::maxdis is changed.
656 *
657 * double totdis
658 * (Given) The maximum absolute value of the combination of all distortion
659 * functions specified as an offset in pixel coordinates computed over the
660 * whole image.
661 *
662 * It is not necessary to reset the disprm struct (via disset()) when
663 * disprm::totdis is changed.
664 *
665 * int **axmap
666 * (Returned) Pointer to the first element of an array of int* containing
667 * pointers to the first elements of the axis mapping arrays for each axis.
668 *
669 * An axis mapping associates the independent variables of a distortion
670 * function with the 1-relative image axis number. For example, consider
671 * an image with a spectrum on the first axis, followed by RA, Dec, and
672 * time axes. For a distortion in (RA,Dec) and no distortion on the
673 * spectral or time axes, the axis mapping arrays, axmap[j][], would be
674 *
675 = j=0: [0, 0, 0, 0] ...no distortion on spectral axis,
676 = 1: [2, 3, 0, 0] ...RA distortion depends on RA and Dec,
677 = 2: [3, 2, 0, 0] ...Dec distortion depends on Dec and RA,
678 = 3: [0, 0, 0, 0] ...no distortion on time axis,
679 *
680 * where zero indicates that there is no corresponding independent
681 * variable.
682 *
683 * int *Nhat
684 * (Returned) Pointer to the first element of an array of int* containing
685 * the number of coordinate axes that form the independent variables of the
686 * distortion function.
687 *
688 * double **offset
689 * (Returned) Pointer to the first element of an array of double*
690 * containing an offset used to renormalize the independent variables of
691 * the distortion function for each axis.
692 *
693 * The offsets are subtracted from the independent variables before
694 * scaling.
695 *
696 * double **scale
697 * (Returned) Pointer to the first element of an array of double*
698 * containing a scale used to renormalize the independent variables of the
699 * distortion function for each axis.
700 *
701 * The scale is applied to the independent variables after the offsets are
702 * subtracted.
703 *
704 * int **iparm
705 * (Returned) Pointer to the first element of an array of int*
706 * containing pointers to the first elements of the arrays of integer
707 * distortion parameters for each axis.
708 *
709 * double **dparm
710 * (Returned) Pointer to the first element of an array of double*
711 * containing pointers to the first elements of the arrays of floating
712 * point distortion parameters for each axis.
713 *
714 * int i_naxis
715 * (Returned) Dimension of the internal arrays (normally equal to naxis).
716 *
717 * int ndis
718 * (Returned) The number of distortion functions.
719 *
720 * struct wcserr *err
721 * (Returned) If enabled, when an error status is returned, this struct
722 * contains detailed information about the error, see wcserr_enable().
723 *
724 * int (**disp2x)(DISP2X_ARGS)
725 * (For internal use only.)
726 * int (**disx2p)(DISX2P_ARGS)
727 * (For internal use only.)
728 * double *tmpmem
729 * (For internal use only.)
730 * int m_flag
731 * (For internal use only.)
732 * int m_naxis
733 * (For internal use only.)
734 * char (*m_dtype)[72]
735 * (For internal use only.)
736 * double **m_dp
737 * (For internal use only.)
738 * double *m_maxdis
739 * (For internal use only.)
740 *
741 *
742 * dpkey struct - Store for DPja and DQia keyvalues
743 * ------------------------------------------------
744 * The dpkey struct is used to pass the parsed contents of DPja or DQia
745 * keyrecords to disset() via the disprm struct. A disprm struct must hold
746 * only DPja or DQia keyvalues, not both.
747 *
748 * All members of this struct are to be set by the user.
749 *
750 * char field[72]
751 * (Given) The full field name of the record, including the keyword name.
752 * Note that the colon delimiter separating the field name and the value in
753 * record-valued keyvalues is not part of the field name. For example, in
754 * the following:
755 *
756 = DP3A = 'AXIS.1: 2'
757 *
758 * the full record field name is "DP3A.AXIS.1", and the record's value
759 * is 2.
760 *
761 * int j
762 * (Given) Axis number (1-relative), i.e. the j in DPja or i in DQia.
763 *
764 * int type
765 * (Given) The data type of the record's value
766 * - 0: Integer (stored as an int),
767 * - 1: Floating point (stored as a double).
768 *
769 * union value
770 * (Given) A union comprised of
771 * - dpkey::ival,
772 * - dpkey::fval,
773 *
774 * the record's value.
775 *
776 *
777 * Global variable: const char *dis_errmsg[] - Status return messages
778 * ------------------------------------------------------------------
779 * Error messages to match the status value returned from each function.
780 *
781 *===========================================================================*/
782 
783 #ifndef WCSLIB_DIS
784 #define WCSLIB_DIS
785 
786 #ifdef __cplusplus
787 extern "C" {
788 #endif
789 
790 
791 extern const char *dis_errmsg[];
792 
794  DISERR_SUCCESS = 0, /* Success. */
795  DISERR_NULL_POINTER = 1, /* Null disprm pointer passed. */
796  DISERR_MEMORY = 2, /* Memory allocation failed. */
797  DISERR_BAD_PARAM = 3, /* Invalid parameter value. */
798  DISERR_DISTORT = 4, /* Distortion error. */
799  DISERR_DEDISTORT = 5 /* De-distortion error. */
800 };
801 
802 /* For use in declaring distortion function prototypes (= DISX2P_ARGS). */
803 #define DISP2X_ARGS int inverse, const int iparm[], const double dparm[], \
804 int ncrd, const double rawcrd[], double *discrd
805 
806 /* For use in declaring de-distortion function prototypes (= DISP2X_ARGS). */
807 #define DISX2P_ARGS int inverse, const int iparm[], const double dparm[], \
808 int ncrd, const double discrd[], double *rawcrd
809 
810 
811 /* Struct used for storing DPja and DQia keyvalues. */
812 struct dpkey {
813  char field[72]; /* Full record field name (no colon). */
814  int j; /* Axis number, as in DPja (1-relative). */
815  int type; /* Data type of value. */
816  union {
817  int i; /* Integer record value. */
818  double f; /* Floating point record value. */
819  } value; /* Record value. */
820 };
821 
822 /* Size of the dpkey struct in int units, used by the Fortran wrappers. */
823 #define DPLEN (sizeof(struct dpkey)/sizeof(int))
824 
825 
826 struct disprm {
827  /* Initialization flag (see the prologue above). */
828  /*------------------------------------------------------------------------*/
829  int flag; /* Set to zero to force initialization. */
830 
831  /* Parameters to be provided (see the prologue above). */
832  /*------------------------------------------------------------------------*/
833  int naxis; /* The number of pixel coordinate elements, */
834  /* given by NAXIS. */
835  char (*dtype)[72]; /* For each axis, the distortion type. */
836  int ndp; /* Number of DPja or DQia keywords, and the */
837  int ndpmax; /* number for which space was allocated. */
838  struct dpkey *dp; /* DPja or DQia keyvalues (not both). */
839  double *maxdis; /* For each axis, the maximum distortion. */
840  double totdis; /* The maximum combined distortion. */
841 
842  /* Information derived from the parameters supplied. */
843  /*------------------------------------------------------------------------*/
844  int **axmap; /* For each axis, the axis mapping array. */
845  int *Nhat; /* For each axis, the number of coordinate */
846  /* axes that form the independent variables */
847  /* of the distortion function. */
848  double **offset; /* For each axis, renormalization offsets. */
849  double **scale; /* For each axis, renormalization scales. */
850  int **iparm; /* For each axis, the array of integer */
851  /* distortion parameters. */
852  double **dparm; /* For each axis, the array of floating */
853  /* point distortion parameters. */
854  int i_naxis; /* Dimension of the internal arrays. */
855  int ndis; /* The number of distortion functions. */
856 
857  /* Error handling, if enabled. */
858  /*------------------------------------------------------------------------*/
859  struct wcserr *err;
860 
861  /* Private - the remainder are for internal use. */
862  /*------------------------------------------------------------------------*/
863  int (**disp2x)(DISP2X_ARGS); /* For each axis, pointers to the */
864  int (**disx2p)(DISX2P_ARGS); /* distortion function and its inverse. */
865 
866  double *tmpmem;
867 
868  int m_flag, m_naxis; /* The remainder are for memory management. */
869  char (*m_dtype)[72];
870  struct dpkey *m_dp;
871  double *m_maxdis;
872 };
873 
874 /* Size of the disprm struct in int units, used by the Fortran wrappers. */
875 #define DISLEN (sizeof(struct disprm)/sizeof(int))
876 
877 
878 int disndp(int n);
879 
880 int dpfill(struct dpkey *dp, const char *keyword, const char *field, int j,
881  int type, int ival, double fval);
882 
883 int disini(int alloc, int naxis, struct disprm *dis);
884 
885 int discpy(int alloc, const struct disprm *dissrc, struct disprm *disdst);
886 
887 int disfree(struct disprm *dis);
888 
889 int disprt(const struct disprm *dis);
890 
891 int disset(struct disprm *dis);
892 
893 int disp2x(struct disprm *dis, const double rawcrd[], double discrd[]);
894 
895 int disx2p(struct disprm *dis, const double discrd[], double rawcrd[]);
896 
897 int diswarp(struct disprm *dis, const double pixblc[], const double pixtrc[],
898  const double pixsamp[], int *nsamp,
899  double maxdis[], double *maxtot,
900  double avgdis[], double *avgtot,
901  double rmsdis[], double *rmstot);
902 
903 
904 /* Specialist distortion functions (internal use only). */
905 int polyset(int j, struct disprm *dis);
906 int pol2tpd(int j, struct disprm *dis);
907 int dispoly(DISP2X_ARGS);
908 
909 int tpvset(int j, struct disprm *dis);
910 int sipset(int j, struct disprm *dis);
911 
912 int tpdset(int j, struct disprm *dis);
913 int tpd1(DISP2X_ARGS);
914 int tpd2(DISP2X_ARGS);
915 int tpd3(DISP2X_ARGS);
916 int tpd4(DISP2X_ARGS);
917 int tpd5(DISP2X_ARGS);
918 int tpd6(DISP2X_ARGS);
919 int tpd7(DISP2X_ARGS);
920 int tpd8(DISP2X_ARGS);
921 int tpd9(DISP2X_ARGS);
922 
923 #ifdef __cplusplus
924 }
925 #endif
926 
927 #endif /* WCSLIB_DIS */
int type
Definition: dis.h:815
int flag
Definition: dis.h:829
Store for DPja and DQia keyvalues.
Definition: dis.h:812
int discpy(int alloc, const struct disprm *dissrc, struct disprm *disdst)
Copy routine for the disprm struct.
int ** iparm
Definition: dis.h:850
Definition: dis.h:798
const char * dis_errmsg[]
Status return messages.
int ** axmap
Definition: dis.h:844
int disp2x(struct disprm *dis, const double rawcrd[], double discrd[])
Apply distortion function.
int tpdset(int j, struct disprm *dis)
(Internal use only.)
double ** scale
Definition: dis.h:849
int tpd8(DISP2X_ARGS)
(Internal use only.)
int tpd5(DISP2X_ARGS)
(Internal use only.)
int pol2tpd(int j, struct disprm *dis)
(Internal use only.)
Error message handling.
Definition: wcserr.h:225
int disx2p(struct disprm *dis, const double discrd[], double rawcrd[])
Apply de-distortion function.
Definition: dis.h:797
int dpfill(struct dpkey *dp, const char *keyword, const char *field, int j, int type, int ival, double fval)
Fill the contents of a dpkey struct.
int disset(struct disprm *dis)
Setup routine for the disprm struct.
int naxis
Definition: dis.h:833
struct dpkey * dp
Definition: dis.h:838
int m_flag
Definition: dis.h:868
Definition: dis.h:799
int ndis
Definition: dis.h:855
Distortion parameters.
Definition: dis.h:826
char field[72]
Definition: dis.h:813
int dispoly(DISP2X_ARGS)
(Internal use only.)
int ndp
Definition: dis.h:836
int tpd1(DISP2X_ARGS)
(Internal use only.)
int tpd9(DISP2X_ARGS)
(Internal use only.)
char(* m_dtype)[72]
Definition: dis.h:869
int j
Definition: dis.h:814
Definition: dis.h:795
int sipset(int j, struct disprm *dis)
(Internal use only.)
int tpd3(DISP2X_ARGS)
(Internal use only.)
int * Nhat
Definition: dis.h:845
int disfree(struct disprm *dis)
Destructor for the disprm struct.
dis_errmsg_enum
Definition: dis.h:793
int m_naxis
Definition: dis.h:868
int disprt(const struct disprm *dis)
Print routine for the disprm struct.
double * tmpmem
Definition: dis.h:866
int tpd7(DISP2X_ARGS)
(Internal use only.)
int i_naxis
Definition: dis.h:854
double * maxdis
Definition: dis.h:839
double totdis
Definition: dis.h:840
int tpd2(DISP2X_ARGS)
(Internal use only.)
int(** disx2p)(DISX2P_ARGS)
Definition: dis.h:864
Definition: dis.h:794
int tpd4(DISP2X_ARGS)
(Internal use only.)
int tpvset(int j, struct disprm *dis)
(Internal use only.)
struct wcserr * err
Definition: dis.h:859
char(* dtype)[72]
Definition: dis.h:835
int disini(int alloc, int naxis, struct disprm *dis)
Default constructor for the disprm struct.
union dpkey::@0 value
double f
Definition: dis.h:818
Definition: dis.h:796
struct dpkey * m_dp
Definition: dis.h:870
double * m_maxdis
Definition: dis.h:871
int diswarp(struct disprm *dis, const double pixblc[], const double pixtrc[], const double pixsamp[], int *nsamp, double maxdis[], double *maxtot, double avgdis[], double *avgtot, double rmsdis[], double *rmstot)
Compute measures of distortion.
double ** offset
Definition: dis.h:848
#define DISX2P_ARGS
Definition: dis.h:807
int(** disp2x)(DISP2X_ARGS)
Definition: dis.h:863
int polyset(int j, struct disprm *dis)
(Internal use only.)
int ndpmax
Definition: dis.h:837
int tpd6(DISP2X_ARGS)
(Internal use only.)
int disndp(int n)
Memory allocation for DPja and DQia.
int i
Definition: dis.h:817
#define DISP2X_ARGS
Definition: dis.h:803
double ** dparm
Definition: dis.h:852