int main (int argc, char **argv) { char *inlist; /* input file name */ char *outlist; /* output blev file name */ int switch_on = 0; /* was any switch specified? */ int printtime = NO; /* print time after each step? */ int verbose = NO; /* print additional info? */ int quiet = NO; /* print additional info? */ int too_many = 0; /* too many command-line arguments? */ int i, j; /* loop indexes */ IRAFPointer i_imt, o_imt; /* imt list pointers */ char *input; /* name of input science file */ char *output; /* name of output file */ int n_in, n_out; /* number of files in each list */ int n; /* Input and output suffixes. */ char *isuffix[] = {"_raw", "_rac_tmp"}; char *osuffix[] = {"_blv_tmp", "_blc_tmp"}; int nsuffix = 2; /* A structure to pass the calibration switches to WF3CCD */ CCD_Switch ccd_sw; /* reference file keywords and names */ RefFileInfo refnames; void InitRefFile (RefFileInfo *); void FreeRefFile (RefFileInfo *); void initCCDSwitches (CCD_Switch *); int WF3ccd (char *, char *, CCD_Switch *, RefFileInfo *, int, int); int DefSwitch (char *); int MkName (char *, char *, char *, char *, char *, int); void WhichError (int); int CompareNumbers (int, int, char *); /*===========================================================================*/ /* Initialize IRAF interface environment */ c_irafinit (argc, argv); /* Post HSTIO error handler */ push_hstioerr (errchk); /* Allocate space for file names. */ inlist = calloc (SZ_LINE+1, sizeof (char)); outlist = calloc (SZ_LINE+1, sizeof (char)); input = calloc (SZ_LINE+1, sizeof (char)); output = calloc (SZ_LINE+1, sizeof (char)); if (inlist == NULL || outlist == NULL || input == NULL || output == NULL) { printf ("Can't even begin; out of memory.\n"); exit (ERROR_RETURN); } inlist[0] = '\0'; outlist[0] = '\0'; input[0] = '\0'; output[0] = '\0'; /* Initialize the lists of reference file keywords and names. */ InitRefFile (&refnames); /* Initial values. */ initCCDSwitches (&ccd_sw); /* Parse the command-line arguments */ for (i = 1; i < argc; i++) { if (!(strcmp(argv[i],"--version"))) { printf("%s\n",WF3_CAL_VER_NUM); exit(0); } if (strcmp (argv[i], "-dqi") == 0) { /* turn on */ ccd_sw.dqicorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-atod") == 0) { ccd_sw.atodcorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-blev") == 0) { ccd_sw.blevcorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-bias") == 0) { ccd_sw.biascorr = PERFORM; switch_on = 1; } else if (strcmp (argv[i], "-flash") == 0) { ccd_sw.flashcorr = PERFORM; switch_on = 1; } else if (argv[i][0] == '-') { for (j = 1; argv[i][j] != '\0'; j++) { if (argv[i][j] == 't') { printtime = YES; } else if (argv[i][j] == 'v') { verbose = YES; } else if (argv[i][j] == 'q') { quiet = YES; } else if (argv[i][j] == 'r'){ printf ("Current version: %s\n", WF3_CAL_VER); exit(0); } else { printf (MsgText, "Unrecognized option %s\n", argv[i]); FreeNames (inlist, outlist, input, output); exit (1); } } } else if (inlist[0] == '\0') { strcpy (inlist, argv[i]); } else if (outlist[0] == '\0') { strcpy (outlist, argv[i]); } else { too_many = 1; } } if (inlist[0] == '\0' || too_many) { printf ("syntax: wf3ccd [-t] [-v] [-q] [-r] input output\n"); printf (" command-line switches:\n"); printf (" -dqi -atod -blev -bias\n"); FreeNames (inlist, outlist, input, output); exit (ERROR_RETURN); } /* Initialize the structure for managing trailer file comments */ InitTrlBuf (); /* Copy command-line value for QUIET to structure */ SetTrlQuietMode(quiet); /* Was no calibration switch specified on command line? */ if (!switch_on) { /* default values (mostly PERFORM) */ ccd_sw.dqicorr = DefSwitch ("dqicorr"); ccd_sw.atodcorr = DefSwitch ("atodcorr"); ccd_sw.blevcorr = DefSwitch ("blevcorr"); ccd_sw.biascorr = DefSwitch ("biascorr"); ccd_sw.flashcorr = DefSwitch ("flshcorr"); ccd_sw.fluxcorr = DefSwitch ("fluxcorr"); ccd_sw.pctecorr = DefSwitch ("pctecorr"); } /* Expand the templates. */ i_imt = c_imtopen (inlist); o_imt = c_imtopen (outlist); n_in = c_imtlen (i_imt); n_out = c_imtlen (o_imt); /* The number of input and output files must be the same. */ if (CompareNumbers (n_in, n_out, "output")) status = 1; if (status) { FreeNames (inlist, outlist, input, output); CloseTrlBuf(); exit (ERROR_RETURN); } /* Loop over the list of input files. */ for (n = 0; n < n_in; n++) { i = c_imtgetim (i_imt, input, SZ_LINE); if (n_out > 0) { i = c_imtgetim (o_imt, output, SZ_LINE); } else { output[0] = '\0'; } if (MkOutName (input, isuffix, osuffix, nsuffix, output, SZ_LINE)) { WhichError (status); sprintf (MsgText, "Skipping %s", input); trlmessage (MsgText); continue; } /* Calibrate the current input file. */ if (WF3ccd (input, output, &ccd_sw, &refnames, printtime, verbose)){ sprintf (MsgText, "Error processing %s.", input); trlerror (MsgText); WhichError (status); } } /* Close lists of file names, and free name buffers. */ c_imtclose (i_imt); c_imtclose (o_imt); CloseTrlBuf(); FreeRefFile (&refnames); FreeNames (inlist, outlist, input, output); if (status) exit (ERROR_RETURN); else exit (0); }
int CalAcsRun (char *input, int printtime, int save_tmp, int verbose, int debug, const unsigned nThreads, const unsigned cteAlgorithmGen, const char * pcteTabNameFromCmd) { /* arguments: char *input i: name of the FITS file/table to be processed int printtime i: true --> print time stamps at intermediate steps int *save_tmp i: true --> save temporary files int verbose i: true --> print info during processing int debug i: true --> print debugging info during processing int onecpu i: true --> turn off use of OpenMP during processing */ extern int status; ACSInfo acshdr; /* calibration switches, etc */ AsnInfo asn; /* association table data */ char *acsdth_input; /* Input list for ACSDTH */ int prod; void PrBegin (char *); void PrEnd (char *); void PrFileName (char *, char *); void TimeStamp (char *, char *); /* Association table routines */ void initAsnInfo (AsnInfo *); void freeAsnInfo (AsnInfo *); int LoadAsn (AsnInfo *); int ProcessACSCCD (AsnInfo *, ACSInfo *, int *, int, const unsigned nThreads, const unsigned cteAlgorithmGen, const char * pcteTabNameFromCmd); int ProcessMAMA (AsnInfo *, ACSInfo *, int); int AcsDth (char *, char *, int, int, int); char *BuildDthInput (AsnInfo *, int); void InitDthTrl (char *, char *); /* Post error handler */ push_hstioerr (errchk); PrBegin ("CALACS"); /* *** CALACS -- Version ... *** */ if (printtime) TimeStamp ("CALACS started", ""); /* Determine if input is a single file or an association table, then populate ASN structure with appropriate information to control processing. */ initAsnInfo(&asn); if (debug) { trlmessage ("Initialized Association data ... "); } /* Copy Input filename to ASN structure */ strcpy (asn.input, input); /* Print image name. */ trlmessage ("\n"); PrFileName ("input", asn.input); /* Set verbose flag... */ asn.verbose = verbose; asn.debug = debug; /* LoadAsn will determine whether input is a single file or an Association table. If a single image, it will look in that images association table to see what products are associated with it, and process them accordingly. If it is just a single image as its own output, it will proceed as a 1 element table. Based on routines from n_getAsnTable() and n_setup() in CALNICB */ if(LoadAsn(&asn)) { freeAsnInfo (&asn); return (status); } /* Check to see that detector is known, as it could come through with a value of 0 or UNKNOWN_DETECTOR. WJH 2Mar99 */ if (asn.detector == UNKNOWN_DETECTOR || asn.detector == 0) { trlwarn ("Unknown detector type for observations."); freeAsnInfo(&asn); return (status = NOTHING_TO_DO); } if (asn.verbose) { sprintf (MsgText,"CALACS: Detector %s, type %d ",asn.instr, asn.detector); trlmessage (MsgText); } /* Determine what detector we are working with... */ if (asn.detector != MAMA_DETECTOR ) { /* Process CCD data ... */ if (asn.verbose) { trlmessage ("CALACS: processing a CCD product"); } if (ProcessACSCCD(&asn, &acshdr, &save_tmp, printtime, nThreads, cteAlgorithmGen, pcteTabNameFromCmd)) { if (status == NOTHING_TO_DO) { trlwarn ("No processing desired for CCD data."); } else { trlerror ("Couldn't process CCD data"); } freeAsnInfo(&asn); return (status); } trlmessage("Finished CCD processing..."); } else { /* Process MAMA observations here */ trlmessage("Starting to process MAMA data now..."); if (ProcessMAMA(&asn, &acshdr, printtime)) { if (status == NOTHING_TO_DO){ trlwarn ("No processing desired for MAMA data."); } else{ trlerror ("Couldn't process MAMA data"); } freeAsnInfo(&asn); return (status); } trlmessage("Finished MAMA processing..."); } /* Add DTH processing here... */ /* For each DTH product... */ if (asn.process == FULL){ if (asn.verbose) { trlmessage ("CALACS: Building DTH products"); } acsdth_input = NULL; for (prod = 0; prod < asn.numprod; prod++) { /* Create empty DTH product, header only */ /* This uses only one sub-product for the header template, but later versions should use a function similar to BuildSumInput to create list of subproducts as inputs... */ acsdth_input = BuildDthInput (&asn, prod); /* We always want to create a final concatenated trailer file for the entire association whether there is a product or not. So, we set up the trailer file based on the association file name itself. */ /* If desired, we could optionally use the full _drz.tra filename as the trailer filename, based on the output dither product name. if (strcmp(asn.product[prod].prodname,"") != 0) { InitDthTrl (acsdth_input, asn.product[prod].prodname); } else { */ InitDthTrl(acsdth_input, asn.rootname); /* End brace for optional dither product name assignment... } */ /* Check if we have a PROD-DTH specified...*/ if (strcmp(asn.product[prod].prodname, "") != 0) { if ((asn.dthcorr == PERFORM || asn.dthcorr == DUMMY)) { if (AcsDth (acsdth_input, asn.product[prod].prodname, asn.dthcorr, printtime, asn.verbose) ) return (status); /* Pass posid of 0 to indicate a PRODUCT is to be updated */ updateAsnTable(&asn, prod, NOPOSID); } } else { trlwarn ("No DTH product name specified. No product created."); /*status = ACS_OK; */ } } free (acsdth_input); } if (asn.verbose) { trlmessage ("CALACS: Finished processing product "); } freeAsnInfo(&asn); trlmessage ("\n"); PrEnd ("CALACS"); /* *** CALACS complete *** */ if (printtime) TimeStamp ("CALACS completed", acshdr.rootname); /* Return the final value of status, which should be ACS_OK if all went well or some error condition otherwise. */ return (status); }