WCSLIB 5.11

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

spc.h
Go to the documentation of this file.
1 /*============================================================================
2
3 WCSLIB 5.11 - 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: spc.h,v 5.11 2015/10/18 09:13:05 mcalabre Exp $
26 *=============================================================================
27 *
28 * WCSLIB 5.11 - 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 * Returned:
652 * ctype char[9] Translated CTYPEia keyvalue, or a copy of ctypeA if no
653 * translation was performed (in which case any trailing
654 * blanks in ctypeA will be replaced with nulls).
655 *
656 * specsys char[9] Doppler reference frame indicated by VELREF or else
657 * by CTYPEia with value corresponding to the SPECSYS
658 * keyvalue in the FITS WCS standard. May be returned
659 * blank if neither specifies a Doppler frame, e.g.
660 * ctypeA = 'FELO' and velref%256 == 0.
661 *
662 * Function return value:
663 * int Status return value:
664 * -1: No translation required (not an error).
665 * 0: Success.
666 * 2: Invalid value of VELREF.
667 *
668 *
669 * spcprm struct - Spectral transformation parameters
670 * --------------------------------------------------
671 * The spcprm struct contains information required to transform spectral
672 * coordinates. It consists of certain members that must be set by the user
673 * ("given") and others that are set by the WCSLIB routines ("returned"). Some
674 * of the latter are supplied for informational purposes while others are for
675 * internal use only.
676 *
677 * int flag
678 * (Given and returned) This flag must be set to zero whenever any of the
679 * following spcprm structure members are set or changed:
680 *
681 * - spcprm::type,
682 * - spcprm::code,
683 * - spcprm::crval,
684 * - spcprm::restfrq,
685 * - spcprm::restwav,
686 * - spcprm::pv[].
687 *
688 * This signals the initialization routine, spcset(), to recompute the
689 * returned members of the spcprm struct. spcset() will reset flag to
690 * indicate that this has been done.
691 *
692 * char type[8]
693 * (Given) Four-letter spectral variable type, e.g "ZOPT" for
694 * CTYPEia = 'ZOPT-F2W'. (Declared as char[8] for alignment reasons.)
695 *
696 * char code[4]
697 * (Given) Three-letter spectral algorithm code, e.g "F2W" for
698 * CTYPEia = 'ZOPT-F2W'.
699 *
700 * double crval
701 * (Given) Reference value (CRVALia), SI units.
702 *
703 * double restfrq
704 * (Given) The rest frequency [Hz], and ...
705 *
706 * double restwav
707 * (Given) ... the rest wavelength in vacuo [m], only one of which need be
708 * given, the other should be set to zero. Neither are required if the
709 * X and S spectral variables are both wave-characteristic, or both
710 * velocity-characteristic, types.
711 *
712 * double pv[7]
713 * (Given) Grism parameters for 'GRI' and 'GRA' algorithm codes:
714 * - 0: G, grating ruling density.
715 * - 1: m, interference order.
716 * - 2: alpha, angle of incidence [deg].
717 * - 3: n_r, refractive index at the reference wavelength, lambda_r.
718 * - 4: n'_r, dn/dlambda at the reference wavelength, lambda_r (/m).
719 * - 5: epsilon, grating tilt angle [deg].
720 * - 6: theta, detector tilt angle [deg].
721 *
722 * The remaining members of the spcprm struct are maintained by spcset() and
723 * must not be modified elsewhere:
724 *
725 * double w[6]
726 * (Returned) Intermediate values:
727 * - 0: Rest frequency or wavelength (SI).
728 * - 1: The value of the X-type spectral variable at the reference point
729 * (SI units).
730 * - 2: dX/dS at the reference point (SI units).
731 * The remainder are grism intermediates.
732 *
733 * int isGrism
734 * (Returned) Grism coordinates?
735 * - 0: no,
736 * - 1: in vacuum,
737 * - 2: in air.
738 *
739 * int padding1
740 * (An unused variable inserted for alignment purposes only.)
741 *
742 * struct wcserr *err
743 * (Returned) If enabled, when an error status is returned, this struct
744 * contains detailed information about the error, see wcserr_enable().
745 *
746 * void *padding2
747 * (An unused variable inserted for alignment purposes only.)
748 * int (*spxX2P)(SPX_ARGS)
749 * (Returned) The first and ...
750 * int (*spxP2S)(SPX_ARGS)
751 * (Returned) ... the second of the pointers to the transformation
752 * functions in the two-step algorithm chain X -> P -> S in the
753 * pixel-to-spectral direction where the non-linear transformation is from
754 * X to P. The argument list, SPX_ARGS, is defined in spx.h.
755 *
756 * int (*spxS2P)(SPX_ARGS)
757 * (Returned) The first and ...
758 * int (*spxP2X)(SPX_ARGS)
759 * (Returned) ... the second of the pointers to the transformation
760 * functions in the two-step algorithm chain S -> P -> X in the
761 * spectral-to-pixel direction where the non-linear transformation is from
762 * P to X. The argument list, SPX_ARGS, is defined in spx.h.
763 *
764 *
765 * Global variable: const char *spc_errmsg[] - Status return messages
766 * ------------------------------------------------------------------
767 * Error messages to match the status value returned from each function.
768 *
769 *===========================================================================*/
770
771 #ifndef WCSLIB_SPC
772 #define WCSLIB_SPC
773
774 #include "spx.h"
775
776 #ifdef __cplusplus
777 extern "C" {
778 #endif
779
780
781 extern const char *spc_errmsg[];
782
783 enum spc_errmsg_enum {
784 SPCERR_NO_CHANGE = -1, /* No change. */
785 SPCERR_SUCCESS = 0, /* Success. */
786 SPCERR_NULL_POINTER = 1, /* Null spcprm pointer passed. */
787 SPCERR_BAD_SPEC_PARAMS = 2, /* Invalid spectral parameters. */
788 SPCERR_BAD_X = 3, /* One or more of x coordinates were
789 invalid. */
790 SPCERR_BAD_SPEC = 4 /* One or more of the spec coordinates were
791 invalid. */
792 };
793
794 struct spcprm {
795 /* Initialization flag (see the prologue above). */
796 /*------------------------------------------------------------------------*/
797 int flag; /* Set to zero to force initialization. */
798
799 /* Parameters to be provided (see the prologue above). */
800 /*------------------------------------------------------------------------*/
801 char type[8]; /* Four-letter spectral variable type. */
802 char code[4]; /* Three-letter spectral algorithm code. */
803
804 double crval; /* Reference value (CRVALia), SI units. */
805 double restfrq; /* Rest frequency, Hz. */
806 double restwav; /* Rest wavelength, m. */
807
808 double pv[7]; /* Grism parameters: */
809 /* 0: G, grating ruling density. */
810 /* 1: m, interference order. */
811 /* 2: alpha, angle of incidence. */
812 /* 3: n_r, refractive index at lambda_r. */
813 /* 4: n'_r, dn/dlambda at lambda_r. */
814 /* 5: epsilon, grating tilt angle. */
815 /* 6: theta, detector tilt angle. */
816
817 /* Information derived from the parameters supplied. */
818 /*------------------------------------------------------------------------*/
819 double w[6]; /* Intermediate values. */
820 /* 0: Rest frequency or wavelength (SI). */
821 /* 1: CRVALX (SI units). */
822 /* 2: CDELTX/CDELTia = dX/dS (SI units). */
823 /* The remainder are grism intermediates. */
824
825 int isGrism; /* Grism coordinates? 1: vacuum, 2: air. */
826 int padding1; /* (Dummy inserted for alignment purposes.) */
827
828 /* Error handling */
829 /*------------------------------------------------------------------------*/
830 struct wcserr *err;
831
832 /* Private */
833 /*------------------------------------------------------------------------*/
834 void *padding2; /* (Dummy inserted for alignment purposes.) */
835 int (*spxX2P)(SPX_ARGS); /* Pointers to the transformation functions */
836 int (*spxP2S)(SPX_ARGS); /* in the two-step algorithm chain in the */
837 /* pixel-to-spectral direction. */
838
839 int (*spxS2P)(SPX_ARGS); /* Pointers to the transformation functions */
840 int (*spxP2X)(SPX_ARGS); /* in the two-step algorithm chain in the */
841 /* spectral-to-pixel direction. */
842 };
843
844 /* Size of the spcprm struct in int units, used by the Fortran wrappers. */
845 #define SPCLEN (sizeof(struct spcprm)/sizeof(int))
846
847
848 int spcini(struct spcprm *spc);
849
850 int spcfree(struct spcprm *spc);
851
852 int spcprt(const struct spcprm *spc);
853
854 int spcperr(const struct spcprm *spc, const char *prefix);
855
856 int spcset(struct spcprm *spc);
857
858 int spcx2s(struct spcprm *spc, int nx, int sx, int sspec,
859 const double x[], double spec[], int stat[]);
860
861 int spcs2x(struct spcprm *spc, int nspec, int sspec, int sx,
862 const double spec[], double x[], int stat[]);
863
864 int spctype(const char ctype[9], char stype[], char scode[], char sname[],
865 char units[], char *ptype, char *xtype, int *restreq,
866 struct wcserr **err);
867
868 int spcspxe(const char ctypeS[9], double crvalS, double restfrq,
869 double restwav, char *ptype, char *xtype, int *restreq,
870 double *crvalX, double *dXdS, struct wcserr **err);
871
872 int spcxpse(const char ctypeS[9], double crvalX, double restfrq,
873 double restwav, char *ptype, char *xtype, int *restreq,
874 double *crvalS, double *dSdX, struct wcserr **err);
875
876 int spctrne(const char ctypeS1[9], double crvalS1, double cdeltS1,
877 double restfrq, double restwav, char ctypeS2[9], double *crvalS2,
878 double *cdeltS2, struct wcserr **err);
879
880 int spcaips(const char ctypeA[9], int velref, char ctype[9], char specsys[9]);
881
882
883 /* Deprecated. */
884 #define spcini_errmsg spc_errmsg
885 #define spcprt_errmsg spc_errmsg
886 #define spcset_errmsg spc_errmsg
887 #define spcx2s_errmsg spc_errmsg
888 #define spcs2x_errmsg spc_errmsg
889
890 int spctyp(const char ctype[9], char stype[], char scode[], char sname[],
891 char units[], char *ptype, char *xtype, int *restreq);
892 int spcspx(const char ctypeS[9], double crvalS, double restfrq,
893 double restwav, char *ptype, char *xtype, int *restreq,
894 double *crvalX, double *dXdS);
895 int spcxps(const char ctypeS[9], double crvalX, double restfrq,
896 double restwav, char *ptype, char *xtype, int *restreq,
897 double *crvalS, double *dSdX);
898 int spctrn(const char ctypeS1[9], double crvalS1, double cdeltS1,
899 double restfrq, double restwav, char ctypeS2[9], double *crvalS2,
900 double *cdeltS2);
901
902 #ifdef __cplusplus
903 }
904 #endif
905
906 #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:825
spcprm::crval
double crval
Definition: spc.h:804
SPCERR_SUCCESS
Definition: spc.h:785
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:819
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:787
spcprm
Spectral transformation parameters.
Definition: spc.h:794
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:805
spc_errmsg_enum
spc_errmsg_enum
Definition: spc.h:783
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:835
spcprm::code
char code[4]
Definition: spc.h:802
SPCERR_BAD_SPEC
Definition: spc.h:790
spcprm::type
char type[8]
Definition: spc.h:801
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:806
spcprm::padding2
void * padding2
Definition: spc.h:834
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:797
spcprm::spxP2X
int(* spxP2X)(SPX_ARGS)
Definition: spc.h:840
spcprm::pv
double pv[7]
Definition: spc.h:808
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:826
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:830
spcprm::spxP2S
int(* spxP2S)(SPX_ARGS)
Definition: spc.h:836
SPCERR_NO_CHANGE
Definition: spc.h:784
SPCERR_NULL_POINTER
Definition: spc.h:786
spcset
int spcset(struct spcprm *spc)
Setup routine for the spcprm struct.
SPCERR_BAD_X
Definition: spc.h:788
spcprm::spxS2P
int(* spxS2P)(SPX_ARGS)
Definition: spc.h:839
spx.h