int doPhot (StisInfo1 *sts, SingleGroup *x) { /* arguments: StisInfo1 *sts i: calibration switches, etc SingleGroup *x io: image to be calibrated; primary header is modified */ int status; PhotPar obs; char photmode[STIS_LINE+1]; /* the photmode string */ char tempphot[STIS_LINE+1]; /* photmode without A2D */ char obsmode[STIS_LINE+1]; /* based on the photmode string */ int use_default = 1; /* use default value if keyword is missing */ int found_a2d = 0; /* true if there's a CCD A2D component */ TdsInfo tds; /* time-dep, but use only temperature corr */ int GetTds1 (char *, char *, TdsInfo *); void FreeTds1 (TdsInfo *); /* Get PHOTMODE from the primary header. */ if ((status = Get_KeyS (x->globalhdr, "PHOTMODE", use_default, "", photmode, STIS_LINE)) != 0) return (status); found_a2d = removeA2D (photmode, tempphot); Phot2Obs (tempphot, obsmode); /* Initialize PhotPar struct. */ InitPhotPar (&obs, sts->phot.name, sts->phot.pedigree); /* Get the photometry values. */ if ((status = GetPhotTab (&obs, obsmode)) != 0) { printf ("Warning photmode '%s' not found.\n", obsmode); FreePhotPar (&obs); sts->photcorr = IGNORED; return 0; } /* The flag value that indicates that the time of observation is outside the range of times in the imphttab is actually -9999., but test on -9990. to avoid roundoff problems. Extrapolation is not supported, so the values were not computed. Set photcorr to IGNORED (which results in SKIPPED), but set the keywords to -9999. anyway. */ if (obs.photflam < -9990. && obs.photplam < -9990. && obs.photbw < -9990.) { sts->photcorr = IGNORED; } /* Make further changes to photflam. */ if (found_a2d && sts->photcorr == PERFORM) obs.photflam *= sts->atodgain; /* Get values from the TDS table */ if (sts->tdscorr == PERFORM && sts->photcorr == PERFORM) { if ((status = GetTds1(sts->tdstab.name, sts->opt_elem, &tds))) return (status); obs.photflam /= tempFactor(&tds, obs.photplam, sts->detector_temp); FreeTds1 (&tds); } /* Update the photometry keyword values in the primary header. */ if ((status = Put_KeyF (x->globalhdr, "PHOTFLAM", obs.photflam, "inverse sensitivity")) != 0) return (status); if ((status = Put_KeyF (x->globalhdr, "PHOTZPT", obs.photzpt, "zero point")) != 0) return (status); if ((status = Put_KeyF (x->globalhdr, "PHOTPLAM", obs.photplam, "pivot wavelength")) != 0) return (status); if ((status = Put_KeyF (x->globalhdr, "PHOTBW", obs.photbw, "RMS bandwidth")) != 0) return (status); FreePhotPar (&obs); return (0); }
int UpdateCCDTemperature(StisInfo1 *sts, Hdr *hdr) { /* arguments: StisInfo1 *sts io: calibration switches and info Hdr *hdr i: header of current extension */ int status = 0; int row; int row_start = -1; /* beginning row of EPC table data */ int row_end = -1; /* ending row of EPC table data */ double ccd_temperature = -1.; /* average from EPC table */ /* If CRCORR is complete we don't need to update OCCDHTAV */ if (sts->crcorr == COMPLETE) return (0); /* Finding starting and ending row of EPC table data for this image extension ONLY if the EPC data bounds the exposure data. */ for (row = 0; row < sts->epc_rows; row++) { if (sts->epc_mjd[row] < sts->expstart) row_start = row; if (sts->epc_mjd[row] > sts->expend) { row_end = row; break; } } /* Determine CCD temperature */ if (row_start >= 0 && sts->exptime == 0.) { ccd_temperature = sts->epc_temp[row_start]; status = Put_KeyF(hdr, "OCCDHTAV", (float) ccd_temperature, ""); } else if (row_start >= 0 && row_end >= 0) { /* From time-averaged CCD temperatures in EPC table. */ double avtemp = 0.; for (row = row_start; row < row_end; row++) { double fmjd, ftemp; if (row_start == row_end-1) { fmjd = sts->expend - sts->expstart; ftemp = sts->epc_temp[row]; } else if (row == row_end-1) { fmjd = sts->expend - sts->epc_mjd[row]; ftemp = 0.5*(sts->epc_temp[row+1] - sts->epc_temp[row]) * (sts->expend - sts->epc_mjd[row]) / (sts->epc_mjd[row+1] - sts->epc_mjd[row]) + sts->epc_temp[row]; } else if (row == row_start) { fmjd = sts->epc_mjd[row+1] - sts->expstart; ftemp = 0.5*(sts->epc_temp[row+1] - sts->epc_temp[row]) * (sts->expstart - sts->epc_mjd[row]) / (sts->epc_mjd[row+1] - sts->epc_mjd[row]) + sts->epc_temp[row]; } else { fmjd = sts->epc_mjd[row+1] - sts->epc_mjd[row]; ftemp = 0.5*(sts->epc_temp[row+1] + sts->epc_temp[row]); } avtemp += fmjd*ftemp; } ccd_temperature = avtemp/(sts->expend-sts->expstart); /* Update the header keyword with the average temperature */ status = Put_KeyF(hdr, "OCCDHTAV", (float) ccd_temperature, ""); } return (status); }