DbState Debouncer(SwitchDefine *Switch) { //Debouncer method moves states according to the state machine provided in the notes. DbState MyState = Switch->ControlState; //Save current control state unsigned int time = Switch->prev; //Save last recorded time to calculate delay Switch->CurrentSwitchReading = GetSwitch(Switch->SwitchSelect); //Set current switch reading to the switch select switch (MyState) { //Initialize switch cases case DbExpectHigh: //If MyState is DbExpectHigh: if (!(Switch->CurrentSwitchReading == On)) { //And if the current reading is not "on".. Switch->ControlState = DbValidateHigh; //Set the co00ntrol state to DbValidateHigh } else { time = counter; //else update with new time } break; case DbValidateHigh: //If MyState is DbValidateHigh if (Switch->CurrentSwitchReading == On) { //And if the current switch reading is "on"... time = counter; //Update recorded time Switch->ControlState = DbExpectHigh; //Move to next state } else if ((counter - time) >= Switch->RELEASEBOUNCETIME) { //Else if the different in times is greate than the release time Switch->PreviousValidState = On; //Previous valud state toggled on Switch->CurrentValidState = Off; //Current valid state toggled on Switch->ControlState = DbExpectLow; //Move control state to next state of machine. time = counter; //And update time } break; case DbExpectLow: //If MyState is DbExpectLow if (Switch->CurrentSwitchReading == On) { //Set current switch reading on Switch->ControlState = DbValidateLow; //Move along state machine } else { time = counter; //If not, update time } break; case DbValidateLow: //If MyState is DbValidateLow if (!(Switch->CurrentSwitchReading == On)) { //And if current switch reading is not "on" time = counter; //Update time Switch->ControlState = DbExpectLow; //Move along state machine } else if ((counter - time) >= Switch->MAKEDEBOUNCETIME) { //If not, check if time difference is greater than makedebounce time. If it is: Switch->PreviousValidState = Off; //Previous valid state off Switch->CurrentValidState = On; //Current valid state on Switch->ControlState = DbExpectHigh; //Move along state machine time = counter; //Update time } break; default: MyState = DbExpectHigh; } MyState = Switch->ControlState; //Update MyState with the current control state and return it for debugging return MyState; }
static int checkShad (Hdr *phdr, WF3Info *wf32d, int *missing, int *nsteps) { /* arguments: Hdr *phdr i: primary header WF3Info *wf32d i: switches, file names, etc int *missing io: incremented if the file is missing int *nsteps io: incremented if this step can be performed */ extern int status; int calswitch; int GetSwitch (Hdr *, char *, int *); int GetImageRef (RefFileInfo *, Hdr *, char *, RefImage *, int *); void MissingFile (char *, char *, int *); void CheckImgType (RefImage *, char *, char *, int *); int CheckDetector (char *, int, char *, int *); if (wf32d->shadcorr == PERFORM) { if (GetSwitch (phdr, "SHADCORR", &calswitch)) return (status); if (calswitch == COMPLETE) { wf32d->shadcorr = OMIT; return (status); } if (GetImageRef (wf32d->refnames, phdr, "SHADFILE", &wf32d->shad, &wf32d->shadcorr)) return (status); if (wf32d->shad.exists != EXISTS_YES) { MissingFile ("SHADFILE", wf32d->shad.name, missing); } else { /* Is the FILETYPE appropriate for a SHAD file? */ CheckImgType (&wf32d->shad, "SHUTTER SHADING", "SHADFILE", missing); /* Does it have the correct DETECTOR value? */ if (CheckDetector(wf32d->shad.name, wf32d->detector, "DETECTOR", missing)) return (status); } if (wf32d->shadcorr == PERFORM) (*nsteps)++; } return (status); }
//---initializing buttons and rotary void InitializeVariables(void) { rotaryEncoder.SwitchA.ControlState = DbExpectHigh; //Set up SwitchA(clockwise turns) defaults. Start at DbExpectHigh rotaryEncoder.SwitchA.CurrentSwitchReading = GetSwitch(Switch1); //Set current switch reading rotaryEncoder.SwitchA.CurrentValidState = Off; //Set current valid state to off rotaryEncoder.SwitchA.MAKEDEBOUNCETIME = 5; //Debounce time set to 5ms both ways (rise and fall). rotaryEncoder.SwitchA.RELEASEBOUNCETIME = 5; rotaryEncoder.SwitchA.SwitchSelect = Switch1; //Set switch 1 as available. rotaryEncoder.SwitchB.ControlState = DbExpectHigh; //Set up SwitchB (counter-clockswise turns) defaults. Start at DbExpectHigh rotaryEncoder.SwitchB.CurrentSwitchReading = GetSwitch(Switch2); //Set current switch reading rotaryEncoder.SwitchB.CurrentValidState = Off; //Set current valid state off rotaryEncoder.SwitchB.MAKEDEBOUNCETIME = 5; //Debounce time set to 5ms both ways. rotaryEncoder.SwitchB.RELEASEBOUNCETIME = 5; rotaryEncoder.SwitchB.SwitchSelect = Switch2; //Set switch 2 as available. cwDesired=Num*48; ccwDesired=Num*48; }
static int GetSw (Hdr *phdr, char *calswitch, int *flag) { /* arguments: Hdr *phdr i: primary header char *calswitch i: name of keyword (e.g. FLATCORR) int *flag o: value (0 or 1) of calibration switch */ extern int status; int GetSwitch (Hdr *, char *, int *); if (GetSwitch (phdr, calswitch, flag)) return (status); if (*flag != PERFORM) { if (*flag != COMPLETE) *flag = OMIT; } return (status); }
/* acsrej_do -- Perform the cosmic ray rejection for ACS images Description: ------------ This is mostly a file bookkeeping routine for the cosmic ray rejection task. It takes care of input/output files open/close, check for dimensions, read/ write data from/to files, allocate memory spaces etc. Date Author Description ---- ------ ----------- 06-May-1996 J.-C. Hsu Adapt from the SPP code crrej_do.x 05-Aug-1998 W. Hack Modified to handle ACS data 11-Feb-1999 W. Hack EXPTIME now in Pri. Hdr. 18-Mar-1999 W.J. Hack Revised to read EXPTIMEs from Primary headers for cr_scaling using tpin directly 14-Sep-1999 W.J. Hack Cleaned up SHADCORR usage. Added check for max number of files here. */ int acsrej_do (IRAFPointer tpin, char *outfile, char *mtype, clpar *par, int newpar[]) { extern int status; IODescPtr ipsci[MAX_FILES]; /* science image descriptor */ IODescPtr ipdq[MAX_FILES]; /* data quality image descriptor */ float skyval[MAX_FILES]; /* background DN values */ float efac[MAX_FILES]; /* exposure factors */ multiamp noise; /* readout noise */ multiamp gain; /* A-to-D gain factors */ float exptot; float texpt; int nimgs; SingleGroup sg; int niter = 0; float sigma[MAX_ITER]; Hdr phdr; /* primary header */ int extver; /* Current extension being processed*/ int numext; /* Number of extensions in each image */ int nextend; /* Number of output extensions */ char imgname[MAX_FILES][CHAR_FNAME_LENGTH]; char fimage[CHAR_FNAME_LENGTH]; /* Name of first image in list */ char root[CHAR_FNAME_LENGTH]; /* ROOTNAME for output CRJ file */ char uroot[CHAR_FNAME_LENGTH]; /* Upper case version of rootname */ char *shadrefname; int ext[MAX_FILES]; int dim_x, dim_y; /* image dimensions */ int i, j, n; /* loop indices */ float *efacsum, *work; int nrej; /* total number of rejected pixels */ float skysum; /* total sky level */ int logit; RefImage shadref; int shadswitch; double expend, expstart; int non_zero; /* number of input images with EXPTIME>0.*/ int found; char imgdefault[CHAR_FNAME_LENGTH]; /* name of first input image with EXPTIME > 0. */ int GetSwitch (Hdr *, char *, int *); int UpdateSwitch (char *, int, Hdr *, int *); void InitRefImg (RefImage *); int ImgHistory (const RefImage *, Hdr *); int ImgPedigree (RefImage *); int acsrej_check (IRAFPointer, int, int, clpar *, int [], char [][CHAR_FNAME_LENGTH], int [], IODescPtr [], IODescPtr [], multiamp *, multiamp *, int *, int *, int); int cr_scaling (char *, IRAFPointer, float [], int *, double *, double *); int rejpar_in(clpar *, int [], int, float, int *, float []); void acsrej_sky (char *, IODescPtr [], IODescPtr [], int, short, float []); void cr_history (SingleGroup *, clpar *, int); int acsrej_init (IODescPtr [], IODescPtr [], clpar *, int, int, int, multiamp, multiamp, float [], float [], SingleGroup *, float *); int acsrej_loop (IODescPtr [], IODescPtr [], char [][CHAR_FNAME_LENGTH], int [], int, clpar *, int, int, int, float [], multiamp, multiamp, float [], float [], FloatTwoDArray *, FloatTwoDArray *, float *, ShortTwoDArray *, int *, char *); int PutKeyFlt (Hdr *, char *, float, char *); int PutKeyDbl (Hdr *, char *, double, char *); int PutKeyStr (Hdr *, char *, char *, char *); int GetKeyStr (Hdr *, char *, int, char *, char *, int); int PutKeyInt (Hdr *, char *, int, char *); int GetKeyInt (Hdr *, char *, int, int, int *); void UFilename (char *, Hdr *); void UMemType (char *, Hdr *); void UExpname (char *, Hdr *); int LoadHdr (char *, Hdr *); void UpperAll (char *, char *, int); void TimeStamp (char *, char *); void WhichError (int); void PrSwitch (char *, int); void FindAsnRoot (char *, char *); void initmulti (multiamp *); /* -------------------------------- begin ---------------------------------- */ /* Initialize necessary structures */ InitRefImg (&shadref); root[0] = '\0'; uroot[0] = '\0'; initmulti (&noise); initmulti (&gain); numext = 0; nextend = 0; /* Since CR-SPLIT images are in separate files, we need to combine the same chip's exposure from each file. Therefore we will loop over each extension in the first image, determine what chip that corresponds to, and get the same chip from the rest of the images (which could be in any arbitrary extension in each of the images). */ /* First, let's determine how many extensions/chips in each file */ c_imtgetim (tpin, fimage, CHAR_FNAME_LENGTH); if (LoadHdr (fimage, &phdr) ) return (status = ERROR_RETURN); if (GetKeyInt (&phdr, "NEXTEND", NO_DEFAULT, 0, &nextend) == 0) numext = nextend / EXT_PER_GROUP; else numext = 1; shadswitch = 0; /* Check to see if SHADCORR was set to PERFORM in image header */ if (GetSwitch (&phdr, "SHADCORR", &shadswitch) ) return(status); /* If shadcorr was set either by the user on the command line or in the image header, initialize shadcorr processing. */ if (par->shadcorr == PERFORM || shadswitch == PERFORM) { /* Use par->shadcorr as switch for performing shading correction */ par->shadcorr = PERFORM; shadrefname = calloc(CHAR_FNAME_LENGTH, sizeof(char)); if (GetKeyStr (&phdr, "SHADFILE", NO_DEFAULT, "", shadrefname, CHAR_FNAME_LENGTH) ) return(status); strcpy (shadref.name, shadrefname); /* Read in PEDIGREE and DESCRIPTION for SHADFILE */ if (ImgPedigree (&shadref) ) return (status); /* If a DUMMY shadfile was specified, turn off shadcorr */ if (shadref.goodPedigree == DUMMY) par->shadcorr = OMIT; free (shadrefname); } freeHdr (&phdr); /* Initialize efac */ for (n = 0; n < MAX_FILES; n++) efac[n] = 1.0; /* calculate the scaling factors due to different exposure time */ strcpy (par->expname, "EXPTIME"); if (cr_scaling (par->expname, tpin, efac, &nimgs, &expend, &expstart) ){ WhichError (status); return (status); } /* make sure there is more than one image to process */ if (nimgs < 2) { trlmessage ("Needs more than one input image."); return (status = NOTHING_TO_DO); } /* calculate the total exposure time */ exptot = 0.; non_zero = 0; for (n = 0; n < nimgs; ++n) { exptot += efac[n]; /* Count how many inputs have non-zero(valid) EXPTIME */ if (efac[n] > 0.) non_zero++; } /* for the case of all images have zero exposure time, use equal exposure time of 1. */ if (exptot == 0.) { for (n = 0; n < nimgs; ++n) { efac[n] = 1.; } texpt = (float) nimgs; non_zero = nimgs; } else { texpt = exptot; } /* Now, start the loop. */ for (extver = 1; extver <= numext; extver++) { if (par->printtime) { TimeStamp ("Start cosmic ray rejection",""); } /* open input files and temporary files, check the parameters */ if (acsrej_check (tpin, extver, numext, par, newpar, imgname, ext, ipsci, ipdq, &noise, &gain, &dim_x, &dim_y, nimgs)) { WhichError (status); return(status); } /* Now that we have read in SHADCORR, report if it will be performed */ PrSwitch ("shadcorr", par->shadcorr); /* read in the parameters */ if (rejpar_in (par, newpar, nimgs, exptot, &niter, sigma) ) return(status); /* allocate array space */ efacsum = calloc (dim_x*dim_y, sizeof(float)); work = calloc (nimgs*dim_x, sizeof(float)); /* calculate the sky levels */ acsrej_sky (par->sky, ipsci, ipdq, nimgs, par->badinpdq, skyval); if (status != ACS_OK) { WhichError (status); return (status); } if (par->verbose) { for (n = 0; n < nimgs; n++) { sprintf (MsgText, "sky of '%s[sci,%d]' is %0.3f DN", imgname[n], ext[n], skyval[n]); trlmessage (MsgText); } } /* use the first input image to set up the data structure */ initSingleGroup (&sg); /* Find the first image in the input list which has an EXPTIME > 0. to use for initializing the output SingleGroup. */ found = 0; n = 0; /* By default, simply use the first one, so initialize accordingly.*/ strcpy (imgdefault, imgname[0]); do { if (efac[n] > 0.) { strcpy(imgdefault,imgname[n]); found = 1; } n++; } while (found == 0); getSingleGroup (imgdefault, extver, &sg); if (non_zero > 1){ /* compute the initial pixel values to be used to compare against all images. */ if (non_zero < nimgs){ trlwarn ("Some input exposures had EXPTIME = 0."); } if (acsrej_init (ipsci, ipdq, par, nimgs, dim_x, dim_y, noise, gain, efac, skyval, &sg, work) ) { WhichError(status); closeSciDq(nimgs, ipsci, ipdq, par); return (status); } if (par->printtime) TimeStamp ("Calculated initial guess for extension", ""); /* do the iterative cosmic ray rejection calculations */ if (acsrej_loop (ipsci, ipdq, imgname, ext, nimgs, par, niter, dim_x, dim_y, sigma, noise, gain, efac, skyval, &sg.sci.data, &sg.err.data, efacsum, &sg.dq.data, &nrej, shadref.name) ) { WhichError(status); closeSciDq(nimgs, ipsci, ipdq, par); return (status); } } else { trlwarn ("Cosmic-ray rejection NOT performed!"); if (non_zero > 0) { trlwarn ("Some input exposures had EXPTIME = 0."); trlwarn ("Output product will not be cosmic-ray cleaned!"); } /*else { trlwarn ("ALL input exposures had EXPTIME = 0."); trlwarn ("Output product will be BLANK!"); } */ } /* End if(non_zero) block */ /* must close all images, now that we are done reading them */ closeSciDq(nimgs, ipsci, ipdq, par); /* calculate the total sky ... */ skysum = 0.; for (n = 0; n < nimgs; ++n) { skysum += skyval[n]; } /* ... and force it to be non-negative */ if (skysum < 0.) skysum = 0.; if (par->printtime){ if (non_zero > 1){ TimeStamp ("Finished detecting cosmic rays on extension", ""); } else { TimeStamp ("Done checking this extension",""); } } /* write to the output image */ if (non_zero > 0){ for (j = 0; j < dim_y; ++j) { for (i = 0; i < dim_x; ++i) { PPix(&sg.sci.data,i,j) = PPix(&sg.sci.data,i,j)*texpt + skysum; PPix(&sg.err.data,i,j) *= texpt; } } } else { for (j = 0; j < dim_y; ++j) { for (i = 0; i < dim_x; ++i) { PPix(&sg.sci.data,i,j) = par->fillval; PPix(&sg.err.data,i,j) = 0.; /* Set DQ value to one which will always be considered BAD */ PPix(&sg.dq.data,i,j) = 1; } } /* Set at least one pixel to a different value to insure that an image array actually gets produced. */ PPix(&sg.err.data,0,0) = -1.; PPix(&sg.dq.data,0,0) = 8; } /* update the exposure time of the output images */ PutKeyFlt (sg.globalhdr, "TEXPTIME", exptot, ""); PutKeyFlt (sg.globalhdr, "SKYSUM", skysum, "Total sky level (DN)"); PutKeyDbl (sg.globalhdr, "EXPSTART", expstart, "computed exposure start time (Modified Julian Date)"); PutKeyDbl (sg.globalhdr, "EXPEND", expend, "exposure end time (Modified Julian Date)"); /* Updated REJ_RATE to use 'texpt' as a safe value when EXPTIME=0 for all members. WJH, 24 Feb 2003 */ PutKeyFlt (sg.globalhdr, "REJ_RATE", (float)nrej/texpt, "Cosmic ray impact rate (pixels/sec)"); PutKeyFlt (sg.globalhdr, "EXPTIME", exptot, ""); if (par->shadcorr) { logit = 0; if (UpdateSwitch ("SHADCORR", par->shadcorr, sg.globalhdr, &logit) ) return (status); PrSwitch ("shadcorr", COMPLETE); if (logit) { /*Records SHADFILE information in header comments... */ if (ImgHistory (&shadref, sg.globalhdr)) return (status); } } /* record parameters to the output file */ cr_history (&sg, par, nextend); PutKeyInt (&sg.sci.hdr, "NCOMBINE", nimgs, ""); UFilename (outfile, sg.globalhdr); UMemType (mtype, sg.globalhdr); FindAsnRoot (outfile, root); UpperAll (root, uroot, strlen(root)+1 ); /* EXPNAME values modified for all extensions in a SingleGroup. WJH 7 July 1999 */ UExpname (root, &sg.sci.hdr); UExpname (root, &sg.err.hdr); UExpname (root, &sg.dq.hdr); PutKeyStr (sg.globalhdr, "ROOTNAME", uroot,"Rootname of the observation set"); /* Output CHIP to the same EXTVER as the CHIP ID */ putSingleGroup (outfile, extver, &sg, 0); freeSingleGroup (&sg); if (par->printtime) TimeStamp ("Finished writing out extension", ""); /* deallocate memories */ free (efacsum); free (work); } /* Set status to a value which will be understood by CALACS to turn off subsequent processing. */ if (non_zero == 0) status = NO_GOOD_DATA; return (status); }
static int checkFlat (Hdr *phdr, WF3Info *wf32d, int *missing, int *nsteps) { /* arguments: Hdr *phdr i: primary header WF3Info *wf32d i: switches, file names, etc int *missing io: incremented if a file is missing int *nsteps io: incremented if this step can be performed */ extern int status; int calswitch; int GetSwitch (Hdr *, char *, int *); int GotFileName (char *); int GetImageRef (RefFileInfo *, Hdr *, char *, RefImage *, int *); void MissingFile (char *, char *, int *); void CheckImgType (RefImage *, char *, char *, int *); int CheckFilter (char *, char *, char *, int *); int CheckDetector (char *, int, char *, int *); /* Are we supposed to do this step? */ if (wf32d->flatcorr == PERFORM) { if (GetSwitch (phdr, "FLATCORR", &calswitch)) return (status); if (calswitch == COMPLETE) { wf32d->flatcorr = OMIT; return (status); } /* Initial values; may be reset below. */ wf32d->pfltcorr = PERFORM; wf32d->dfltcorr = PERFORM; wf32d->lfltcorr = PERFORM; if (GetImageRef (wf32d->refnames, phdr, "PFLTFILE", &wf32d->pflt, &wf32d->pfltcorr)) return (status); if (wf32d->pflt.exists != EXISTS_YES) { if (GotFileName (wf32d->pflt.name)) { /* name specified? */ MissingFile ("PFLTFILE", wf32d->pflt.name, missing); } else { wf32d->pfltcorr = OMIT; /* name was blank or "N/A" */ } } else { /* Is the FILETYPE appropriate for a PFLT file? */ CheckImgType (&wf32d->pflt, "PIXEL-TO-PIXEL FLAT", "PFLTFILE", missing); /* Does it have the correct FILTER value? */ if (CheckFilter(wf32d->pflt.name, wf32d->filter, "FILTER", missing)) return (status); /* Does it have the correct DETECTOR value? */ if (CheckDetector(wf32d->pflt.name, wf32d->detector, "DETECTOR", missing)) return (status); } if (GetImageRef (wf32d->refnames, phdr, "DFLTFILE", &wf32d->dflt, &wf32d->dfltcorr)) return (status); if (wf32d->dflt.exists != EXISTS_YES) { if (GotFileName (wf32d->dflt.name)) { MissingFile ("DFLTFILE", wf32d->dflt.name, missing); } else { wf32d->dfltcorr = OMIT; } } else { /* Is the FILETYPE appropriate for a DFLT file? */ CheckImgType (&wf32d->dflt, "DELTA FLAT", "DFLTFILE", missing); /* Does it have the correct FILTER value? */ if (CheckFilter(wf32d->dflt.name, wf32d->filter, "FILTER", missing)) return (status); /* Does it have the correct DETECTOR value? */ if (CheckDetector(wf32d->dflt.name, wf32d->detector, "DETECTOR", missing)) return (status); } if (GetImageRef (wf32d->refnames, phdr, "LFLTFILE", &wf32d->lflt, &wf32d->lfltcorr)) return (status); if (wf32d->lflt.exists != EXISTS_YES) { if (GotFileName (wf32d->lflt.name)) { MissingFile ("LFLTFILE", wf32d->lflt.name, missing); } else { wf32d->lfltcorr = OMIT; } } else { /* Is the FILETYPE appropriate for a LFLT file? */ CheckImgType (&wf32d->lflt, "LARGE SCALE FLAT", "LFLTFILE", missing); /* Does it have the correct FILTER value? */ if (CheckFilter(wf32d->lflt.name, wf32d->filter, "FILTER", missing)) return (status); /* Does it have the correct DETECTOR value? */ if (CheckDetector(wf32d->lflt.name, wf32d->detector, "DETECTOR", missing)) return (status); } /* If any of the three parts of flat fielding is set to PERFORM, then we can do this step. If not, and if any part is DUMMY because of the reference file, reset the flat field flag to DUMMY; this will mean that all the files that were specified have pedigree=dummy. */ if (wf32d->pfltcorr == PERFORM || wf32d->dfltcorr == PERFORM || wf32d->lfltcorr == PERFORM) { (*nsteps)++; } else if (wf32d->pfltcorr == OMIT && wf32d->dfltcorr == OMIT && wf32d->lfltcorr == OMIT) { (*missing)++; trlerror ("PFLTFILE, DFLTFILE, and LFLTFILE are all blank."); } else if (wf32d->pfltcorr == DUMMY || wf32d->dfltcorr == DUMMY || wf32d->lfltcorr == DUMMY) { wf32d->flatcorr = DUMMY; } } return (status); }
static int checkDark (Hdr *phdr, WF3Info *wf32d, int *missing, int *nsteps) { /* arguments: Hdr *phdr i: primary header WF3Info *wf32d i: switches, file names, etc int *missing io: incremented if the file is missing int *nsteps io: incremented if this step can be performed */ extern int status; int calswitch; int GetSwitch (Hdr *, char *, int *); int GetImageRef (RefFileInfo *, Hdr *, char *, RefImage *, int *); void MissingFile (char *, char *, int *); void CheckImgType (RefImage *, char *, char *, int *); int CheckDetector (char *, int, char *, int *); char *darktouse; char *darktype; if (wf32d->darkcorr == PERFORM) { if (GetSwitch (phdr, "DARKCORR", &calswitch)) return (status); if (calswitch == COMPLETE) { wf32d->darkcorr = OMIT; return (status); } else { if (GetSwitch (phdr, "PCTECORR", &calswitch)) return(status); if (calswitch == COMPLETE){ darktouse="DRKCFILE"; darktype="CTEDARK"; } else { darktouse="DARKFILE"; darktype="DARK"; } } if (GetImageRef (wf32d->refnames, phdr, darktouse, &wf32d->dark, &wf32d->darkcorr)) return (status); if (wf32d->dark.exists != EXISTS_YES) { MissingFile (darktouse, wf32d->dark.name, missing); } else { /* Is the FILETYPE appropriate for a DARK file? */ CheckImgType (&wf32d->dark, darktype, darktouse, missing); /* Does it have the correct DETECTOR value? */ if (CheckDetector(wf32d->dark.name, wf32d->detector, "DETECTOR", missing)) return (status); } if (wf32d->darkcorr == PERFORM) (*nsteps)++; } return (status); }
static int FluxToNet (StisInfo6 *sts, IntensArray *inta, int sporder) { /* This is used to store information from the fflux file in a form suitable for the reference file input routines. */ StisInfo6 fsts; ApInfo slit; PhotInfo phot; IODescPtr im; Hdr phdr; double photfactor, throughput, response, dispersion; double atodgain, readnoise; float correction; int i, dispc, helc, status; int abs_starti, thr_starti; int dummy; void FreePhot6 (PhotInfo *); void FreeThroughput6 (ApInfo *); int GetAbsPhot6 (StisInfo6 *, int, PhotInfo *, int, int *); int GetApDes6 (StisInfo6 *, ApInfo *); int GetApThr6 (StisInfo6 *, ApInfo *); int Get_KeyD (Hdr *, char *, int, double, double *); int Get_KeyS (Hdr *, char *, int, char *, char *, int); int GetSwitch (Hdr *, char *, int *); double interp1d (double, double *, double *, int, int *); void StisInit6 (StisInfo6 *); photfactor = H_PLANCK * C_LIGHT / HST_AREA; /* Initialize local data structures. */ StisInit6 (&fsts); InitRefTab (&fsts.phottab); InitRefTab (&fsts.apertab); InitRefTab (&fsts.apdestab); slit.allocated = 0; slit.gac_allocated = 0; phot.allocated = 0; phot.pcorr = NULL; /* Handling the primary header here is not efficient. But keeps this new code manageable since everything new is added at a single point. In the future we may move this to outside the main loop and pass the necessary values as part of the sts structure. */ initHdr (&phdr); im = openInputImage (sts->pxtab.name, "", 0); if (hstio_err()) return (OPEN_FAILED); getHeader (im, &phdr); if (hstio_err()) return (OPEN_FAILED); closeImage (im); /* Abort if both helcorr and dispcorr weren't performed. The criterion is: if a keyword is set to either COMPLETE or PERFORM, we assume that the operation was performed. This is because UpdHdrSwitch in Do1Dx only updates the keywords to COMPLETE if they are set to PERFORM in the input file. (note: UpdHdrSwitch is no longer used) */ if ((status = GetSwitch (&phdr, "DISPCORR", &dispc))) return (status); if ((status = GetSwitch (&phdr, "HELCORR", &helc))) return (status); if (!((dispc == PERFORM || dispc == COMPLETE) && (helc == PERFORM || helc == COMPLETE))) { printf ("ERROR No DISPCORR/HELCORR in fflux file.\n"); return (ERROR_RETURN); } /* Read header keywords. */ if ((status = Get_KeyD (&phdr, "READNSE", 1, 0., &readnoise))) return (status); if ((status = Get_KeyD (&phdr, "ATODGAIN", 1, 1., &atodgain))) return (status); if ((status = Get_KeyS (&phdr, "PHOTTAB", FATAL, "", fsts.phottab.name, STIS_LINE))) return (status); if ((status = Get_KeyS (&phdr, "APDESTAB", FATAL, "", fsts.apdestab.name, STIS_LINE))) return (status); if ((status = Get_KeyS (&phdr, "APERTAB", FATAL, "", fsts.apertab.name, STIS_LINE))) return (status); /* Copy stuff from primary data structure into local one. */ fsts.x1d_o = sts->x1d_o; fsts.dispcorr = sts->dispcorr; fsts.fluxcorr = sts->fluxcorr; fsts.pctcorr = sts->pctcorr; fsts.cenwave = sts->cenwave; strcpy (fsts.opt_elem, sts->opt_elem); strcpy (fsts.aperture, sts->aperture); /* Read the required reference info. */ dummy = 0; if ((status = GetAbsPhot6 (&fsts, sporder, &phot, 0, &dummy))) return (status); if ((status = GetApDes6 (&fsts, &slit))) return (status); if ((status = GetApThr6 (&fsts, &slit))) return (status); abs_starti = 1; /* initial values */ thr_starti = 1; /* Loop over flux array. */ for (i = 0; i < inta->nelem; i++) { response = interp1d (inta->wave[i], phot.wl, phot.thru, phot.nelem, &abs_starti); throughput = interp1d (inta->wave[i], slit.wl, slit.thr, slit.nelem, &thr_starti); if (i > 0) dispersion = inta->wave[i] - inta->wave[i-1]; else dispersion = inta->wave[1] - inta->wave[0]; /* This check is provisional; final version awaits IS's words. */ if (response <= 0.0 || dispersion <= 0.0 || throughput <= 0.0) { printf ("ERROR Error in fflux file contents.\n"); return (ERROR_RETURN); } correction = (float) (photfactor / (response * throughput * inta->wave[i] * dispersion * atodgain * CM_PER_ANGSTROM)); inta->intens[i] = inta->intens[i] / correction; } FreeThroughput6 (&slit); FreePhot6 (&phot); freeHdr (&phdr); return STIS_OK; }