/* This file contains: GetGrpInfo1 GetTemperature */ # include # include # include /* sqrt */ # include # include "../stis.h" # include "calstis1.h" # include "../stiserr.h" # include "../stistemperature.h" /* used by GetTemperature */ static int GetTemperature (StisInfo1 *, Hdr *); /* This routine gets keyword values from the SCI extension header. Phil Hodge, 1998 May 4: Get NCOMBINE from the SCI extension header. Previously we were getting it from the primary header. Phil Hodge, 1998 June 8: Get CD matrix and compute the pixel size in each axis. Phil Hodge, 1998 July 30: Check value of ASN_MTYP to see if the input file is a wavecal, and set sts->wavecal instead of sts->assoc_typ. Phil Hodge, 1998 Oct 5: Change status value 1001 to GENERIC_ERROR_CODE. Phil Hodge, 1999 Mar 29: Move GetTemperature from getkeyinfo1.c to this file. In GetTemperature, read the [UDL,1] extension (instead of the primary header) of the support file to get OM2CAT; use MIN_OM2CAT as a minimum valid value for om2cat; if there's a problem, print a warning regardless of the verbose switch. Phil Hodge, 1999 July 26: Initialize the temperature to -1. */ int GetGrpInfo1 (StisInfo1 *sts, Hdr *hdr) { /* arguments: StisInfo1 *sts io: calibration switches and info Hdr *hdr i: header of current extension */ int status; char *buf; /* scratch for keyword value */ int sdqflags; /* serious data quality flags */ int rsize; /* 1 for CCD, 2 for MAMA */ int corner[2]; /* subarray start points, detector coords */ double cd11, cd12, cd21, cd22; /* CD matrix */ int doppon; /* Doppler correction done on-board? */ int use_def = 1; /* use default if missing keyword */ int no_default = 0; /* missing keyword is fatal error */ int Get_KeyD (Hdr *, char *, int, double, double *); int Get_KeyI (Hdr *, char *, int, int, int *); int Get_KeyS (Hdr *, char *, int, char *, char *, int); int GetCorner (Hdr *, int, int *, int *); /* Get generic parameters. */ /* Check whether we're processing a science file or wavecal. */ if ((buf = calloc (STIS_FNAME+1, sizeof(char))) == NULL) return (OUT_OF_MEMORY); if (status = Get_KeyS (hdr, "ASN_MTYP", use_def, "unknown", buf, STIS_FNAME)) return (status); /* Possible values for wavecals are "AUTO-WAVECAL" and "GO-WAVECAL" */ sts->wavecal = (strstr (buf, "WAVECAL") != NULL); free (buf); if (status = Get_KeyD (hdr, "EXPTIME", no_default, 0., &sts->exptime)) return (status); if (sts->exptime < 0.) { printf ("ERROR Exposure time is invalid: %14.6g.\n", sts->exptime); return (GENERIC_ERROR_CODE); } /* Find out which data quality bits are considered serious; default value means all bits are serious. */ if (status = Get_KeyI (hdr, "SDQFLAGS", use_def, 32767, &sdqflags)) return (status); sts->sdqflags = (short) sdqflags; /* Get the pixel size (ignore corner location) from ltm & ltv. */ rsize = (sts->detector == CCD_DETECTOR) ? 1 : 2; if (status = GetCorner (hdr, rsize, sts->bin, corner)) return (status); /* For spectroscopic data, we want the dispersion axis and the sign of the dispersion. We'll get the latter from one element of the CD matrix. We also want the pixel size, which we compute from the CD matrix. */ sts->dispaxis = 1; /* initial values */ sts->dispsign = 1; if (strcmp (sts->obstype, "IMAGING") == 0) { if (status = Get_KeyD (hdr, "CD1_1", use_def, 1., &cd11)) return (status); if (status = Get_KeyD (hdr, "CD1_2", use_def, 0., &cd12)) return (status); if (status = Get_KeyD (hdr, "CD2_1", use_def, 0., &cd21)) return (status); if (status = Get_KeyD (hdr, "CD2_2", use_def, 1., &cd22)) return (status); sts->cdelt[0] = sqrt (cd11 * cd11 + cd21 * cd21); sts->cdelt[1] = sqrt (cd12 * cd12 + cd22 * cd22); } else if (strcmp (sts->obstype, "SPECTROSCOPIC") == 0) { if (status = Get_KeyI (hdr, "DISPAXIS", use_def, 1, &sts->dispaxis)) return (status); if (status = Get_KeyD (hdr, "CD1_1", use_def, 1., &cd11)) return (status); if (status = Get_KeyD (hdr, "CD2_2", use_def, 1., &cd22)) return (status); if (sts->dispaxis == 1) { if (cd11 >= 0.) sts->dispsign = 1; else sts->dispsign = -1; sts->cdelt[0] = cd22; /* assume square pixels */ sts->cdelt[1] = cd22; } else if (sts->dispaxis == 2) { if (cd22 >= 0.) sts->dispsign = 1; else sts->dispsign = -1; sts->cdelt[0] = cd11; sts->cdelt[1] = cd11; } } /* Get MAMA-specific parameters. */ sts->temperature = -1.; /* initial value (not defined) */ if (sts->detector == NUV_MAMA_DETECTOR || sts->detector == FUV_MAMA_DETECTOR) { if (status = Get_KeyD (hdr, "GLOBRATE", no_default, 0., &sts->globrate)) return (status); if (sts->detector == NUV_MAMA_DETECTOR) { /* Darkcorr could get reset later, but even if it does, it's OK to call this routine because we should never get a fatal error. */ if (sts->darkcorr == PERFORM) { if (status = GetTemperature (sts, hdr)) return (status); } } /* Get info if we need to do Doppler convolution of ref files. */ if (sts->doppcorr == PERFORM) { /* Was Doppler correction done on-board? */ if (status = Get_KeyI (hdr, "DOPPON", use_def, 0, &doppon)) return (status); /* doppon could be False in timetag mode. */ if (!doppon) { if (strcmp (sts->obsmode, "TIME-TAG") == 0) { if (status = Get_KeyD (hdr, "DOPPMAG", use_def, -1., &sts->doppmag)) return (status); doppon = (sts->doppmag > 0.); } } if (doppon) { if (status = Get_KeyD (hdr, "EXPSTART", no_default, 0., &sts->expstart)) return (status); if (status = Get_KeyD (hdr, "DOPPZERO", no_default, 0., &sts->doppzero)) return (status); if (status = Get_KeyD (hdr, "DOPPMAG", no_default, 0., &sts->doppmag)) return (status); if (status = Get_KeyD (hdr, "ORBITPER", no_default, 0., &sts->orbitper)) return (status); } else { /* Silently reset the switch. */ sts->doppcorr = OMIT; } } } /* Get CCD-specific parameters. */ /* If images have been combined (e.g. by cosmic-ray rejection), then determine the number of images that were combined together; we need this for bias image subtraction. (This isn't really a CCD-specific keyword, but it does only affect CCD data in the context of calstis1.) */ if (status = Get_KeyI (hdr, "NCOMBINE", use_def, 1, &sts->ncombine)) return (status); if (sts->ncombine < 1) { printf ("Warning NCOMBINE = %d, reset to one.\n", sts->ncombine); sts->ncombine = 1; } return (0); } /* This routine gets the temperature from the OM2CAT keyword, if we have NUV MAMA data. For other data, or if OM2CAT cannot be read, sts->temperature will be set to -1. If OM2CAT is present in the input extension header, that value will be read. If the keyword is not found, the extension header of the support file will be opened, and the keyword will be read from there. The name of the support file is obtained by replacing "_raw" or "_wav" in the input file name with "_spt" or "_wsp" respectively. If the support file cannot be opened, or if the keyword is not found, a warning will be printed, but this is not considered to be a fatal error. If the keyword is found, its value will be converted from degrees Celsius to Kelvin, and that value will be assigned to sts->temperature. */ static int GetTemperature (StisInfo1 *sts, Hdr *hdr) { /* arguments: StisInfo1 *sts io: calibration switches and info Hdr *hdr i: header of current extension */ int status; IODescPtr im; /* descriptor for SPT file */ Hdr spt_hdr; /* extension header of SPT file */ double om2cat; /* value of keyword */ char *sptfile; /* Input and output suffixes. */ char *isuffix[] = {"_raw", "_wav"}; char *osuffix[] = {"_spt", "_wsp"}; int nsuffix = 2; int MkOutName (char *, char **, char **, int, char *, int); int use_def = 1; /* use default if missing keyword */ int Get_KeyD (Hdr *, char *, int, double, double *); sts->temperature = -1.; /* default means not defined */ /* Look for the keyword in the header of the input image. */ if (status = Get_KeyD (hdr, "OM2CAT", use_def, -1., &om2cat)) return (status); if (om2cat < 0.) { /* Not found. Try the SPT file. */ /* Create SPT file name from input file name. */ if ((sptfile = calloc (STIS_LINE+1, sizeof (char))) == NULL) return (OUT_OF_MEMORY); if (status = MkOutName (sts->input, isuffix, osuffix, nsuffix, sptfile, STIS_LINE)) return (status); /* Open SPT file in order to read its [UDL,1] header. */ im = openInputImage (sptfile, "UDL", 1); if (hstio_err()) { printf ("Warning Failed to open SPT file %s \\\n", sptfile); clear_hstioerr(); } else { initHdr (&spt_hdr); getHeader (im, &spt_hdr); if (hstio_err()) return (OPEN_FAILED); closeImage (im); if (status = Get_KeyD (&spt_hdr, "OM2CAT", use_def, -1., &om2cat)) return (status); if (om2cat < 0.) { printf ("Warning OM2CAT not found in SPT file %s \\\n", sptfile); } else if (om2cat < MIN_OM2CAT) { printf ( "Warning OM2CAT = %.6g is not valid and will not be used; \\\n", om2cat); } freeHdr (&spt_hdr); } free (sptfile); } /* If the keyword was found, convert from Celsius to Kelvin. */ if (om2cat >= MIN_OM2CAT) { sts->temperature = om2cat + CELSIUS_TO_KELVIN; } else { printf ( "Warning dark reference image will not be scaled using temperature.\n"); } return (0); }