From d54fe7c1f704a63824c5bfa0ece65245572e9b27 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 4 Mar 2015 21:21:30 -0500 Subject: Initial commit --- src/libcf/cf_electronics_dead_time.c | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/libcf/cf_electronics_dead_time.c (limited to 'src/libcf/cf_electronics_dead_time.c') diff --git a/src/libcf/cf_electronics_dead_time.c b/src/libcf/cf_electronics_dead_time.c new file mode 100644 index 0000000..38c2219 --- /dev/null +++ b/src/libcf/cf_electronics_dead_time.c @@ -0,0 +1,104 @@ +/***************************************************************************** + * Johns Hopkins University + * Center For Astrophysical Sciences + * FUSE + ***************************************************************************** + * + * Synopsis: cf_electronics_dead_time(fitsfile *header, long nseconds, + * float *fec_rate, float *elec_dtc) + * + * Description: Scales the weighting factor to correct for the electronics + * dead time. + * + * Arguments: fitsfile *header Pointer to FITS file containing the + * header of the intermediate data file + * long nseconds The number of timeline values + * float *fec_rate An array of Front End Counter (FEC) + * rates + * float *elec_dtc Dead-time correction array (returned) + * Calls: + * + * Return: 0 on success + * + * History: 10/27/02 1.1 peb Begin work + * 11/11/02 1.2 peb Corrected function description and + * added cf_timestamp after ELEC_COR + * check. + * 12/06/02 1.4 wvd Calculate DT correction for each time + * step, then apply to photons. + * Set keyword DET_DEAD. + * 05/20/03 1.5 rdr Added proc_check call + * 08/01/03 1.7 wvd Just calculate correction; don't + * apply it. Return elec_dtc array. + * 08/04/03 1.8 wvd Convert fec_rate to type short. + * 11/26/03 1.9 wvd Change fec_rate to type float. + * 02/12/04 1.10 wvd In verbose mode, write mean DTC. + * 04/07/07 1.11 wvd Clean up compiler warnings. + * + ****************************************************************************/ + +#include +#include +#include "calfuse.h" + +int +cf_electronics_dead_time(fitsfile *header, long nseconds, + float *fec_rate, float *elec_dtc) +{ + char CF_PRGM_ID[] = "cf_electronics_dead_time"; + char CF_VER_NUM[] = "1.11"; + + char elecfile[FLEN_VALUE]={"\0"}, detector[FLEN_VALUE]={"\0"}; + char keyword[FLEN_KEYWORD]={"\0"}; + int errflg=0, status=0; + long k; + float abort, clock, state; + float mean_elec_dtc = 0.; + fitsfile *elecfits; + + cf_error_init(CF_PRGM_ID, CF_VER_NUM, stderr); + cf_timestamp(CF_PRGM_ID, CF_VER_NUM, "Begin Processing"); + + if ((errflg = cf_proc_check(header, CF_PRGM_ID))) return errflg; + + FITS_read_key(header, TSTRING, "DETECTOR", detector, NULL, &status); + /* + * Get the electronics dead-time constants. + */ + FITS_read_key(header, TSTRING, "ELEC_CAL", elecfile, NULL, &status); + FITS_open_file(&elecfits, cf_cal_file(elecfile), READONLY, &status); + sprintf(keyword, "ABORT_%s", detector); + FITS_read_key(elecfits, TFLOAT, keyword, &abort, NULL, &status); + sprintf(keyword, "CLOCK_%s", detector); + FITS_read_key(elecfits, TFLOAT, keyword, &clock, NULL, &status); + sprintf(keyword, "STATE_%s", detector); + FITS_read_key(elecfits, TFLOAT, keyword, &state, NULL, &status); + FITS_close_file(elecfits, &status); + /* + * Calculate dead-time correction. + */ + for (k=0; k