WCSLIB: spc.h Source File

WCSLIB 6.2

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