aboutsummaryrefslogtreecommitdiff
path: root/src/libcf/cf_read_fpa_pos.c
blob: 87e80996510bf35cad1f60987f81975a111e9b21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*****************************************************************************
 *              Johns Hopkins University
 *              Center For Astrophysical Sciences
 *              FUSE
 *****************************************************************************
 *
 * Synopsis:    cf_read_fpa_pos (fitsfile *infits, float *fpaxsic, float *fpaxlif)
 *
 * Description: Returns SiC and LiF FPA positions in microns.  Can read both
 *              old and new FPA position keywords.
 *
 * Arguments:   fitsfile    *infile       Input data file name
 *              float       *fpaxsic      FPA SiC position (returned)
 *              float       *fpaxlif      FPA LiF position (returned)
 *
 * Returns:     int	     status	  CFITSIO status value
 *
 * History:     08/21/01   v1.1   wvd     Subroutine taken from cf_wfits.c
 * 		01/14/03   v1.3   wvd     Change name to cf_read_fpa_pos.
 *              12/18/03   v1.4   bjg     Change calfusettag.h to calfuse.h
 *
 ****************************************************************************/

#include <string.h>
#include "calfuse.h"

/* for all FPA's an increase in "data number" moves the FPA towards +Xipcs */
#define FPALIF1DN2X0 -69.949	/* DN to microns conversion, zero-point */
#define FPALIF1DN2X1 .14144	/* DN to microns conversion, linear term  */
#define FPALIF2DN2X0 -73.189	/* DN to microns conversion, zero-point */
#define FPALIF2DN2X1 .14487	/* DN to microns conversion, linear term  */
#define FPASIC1DN2X0 -132.507	/* DN to microns conversion, zero-point */
#define FPASIC1DN2X1 .14156	/* DN to microns conversion, linear term  */
#define FPASIC2DN2X0 -89.116	/* DN to microns conversion, zero-point */
#define FPASIC2DN2X1 .14206	/* DN to microns conversion, linear term  */

int cf_read_fpa_pos (fitsfile *infits, float *fpaxsic, float *fpaxlif)
{
    char  detector[FLEN_VALUE]; /* detector keyword from FITS header */
    int	status=0;
    float tmpxsic, tmpxlif;

    FITS_read_key(infits, TSTRING, "DETECTOR", detector, NULL, &status);

    /* Get FPA positions */
    /* Use ffgky instead of FITS_read_key so we can read either the old
     * or new FPA position keywords */
    ffgky (infits, TFLOAT, "FPASXPOS", fpaxsic, NULL, &status);
    if (status != 0) {
	/* New keywords are not present; must be the old ones.
	 * Determine which detector provided current spectrum
	 * and convert raw FPA position to microns.
	 */
	status = 0;
	if (strncmp(detector,"1", 1)==0) {
	    FITS_read_key (infits, TFLOAT, "FP1SXPOS", &tmpxsic, NULL, 
			   &status);
	    FITS_read_key (infits, TFLOAT, "FP1LXPOS", &tmpxlif, NULL, 
			   &status);
	    *fpaxsic = FPASIC1DN2X0 + FPASIC1DN2X1 * tmpxsic;
	    *fpaxlif = FPALIF1DN2X0 + FPALIF1DN2X1 * tmpxlif;
	}
	else if (strncmp(detector,"2", 1)==0) {
	    FITS_read_key (infits, TFLOAT, "FP2SXPOS", &tmpxsic, NULL, 
			   &status);
	    FITS_read_key (infits, TFLOAT, "FP2LXPOS", &tmpxlif, NULL, 
			   &status);
	    *fpaxsic = FPASIC2DN2X0 + FPASIC2DN2X1 * tmpxsic;
	    *fpaxlif = FPALIF2DN2X0 + FPALIF2DN2X1 * tmpxlif;
	}
	else {
	    cf_if_error("Could not parse DETECTOR keyword, cannot "
			"convert raw FPA positions.");
	}
    }
    else {
	/* New SiC FPA keyword present. Assume new LiF FPA keyword
	 * is also present */
	FITS_read_key(infits, TFLOAT, "FPALXPOS", fpaxlif, NULL, &status);
    }
    return status;
}