WCSLIB: spc.h Source File

WCSLIB 5.17

spc.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: spc.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 spc routines
34 * ---------------------------
35 * Routines in this suite implement the part of the FITS World Coordinate
36 * System (WCS) standard that deals with spectral 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 spectral coordinates in FITS",
42 = Greisen, E.W., Calabretta, M.R., Valdes, F.G., & Allen, S.L.
43 = 2006, A&A, 446, 747 (WCS Paper III)
44 *
45 * These routines define methods to be used for computing spectral world
46 * coordinates from intermediate world coordinates (a linear transformation
47 * of image pixel coordinates), and vice versa. They are based on the spcprm
48 * struct which contains all information needed for the computations. The
49 * struct contains some members that must be set by the user, and others that
50 * are maintained by these routines, somewhat like a C++ class but with no
51 * encapsulation.
52 *
53 * Routine spcini() is provided to initialize the spcprm struct with default
54 * values, spcfree() reclaims any memory that may have been allocated to store
55 * an error message, and spcprt() prints its contents.
56 *
57 * spcperr() prints the error message(s) (if any) stored in a spcprm struct.
58 *
59 * A setup routine, spcset(), computes intermediate values in the spcprm struct
60 * from parameters in it that were supplied by the user. The struct always
61 * needs to be set up by spcset() but it need not be called explicitly - refer
62 * to the explanation of spcprm::flag.
63 *
64 * spcx2s() and spcs2x() implement the WCS spectral coordinate transformations.
65 * In fact, they are high level driver routines for the lower level spectral
66 * coordinate transformation routines described in spx.h.
67 *
68 * A number of routines are provided to aid in analysing or synthesising sets
69 * of FITS spectral axis keywords:
70 *
71 * - spctype() checks a spectral CTYPEia keyword for validity and returns
72 * information derived from it.
73 *
74 * - Spectral keyword analysis routine spcspxe() computes the values of the
75 * X-type spectral variables for the S-type variables supplied.
76 *
77 * - Spectral keyword synthesis routine, spcxpse(), computes the S-type
78 * variables for the X-types supplied.
79 *
80 * - Given a set of spectral keywords, a translation routine, spctrne(),
81 * produces the corresponding set for the specified spectral CTYPEia.
82 *
83 * - spcaips() translates AIPS-convention spectral CTYPEia and VELREF
84 * keyvalues.
85 *
86 * Spectral variable types - S, P, and X:
87 * --------------------------------------
88 * A few words of explanation are necessary regarding spectral variable types
89 * in FITS.
90 *
91 * Every FITS spectral axis has three associated spectral variables:
92 *
93 * S-type: the spectral variable in which coordinates are to be
94 * expressed. Each S-type is encoded as four characters and is
95 * linearly related to one of four basic types as follows:
96 *
97 * F: frequency
98 * 'FREQ': frequency
99 * 'AFRQ': angular frequency
100 * 'ENER': photon energy
101 * 'WAVN': wave number
102 * 'VRAD': radio velocity
103 *
104 * W: wavelength in vacuo
105 * 'WAVE': wavelength
106 * 'VOPT': optical velocity
107 * 'ZOPT': redshift
108 *
109 * A: wavelength in air
110 * 'AWAV': wavelength in air
111 *
112 * V: velocity
113 * 'VELO': relativistic velocity
114 * 'BETA': relativistic beta factor
115 *
116 * The S-type forms the first four characters of the CTYPEia keyvalue,
117 * and CRVALia and CDELTia are expressed as S-type quantities so that
118 * they provide a first-order approximation to the S-type variable at
119 * the reference point.
120 *
121 * Note that 'AFRQ', angular frequency, is additional to the variables
122 * defined in WCS Paper III.
123 *
124 * P-type: the basic spectral variable (F, W, A, or V) with which the
125 * S-type variable is associated (see list above).
126 *
127 * For non-grism axes, the P-type is encoded as the eighth character of
128 * CTYPEia.
129 *
130 * X-type: the basic spectral variable (F, W, A, or V) for which the
131 * spectral axis is linear, grisms excluded (see below).
132 *
133 * For non-grism axes, the X-type is encoded as the sixth character of
134 * CTYPEia.
135 *
136 * Grisms: Grism axes have normal S-, and P-types but the axis is linear,
137 * not in any spectral variable, but in a special "grism parameter".
138 * The X-type spectral variable is either W or A for grisms in vacuo or
139 * air respectively, but is encoded as 'w' or 'a' to indicate that an
140 * additional transformation is required to convert to or from the
141 * grism parameter. The spectral algorithm code for grisms also has a
142 * special encoding in CTYPEia, either 'GRI' (in vacuo) or 'GRA' (in air).
143 *
144 * In the algorithm chain, the non-linear transformation occurs between the
145 * X-type and the P-type variables; the transformation between P-type and
146 * S-type variables is always linear.
147 *
148 * When the P-type and X-type variables are the same, the spectral axis is
149 * linear in the S-type variable and the second four characters of CTYPEia
150 * are blank. This can never happen for grism axes.
151 *
152 * As an example, correlating radio spectrometers always produce spectra that
153 * are regularly gridded in frequency; a redshift scale on such a spectrum is
154 * non-linear. The required value of CTYPEia would be 'ZOPT-F2W', where the
155 * desired S-type is 'ZOPT' (redshift), the P-type is necessarily 'W'
156 * (wavelength), and the X-type is 'F' (frequency) by the nature of the
157 * instrument.
158 *
159 * Argument checking:
160 * ------------------
161 * The input spectral values are only checked for values that would result in
162 * floating point exceptions. In particular, negative frequencies and
163 * wavelengths are allowed, as are velocities greater than the speed of
164 * light. The same is true for the spectral parameters - rest frequency and
165 * wavelength.
166 *
167 * Accuracy:
168 * ---------
169 * No warranty is given for the accuracy of these routines (refer to the
170 * copyright notice); intending users must satisfy for themselves their
171 * adequacy for the intended purpose. However, closure effectively to within
172 * double precision rounding error was demonstrated by test routine tspc.c
173 * which accompanies this software.
174 *
175 *
176 * spcini() - Default constructor for the spcprm struct
177 * ----------------------------------------------------
178 * spcini() sets all members of a spcprm struct to default values. It should
179 * be used to initialize every spcprm struct.
180 *
181 * Given and returned:
182 * spc struct spcprm*
183 * Spectral transformation parameters.
184 *
185 * Function return value:
186 * int Status return value:
187 * 0: Success.
188 * 1: Null spcprm pointer passed.
189 *
190 *
191 * spcfree() - Destructor for the spcprm struct
192 * --------------------------------------------
193 * spcfree() frees any memory that may have been allocated to store an error
194 * message in the spcprm struct.
195 *
196 * Given:
197 * spc struct spcprm*
198 * Spectral transformation parameters.
199 *
200 * Function return value:
201 * int Status return value:
202 * 0: Success.
203 * 1: Null spcprm pointer passed.
204 *
205 *
206 * spcprt() - Print routine for the spcprm struct
207 * ----------------------------------------------
208 * spcprt() prints the contents of a spcprm struct using wcsprintf(). Mainly
209 * intended for diagnostic purposes.
210 *
211 * Given:
212 * spc const struct spcprm*
213 * Spectral transformation parameters.
214 *
215 * Function return value:
216 * int Status return value:
217 * 0: Success.
218 * 1: Null spcprm pointer passed.
219 *
220 *
221 * spcperr() - Print error messages from a spcprm struct
222 * -----------------------------------------------------
223 * spcperr() prints the error message(s) (if any) stored in a spcprm struct.
224 * If there are no errors then nothing is printed. It uses wcserr_prt(), q.v.
225 *
226 * Given:
227 * spc const struct spcprm*
228 * Spectral transformation parameters.
229 *
230 * prefix const char *
231 * If non-NULL, each output line will be prefixed with
232 * this string.
233 *
234 * Function return value:
235 * int Status return value:
236 * 0: Success.
237 * 1: Null spcprm pointer passed.
238 *
239 *
240 * spcset() - Setup routine for the spcprm struct
241 * ----------------------------------------------
242 * spcset() sets up a spcprm struct according to information supplied within
243 * it.
244 *
245 * Note that this routine need not be called directly; it will be invoked by
246 * spcx2s() and spcs2x() if spcprm::flag is anything other than a predefined
247 * magic value.
248 *
249 * Given and returned:
250 * spc struct spcprm*
251 * Spectral transformation parameters.
252 *
253 * Function return value:
254 * int Status return value:
255 * 0: Success.
256 * 1: Null spcprm pointer passed.
257 * 2: Invalid spectral parameters.
258 *
259 * For returns > 1, a detailed error message is set in
260 * spcprm::err if enabled, see wcserr_enable().
261 *
262 *
263 * spcx2s() - Transform to spectral coordinates
264 * --------------------------------------------
265 * spcx2s() transforms intermediate world coordinates to spectral coordinates.
266 *
267 * Given and returned:
268 * spc struct spcprm*
269 * Spectral transformation parameters.
270 *
271 * Given:
272 * nx int Vector length.
273 *
274 * sx int Vector stride.
275 *
276 * sspec int Vector stride.
277 *
278 * x const double[]
279 * Intermediate world coordinates, in SI units.
280 *
281 * Returned:
282 * spec double[] Spectral coordinates, in SI units.
283 *
284 * stat int[] Status return value status for each vector element:
285 * 0: Success.
286 * 1: Invalid value of x.
287 *
288 * Function return value:
289 * int Status return value:
290 * 0: Success.
291 * 1: Null spcprm pointer passed.
292 * 2: Invalid spectral parameters.
293 * 3: One or more of the x coordinates were invalid,
294 * as indicated by the stat vector.
295 *
296 * For returns > 1, a detailed error message is set in
297 * spcprm::err if enabled, see wcserr_enable().
298 *
299 *
300 * spcs2x() - Transform spectral coordinates
301 * -----------------------------------------
302 * spcs2x() transforms spectral world coordinates to intermediate world
303 * coordinates.
304 *
305 * Given and returned:
306 * spc struct spcprm*
307 * Spectral transformation parameters.
308 *
309 * Given:
310 * nspec int Vector length.
311 *
312 * sspec int Vector stride.
313 *
314 * sx int Vector stride.
315 *
316 * spec const double[]
317 * Spectral coordinates, in SI units.
318 *
319 * Returned:
320 * x double[] Intermediate world coordinates, in SI units.
321 *
322 * stat int[] Status return value status for each vector element:
323 * 0: Success.
324 * 1: Invalid value of spec.
325 *
326 * Function return value:
327 * int Status return value:
328 * 0: Success.
329 * 1: Null spcprm pointer passed.
330 * 2: Invalid spectral parameters.
331 * 4: One or more of the spec coordinates were
332 * invalid, as indicated by the stat vector.
333 *
334 * For returns > 1, a detailed error message is set in
335 * spcprm::err if enabled, see wcserr_enable().
336 *
337 *
338 * spctype() - Spectral CTYPEia keyword analysis
339 * ---------------------------------------------
340 * spctype() checks whether a CTYPEia keyvalue is a valid spectral axis type
341 * and if so returns information derived from it relating to the associated S-,
342 * P-, and X-type spectral variables (see explanation above).
343 *
344 * The return arguments are guaranteed not be modified if CTYPEia is not a
345 * valid spectral type; zero-pointers may be specified for any that are not of
346 * interest.
347 *
348 * A deprecated form of this function, spctyp(), lacks the wcserr** parameter.
349 *
350 * Given:
351 * ctype const char[9]
352 * The CTYPEia keyvalue, (eight characters with null
353 * termination).
354 *
355 * Returned:
356 * stype char[] The four-letter name of the S-type spectral variable
357 * copied or translated from ctype. If a non-zero
358 * pointer is given, the array must accomodate a null-
359 * terminated string of length 5.
360 *
361 * scode char[] The three-letter spectral algorithm code copied or
362 * translated from ctype. Logarithmic ('LOG') and
363 * tabular ('TAB') codes are also recognized. If a
364 * non-zero pointer is given, the array must accomodate a
365 * null-terminated string of length 4.
366 *
367 * sname char[] Descriptive name of the S-type spectral variable.
368 * If a non-zero pointer is given, the array must
369 * accomodate a null-terminated string of length 22.
370 *
371 * units char[] SI units of the S-type spectral variable. If a
372 * non-zero pointer is given, the array must accomodate a
373 * null-terminated string of length 8.
374 *
375 * ptype char* Character code for the P-type spectral variable
376 * derived from ctype, one of 'F', 'W', 'A', or 'V'.
377 *
378 * xtype char* Character code for the X-type spectral variable
379 * derived from ctype, one of 'F', 'W', 'A', or 'V'.
380 * Also, 'w' and 'a' are synonymous to 'W' and 'A' for
381 * grisms in vacuo and air respectively. Set to 'L' or
382 * 'T' for logarithmic ('LOG') and tabular ('TAB') axes.
383 *
384 * restreq int* Multivalued flag that indicates whether rest
385 * frequency or wavelength is required to compute
386 * spectral variables for this CTYPEia:
387 * 0: Not required.
388 * 1: Required for the conversion between S- and
389 * P-types (e.g. 'ZOPT-F2W').
390 * 2: Required for the conversion between P- and
391 * X-types (e.g. 'BETA-W2V').
392 * 3: Required for the conversion between S- and
393 * P-types, and between P- and X-types, but not
394 * between S- and X-types (this applies only for
395 * 'VRAD-V2F', 'VOPT-V2W', and 'ZOPT-V2W').
396 * Thus the rest frequency or wavelength is required for
397 * spectral coordinate computations (i.e. between S- and
398 * X-types) only if restreq%3 != 0.
399 *
400 * err struct wcserr **
401 * If enabled, for function return values > 1, this
402 * struct will contain a detailed error message, see
403 * wcserr_enable(). May be NULL if an error message is
404 * not desired. Otherwise, the user is responsible for
405 * deleting the memory allocated for the wcserr struct.
406 *
407 * Function return value:
408 * int Status return value:
409 * 0: Success.
410 * 2: Invalid spectral parameters (not a spectral
411 * CTYPEia).
412 *
413 *
414 * spcspxe() - Spectral keyword analysis
415 * ------------------------------------
416 * spcspxe() analyses the CTYPEia and CRVALia FITS spectral axis keyword values
417 * and returns information about the associated X-type spectral variable.
418 *
419 * A deprecated form of this function, spcspx(), lacks the wcserr** parameter.
420 *
421 * Given:
422 * ctypeS const char[9]
423 * Spectral axis type, i.e. the CTYPEia keyvalue, (eight
424 * characters with null termination). For non-grism
425 * axes, the character code for the P-type spectral
426 * variable in the algorithm code (i.e. the eighth
427 * character of CTYPEia) may be set to '?' (it will not
428 * be reset).
429 *
430 * crvalS double Value of the S-type spectral variable at the reference
431 * point, i.e. the CRVALia keyvalue, SI units.
432 *
433 * restfrq,
434 * restwav double Rest frequency [Hz] and rest wavelength in vacuo [m],
435 * only one of which need be given, the other should be
436 * set to zero.
437 *
438 * Returned:
439 * ptype char* Character code for the P-type spectral variable
440 * derived from ctypeS, one of 'F', 'W', 'A', or 'V'.
441 *
442 * xtype char* Character code for the X-type spectral variable
443 * derived from ctypeS, one of 'F', 'W', 'A', or 'V'.
444 * Also, 'w' and 'a' are synonymous to 'W' and 'A' for
445 * grisms in vacuo and air respectively; crvalX and dXdS
446 * (see below) will conform to these.
447 *
448 * restreq int* Multivalued flag that indicates whether rest frequency
449 * or wavelength is required to compute spectral
450 * variables for this CTYPEia, as for spctype().
451 *
452 * crvalX double* Value of the X-type spectral variable at the reference
453 * point, SI units.
454 *
455 * dXdS double* The derivative, dX/dS, evaluated at the reference
456 * point, SI units. Multiply the CDELTia keyvalue by
457 * this to get the pixel spacing in the X-type spectral
458 * coordinate.
459 *
460 * err struct wcserr **
461 * If enabled, for function return values > 1, this
462 * struct will contain a detailed error message, see
463 * wcserr_enable(). May be NULL if an error message is
464 * not desired. Otherwise, the user is responsible for
465 * deleting the memory allocated for the wcserr struct.
466 *
467 * Function return value:
468 * int Status return value:
469 * 0: Success.
470 * 2: Invalid spectral parameters.
471 *
472 *
473 * spcxpse() - Spectral keyword synthesis
474 * -------------------------------------
475 * spcxpse(), for the spectral axis type specified and the value provided for
476 * the X-type spectral variable at the reference point, deduces the value of
477 * the FITS spectral axis keyword CRVALia and also the derivative dS/dX which
478 * may be used to compute CDELTia. See above for an explanation of the S-,
479 * P-, and X-type spectral variables.
480 *
481 * A deprecated form of this function, spcxps(), lacks the wcserr** parameter.
482 *
483 * Given:
484 * ctypeS const char[9]
485 * The required spectral axis type, i.e. the CTYPEia
486 * keyvalue, (eight characters with null termination).
487 * For non-grism axes, the character code for the P-type
488 * spectral variable in the algorithm code (i.e. the
489 * eighth character of CTYPEia) may be set to '?' (it
490 * will not be reset).
491 *
492 * crvalX double Value of the X-type spectral variable at the reference
493 * point (N.B. NOT the CRVALia keyvalue), SI units.
494 *
495 * restfrq,
496 * restwav double Rest frequency [Hz] and rest wavelength in vacuo [m],
497 * only one of which need be given, the other should be
498 * set to zero.
499 *
500 * Returned:
501 * ptype char* Character code for the P-type spectral variable
502 * derived from ctypeS, one of 'F', 'W', 'A', or 'V'.
503 *
504 * xtype char* Character code for the X-type spectral variable
505 * derived from ctypeS, one of 'F', 'W', 'A', or 'V'.
506 * Also, 'w' and 'a' are synonymous to 'W' and 'A' for
507 * grisms; crvalX and cdeltX must conform to these.
508 *
509 * restreq int* Multivalued flag that indicates whether rest frequency
510 * or wavelength is required to compute spectral
511 * variables for this CTYPEia, as for spctype().
512 *
513 * crvalS double* Value of the S-type spectral variable at the reference
514 * point (i.e. the appropriate CRVALia keyvalue), SI
515 * units.
516 *
517 * dSdX double* The derivative, dS/dX, evaluated at the reference
518 * point, SI units. Multiply this by the pixel spacing
519 * in the X-type spectral coordinate to get the CDELTia
520 * keyvalue.
521 *
522 * err struct wcserr **
523 * If enabled, for function return values > 1, this
524 * struct will contain a detailed error message, see
525 * wcserr_enable(). May be NULL if an error message is
526 * not desired. Otherwise, the user is responsible for
527 * deleting the memory allocated for the wcserr struct.
528 *
529 * Function return value:
530 * int Status return value:
531 * 0: Success.
532 * 2: Invalid spectral parameters.
533 *
534 *
535 * spctrne() - Spectral keyword translation
536 * ---------------------------------------
537 * spctrne() translates a set of FITS spectral axis keywords into the
538 * corresponding set for the specified spectral axis type. For example, a
539 * 'FREQ' axis may be translated into 'ZOPT-F2W' and vice versa.
540 *
541 * A deprecated form of this function, spctrn(), lacks the wcserr** parameter.
542 *
543 * Given:
544 * ctypeS1 const char[9]
545 * Spectral axis type, i.e. the CTYPEia keyvalue, (eight
546 * characters with null termination). For non-grism
547 * axes, the character code for the P-type spectral
548 * variable in the algorithm code (i.e. the eighth
549 * character of CTYPEia) may be set to '?' (it will not
550 * be reset).
551 *
552 * crvalS1 double Value of the S-type spectral variable at the reference
553 * point, i.e. the CRVALia keyvalue, SI units.
554 *
555 * cdeltS1 double Increment of the S-type spectral variable at the
556 * reference point, SI units.
557 *
558 * restfrq,
559 * restwav double Rest frequency [Hz] and rest wavelength in vacuo [m],
560 * only one of which need be given, the other should be
561 * set to zero. Neither are required if the translation
562 * is between wave-characteristic types, or between
563 * velocity-characteristic types. E.g., required for
564 * 'FREQ' -> 'ZOPT-F2W', but not required for
565 * 'VELO-F2V' -> 'ZOPT-F2W'.
566 *
567 * Given and returned:
568 * ctypeS2 char[9] Required spectral axis type (eight characters with
569 * null termination). The first four characters are
570 * required to be given and are never modified. The
571 * remaining four, the algorithm code, are completely
572 * determined by, and must be consistent with, ctypeS1
573 * and the first four characters of ctypeS2. A non-zero
574 * status value will be returned if they are inconsistent
575 * (see below). However, if the final three characters
576 * are specified as "???", or if just the eighth
577 * character is specified as '?', the correct algorithm
578 * code will be substituted (applies for grism axes as
579 * well as non-grism).
580 *
581 * Returned:
582 * crvalS2 double* Value of the new S-type spectral variable at the
583 * reference point, i.e. the new CRVALia keyvalue, SI
584 * units.
585 *
586 * cdeltS2 double* Increment of the new S-type spectral variable at the
587 * reference point, i.e. the new CDELTia keyvalue, SI
588 * units.
589 *
590 * err struct wcserr **
591 * If enabled, for function return values > 1, this
592 * struct will contain a detailed error message, see
593 * wcserr_enable(). May be NULL if an error message is
594 * not desired. Otherwise, the user is responsible for
595 * deleting the memory allocated for the wcserr struct.
596 *
597 * Function return value:
598 * int Status return value:
599 * 0: Success.
600 * 2: Invalid spectral parameters.
601 *
602 * A status value of 2 will be returned if restfrq or
603 * restwav are not specified when required, or if ctypeS1
604 * or ctypeS2 are self-inconsistent, or have different
605 * spectral X-type variables.
606 *
607 *
608 * spcaips() - Translate AIPS-convention spectral keywords
609 * -------------------------------------------------------
610 * spcaips() translates AIPS-convention spectral CTYPEia and VELREF keyvalues.
611 *
612 * Given:
613 * ctypeA const char[9]
614 * CTYPEia keyvalue possibly containing an
615 * AIPS-convention spectral code (eight characters, need
616 * not be null-terminated).
617 *
618 * velref int AIPS-convention VELREF code. It has the following
619 * integer values:
620 * 1: LSR kinematic, originally described simply as
621 * "LSR" without distinction between the kinematic
622 * and dynamic definitions.
623 * 2: Barycentric, originally described as "HEL"
624 * meaning heliocentric.
625 * 3: Topocentric, originally described as "OBS"
626 * meaning geocentric but widely interpreted as
627 * topocentric.
628 * AIPS++ extensions to VELREF are also recognized:
629 * 4: LSR dynamic.
630 * 5: Geocentric.
631 * 6: Source rest frame.
632 * 7: Galactocentric.
633 *
634 * For an AIPS 'VELO' axis, a radio convention velocity
635 * (VRAD) is denoted by adding 256 to VELREF, otherwise
636 * an optical velocity (VOPT) is indicated (this is not
637 * applicable to 'FREQ' or 'FELO' axes). Setting velref
638 * to 0 or 256 chooses between optical and radio velocity
639 * without specifying a Doppler frame, provided that a
640 * frame is encoded in ctypeA. If not, i.e. for
641 * ctypeA = 'VELO', ctype will be returned as 'VELO'.
642 *
643 * VELREF takes precedence over CTYPEia in defining the
644 * Doppler frame, e.g.
645 *
646 = ctypeA = 'VELO-HEL'
647 = velref = 1
648 *
649 * returns ctype = 'VOPT' with specsys set to 'LSRK'.
650 *
651 * If omitted from the header, the default value of
652 * VELREF is 0.
653 *
654 * Returned:
655 * ctype char[9] Translated CTYPEia keyvalue, or a copy of ctypeA if no
656 * translation was performed (in which case any trailing
657 * blanks in ctypeA will be replaced with nulls).
658 *
659 * specsys char[9] Doppler reference frame indicated by VELREF or else
660 * by CTYPEia with value corresponding to the SPECSYS
661 * keyvalue in the FITS WCS standard. May be returned
662 * blank if neither specifies a Doppler frame, e.g.
663 * ctypeA = 'FELO' and velref%256 == 0.
664 *
665 * Function return value:
666 * int Status return value:
667 * -1: No translation required (not an error).
668 * 0: Success.
669 * 2: Invalid value of VELREF.
670 *
671 *
672 * spcprm struct - Spectral transformation parameters
673 * --------------------------------------------------
674 * The spcprm struct contains information required to transform spectral
675 * coordinates. It consists of certain members that must be set by the user
676 * ("given") and others that are set by the WCSLIB routines ("returned"). Some
677 * of the latter are supplied for informational purposes while others are for
678 * internal use only.
679 *
680 * int flag
681 * (Given and returned) This flag must be set to zero whenever any of the
682 * following spcprm structure members are set or changed:
683 *
684 * - spcprm::type,
685 * - spcprm::code,
686 * - spcprm::crval,
687 * - spcprm::restfrq,
688 * - spcprm::restwav,
689 * - spcprm::pv[].
690 *
691 * This signals the initialization routine, spcset(), to recompute the
692 * returned members of the spcprm struct. spcset() will reset flag to
693 * indicate that this has been done.
694 *
695 * char type[8]
696 * (Given) Four-letter spectral variable type, e.g "ZOPT" for
697 * CTYPEia = 'ZOPT-F2W'. (Declared as char[8] for alignment reasons.)
698 *
699 * char code[4]
700 * (Given) Three-letter spectral algorithm code, e.g "F2W" for
701 * CTYPEia = 'ZOPT-F2W'.
702 *
703 * double crval
704 * (Given) Reference value (CRVALia), SI units.
705 *
706 * double restfrq
707 * (Given) The rest frequency [Hz], and ...
708 *
709 * double restwav
710 * (Given) ... the rest wavelength in vacuo [m], only one of which need be
711 * given, the other should be set to zero. Neither are required if the
712 * X and S spectral variables are both wave-characteristic, or both
713 * velocity-characteristic, types.
714 *
715 * double pv[7]
716 * (Given) Grism parameters for 'GRI' and 'GRA' algorithm codes:
717 * - 0: G, grating ruling density.
718 * - 1: m, interference order.
719 * - 2: alpha, angle of incidence [deg].
720 * - 3: n_r, refractive index at the reference wavelength, lambda_r.
721 * - 4: n'_r, dn/dlambda at the reference wavelength, lambda_r (/m).
722 * - 5: epsilon, grating tilt angle [deg].
723 * - 6: theta, detector tilt angle [deg].
724 *
725 * The remaining members of the spcprm struct are maintained by spcset() and
726 * must not be modified elsewhere:
727 *
728 * double w[6]
729 * (Returned) Intermediate values:
730 * - 0: Rest frequency or wavelength (SI).
731 * - 1: The value of the X-type spectral variable at the reference point
732 * (SI units).
733 * - 2: dX/dS at the reference point (SI units).
734 * The remainder are grism intermediates.
735 *
736 * int isGrism
737 * (Returned) Grism coordinates?
738 * - 0: no,
739 * - 1: in vacuum,
740 * - 2: in air.
741 *
742 * int padding1
743 * (An unused variable inserted for alignment purposes only.)
744 *
745 * struct wcserr *err
746 * (Returned) If enabled, when an error status is returned, this struct
747 * contains detailed information about the error, see wcserr_enable().
748 *
749 * void *padding2
750 * (An unused variable inserted for alignment purposes only.)
751 * int (*spxX2P)(SPX_ARGS)
752 * (Returned) The first and ...
753 * int (*spxP2S)(SPX_ARGS)
754 * (Returned) ... the second of the pointers to the transformation
755 * functions in the two-step algorithm chain X -> P -> S in the
756 * pixel-to-spectral direction where the non-linear transformation is from
757 * X to P. The argument list, SPX_ARGS, is defined in spx.h.
758 *
759 * int (*spxS2P)(SPX_ARGS)
760 * (Returned) The first and ...
761 * int (*spxP2X)(SPX_ARGS)
762 * (Returned) ... the second of the pointers to the transformation
763 * functions in the two-step algorithm chain S -> P -> X in the
764 * spectral-to-pixel direction where the non-linear transformation is from
765 * P to X. The argument list, SPX_ARGS, is defined in spx.h.
766 *
767 *
768 * Global variable: const char *spc_errmsg[] - Status return messages
769 * ------------------------------------------------------------------
770 * Error messages to match the status value returned from each function.
771 *
772 *===========================================================================*/
773
774 #ifndef WCSLIB_SPC
775 #define WCSLIB_SPC
776
777 #include "spx.h"
778
779 #ifdef __cplusplus
780 extern "C" {
781 #endif
782
783
784 extern const char *spc_errmsg[];
785
786 enum spc_errmsg_enum {
787 SPCERR_NO_CHANGE = -1, /* No change. */
788 SPCERR_SUCCESS = 0, /* Success. */
789 SPCERR_NULL_POINTER = 1, /* Null spcprm pointer passed. */
790 SPCERR_BAD_SPEC_PARAMS = 2, /* Invalid spectral parameters. */
791 SPCERR_BAD_X = 3, /* One or more of x coordinates were
792 invalid. */
793 SPCERR_BAD_SPEC = 4 /* One or more of the spec coordinates were
794 invalid. */
795 };
796
797 struct spcprm {
798 /* Initialization flag (see the prologue above). */
799 /*------------------------------------------------------------------------*/
800 int flag; /* Set to zero to force initialization. */
801
802 /* Parameters to be provided (see the prologue above). */
803 /*------------------------------------------------------------------------*/
804 char type[8]; /* Four-letter spectral variable type. */
805 char code[4]; /* Three-letter spectral algorithm code. */
806
807 double crval; /* Reference value (CRVALia), SI units. */
808 double restfrq; /* Rest frequency, Hz. */
809 double restwav; /* Rest wavelength, m. */
810
811 double pv[7]; /* Grism parameters: */
812 /* 0: G, grating ruling density. */
813 /* 1: m, interference order. */
814 /* 2: alpha, angle of incidence. */
815 /* 3: n_r, refractive index at lambda_r. */
816 /* 4: n'_r, dn/dlambda at lambda_r. */
817 /* 5: epsilon, grating tilt angle. */
818 /* 6: theta, detector tilt angle. */
819
820 /* Information derived from the parameters supplied. */
821 /*------------------------------------------------------------------------*/
822 double w[6]; /* Intermediate values. */
823 /* 0: Rest frequency or wavelength (SI). */
824 /* 1: CRVALX (SI units). */
825 /* 2: CDELTX/CDELTia = dX/dS (SI units). */
826 /* The remainder are grism intermediates. */
827
828 int isGrism; /* Grism coordinates? 1: vacuum, 2: air. */
829 int padding1; /* (Dummy inserted for alignment purposes.) */
830
831 /* Error handling */
832 /*------------------------------------------------------------------------*/
833 struct wcserr *err;
834
835 /* Private */
836 /*------------------------------------------------------------------------*/
837 void *padding2; /* (Dummy inserted for alignment purposes.) */
838 int (*spxX2P)(SPX_ARGS); /* Pointers to the transformation functions */
839 int (*spxP2S)(SPX_ARGS); /* in the two-step algorithm chain in the */
840 /* pixel-to-spectral direction. */
841
842 int (*spxS2P)(SPX_ARGS); /* Pointers to the transformation functions */
843 int (*spxP2X)(SPX_ARGS); /* in the two-step algorithm chain in the */
844 /* spectral-to-pixel direction. */
845 };
846
847 /* Size of the spcprm struct in int units, used by the Fortran wrappers. */
848 #define SPCLEN (sizeof(struct spcprm)/sizeof(int))
849
850
851 int spcini(struct spcprm *spc);
852
853 int spcfree(struct spcprm *spc);
854
855 int spcprt(const struct spcprm *spc);
856
857 int spcperr(const struct spcprm *spc, const char *prefix);
858
859 int spcset(struct spcprm *spc);
860
861 int spcx2s(struct spcprm *spc, int nx, int sx, int sspec,
862 const double x[], double spec[], int stat[]);
863
864 int spcs2x(struct spcprm *spc, int nspec, int sspec, int sx,
865 const double spec[], double x[], int stat[]);
866
867 int spctype(const char ctype[9], char stype[], char scode[], char sname[],
868 char units[], char *ptype, char *xtype, int *restreq,
869 struct wcserr **err);
870
871 int spcspxe(const char ctypeS[9], double crvalS, double restfrq,
872 double restwav, char *ptype, char *xtype, int *restreq,
873 double *crvalX, double *dXdS, struct wcserr **err);
874
875 int spcxpse(const char ctypeS[9], double crvalX, double restfrq,
876 double restwav, char *ptype, char *xtype, int *restreq,
877 double *crvalS, double *dSdX, struct wcserr **err);
878
879 int spctrne(const char ctypeS1[9], double crvalS1, double cdeltS1,
880 double restfrq, double restwav, char ctypeS2[9], double *crvalS2,
881 double *cdeltS2, struct wcserr **err);
882
883 int spcaips(const char ctypeA[9], int velref, char ctype[9], char specsys[9]);
884
885
886 /* Deprecated. */
887 #define spcini_errmsg spc_errmsg
888 #define spcprt_errmsg spc_errmsg
889 #define spcset_errmsg spc_errmsg
890 #define spcx2s_errmsg spc_errmsg
891 #define spcs2x_errmsg spc_errmsg
892
893 int spctyp(const char ctype[9], char stype[], char scode[], char sname[],
894 char units[], char *ptype, char *xtype, int *restreq);
895 int spcspx(const char ctypeS[9], double crvalS, double restfrq,
896 double restwav, char *ptype, char *xtype, int *restreq,
897 double *crvalX, double *dXdS);
898 int spcxps(const char ctypeS[9], double crvalX, double restfrq,
899 double restwav, char *ptype, char *xtype, int *restreq,
900 double *crvalS, double *dSdX);
901 int spctrn(const char ctypeS1[9], double crvalS1, double cdeltS1,
902 double restfrq, double restwav, char ctypeS2[9], double *crvalS2,
903 double *cdeltS2);
904
905 #ifdef __cplusplus
906 }
907 #endif
908
909 #endif /* WCSLIB_SPC */
spcprt
int spcprt(const struct spcprm *spc)
Print routine for the spcprm struct.
spcxpse
int spcxpse(const char ctypeS[9], double crvalX, double restfrq, double restwav, char *ptype, char *xtype, int *restreq, double *crvalS, double *dSdX, struct wcserr **err)
Spectral keyword synthesis.
spcprm::isGrism
int isGrism
Definition: spc.h:828
spcprm::crval
double crval
Definition: spc.h:807
SPCERR_SUCCESS
Definition: spc.h:788
spcs2x
int spcs2x(struct spcprm *spc, int nspec, int sspec, int sx, const double spec[], double x[], int stat[])
Transform spectral coordinates.
wcserr
Error message handling.
Definition: wcserr.h:225
spcfree
int spcfree(struct spcprm *spc)
Destructor for the spcprm struct.
spcprm::w
double w[6]
Definition: spc.h:822
SPX_ARGS
#define SPX_ARGS
For use in declaring spectral conversion function prototypes.
Definition: spx.h:510
spcspxe
int spcspxe(const char ctypeS[9], double crvalS, double restfrq, double restwav, char *ptype, char *xtype, int *restreq, double *crvalX, double *dXdS, struct wcserr **err)
Spectral keyword analysis.
SPCERR_BAD_SPEC_PARAMS
Definition: spc.h:790
spcprm
Spectral transformation parameters.
Definition: spc.h:797
spcspx
int spcspx(const char ctypeS[9], double crvalS, double restfrq, double restwav, char *ptype, char *xtype, int *restreq, double *crvalX, double *dXdS)
spcprm::restfrq
double restfrq
Definition: spc.h:808
spc_errmsg_enum
spc_errmsg_enum
Definition: spc.h:786
spctype
int spctype(const char ctype[9], char stype[], char scode[], char sname[], char units[], char *ptype, char *xtype, int *restreq, struct wcserr **err)
Spectral CTYPEia keyword analysis.
spcxps
int spcxps(const char ctypeS[9], double crvalX, double restfrq, double restwav, char *ptype, char *xtype, int *restreq, double *crvalS, double *dSdX)
spcprm::spxX2P
int(* spxX2P)(SPX_ARGS)
Definition: spc.h:838
spcprm::code
char code[4]
Definition: spc.h:805
SPCERR_BAD_SPEC
Definition: spc.h:793
spcprm::type
char type[8]
Definition: spc.h:804
spcini
int spcini(struct spcprm *spc)
Default constructor for the spcprm struct.
spcaips
int spcaips(const char ctypeA[9], int velref, char ctype[9], char specsys[9])
Translate AIPS-convention spectral keywords.
spcprm::restwav
double restwav
Definition: spc.h:809
spcprm::padding2
void * padding2
Definition: spc.h:837
spctrne
int spctrne(const char ctypeS1[9], double crvalS1, double cdeltS1, double restfrq, double restwav, char ctypeS2[9], double *crvalS2, double *cdeltS2, struct wcserr **err)
Spectral keyword translation.
spctyp
int spctyp(const char ctype[9], char stype[], char scode[], char sname[], char units[], char *ptype, char *xtype, int *restreq)
spc_errmsg
const char * spc_errmsg[]
Status return messages.
spcx2s
int spcx2s(struct spcprm *spc, int nx, int sx, int sspec, const double x[], double spec[], int stat[])
Transform to spectral coordinates.
spcprm::flag
int flag
Definition: spc.h:800
spcprm::spxP2X
int(* spxP2X)(SPX_ARGS)
Definition: spc.h:843
spcprm::pv
double pv[7]
Definition: spc.h:811
spctrn
int spctrn(const char ctypeS1[9], double crvalS1, double cdeltS1, double restfrq, double restwav, char ctypeS2[9], double *crvalS2, double *cdeltS2)
spcprm::padding1
int padding1
Definition: spc.h:829
spcperr
int spcperr(const struct spcprm *spc, const char *prefix)
Print error messages from a spcprm struct.
spcprm::err
struct wcserr * err
Definition: spc.h:833
spcprm::spxP2S
int(* spxP2S)(SPX_ARGS)
Definition: spc.h:839
SPCERR_NO_CHANGE
Definition: spc.h:787
SPCERR_NULL_POINTER
Definition: spc.h:789
spcset
int spcset(struct spcprm *spc)
Setup routine for the spcprm struct.
SPCERR_BAD_X
Definition: spc.h:791
spcprm::spxS2P
int(* spxS2P)(SPX_ARGS)
Definition: spc.h:842
spx.h