aboutsummaryrefslogtreecommitdiff
path: root/src/libcf/cf_standard_or_optimal_extraction.c
blob: 2b2a6fac1b869239edfb1d5353f48fb90890dc88 (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
/*****************************************************************************
 *            Johns Hopkins University
 *            Center For Astrophysical Sciences
 *            FUSE
 *****************************************************************************
 *
 * Synopsis:    cf_standard_or_optimal_extraction (fitsfile *header,
 *			int *optimal)
 *
 * Description: Sets optimal to TRUE if optimal extraction is desired.
 *		FALSE if RUN_OPTI = 'NO' in parm*.fit file.
 *		FALSE if SRC_TYPE[0] = 'E' in file header.
 *
 * Arguments:   fitsfile  *header       Pointer to IDF FITS file header
 *              int       *optimal      TRUE if optimal extraction desired
 *
 * Calls:
 *
 * Returns:     0 on success
 *
 * History:     03/02/03  1.1   wvd	Initial coding.
 *		03/12/03  1.2   wvd	Write value of optimal to trailer file.
 *		03/19/03  1.3   wvd	Read SRC_TYPE, not SP_TYPE.
 *		03/19/03  1.4   wvd	Add call to cf_timestamp at start.	
 *					Change printf to cf_verbose
 *		09/30/03  1.5   wvd	Check for lower-case value of
 *					RUN_OPTI.
 *		03/15/05  1.6   wvd	No optimal extraction for HIST targets
 *					unless try_optimal = TRUE;
 *		03/18/05  1.7   wvd	v1.6 was a bad idea.  Returning to v1.5
 *
 ****************************************************************************/

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

static char CF_PRGM_ID[] = "cf_standard_or_optimal_extraction";
static char CF_VER_NUM[] = "1.7";

int
cf_standard_or_optimal_extraction(fitsfile *header, int *optimal)
{
    char  parm_file[FLEN_VALUE], instmode[FLEN_VALUE];
    char  run_opti[FLEN_VALUE], src_type[FLEN_VALUE];
    int   status=0;
    fitsfile *parmfits;

    cf_error_init(CF_PRGM_ID, CF_VER_NUM, stderr);
    cf_timestamp(CF_PRGM_ID, CF_VER_NUM, "Begin processing");

    /* Read SRC_TYPE from IDF header. */
    FITS_read_key(header, TSTRING, "SRC_TYPE", src_type, NULL, &status);
    FITS_read_key(header, TSTRING, "INSTMODE", instmode, NULL, &status);

    /* Read RUN_OPTI from PARM_CAL. */
    FITS_read_key(header, TSTRING, "PARM_CAL", parm_file, NULL, &status);
    FITS_open_file(&parmfits, cf_parm_file(parm_file), READONLY, &status);
    FITS_read_key(parmfits, TSTRING, "RUN_OPTI", run_opti, NULL, &status);
    FITS_close_file(parmfits, &status);

    /* Determine value of optimal. */
    *optimal = TRUE;
    if (*run_opti != 'Y' && *run_opti != 'y') {
	cf_verbose (1, "RUN_OPTI = %s.  No optimal extraction.", run_opti);
	*optimal = FALSE;
    }
    if (*src_type != 'P') {
	cf_verbose (1, "SRC_TYPE = %s.  No optimal extraction.", src_type);
	*optimal = FALSE;
    }
    if (*optimal) cf_verbose (1, "Attempting optimal extraction.");

    cf_timestamp(CF_PRGM_ID, CF_VER_NUM, "Done processing");
    return status;
}