Exemplo n.º 1
0
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 */
    int k;

    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";
    char osuffix[] = "_blv_tmp";

    /* A structure to pass the calibration switches to ACSCCD */
    CalSwitch ccd_sw;

    /* reference file keywords and names */
    RefFileInfo refnames;

    void InitRefFile (RefFileInfo *);
    void FreeRefFile (RefFileInfo *);
    void initSwitch (CalSwitch *);

    int ACSccd (char *, char *, CalSwitch *, RefFileInfo *, int, int);
    int DefSwitch (char *);
    int MkName (char *, char *, char *, char *, char *, int);
    void WhichError (int);
    int CompareNumbers (int, int, char *);

    /* For image header access */
    Hdr phdr;
    int LoadHdr (char *, Hdr *);
    int GetSwitch (Hdr *, char *, int *);

    c_irafinit (argc, argv);

    /* Allocate space for file names. */
    inlist = calloc (ACS_LINE+1, sizeof (char));
    outlist = calloc (ACS_LINE+1, sizeof (char));
    input = calloc (ACS_LINE+1, sizeof (char));
    output = calloc (ACS_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. */
    initSwitch (&ccd_sw);

    for (i = 1;  i < argc;  i++) {

        /**********
        if (strcmp (argv[i], "-dqi") == 0) {
            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 (argv[i][0] == '-') {
        **********/
        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 {
                    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:  acsccd [-t] [-v] [-q] 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?
       default values (mostly PERFORM) except ATODCORR
    if (!switch_on) {*/
    ccd_sw.dqicorr  = DefSwitch ("dqicorr");
    ccd_sw.atodcorr = DefSwitch ("atodcorr");
    ccd_sw.blevcorr = DefSwitch ("blevcorr");
    ccd_sw.biascorr = DefSwitch ("biascorr");
    /*}*/

    /* 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++) {

        k = c_imtgetim (i_imt, input, ACS_LINE);

        if (n_out > 0)
            k = c_imtgetim (o_imt, output, ACS_LINE);
        else
            output[0] = '\0';

        /* Open input image in order to read its primary header. */
        if (LoadHdr (input, &phdr)) {
            WhichError (status);
            sprintf (MsgText, "Skipping %s", input);
            trlmessage (MsgText);
            continue;
        }

        /* Determine osuffix. */
        strcpy(osuffix, "_blv_tmp");

        if (MkName (input, isuffix, osuffix, "", output, ACS_LINE)) {
            WhichError (status);
            sprintf (MsgText, "Skipping %s", input);
            trlmessage (MsgText);
            continue;
        }

        /* Calibrate the current input file. */
        if (ACSccd (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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
int ProcessMAMA (AsnInfo *asn, ACSInfo *acshdr, int printtime) {

    extern int status;

    RefFileInfo sciref;       /* ref file keywords and names */
    CalSwitch sci_sw;         /* all cal switches for science file */
    CalSwitch acsccd_sci_sw;  /* ACSCCD switches for science file */
    CalSwitch acscte_sci_sw;  /* ACSCTE switches for science file */
    CalSwitch acs2d_sci_sw;   /* ACS2D  switches for science file */

    int prod;             /* which CR-split/Rptobs product?    */
    int posid;            /* counter for input products    */
    int expid;            /* counter for input exposures */
    int newpreface = NO;  /* switch for keeping previous comments for
                             all remaining trailer files */

    char *acssum_input;  /* Input list for ACSSUM */
    char acssum_output[CHAR_FNAME_LENGTH+1];
    char acssum_mtype[SZ_STRKWVAL+1];  /* Role of exposure in association */
    char *acssum_msgtext;

    void ACSDefaults (ACSInfo *);
    void InitRefFile (RefFileInfo *);
    void FreeRefFile (RefFileInfo *);
    int ACSRefInit (ACSInfo *, CalSwitch *, RefFileInfo *);
    int ACS2d (char *, char *, CalSwitch *, RefFileInfo *, int, int);
    int AcsSum (char *, char *, char *, int, int);
    char *BuildSumInput (AsnInfo *, int, int);
    int GetAsnMember (AsnInfo *, int, int, int, ACSInfo *);
    int GetSingle (AsnInfo *, ACSInfo *);
    int InsertACSSuffix (ACSInfo *);
    void updateAsnTable (AsnInfo *, int, int);

    if (asn->debug) {
        trlmessage ("CALACS: processing MAMA observations");
    }

    /* Loop over the products/positions for each
       Repeat-Obs or Repeat-Obs/DITHER set.
       PRODID/prod starts at 0, while numprod starts at 1...
    */
    for (prod = 0; prod < asn->numprod; prod++) {

        /* loop over members of a position/product;
           individual CR-SPLIT/Repeat-obs exposures */
        /* Process SINGLE/PARTIAL/FULL product */
        for (posid = 1; posid <= asn->numsp; posid++) {
            if (asn->verbose){
                sprintf (MsgText,"CALACS: processing MAMA posid = %d", posid);
                trlmessage (MsgText);
            }

            for (expid = 1; expid <= asn->spmems[posid]; expid++) {

                /* Read in Member keyword info from --FIRST-- EXP image header */
                if(prod == 0 && posid == 1 && expid == 1) {
                    /* (Re-)Initialize the lists of reference file keywords
                       and names. */
                    InitRefFile (&sciref);

                    /* Assign default values in acs. */
                    ACSDefaults (acshdr);

                   if (asn->process == SINGLE ) {
                       if (GetSingle (asn, acshdr) )
                           return (status);
                   } else {
                       if( GetAsnMember(asn, prod, posid, expid, acshdr))
                           return (status);
                   }

                   /* Initialize variables, and get info (cal switches and
                      reference file names) from primary headers.
                   */
                   if (ACSRefInit (acshdr, &sci_sw, &sciref))
                       return (status);

                   if (asn->verbose) {
                       trlmessage ("CALACS: Got reference file information");
                   }
                   /* Store the trailer file comments into preface */
                   newpreface = YES;

                } else {

                    /* Read in Member keyword info from image header */
                    if (asn->process == SINGLE ) {
                        if (GetSingle (asn, acshdr) )
                            return (status);
                    } else {
                        if( GetAsnMember(asn, prod, posid, expid, acshdr))
                            return (status);
                    }

                    /* Construct output and temporary file names. */
                    if (InsertACSSuffix (acshdr))
                        return (status);
                }

                /* From this point on, we are working with ONE image at a time */

                /* Copy switch values for ACSCCD, ACSCTE, and ACS2D
                   argument lists. */
                SetACSSw (&sci_sw, &acsccd_sci_sw, &acscte_sci_sw, &acs2d_sci_sw);

                /* Ready to process input image now */
                if (acshdr->sci_basic_2d == PERFORM) {

                    /* Copy all messages up to here into preface buffer
                       to be prepended to all input file trailer files */
                    if (newpreface == YES) {
                        InitTrlPreface();
                    }

                    /* Flat field the input MAMA image. */
                    if (ACS2d (acshdr->rawfile, acshdr->fltfile,
                               &acs2d_sci_sw, &sciref, printtime, asn->verbose))
                        return (status);

                } else {

                    /* Copy the input file to fltfile.  We need to do this
                       because ACSSUM needs it for input. */
                    trlwarn ("No processing performed on image.");
                    if (acshdr->sci_rptcorr != PERFORM)
                        status = NOTHING_TO_DO;

                    sprintf (MsgText, "Copying input to %s ",acshdr->fltfile);
                    trlwarn(MsgText);

                    if (CopyFFile (acshdr->rawfile, acshdr->fltfile))
                        return (status);
                }
            }  /* Finished processing EXP images */
        }  /* Finished processing this position's sub-product */
    }  /* Finished looping over all the products */

    /* Reset the trailer file preface to NULL since
       it has already been copied into trailer files */
    ResetTrlPreface();

    /* Done with lists of reference file keywords and names. */
    FreeRefFile (&sciref);

    /* Perform RPTCORR here, as needed. */
    if (acshdr->sci_rptcorr == PERFORM) {
        /* We need to pass a list of input fltfile images for each subproduct
           to be produced, with the subproducts as inputs to DTHCORR. */
        acssum_input = NULL;
        acssum_mtype[0] = '\0';

        trlmessage("Starting RPTCORR now...");

        /* For each DTH product... */
        for (prod = 0; prod < asn->numprod; prod++) {
            /* Loop through all the input subproducts... */
            for (posid = 1; posid <= asn->numsp; posid++) {
                if (asn->spmems[posid] == 0) {
                    continue;
                }
                acssum_input = BuildSumInput (asn, prod, posid);

                strcpy(acssum_output, asn->product[prod].subprod[posid].spname);
                if (asn->verbose) {
                    /* Need to allocate memory for a separate string to be long
                       enough to hold all the input names when printing it
                       out.  Caused pipeline problems otherwise. WJH 19-Mar-04
                    */
                    acssum_msgtext = calloc(strlen(acssum_input)+25, sizeof(char));
                    sprintf (acssum_msgtext, "Input to ASCSUM is: %s",acssum_input);
                    trlmessage(acssum_msgtext);
                    free(acssum_msgtext);

                    sprintf (MsgText, "Output for ASCSUM is: %s",acssum_output);
                    trlmessage(MsgText);
                }

                strcpy(acssum_mtype, asn->product[prod].subprod[posid].mtype);
                if (acssum_mtype[0] == '\0'){
                    strcpy(acssum_mtype, asn->product[prod].mtype);
                }
                trlmessage("ACSSUM starting now...");

                if (AcsSum (acssum_input, acssum_output, acssum_mtype, printtime, asn->verbose)) {
                    return (status);
                }

                /* Pass posid of 0 to indicate a PRODUCT is to be updated */
                updateAsnTable(asn, prod, posid);
            }
        }
        free (acssum_input);
    } /* End RPTCORR Processing */

    return (status);
}
Exemplo n.º 4
0
int ProcessACSCCD (AsnInfo *asn, ACSInfo *acshdr, int *save_tmp, int printtime, const unsigned nThreads, const unsigned cteAlgorithmGen, const char * pcteTabNameFromCmd) {

    extern int status;

    RefFileInfo sciref;       /* ref file keywords and names */
    CalSwitch sci_sw;         /* all cal switches for science file */
    CalSwitch acsccd_sci_sw;  /* ACSCCD switches for science file */
    CalSwitch acscte_sci_sw;  /* ACSCTE switches for science file */
    CalSwitch acs2d_sci_sw;   /* ACS2D switches for science file */
    int save_crj;             /* don't delete crj_tmp file? */

    int prod;             /* which CR-split/Rptobs product? */
    int posid;            /* counter for input products */
    int expid;            /* counter for input exposures */
    int newpreface = NO;  /* switch for keeping previous comments for
                             all remaining trailer files */

    char *acsrej_input;     /* list of input names for ACSREJ */
    char *acsrejc_input;    /* list of CTE corrected input names for ACSREJ */
    char *acsrej_msgtext;   /* str for list of input filenames */
    char *acsrejc_msgtext;  /* str for list of CTE corrected input filenames */
    int nchars;             /* Number of chars for input string to ACSREJ */

    void ACSDefaults (ACSInfo *);
    void InitRefFile (RefFileInfo *);
    void FreeRefFile (RefFileInfo *);
    int ACSRefInit (ACSInfo *, CalSwitch *, RefFileInfo *);
    int ACSccd (char *, char *, CalSwitch *, RefFileInfo *, int, int);
    int ACScte (char *, char *, CalSwitch *, RefFileInfo *, int, int, int, const unsigned cteAlgorithmGen, const char * pcteTabNameFromCmd, const bool forwardModelOnly);
    int ACS2d (char *, char *,CalSwitch *, RefFileInfo *, int, int);
    int GetAsnMember (AsnInfo *, int, int, int, ACSInfo *);
    int GetSingle (AsnInfo *, ACSInfo *);
    int CheckCorr (AsnInfo *, ACSInfo *);
    int InsertACSSuffix (ACSInfo *);

    save_crj = *save_tmp;  /* initial value; */

    /* Loop over the products/positions for each CR-split/Repeat-Obs set. */
    for (prod = 0; prod < asn->numprod; prod++) {
        if (asn->verbose){
            sprintf (MsgText, "CALACS: processing CCD product %d", prod);
            trlmessage (MsgText);
        }

        /* Process this PARTIAL/SINGLE/FULL product... */
        for (posid = 1; posid <= asn->numsp; posid++) {

            if (asn->verbose) {
                sprintf (MsgText,"CALACS: processing posid = %d", posid);
                trlmessage (MsgText);
            }
            /*  Allocate space for ACSREJ input image list */
            if ( (asn->crcorr == PERFORM) || (asn->rptcorr == PERFORM) ) {
                nchars = asn->spmems[posid] * CHAR_FNAME_LENGTH;
                acsrej_input = (char *) calloc( nchars + 1, sizeof(char));
                /* Initialize this string to NULL */
                acsrej_input[0] = '\0';

                acsrejc_input = (char *) calloc( nchars + 1, sizeof(char));
                /* Initialize this string to NULL */
                acsrejc_input[0] = '\0';
            }

            /* Run ACSCCD on individual EXPosures. */
            for (expid = 1; expid <= asn->spmems[posid]; expid++) {
                /* From this point on, we are working with ONE image at a time */

                /* Read in Member keyword info from --FIRST-- EXP image header */
                /*if(prod == 0 && posid == 1 && expid == 1) { */
                if(expid == 1) {
                    /* (Re-)Initialize the lists of reference file keywords
                       and names. */
                    InitRefFile (&sciref);

                    /* Assign default values in acs. */
                    ACSDefaults (acshdr);

                    if (asn->process == SINGLE ) {
                        if (GetSingle (asn, acshdr) )
                            return (status);
                    } else {
                        if( GetAsnMember(asn, prod, posid, expid, acshdr))
                            return (status);
                    }
                    /* Initialize variables, and get info (cal switches and
                       reference file names) from primary headers.
                    */
                    if (ACSRefInit (acshdr, &sci_sw, &sciref))
                        return (status);

                    /* Make sure 'save_tmp' and 'save_crj' are no
                       longer set to 'DUMMY'.

                       If save_tmp was set from the command-line, then
                       ignore what is set in the header keyword
                       EXPSCORR.
                    */
                    if (*save_tmp == DUMMY) {
                        *save_tmp = NO;
                        save_crj = *save_tmp;
                    }

                    if (asn->verbose) {
                        trlmessage ("CALACS: Got reference file information");
                    }
                    /* Store the trailer file comments into preface */
                    newpreface = YES;

                } else {

                    if (asn->process == SINGLE ) {
                        if (GetSingle (asn, acshdr))
                            return (status);
                    } else {
                        if( GetAsnMember(asn, prod, posid, expid, acshdr))
                            return (status);
                    }

                    /* Construct output and temporary file names. */
                    if (InsertACSSuffix (acshdr))
                        return (status);
                }

                /* Check ASN table settings for CRCORR/RPTCORR
                   against image header values.  If they are not
                   consistent, print out a ERROR message and quit.
                   Only need to perform this check on the first image
                   in the association. WJH 21 May 1999
                */
                if (prod == 0 && posid == 1 && expid == 1) {
                    if (CheckCorr(asn, acshdr))
                        return (status);
                }

                /* Copy switch values for ACSCCD, ACSCTE, and ACS2D
                   argument lists. */
                SetACSSw(&sci_sw, &acsccd_sci_sw, &acscte_sci_sw, &acs2d_sci_sw);

                if (asn->verbose) {
                    trlmessage ("CALACS: Processing switches set... ");
                }

                /* Ready to process input image now... */
                /* Do we have anything to do with this image? */
                if (acshdr->sci_basic_2d != PERFORM &&
                        acshdr->sci_basic_ccd != PERFORM &&
                        acshdr->sci_basic_cte != PERFORM &&
                        acshdr->sci_crcorr != PERFORM &&
                        acshdr->sci_rptcorr != PERFORM ){
                    trlwarn ("No calibration switch was set to PERFORM.");
                    FreeRefFile (&sciref);
                    return (status = NOTHING_TO_DO);
                }

                /* First, initialize the Input CCD image with ACSCCD.
                   Then, perform PCTECORR if needed.
                   Then, either do cosmic ray rejection followed by ACS2D,
                   or just run ACS2D. */

                /* First do atodcorr, dqicorr, and blevcorr
                   (or copy the name). */
                if (acshdr->sci_basic_ccd == PERFORM) {
                    /* This is acsccd; note that we use acsccd_sci_sw. */

                    /* Copy all messages up to here into preface buffer
                       to be prepended to all input file trailer files */
                    if (newpreface == YES) {
                        InitTrlPreface();
                    }

                    SetTrlPrefaceMode (YES);

                    if (ACSccd (acshdr->rawfile, acshdr->blv_tmp,
                                &acsccd_sci_sw, &sciref, printtime,
                                asn->verbose))
                        return (status);

                    /* Reset switches */
                    ResetACSSw (&acsccd_sci_sw, &acs2d_sci_sw);

                } else {
                    /* Copy the input file to blv_tmp. We need to do this
                       because acsrej may (depending on the crmask column
                       in the crrejtab) modify the DQ flags in its input file.
                    */
                    if (CopyFFile (acshdr->rawfile, acshdr->blv_tmp))
                        return (status);
                }

                /* Do PCTECORR now. */
                if (acshdr->sci_basic_cte == PERFORM) {
                    // ``forwardModelOnly = false`` because it is not part of the pipeline processing.
                    if (ACScte(acshdr->blv_tmp, acshdr->blc_tmp,
                               &acscte_sci_sw, &sciref, printtime,
                               asn->verbose, nThreads, cteAlgorithmGen, pcteTabNameFromCmd, false)) {
                        return (status);
                    }
                }

                /* We now are working with blv_tmp here... */
                /* Copy (cat) blv_tmp name to acsrej_input string */
                if ( (acshdr->sci_crcorr == PERFORM) ||
                     (acshdr->sci_rptcorr == PERFORM) ) {
                    strcat(acsrej_input, acshdr->blv_tmp);
                    if (expid < asn->spmems[posid]) {
                        /* Don't add a comma to the end of the last filename*/
                        strcat(acsrej_input, ",");
                    }
                    /* Also, add blv_tmp to list of files to be deleted */
                    strcpy(asn->product[prod].subprod[posid].exp[expid].blv_tmp,
                           acshdr->blv_tmp);

                    /* do this again for CTE corrected exposures */
                    if (acscte_sci_sw.pctecorr == PERFORM) {
                        strcat(acsrejc_input, acshdr->blc_tmp);
                        if (expid < asn->spmems[posid]) {
                            /* Don't add a comma to the end of the last filename*/
                            strcat(acsrejc_input, ",");
                        }
                        /* Also, add blc_tmp to list of files to be deleted */
                        strcpy(asn->product[prod].subprod[posid].exp[expid].blc_tmp, acshdr->blc_tmp);
                    }
                }
            }  /* end loop of individual EXPosures for running ACSCCD */

            /* Cosmic ray rejection, followed by basic 2-D processing
               of _crj_tmp. */
            if ( (acshdr->sci_crcorr == PERFORM) ||
                 (acshdr->sci_rptcorr == PERFORM) ) {
                if (asn->verbose) {
                    sprintf (MsgText,"CALACS: Now process position %d from product %d", posid, prod);
                    trlmessage (MsgText);
                }

                /* Commented out, not sure why these need to be reset.
                   Everything should have correct settings after ACSCCD.
                   MRD 17-May-2011 */
                /* Copy switch values for ACSCCD, ACSCTE, and ACS2D
                   argument lists. */
                /*SetACSSw (&sci_sw, &acsccd_sci_sw, &acscte_sci_sw, &acs2d_sci_sw); */
                /* Reset DQICORR, since it will already have been done...
                   WJH  23-Apr-2002 */
                /*acs2d_sci_sw.dqicorr = COMPLETE; */

                if (asn->debug){
                    sprintf(MsgText,"Non-CTE corrected Input to ACSREJ is:");
                    trlmessage(MsgText);

                    /* Need to allocate memory for a separate string to be
                       long enough to hold all the input names when printing
                       it out. Caused pipeline problems otherwise.
                       WJH 19-Mar-04 */
                    acsrej_msgtext = calloc(strlen(acsrej_input)+25,
                                            sizeof(char));
                    sprintf (acsrej_msgtext, "%s", acsrej_input);
                    trlmessage(acsrej_msgtext);
                    free(acsrej_msgtext);

                    sprintf(MsgText,"Non-CTE corrected Output to ACSREJ is: %s", acshdr->crj_tmp);
                    trlmessage(MsgText);

                    if (acscte_sci_sw.pctecorr == PERFORM) {
                        sprintf(MsgText,"CTE corrected Input to ACSREJ is:");
                        trlmessage(MsgText);

                        /* Need to allocate memory for a separate string to be
                           long enough to hold all the input names when printing
                           it out. Caused pipeline problems otherwise.
                           WJH 19-Mar-04 */
                        acsrejc_msgtext = calloc(strlen(acsrejc_input)+25, sizeof(char));
                        sprintf (acsrejc_msgtext, "%s",acsrejc_input);
                        trlmessage(acsrejc_msgtext);
                        free(acsrejc_msgtext);

                        sprintf(MsgText,"CTE corrected Output to ACSREJ is: %s", acshdr->crc_tmp);
                        trlmessage(MsgText);
                    }
                }

                /* Set up the correct value of ASN_MTYP for ACSREJ
                   output image. */
                if ( strncmp(acshdr->asn_table, acshdr->crj_tmp, 9) ) {
                    /* crj_tmp is a sub-product */
                    strcpy (acshdr->mtype, asn->product[prod].subprod[posid].mtype);
                } else {
                    /* crj_tmp leads to a product with same rootname as asn_table */
                    strcpy (acshdr->mtype, asn->product[prod].mtype);
                }

                // Reject cosmic rays.
                int pctecorrSwitchState = acscte_sci_sw.pctecorr;
                if (!OmitStep(pctecorrSwitchState))
                {
                    // Temporarily set this to OMIT so that ACS2d, called within
                    // the ACSRej_oWrapper call stack, uses the non-CTE darks.
                    // This is not thread safe.
                    acs2d_sci_sw.pctecorr = OMIT;
                }
                if ((status = ACSRej_0Wrapper(acsrej_input,
                        acshdr->crj_tmp,
                        acshdr->crjfile,
                        asn->product[prod].subprod[posid].crj_tmp,
                        acshdr,
                        asn,
                        prod,
                        posid,
                        &acs2d_sci_sw,
                        &sciref,
                        printtime,
                        save_crj,
                        True)))
                {
                    //freeStuff
                    delete((void**)&acsrej_input);
                    return status;
                }
                if (!OmitStep(pctecorrSwitchState))
                    acs2d_sci_sw.pctecorr = pctecorrSwitchState;
                delete((void**)&acsrej_input);



                /* now repeat the same thing with CTE corrected products */
                if (!OmitStep(acscte_sci_sw.pctecorr))
                {
                    if ((status = ACSRej_0Wrapper(acsrejc_input,
                            acshdr->crc_tmp,
                            acshdr->crcfile,
                            asn->product[prod].subprod[posid].crc_tmp,
                            acshdr,
                            asn,
                            prod,
                            posid,
                            &acs2d_sci_sw,
                            &sciref,
                            printtime,
                            save_crj,
                            False)))
                    {
                        //freeStuff
                        delete((void**)&acsrejc_input);
                        return status;
                    }
                }
                delete((void**)&acsrejc_input);
            }  /* End of CRCORR processing */

            if (asn->debug){
                trlmessage("Run ACS2D for CCD next...");
            }

            /* Run ACS2D on individual EXPosures. */
            for (expid = 1; expid <= asn->spmems[posid]; expid++) {
                /* From this point on, we are working with ONE image
                   at a time... */

                /* load acs file info */
                if (asn->process == SINGLE ) {
                    if (GetSingle (asn, acshdr) )
                        return (status);
                } else {
                    if( GetAsnMember(asn, prod, posid, expid, acshdr))
                        return (status);
                }

                /* Construct output and temporary file names. */
                if (InsertACSSuffix (acshdr))
                    return (status);

                /* If we are not performing CRCORR or RPTCORR or
                   EXPSCORR is set to PERFORM, then finish
                   processing individual EXP files with ACS2D...
                */
                if ( (acshdr->sci_crcorr != PERFORM) ||
                     (acshdr->sci_rptcorr != PERFORM) ||
                     (sci_sw.expscorr == PERFORM) ) {
                    if (asn->debug) {
                        trlmessage("CRCORR not set to Perform or EXPSCORR turned on...");
                    }

                    if (acshdr->sci_basic_2d == PERFORM) {
                        SetTrlPrefaceMode (NO);
                        if (asn->copy_input == PERFORM) {
                            if (CopyFFile (acshdr->fltfile, acshdr->blv_tmp))
                                return (status);
                            remove (acshdr->fltfile);
                        }

                        /* Basic 2-D processing (flat field, etc). */
                        /* temporarily set acs2d_sci_sw.pctecorr to omit so the
                           correct acs2d processing is done */
                        if (acs2d_sci_sw.pctecorr == PERFORM) {
                            acs2d_sci_sw.pctecorr = OMIT;

                            if (ACS2d (acshdr->blv_tmp, acshdr->fltfile,
                                       &acs2d_sci_sw, &sciref, printtime,
                                       asn->verbose))
                                return (status);

                            acs2d_sci_sw.pctecorr = PERFORM;
                        } else {
                            if (ACS2d (acshdr->blv_tmp, acshdr->fltfile,
                                       &acs2d_sci_sw, &sciref, printtime,
                                       asn->verbose))
                                return (status);
                        }

                    } else {
                        /* If we are not performing CRCORR, then copy
                           blv_tmp file into a final _flt file. */
                        if (acshdr->sci_crcorr != PERFORM ||
                            acshdr->sci_rptcorr != PERFORM) {
                            if (CopyFFile (acshdr->blv_tmp, acshdr->fltfile))
                                return (status);
                        }
                    }

                    /* now repeat ACS2D processing for CTE products */
                    if (acshdr->sci_basic_2d == PERFORM &&
                            acscte_sci_sw.pctecorr == PERFORM) {
                        if (asn->copy_input == PERFORM) {
                            if (CopyFFile (acshdr->flcfile, acshdr->blc_tmp))
                                return (status);
                            remove (acshdr->flcfile);
                        }

                        /* Basic 2-D processing (flat field, etc). */
                        if (ACS2d (acshdr->blc_tmp, acshdr->flcfile,
                                   &acs2d_sci_sw, &sciref, printtime,
                                   asn->verbose))
                            return (status);
                    } else if (acscte_sci_sw.pctecorr == PERFORM) {
                        /* If we are not performing CRCORR, then copy
                           blc_tmp file into a final _flc file. */
                        if (acshdr->sci_crcorr != PERFORM ||
                            acshdr->sci_rptcorr != PERFORM) {
                            if (CopyFFile (acshdr->blc_tmp, acshdr->flcfile))
                                return (status);
                        }
                    }

                }  /* Finished processing blv_tmp file through ACS2D */

                /* Now, delete _blv_tmp and _blc_tmp files */
                if (*save_tmp != YES) {
                    remove (acshdr->blv_tmp);
                    if (acscte_sci_sw.pctecorr == PERFORM) {
                        remove (acshdr->blc_tmp);
                    }
                }
            }  /* End loop over ind EXP for making _flt and _flc files. */

            /* Reset the trailer file preface to NULL since
               it has already been copied into trailer files */
            ResetTrlPreface();

        }  /* End of processing for SINGLE/PARTIAL product */
    }  /* End loop over CCD products here... */

    /* Done with lists of reference file keywords and names. */
    FreeRefFile (&sciref);

    return (status);
}
Exemplo n.º 5
0
int main (int argc, char **argv) {

	int status;		/* zero is OK */
	char *inlist;		/* list of input file names */
	char *outlist;		/* list of output file names */
	int switch_on = 0;	/* was any switch specified? */
	int sgeocorr = OMIT;	/* calibration switches */
	int helcorr = OMIT;
	int fluxcorr = OMIT;
	int statcorr = OMIT;
	int err_algorithm = WGT_VARIANCE;
	int printtime = 0;	/* print time after each step? */
	int verbose = 0;	/* print additional info? */
	int center_target = 0;	/* center target in output image? */
	int too_many = 0;	/* too many command-line arguments? */
	int i, j;		/* loop indexes */
	double blazeshift = NO_VALUE;

	IRAFPointer i_imt, o_imt;	/* imt list pointers */
	char *input;		/* name of input science file */
	char *output;		/* optional name of output file */
	int n_in, n_out;	/* number of files in each list */
	int n;

	/* Input and output suffixes. */
	char *isuffix[] =
		{"_flt", "_crj", "_fwv", "_cwv", "_fwv_tmp", "_cwv_tmp"};
	char *osuffix[] =
		{"_x2d", "_sx2", "_w2d", "_w2d", "_w2d_tmp", "_w2d_tmp"};
	int nsuffix = 6;

	/* reference file keywords and names */
	RefFileInfo refnames;

	c_irafinit (argc, argv);

	inlist = calloc (STIS_LINE+1, sizeof (char));
	outlist = calloc (STIS_LINE+1, sizeof (char));
	input = calloc (STIS_LINE+1, sizeof (char));
	output = calloc (STIS_LINE+1, sizeof (char));
	if (inlist == NULL || outlist == NULL ||
		input == NULL || output == NULL) {
	    printf ("ERROR:  Can't even begin:  out of memory.\n");
	    exit (ERROR_RETURN);
	}

	/* Get command-line arguments. */
	for (i = 1;  i < argc;  i++) {
	    if (strcmp (argv[i], "-x2d") == 0 ||
		strcmp (argv[i], "-geo") == 0) {
		switch_on = 1;
	    } else if (strcmp (argv[i], "-sgeo") == 0) {	/* turn on */
		sgeocorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-hel") == 0) {
		helcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-flux") == 0) {
		fluxcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-stat") == 0) {
		statcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-wgt_err") == 0) {
		err_algorithm = WGT_ERROR;
	    } else if (argv[i][0] == '-') {
		if (strcmp (argv[i], "--version") == 0) {
		    PrVersion();
		    exit (0);
		}
		if (strcmp (argv[i], "-r") == 0) {
		    PrFullVersion();
		    exit (0);
		}
		for (j = 1;  argv[i][j] != '\0';  j++) {
		    if (argv[i][j] == 't') {
			printtime = 1;
		    } else if (argv[i][j] == 'v') {
			verbose = 1;
		    } else if (argv[i][j] == 'c') {
			center_target = 1;	/* yes, center target */
		    } else if (argv[i][j] == 'b') {
	                blazeshift = (double) atof (argv[++i]);
	                if (i == argc-1)
	                    break;
		    } else {
			printf ("ERROR:  Unrecognized option %s\n", argv[i]);
			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:  cs7.e [-t] [-v] [-c] [-wgt_err] [-b blazeshift] input output\n");
	    printf ("  command-line switches:  -x2d -sgeo -hel -flux -stat\n");
	    FreeNames (inlist, outlist, input, output);
	    exit (ERROR_RETURN);
	}

	/* Was no calibration switch specified on command line? */
	if (!switch_on) {	/* default values (mostly PERFORM) */
	    sgeocorr = DefSwitch ("sgeocorr");
	    helcorr  = DefSwitch ("helcorr");
	    fluxcorr = DefSwitch ("fluxcorr");
	    statcorr = DefSwitch ("statcorr");
	}

	/* Initialize the list of reference file keywords and names. */
	InitRefFile (&refnames);

	/* 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")) {
	    FreeNames (inlist, outlist, input, output);
	    exit (ERROR_RETURN);
	}

	/* Loop over the list of input files. */
	for (n = 0;  n < n_in;  n++) {

	    j = c_imtgetim (i_imt, input, STIS_LINE);
	    if (n_out > 0)
		j = c_imtgetim (o_imt, output, STIS_LINE);
	    else
		output[0] = '\0';

	    status = 0;
	    if ((status = MkOutName (input, isuffix, osuffix, nsuffix,
                                     output, STIS_LINE))) {
		WhichError (status);
		printf ("Skipping %s\n", input);
		continue;
	    }

	    /* Calibrate the current input file. */
	    if ((status = CalStis7 (input, output,
			sgeocorr, helcorr, fluxcorr, statcorr,
			&refnames, printtime, verbose, center_target,
                                    blazeshift, err_algorithm))) {
		printf ("Error processing %s.\n", input);
		WhichError (status);
	    }
	}

	/* Close lists of file names, and free name buffers. */
	c_imtclose (i_imt);
	c_imtclose (o_imt);
	FreeRefFile (&refnames);
	FreeNames (inlist, outlist, input, output);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}
Exemplo n.º 6
0
int main (int argc, char **argv) {

	int status;			/* zero is OK */

	char *inlist;		/* list of input file names */
	char *outlist;		/* list of output file names */
	char *blevlist;		/* list of output blev file names */
	int switch_on = 0;	/* was any switch specified? */
	int printtime = 0;	/* print time after each step? */
	int verbose = 0;	/* print additional info? */
	int too_many = 0;	/* too many command-line arguments? */
	int i, j;		/* loop indexes */
	int junk;

	IRAFPointer i_imt, o_imt, b_imt;	/* imt list pointers */
	char *input;		/* name of input science file */
	char *output;		/* optional name of output file */
	char *outblev;		/* optional file for blev values */
	int n_in, n_out, n_blev;	/* number of files in each list */
	int n;

	/* Input and output suffixes. */
	char *isuffix[] = {"_raw", "_blv_tmp", "_crj_tmp", "_wav"};
	char *osuffix[] = {"_flt", "_flt",     "_crj",     "_fwv"};
	int nsuffix = 4;

	/* A structure to pass the calibration switches to CalStis1 */
	cs1_switch cs1_sw;

	/* reference file keywords and names */
	RefFileInfo refnames;

	c_irafinit (argc, argv);

	/* Allocate space for file names. */
	inlist = calloc (1, sizeof (char));	/* allocated later */
	outlist = calloc (1, sizeof (char));
	blevlist = calloc (1, sizeof (char));
	input = calloc (STIS_LINE+1, sizeof (char));
	output = calloc (STIS_LINE+1, sizeof (char));
	outblev = calloc (STIS_LINE+1, sizeof (char));
	if (inlist == NULL || outlist == NULL || blevlist == NULL ||
		input == NULL || output == NULL || outblev == NULL) {
	    printf ("ERROR:  Can't even begin; out of memory.\n");
	    exit (ERROR_RETURN);
	}

	/* Initialize the lists of reference file keywords and names. */
	InitRefFile (&refnames);

	/* Initial values. */
	cs1_sw.dqicorr = OMIT;
	cs1_sw.atodcorr = OMIT;
	cs1_sw.blevcorr = OMIT;
	cs1_sw.doppcorr = OMIT;
	cs1_sw.lorscorr = OMIT;
	cs1_sw.glincorr = OMIT;
	cs1_sw.lflgcorr = OMIT;
	cs1_sw.biascorr = OMIT;
	cs1_sw.darkcorr = OMIT;
	cs1_sw.flatcorr = OMIT;
	cs1_sw.shadcorr = OMIT;
	cs1_sw.photcorr = OMIT;
	cs1_sw.statcorr = OMIT;

	strcpy (cs1_sw.darkscale_string, "");

	for (i = 1;  i < argc;  i++) {

	    if (strcmp (argv[i], "--version") == 0) {
		PrVersion();
		exit (0);
	    }
	    if (strcmp (argv[i], "-r") == 0) {
		PrFullVersion();
		exit (0);
	    }
	    if (strcmp (argv[i], "-dqi") == 0) {	/* turn on */
		cs1_sw.dqicorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-atod") == 0) {
		cs1_sw.atodcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-blev") == 0) {
		cs1_sw.blevcorr = PERFORM;
		switch_on = 1;

	    } else if (strcmp (argv[i], "-dopp") == 0) {
		cs1_sw.doppcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-lors") == 0) {
		cs1_sw.lorscorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-glin") == 0) {
		cs1_sw.glincorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-lflg") == 0) {
		cs1_sw.lflgcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-bias") == 0) {
		cs1_sw.biascorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-dark") == 0) {
		cs1_sw.darkcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-flat") == 0) {
		cs1_sw.flatcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-shad") == 0) {
		cs1_sw.shadcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-phot") == 0) {
		cs1_sw.photcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-stat") == 0) {
		cs1_sw.statcorr = PERFORM;
		switch_on = 1;
	    } else if (strcmp (argv[i], "-dscl") == 0) {
		strcpy (cs1_sw.darkscale_string, argv[++i]);
		switch_on = 1;
	    } else if (argv[i][0] == '-') {
		for (j = 1;  argv[i][j] != '\0';  j++) {
		    if (argv[i][j] == 't') {
			printtime = 1;
		    } else if (argv[i][j] == 'v') {
			verbose = 1;
		    } else {
			printf ("ERROR:  Unrecognized option %s\n", argv[i]);
			exit (1);
		    }
		}
	    } else if (inlist[0] == '\0') {
		free (inlist);
		if ((inlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (inlist, argv[i]);
	    } else if (outlist[0] == '\0') {
		free (outlist);
		if ((outlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (outlist, argv[i]);
	    } else if (blevlist[0] == '\0') {
		free (blevlist);
		if ((blevlist = calloc (strlen(argv[i])+1, sizeof(char)))
			== NULL) {
		    printf ("ERROR:  Out of memory.\n");
		    exit (ERROR_RETURN);
		}
		strcpy (blevlist, argv[i]);
	    } else {
		too_many = 1;
	    }
	}
	if (inlist[0] == '\0' || too_many) {
	    printf ("syntax:  cs1.e [-t] [-v] input output [outblev]\n");
	    printf ("  command-line switches:\n");
	    printf ("       -dqi  -atod -blev\n");
	    printf ("       -dopp -lors -glin -lflg\n");
	    printf ("       -bias -dark -flat -shad -phot -stat\n");
	    FreeNames (inlist, outlist, blevlist, input, output, outblev);
	    exit (ERROR_RETURN);
	}

	/* Was no calibration switch specified on command line? */
	if (!switch_on) {	/* default values (mostly PERFORM) */
	    cs1_sw.dqicorr  = DefSwitch ("dqicorr");
	    cs1_sw.atodcorr = DefSwitch ("atodcorr");
	    cs1_sw.blevcorr = DefSwitch ("blevcorr");
	    cs1_sw.doppcorr = DefSwitch ("doppcorr");
	    cs1_sw.lorscorr = DefSwitch ("lorscorr");
	    cs1_sw.glincorr = DefSwitch ("glincorr");
	    cs1_sw.lflgcorr = DefSwitch ("lflgcorr");
	    cs1_sw.biascorr = DefSwitch ("biascorr");
	    cs1_sw.darkcorr = DefSwitch ("darkcorr");
	    cs1_sw.flatcorr = DefSwitch ("flatcorr");
	    cs1_sw.shadcorr = DefSwitch ("shadcorr");
	    cs1_sw.photcorr = DefSwitch ("photcorr");
	    cs1_sw.statcorr = DefSwitch ("statcorr");
	}

	/* Expand the templates. */
	i_imt = c_imtopen (inlist);
	o_imt = c_imtopen (outlist);
	b_imt = c_imtopen (blevlist);
	n_in = c_imtlen (i_imt);
	n_out = c_imtlen (o_imt);
	n_blev = c_imtlen (b_imt);

	/* The number of input and output files must be the same. */
	status = 0;
	if (CompareNumbers (n_in, n_out, "output"))
	    status = ERROR_RETURN;
	if (CompareNumbers (n_in, n_blev, "outblev"))
	    status = ERROR_RETURN;
	if (status) {
	    FreeNames (inlist, outlist, blevlist, input, output, outblev);
	    exit (ERROR_RETURN);
	}

	/* Loop over the list of input files. */
	for (n = 0;  n < n_in;  n++) {

	    junk = c_imtgetim (i_imt, input, STIS_LINE);
	    if (n_out > 0)
		junk = c_imtgetim (o_imt, output, STIS_LINE);
	    else
		output[0] = '\0';
	    if (n_blev > 0)
		junk = c_imtgetim (b_imt, outblev, STIS_LINE);
	    else
		outblev[0] = '\0';

	    status = 0;
	    if ((status = MkOutName (input, isuffix, osuffix, nsuffix,
                                     output, STIS_LINE))) {
		WhichError (status);
		printf ("Skipping %s\n", input);
		continue;
	    }

	    /* Calibrate the current input file. */
	    if ((status = CalStis1 (input, output, outblev,
                                    &cs1_sw, &refnames, printtime, verbose))) {
		printf ("Error processing %s.\n", input);
		WhichError (status);
	    }
	}

	/* Close lists of file names, and free name buffers. */
	c_imtclose (i_imt);
	c_imtclose (o_imt);
	c_imtclose (b_imt);
	FreeRefFile (&refnames);
	FreeNames (inlist, outlist, blevlist, input, output, outblev);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}