コード例 #1
0
ファイル: getgrpinfo1.c プロジェクト: brechmos-stsci/hstcal
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 GetDetTemp (Hdr *, int, double *);
	int GetEPCTab (StisInfo1 *, float);

	/* Get generic parameters. */

	/* Check whether we're processing a science file or wavecal,
	   based on ASN_MTYP.  Note that we won't reset the wavecal flag
	   to false (it may have been set in GetKeyInfo1) if ASN_MTYP
	   doesn't indicate that the observation is a wavecal, because
	   this file might not be part of an association.
	*/
	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" */
	if (strstr (buf, "WAVECAL") != NULL)
	    sts->wavecal = 1;
	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);
	}
	if ((status = Get_KeyD (hdr, "EXPSTART", no_default, 0., &sts->expstart)))
	    return (status);
	if ((status = Get_KeyD (hdr, "EXPEND", no_default, 0., &sts->expend)))
	    return (status);

	/* 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;
	    }
	}

	sts->detector_temp = -1.;	/* initial value (not defined) */

	/* Get MAMA-specific parameters. */

	if (sts->detector == NUV_MAMA_DETECTOR ||
	    sts->detector == FUV_MAMA_DETECTOR) {

	    if ((status = Get_KeyD (hdr, "GLOBRATE",
                                    no_default, 0., &sts->globrate)))
		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, "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 (sts->detector == CCD_DETECTOR) {
	    float occdhtav = -1.;

	    /*  if OCCDHTAV is present and > 0, then data is from Side B,
	     *  so look for EPC file.  Otherwise, data is from Side A and
	     *  EPC file and temperature can be ignored.
	     */

	    if (((status = Get_KeyF(hdr, "OCCDHTAV", use_def, -1.,
				    &occdhtav)) == 0) && (occdhtav >= 0.)) {
		char expname[81], epcname[81];
		expname[0] = epcname[0] = '\0';
		if ((status = Get_KeyS(hdr, "EXPNAME", no_default, "",
                                       expname, 80)))
		    return (status);
		if (sts->crcorr != COMPLETE) {
		    strncpy(epcname, expname, 8); epcname[8] = '\0';
		    sprintf(sts->epctab.name, "%sj_epc.fits", epcname);
		    PrFileName("epcfile", sts->epctab.name);
		    status = GetEPCTab(sts, 0.40);
		    if (status && status != OPEN_FAILED)
			return (status);
		}
		if ((status = UpdateCCDTemperature(sts, hdr)))
		    return (status);
	    }
        }

	/* Get the detector temperature (or housing temperature, if CCD).
	   Note that for side-2 CCD data this function must be called after
	   calling UpdateCCDTemperature.
	*/
	if ((status = GetDetTemp (hdr, sts->detector, &sts->detector_temp))) {
	    return (status);
	}

	/* 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);
}
コード例 #2
0
ファイル: getgrpinfo6.c プロジェクト: jhunkeler/hstcal
int GetGrpInfo6 (StisInfo6 *sts, Hdr *hdr) {

/* arguments:
StisInfo6 *sts  io: calibration switches and info
Hdr *hdr        i: header of current IMSET
*/

	int status;

	int sdqflags;			/* serious data quality flags */
	char *buf;			/* scratch for keyword value */
	int use_def = 1;		/* use default if missing keyword */
	int no_default = 0;		/* missing keyword is fatal error */
	int GetDetTemp (Hdr *, int, double *);

	/* Get the dispersion axis. */
	if ((status = Get_KeyI (hdr, "DISPAXIS", use_def, 1, &sts->dispaxis)))
	    return (status);
	if (sts->dispaxis < 1 || sts->dispaxis > 2) {
	    printf ("ERROR    Dispaxis = %d is invalid\n", sts->dispaxis);
	    return (INVALID);
	}

	/* This should be SCIENCE or WAVECAL. */
	if ((buf = (char *) 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);
	sts->wavecal = (strcmp (buf, "WAVECAL") == 0);
	free (buf);

	/* Exposure info. */
	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 (INVALID);
	}
	if ((status = Get_KeyD (hdr, "EXPSTART", no_default, 0., &sts->expstart)))
	    return (status);
	if ((status = Get_KeyD (hdr, "EXPEND", no_default, 0., &sts->expend)))
	    return (status);
	if ((status = Get_KeyD (hdr, "DOPPMAG", use_def, 0., &sts->doppmag)))
	    return (status);
	if (sts->doppmag > 0. && strcmp (sts->obsmode, "TIME-TAG") != 0) {
	    /* doppon could be False in timetag mode; otherwise, reset
		doppzero to zero if on-board Doppler correction was not done.
	    */
	    int doppon;
	    if ((status = Get_KeyI (hdr, "DOPPON", use_def, 0, &doppon)))
		return (status);
	    if (!doppon)
		sts->doppmag = 0.;
	}
	if ((status = Get_KeyD (hdr, "DOPPZERO", use_def, 0., &sts->doppzero)))
	    return (status);
	if ((status = Get_KeyD (hdr, "ORBITPER", use_def, 1., &sts->orbitper)))
	    return (status);

	/* Find out which data quality bits are considered serious;
	   default value means all bits are serious.
	*/
	if ((status = Get_KeyI (hdr, "SDQFLAGS", use_def, ALL_BITS, &sdqflags)))
	    return (status);
	sdqflags &= ~HOTPIX;		/* hot (but probably just warm) pixel */
	sdqflags &= ~SMALLBLEM;		/* too small to be concerned about */
	sts->sdqflags_orig = (short) sdqflags;
	sts->cc_sdqflags   = (short) sdqflags;

	/* This turns off the data quality flag checking everywhere
           except  in crosscorrelation module.
        */
	sts->sdqflags = 0;

	/* Get the "plate scale" coefficients. */
	if ((status = Get_KeyD (hdr, "CD1_1", no_default, 0., &sts->cd[0])))
	    return (status);
	if ((status = Get_KeyD (hdr, "CD2_2", no_default, 0., &sts->cd[1])))
	    return (status);
	if ((status = Get_KeyD (hdr, "CRPIX1", no_default, 1., &sts->crpix[0])))
	    return (status);
	if ((status = Get_KeyD (hdr, "CRVAL1", no_default, 0., &sts->crval[0])))
	    return (status);

	/* Get the linear transformation (zero indexed) from the reference
	   coordinate system to current image pixel coordinates.
	*/
	if ((status = GetLT0 (hdr, sts->ltm, sts->ltv)))
	    return (status);

	/* Get the detector temperature (or housing temperature, if CCD). */
	if (sts->fluxcorr == PERFORM) {
	    if ((status = GetDetTemp (hdr, sts->detector,
			&sts->detector_temp))) {
		return (status);
	    }
	} else {
	    sts->detector_temp = -1.;
	}

	/* Get the MSM slop. */
	if (sts->wavecal) {
	    sts->msm_offset[0] = 0.0;
	    sts->msm_offset[1] = 0.0;
	} else {
	    if ((status = Get_KeyD (hdr, "SHIFTA1",
                                    use_def, 0., &sts->msm_offset[0])))
		return (status);
	    if ((status = Get_KeyD (hdr, "SHIFTA2",
                                    use_def, 0., &sts->msm_offset[1])))
		return (status);
	}

        /* Get the mean dark count rate and the number of
           combined images for CTI correction. */
        if ((status = Get_KeyD(hdr, "MEANDARK", no_default, 0.,
                               &sts->meandark)))
            return status;
        if ((status = Get_KeyI(hdr, "NCOMBINE", no_default, 0.,
                               &sts->ncombine)))
            return status;

	return (0);
}
コード例 #3
0
ファイル: getgrpinfo7.c プロジェクト: brechmos-stsci/hstcal
int GetGrpInfo7 (StisInfo7 *sts, Hdr *hdr) {

/* arguments:
StisInfo7 *sts  io: calibration switches and info
Hdr *hdr        i: header of current imset
*/

	int status;

	int sdqflags;			/* serious data quality flags */
	char *buf;			/* scratch for keyword value */
	int use_def = 1;		/* use default if missing keyword */
	int no_default = 0;		/* missing keyword is fatal error */
	int GetDetTemp (Hdr *, int, double *);

	/* Get generic parameters. */

	/* This should be SCIENCE 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 %.6g is invalid.\n",
		sts->exptime);
	    return (GENERIC_ERROR_CODE);
	}
	if ((status = Get_KeyD (hdr, "EXPSTART", no_default, 0., &sts->expstart)))
	    return (status);
	if ((status = Get_KeyD (hdr, "EXPEND", no_default, 0., &sts->expend)))
	    return (status);

	/* 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 linear transformation (zero indexed) from the reference
	   coordinate system to current image pixel coordinates.
	*/
	if ((status = GetLT0 (hdr, sts->ltm, sts->ltv)))
	    return (status);

	if ((status = Get_KeyD (hdr, "CRPIX1", use_def, 0., &sts->crpix[0])))
	    return (status);
	if ((status = Get_KeyD (hdr, "CRPIX2", use_def, 0., &sts->crpix[1])))
	    return (status);
	sts->crpix[0]--;	/* convert to zero-indexed */
	sts->crpix[1]--;

	/* Get the detector temperature (or housing temperature, if CCD). */
	if (sts->fluxcorr == PERFORM) {
	    if ((status = GetDetTemp (hdr, sts->detector,
			&sts->detector_temp))) {
		return (status);
	    }
	} else {
	    sts->detector_temp = -1.;
	}

	/* Get the MSM offset found during wavecal processing. */
	if (sts->wavecal) {

	    sts->msm_slop[0] = 0.;
	    sts->msm_slop[1] = 0.;

	} else {

	    if ((status = Get_KeyD (hdr, "SHIFTA1",
                                    use_def, 0., &sts->msm_slop[0])))
		return (status);

	    if (sts->wx2dcorr == COMPLETE) {
		/* shifta2 has already been accounted for by wx2d */
		sts->msm_slop[1] = 0.;
	    } else {
		if ((status = Get_KeyD (hdr, "SHIFTA2",
                                        use_def, 0., &sts->msm_slop[1])))
		    return (status);
	    }
	}

	if (sts->obstype == SPECTROSCOPIC_TYPE) {

	    /* Get the dispersion axis. */
	    if ((status = Get_KeyI (hdr, "DISPAXIS",
                                    use_def, 1, &sts->dispaxis)))
		return (status);
	    if (sts->dispaxis < 1 || sts->dispaxis > 2) {
		printf ("ERROR    Dispaxis = %d is invalid.\n", sts->dispaxis);
		return (GENERIC_ERROR_CODE);
	    }

	} else {

	    sts->dispaxis = 0;
	}

	return (0);
}