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