WCSLIB: spc.h Source File

WCSLIB 8.7

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