/* acsccd -- basic CCD image reduction This file contains: ACSccd */ # include # include # include # include "../acs.h" # include "../acsinfo.h" # include "../acserr.h" # include "../acscorr.h" /* calibration switch names */ /* Do basic CCD calibration. Warren Hack, 1998 July 28: Revised for ACS... Warren Hack, 2000 Sept 11: Revised to support post-flash processing. ** Not much modification from the basic outline ** followed in CALSTIS1... ** */ int ACSccd (char *input, char *output, CalSwitch *ccd_sw, RefFileInfo *refnames, int printtime, int verbose) { extern int status; ACSInfo acs; /* calibration switches, reference files, etc */ int extver; Hdr phdr; /* primary header for input image */ int DoCCD (ACSInfo *, int); int FileExists (char *); int GetACSFlags (ACSInfo *, Hdr *); int GetACSKeys (ACSInfo *, Hdr *); void TimeStamp (char *, char *); void PrBegin (char *); void PrEnd (char *); void PrFileName (char *, char *); void PrHdrInfo (char *, char *, char *, char *); void PrGrpBegin (char *, int); void PrGrpEnd (char *, int); int LoadHdr (char *, Hdr *); void InitCCDTrl (char *, char *); void ACSInit (ACSInfo *); int MkName (char *, char *, char *, char *, char *, int); /* ----------------------- Start Code --------------------------------*/ /* Determine the names of the trailer files based on the input and output file names, then initialize the trailer file buffer with those names. */ InitCCDTrl (input, output); /* If we had a problem initializing the trailer files, quit... */ if (status != ACS_OK) return (status); PrBegin ("ACSCCD"); if (printtime) TimeStamp ("ACSCCD started", ""); /* Initialize structure containing calacs information. */ ACSInit (&acs); /* Copy command-line arguments into acs. */ /* Start by making sure input name is a full filename... */ if (MkName (input, "_raw", "_raw", "", acs.input, ACS_LINE) ) { strcpy(acs.input, input); strcat (acs.input,"_raw.fits"); } strcpy (acs.output, output); acs.dqicorr = ccd_sw->dqicorr; acs.atodcorr = ccd_sw->atodcorr; acs.blevcorr = ccd_sw->blevcorr; acs.biascorr = ccd_sw->biascorr; acs.flashcorr = ccd_sw->flashcorr; acs.noisecorr = PERFORM; acs.printtime = printtime; acs.verbose = verbose; /* For debugging... acs.dqicorr = PERFORM; acs.atodcorr = PERFORM; acs.blevcorr = PERFORM; acs.biascorr = PERFORM; acs.noisecorr = PERFORM; acs.printtime = 1; acs.verbose = 1; */ acs.refnames = refnames; PrFileName ("input", acs.input); PrFileName ("output", acs.output); /* Check whether the output file already exists. */ if (FileExists (acs.output)) return (status); /* Open input image in order to read its primary header. */ if (LoadHdr (acs.input, &phdr) ) return (status); /* Get keyword values from primary header. */ if (GetACSKeys (&acs, &phdr)) { freeHdr (&phdr); return (status); } /* If we have MAMA data, do not even proceed here... */ if (acs.detector == MAMA_DETECTOR) { /* Return ACS_OK, since processing can proceed, just with a different function */ trlwarn ("Can NOT process MAMA data with ACSCCD..."); freeHdr (&phdr); return (status); } /* Print information about this image. */ PrHdrInfo (acs.aperture, acs.filter1, acs.filter2, acs.det); /* Get reference file names from input image header. Pedigree is checked, and the calibration switch (an internal flag, not the header keyword) will be reset from PERFORM to DUMMY if the reference file has pedigree = "DUMMY". Switches that are currently set to PERFORM will be reset to OMIT if the value in the header is COMPLETE. */ if (GetACSFlags (&acs, &phdr)) { freeHdr (&phdr); return (status); } freeHdr (&phdr); /* Do basic CCD image reduction. */ if (acs.printtime) TimeStamp ("Begin processing", acs.rootname); for (extver = 1; extver <= acs.nimsets; extver++) { trlmessage ("\n"); PrGrpBegin ("imset", extver); if (DoCCD (&acs, extver)) return (status); PrGrpEnd ("imset", extver); } trlmessage ("\n"); PrEnd ("ACSCCD"); if (acs.printtime) TimeStamp ("ACSCCD completed", acs.rootname); /* Write out temp trailer file to final file */ WriteTrlFile (); return (status); } void InitCCDTrl (char *input, char *output) { extern int status; char trl_in[ACS_LINE+1]; /* trailer filename for input */ char trl_out[ACS_LINE+1]; /* output trailer filename */ int exist; char isuffix[] = "_raw"; char osuffix[] = "_blv_tmp"; int MkName (char *, char *, char *, char *, char *, int); void WhichError (int); int TrlExists (char *); void SetTrlOverwriteMode (int); /* Initialize internal variables */ trl_in[0] = '\0'; trl_out[0] = '\0'; exist = EXISTS_UNKNOWN; /* Start by stripping off suffix from input/output filenames */ if (MkName (input, isuffix, "", TRL_EXTN, trl_in, ACS_LINE)) { WhichError (status); sprintf (MsgText, "Couldn't determine trailer filename for %s", input); trlmessage (MsgText); } if (MkName (output, osuffix, "", TRL_EXTN, trl_out, ACS_LINE)) { WhichError (status); sprintf (MsgText, "Couldn't create trailer filename for %s", output); trlmessage (MsgText); } /* Test whether the output file already exists */ exist = TrlExists(trl_out); if (exist == EXISTS_YES) { /* The output file exists, so we want to overwrite them with the new trailer comments. */ SetTrlOverwriteMode (YES); } /* Sets up temp trailer file for output and copies input trailer file into it. */ InitTrlFile (trl_in, trl_out); }