int GetGrpInfo4 (StisInfo4 *sts, Hdr *hdr) { /* arguments: StisInfo4 *sts io: calibration switches and info Hdr *hdr i: header of current imset */ int status; int sdqflags; /* serious data quality flags */ int use_def = 1; /* use default if missing keyword */ Bool value; /* value of IMSET_OK keyword */ /* Get IMSET_OK, which will be false if the current imset was flagged as having zero exptime or constant pixel values. */ if ((status = Get_KeyB (hdr, "IMSET_OK", use_def, True, &value)) != 0) return status; if (value) sts->imset_ok = 1; else sts->imset_ok = 0; /* 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 for spectroscopic data.\n", sts->dispaxis); return (GENERIC_ERROR_CODE); } /* Find out which data quality bits (all, by default) are considered serious. Note that we reset some bits, so that we can include pixels that are flagged with these conditions. */ if ((status = Get_KeyI (hdr, "SDQFLAGS", use_def, 32767, &sdqflags))) return (status); sdqflags &= ~DATAMASKED; /* behind occulting bar */ sdqflags &= ~HOTPIX; /* hot (but probably just warm) pixel */ sdqflags &= ~SMALLBLEM; /* too small to be concerned about */ sts->sdqflags = (short) sdqflags; /* Get the LTMi_i and LTVi keywords, converted to zero indexing. */ if ((status = GetLT0 (hdr, sts->ltm, sts->ltv))) return (status); sts->scale[0] = 1. / sts->ltm[0]; sts->scale[1] = 1. / sts->ltm[1]; /* Get the coordinate parameters. */ if (sts->disp_type == PRISM_DISP) { /* For prism data prior to 2-D rectification, the coordinate parameters in the header are for RA & Dec, but we need cross-dispersion spatial coordinates. */ GetSDC (sts); sts->crpix[1] = sts->crpix[1] * sts->ltm[1] + sts->ltv[1]; sts->cdelt[1] /= sts->ltm[1]; } else { 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); if ((status = Get_KeyD (hdr, "CRVAL1", use_def, 0., &sts->crval[0]))) return (status); if ((status = Get_KeyD (hdr, "CRVAL2", use_def, 0., &sts->crval[1]))) return (status); if ((status = Get_KeyD (hdr, "CD1_1", use_def, 1., &sts->cdelt[0]))) return (status); if ((status = Get_KeyD (hdr, "CD2_2", use_def, 1., &sts->cdelt[1]))) return (status); /* Convert CRPIX to zero index. */ sts->crpix[0]--; sts->crpix[1]--; } /* We only need the exposure time to verify that it's greater than zero. That's why the default is zero. */ if ((status = Get_KeyD (hdr, "EXPTIME", use_def, 0., &sts->exptime))) return (status); /* Exposure start time is needed for trace rotation */ if ((status = Get_KeyD (hdr, "EXPSTART", 0, 0., &sts->expstart))) return (status); return (0); }
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); }
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); }
int GetKeyInfo1 (StisInfo1 *sts, Hdr *phdr) { /* arguments: StisInfo1 *sts io: calibration switches and info Hdr *phdr i: primary header */ int status; int nextend; /* number of FITS extensions */ char targname[STIS_CBUF+1]; /* target name, check if BIAS or DARK */ char crcorr[STIS_CBUF+1]; /* cosmic-ray rejection keyword */ int use_def = 1; /* use default if missing keyword */ int no_default = 0; /* missing keyword is fatal error */ /* Get generic parameters. */ if ((status = Get_KeyS (phdr, "ROOTNAME", no_default, "", sts->rootname, STIS_CBUF))) return (status); if ((status = Get_KeyS (phdr, "OBSMODE", use_def, "unknown", sts->obsmode, STIS_CBUF))) return (status); if ((status = Get_KeyS (phdr, "APERTURE", use_def, "", sts->aperture, STIS_CBUF))) return (status); if ((status = Get_KeyS (phdr, "DETECTOR", no_default, "", sts->det, STIS_CBUF))) return (status); if (strcmp (sts->det, "NUV-MAMA") == 0) { sts->detector = NUV_MAMA_DETECTOR; } else if (strcmp (sts->det, "FUV-MAMA") == 0) { sts->detector = FUV_MAMA_DETECTOR; } else if (strcmp (sts->det, "CCD") == 0) { sts->detector = CCD_DETECTOR; } else { printf ("ERROR DETECTOR = %s is invalid\n", sts->det); return (HEADER_PROBLEM); } /* Grating or mirror name. */ if ((status = Get_KeyS (phdr, "OPT_ELEM", use_def, "", sts->opt_elem, STIS_CBUF))) return (status); /* If TARGNAME is BIAS or DARK, set the flag to indicate this. */ if ((status = Get_KeyS (phdr, "TARGNAME", use_def, "", targname, STIS_CBUF))) return (status); if (strcmp (targname, "BIAS") == 0) sts->bias_exposure = 1; else sts->bias_exposure = 0; if (strcmp (targname, "BIAS") == 0 || strcmp (targname, "DARK") == 0) sts->bias_or_dark = 1; else sts->bias_or_dark = 0; /* If TARGNAME indicates that this is a wavecal observation, set the wavecal flag. */ if (strcmp (targname, "WAVELINE") == 0 || strcmp (targname, "WAVEHITM") == 0) { sts->wavecal = 1; } if ((status = Get_KeyD (phdr, "RA_TARG", no_default, 0., &sts->ra_targ))) return (status); if ((status = Get_KeyD (phdr, "DEC_TARG", no_default, 0., &sts->dec_targ))) return (status); /* Check if CRCORR is complete */ if ((status = Get_KeyS (phdr, "CRCORR", use_def, "", crcorr, STIS_CBUF))) return (status); if (strcmp(crcorr, "COMPLETE") == 0) { sts->crcorr = COMPLETE; } else { sts->crcorr = PERFORM; } /* Find out how many extensions there are in this file. */ if ((status = Get_KeyI (phdr, "NEXTEND", use_def, EXT_PER_GROUP, &nextend))) return (status); /* Convert number of extensions to number of SingleGroups. */ sts->nimages = nextend / EXT_PER_GROUP; if (sts->nimages < 1) { printf ("ERROR NEXTEND = %d; must be at least three.\n", sts->nimages); return (GENERIC_ERROR_CODE); } /* If obstype is spectroscopic and photcorr is set to perform, we will reset photcorr. */ if ((status = Get_KeyS (phdr, "OBSTYPE", use_def, "", sts->obstype, STIS_CBUF))) return (status); if (strcmp (sts->obstype, "IMAGING") != 0 && strcmp (sts->obstype, "SPECTROSCOPIC") != 0) { printf ( "Warning OBSTYPE = %s; should be either IMAGING or SPECTROSCOPIC\n", sts->obstype); } /* For CCD observations, we need the APER_FOV in order to flag regions beyond the aperture for such apertures as F28X50LP. */ if ((status = Get_KeyS (phdr, "APER_FOV", use_def, "", sts->aper_fov, STIS_CBUF))) return (status); /* Get MAMA-specific parameters. */ /* there are none, at present */ /* Get CCD-specific parameters. */ if (sts->detector == CCD_DETECTOR) { if ((status = Get_KeyS (phdr, "CCDAMP", no_default, "", sts->ccdamp, STIS_CBUF-1))) return (status); if (sts->ccdamp[0] != '\0' && sts->ccdamp[1] != '\0') { printf ( "Warning Multiple amp readout `%s' is not supported.\n", sts->ccdamp); } if (islower (sts->ccdamp[0])) sts->ccdamp[0] = toupper (sts->ccdamp[0]); if (strchr ("ABCD", sts->ccdamp[0]) == NULL) { printf ("ERROR CCDAMP = `%s' is invalid.\n", sts->ccdamp); return (GENERIC_ERROR_CODE); } if ((status = Get_KeyI (phdr, "CCDGAIN", use_def, 1, &sts->ccdgain))) return (status); if ((status = Get_KeyI (phdr, "CCDOFFST", use_def, 1, &sts->ccdoffset))) return (status); if ((status = Get_KeyI (phdr, "BINAXIS1", use_def, 1, &sts->binaxis[0]))) return (status); if ((status = Get_KeyI (phdr, "BINAXIS2", use_def, 1, &sts->binaxis[1]))) return (status); } return (0); }
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); }
static int GetRipple (Hdr *phdr, char *name, ScatterFunctions *scf) { /* arguments Hdr *phdr i: primary header char *name; i: name of RIPTAB reference file ScatterFunctions *scf; o: data structure with ripple functions */ IRAFPointer tp; IRAFPointer cp_optelem, cp_cenwave, cp_sporder, cp_wave, cp_nelem, cp_ripple; char opt_elem[STIS_CBUF]; int row, nrows, i, k, cenwave, status; /* get reference CENWAVE. */ if ((status = Get_KeyI (phdr, "CENWAVE", 0, 0, &cenwave))) return (status); /* Open table and get column pointers. */ tp = c_tbtopn (name, IRAF_READ_ONLY, 0); if (c_iraferr()) { printf ("ERROR RIPTAB `%s' not found\n", name); return (OPEN_FAILED); } c_tbcfnd1 (tp, "OPT_ELEM", &cp_optelem); c_tbcfnd1 (tp, "CENWAVE", &cp_cenwave); c_tbcfnd1 (tp, "SPORDER", &cp_sporder); c_tbcfnd1 (tp, "NELEM", &cp_nelem); c_tbcfnd1 (tp, "WAVELENGTH", &cp_wave); c_tbcfnd1 (tp, "RIPPLE", &cp_ripple); if (cp_cenwave == 0 || cp_sporder == 0 || cp_wave == 0 || cp_ripple == 0 || cp_nelem == 0 || cp_optelem == 0) { printf( "ERROR Column not found in RIPTAB\n"); c_tbtclo (tp); return (COLUMN_NOT_FOUND); } /* Get # of matching rows. */ nrows = c_tbpsta (tp, TBL_NROWS); scf->nrp = 0; for (row = 1; row <= nrows; row++) { c_tbegti (tp, cp_cenwave, row, &i); c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1); if (c_iraferr()) return (TABLE_ERROR); if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem))) (scf->nrp)++; } if (scf->nrp == 0) { printf ("ERROR No matching rows in RIPTAB `%s'\n", name); return (TABLE_ERROR); } /* Alloc memory. */ scf->rpfunc = (RippleFunc *) calloc (scf->nrp, sizeof (RippleFunc)); if (scf->rpfunc == NULL) return (OUT_OF_MEMORY); /* Ingest data from matching rows. */ k = 0; for (row = 1; row <= nrows ; row++) { c_tbegti (tp, cp_cenwave, row, &i); c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1); if (c_iraferr()) return (TABLE_ERROR); if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem))) { c_tbegti (tp, cp_sporder, row, &(scf->rpfunc[k].sporder)); if (c_iraferr()) return (TABLE_ERROR); scf->rpfunc[k].nelem = c_tbcigi (cp_ripple, TBL_COL_LENDATA); scf->rpfunc[k].wavelengths = (double *) calloc ( scf->rpfunc[k].nelem, sizeof (double)); if (scf->rpfunc[k].wavelengths == NULL) return (OUT_OF_MEMORY); scf->rpfunc[k].values = (double *) calloc ( scf->rpfunc[k].nelem, sizeof (double)); if (scf->rpfunc[k].values == NULL) return (OUT_OF_MEMORY); i = c_tbagtd (tp, cp_wave, row, scf->rpfunc[k].wavelengths, 1, scf->rpfunc[k].nelem); if (c_iraferr()) return (TABLE_ERROR); i = c_tbagtd (tp, cp_ripple, row, scf->rpfunc[k].values, 1, scf->rpfunc[k].nelem); if (c_iraferr()) return (TABLE_ERROR); k++; } } c_tbtclo (tp); return (STIS_OK); }
static int GetRefWave (Hdr *phdr, char *name, ScatterFunctions *scf) { /* arguments Hdr *phdr i: primary header char *name; i: name of SRWTAB reference file ScatterFunctions *scf; o: data structure with reference wavelengths */ IRAFPointer tp; IRAFPointer cp_optelem, cp_cenwave, cp_nrw, cp_hrwlist, cp_prwlist; char opt_elem[STIS_CBUF]; int row, nrows, i, cenwave, status; double holdh[10], holdp[10]; /* holds a maximum of 10 wavelengths */ /* This is necessary to avoid rui warnings from the debugger. */ for (i = 0; i < 10; i++) { holdh[i] = 0.0; holdp[i] = 0.0; } for (i = 0; i <= NREFWAVE; i++) { scf->kernw[i] = 0.0; scf->psfw[i] = 0.0; } /* get reference CENWAVE. */ if ((status = Get_KeyI (phdr, "CENWAVE", 0, 0, &cenwave))) return (status); tp = c_tbtopn (name, IRAF_READ_ONLY, 0); if (c_iraferr()) { printf ("ERROR SRWTAB `%s' not found\n", name); return (OPEN_FAILED); } nrows = c_tbpsta (tp, TBL_NROWS); c_tbcfnd1 (tp, "OPT_ELEM", &cp_optelem); c_tbcfnd1 (tp, "CENWAVE", &cp_cenwave); c_tbcfnd1 (tp, "NRW", &cp_nrw); c_tbcfnd1 (tp, "HALOWAVES", &cp_hrwlist); c_tbcfnd1 (tp, "PSFWAVES", &cp_prwlist); if (cp_optelem == 0 || cp_cenwave == 0 || cp_nrw == 0 || cp_hrwlist == 0 || cp_prwlist == 0) { printf( "ERROR Column not found in SRWTAB\n"); c_tbtclo (tp); return (COLUMN_NOT_FOUND); } scf->nwave = 0; for (row = 1; row <= nrows ; row++) { c_tbegti (tp, cp_cenwave, row, &i); c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1); if (c_iraferr()) return (TABLE_ERROR); if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem))) { c_tbegti (tp, cp_nrw, row, &(scf->nwave)); if (c_iraferr()) return (TABLE_ERROR); i = c_tbagtd (tp, cp_hrwlist, row, holdh, 1, scf->nwave); if (c_iraferr()) return (TABLE_ERROR); i = c_tbagtd (tp, cp_prwlist, row, holdp, 1, scf->nwave); if (c_iraferr()) return (TABLE_ERROR); c_tbtclo (tp); scf->kernw[0] = holdh[0]; scf->psfw[0] = holdp[0]; if (scf->nwave > 1) { scf->kernw[1] = holdh[1]; scf->psfw[1] = holdp[1]; } if (scf->nwave > 2) { scf->kernw[2] = holdh[2]; scf->psfw[2] = holdp[2]; } return (STIS_OK); } } printf( "ERROR Row not found in SRWTAB\n"); c_tbtclo (tp); return (ROW_NOT_FOUND); }