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
void InitSumTrl (char *input, char *output) {

    extern int status;
    IRAFPointer    tpin;
    int n;

    char *trl_in;     /* trailer filename for input */
    char trl_out[CHAR_LINE_LENGTH+1];     /* output trailer filename */
    char in_name[CHAR_FNAME_LENGTH+1];
    char out_name[CHAR_FNAME_LENGTH+1];

    int trl_len;

    char *isuffix[] = {"_crj", "_flt"};
    char *osuffix[] = {"_sfl", "_sfl"};
    char *trlsuffix[] = {"", ""};
    int nsuffix = 2;

    int MkOutName (char *, char **, char **, int, char *, int);
    int MkNewExtn (char *, char *);
    void WhichError (int);

    trl_in = realloc (NULL, (CHAR_LINE_LENGTH));
    trl_len = CHAR_LINE_LENGTH;

    if (trl_in == NULL) {
        trlerror ("Out of memory: Couldn't allocate for CRJ_TMP trailer file.");
         status = OUT_OF_MEMORY;
        trl_len = 0;
     }
    /* Initialize TRL filenames */
    trl_in[0] = '\0';
    trl_out[0] = '\0';

    /* open the input file template */
    tpin = c_imtopen (input);

     for (n = 0; n < c_imtlen(tpin); ++n) {
        c_imtgetim (tpin, in_name, CHAR_FNAME_LENGTH);
        out_name[0] = '\0';


        /* Start by stripping off suffix from input/output filenames */
        if (MkOutName (in_name, isuffix, trlsuffix, nsuffix, out_name, CHAR_LINE_LENGTH)) {
            WhichError (status);
            sprintf (MsgText, "Couldn't create trailer filename for %s", in_name);
            trlerror (MsgText);
            continue;
        }

        /* Now, convert trailer filename extensions from '.fits' to '.trl' */
        if (MkNewExtn (out_name, TRL_EXTN) ) {
            sprintf(MsgText, "Error with input trailer filename %s", out_name);
            trlerror (MsgText);
            WhichError (status);
        }

        if ( (strlen(out_name) + strlen(trl_in) + 1) >= trl_len) {
            /*
                Add 1 to out_name to account for comma to be appended.
                WJH  4 June 2002
            */
            trl_len += strlen(out_name) + 1;
            trl_in = realloc (trl_in, trl_len);
        }

        /* Append each filename to create list of input trailer files */
        strcat(trl_in, out_name);

        /* But don't put a comma after the last filename */
        if (n < (c_imtlen(tpin)-1)) strcat (trl_in, ",");

    }

    if (MkOutName (output, osuffix, trlsuffix, nsuffix, trl_out, CHAR_LINE_LENGTH)) {
        WhichError (status);
        sprintf (MsgText, "Couldn't create trailer filename for %s", output);
        trlerror (MsgText);
    }

    /* Now, convert trailer filename extensions from '.fits' to '.trl' */
    if (MkNewExtn (trl_out, TRL_EXTN) ) {
        sprintf(MsgText, "Error with input trailer filename %s", trl_out);
        trlerror (MsgText);
        WhichError (status);
    }
    /* Sets up temp trailer file for output and copies input
        trailer file into it.
    */
    InitTrlFile (trl_in, trl_out);

    /* Deallocate memory */
    free(trl_in);
    c_imtclose (tpin);
}
Exemplo n.º 3
0
/*  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);
}
Exemplo n.º 4
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.º 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
/*  rejpar_in -- Read parameters either from user input or table.

  Description:
  ------------
  Reads CL parameters and does necessary checkings
  
  Input parameters from crrej reference table:
  -------------------------------------------
  Col. Name     Parameter
  "skysub"      sky         Sky levels subtraction scheme
  "crsigmas"    sigmas      Rejection thresholds
  "crradius"    radius      Radius (in pixels) to propagate the cosmic ray
  "crthresh"    thresh      Propagation factor
  "initgues"    initgues    Scheme of computing initial-guess image
  "scalense"    scalense    multiplicative noise in percents
  "badinpdq"    badinpdq    Data quality pset
  "crmask"      mask        flag CR-rejected pixels in input files?

  Input parameters from input image primary header:
  ------------------------------------------------


  Date          Author          Description
  ----          ------          -----------
  24-Sep-1998   W.J. Hack       Initial ACS Version	
*/
int rejpar_in (clpar *par, int newpar[], int nimgs, float exptot, int *niter, float sigma[])
{
    extern int status;

    IRAFPointer     tp;
    IRAFPointer     colptr, colptr1;
    int             i, nrows, nmatch, row;
    int             crsplit_in, crsplit, maxcrsplit;
    float           exp_in, meanexp, mindiff, diff;
    char            maskstr[ACS_CBUF+1];

    void    PrRefInfo (char *, char *, char *, char *, char *);
    void    WhichError (int);

/* -------------------------------- begin ---------------------------------- */

    crsplit_in = nimgs;

    exp_in = exptot / (float) crsplit_in;
    par->meanexp = exp_in;

    /* if all parameters are specified by the user, no need to open the 
	    reference CRREJ table */
    if (newpar[0] < MAX_PAR) {

        tp = c_tbtopn (par->tbname, IRAF_READ_ONLY, 0);
            if (c_iraferr() != 0) {
                sprintf (MsgText,"CRREJTAB table '%s' does not exist", par->tbname);
                trlerror (MsgText);
                return (status = TABLE_ERROR);
            }
        nrows = c_tbpsta (tp, TBL_NROWS);

        /* read the columns CRSPLIT and MEANEXP */
        c_tbcfnd1 (tp, "crsplit", &colptr);
        if (colptr == 0) {
            trlerror ("column CRSPLIT does not exist in CRREJTAB");
            return (status = COLUMN_NOT_FOUND);
        }
        c_tbcfnd1 (tp, "meanexp", &colptr1);
        if (colptr1 == 0) {
            trlerror ("column MEANEXP does not exist in CRREJTAB\n");
            return (status = COLUMN_NOT_FOUND);
        }
        nmatch = 0;

        /* find the largest value in the CRSPLIT column */
        for (i = 1; i <= nrows; i++) {
            c_tbegti (tp, colptr, i, &crsplit);
            if (i == 1) maxcrsplit = crsplit;
            if (crsplit > maxcrsplit)
            maxcrsplit = crsplit;
        }
        if (crsplit_in >= maxcrsplit) crsplit_in = maxcrsplit;

        /* find the matching row in CRREJTAB to use */
        for (i = 1; i <= nrows; i++) {
            c_tbegti (tp, colptr, i, &crsplit);
            c_tbegtr (tp, colptr1, i, &meanexp);
            diff = meanexp - exp_in;
            if (crsplit_in == crsplit && diff >= 0.) {
                nmatch++;
                if (nmatch == 1) mindiff = diff;
                if (diff <= mindiff) {
                    row = i;
                    mindiff = diff;
                }
            }
        }
        if (nmatch == 0) {
            trlerror (" No matching CRSPLIT and MEANEXP in CRREJTAB");
            return (status = ROW_NOT_FOUND);
        }

        /* read the sigmas parameter */ 
        if (newpar[CRSIGMAS] == 0) {
            c_tbcfnd1 (tp, "crsigmas", &colptr);
            if (colptr == 0) {
                trlerror ("column CRSIGMAS does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtt (tp, colptr, row, par->sigmas, ACS_LINE);
        }

        /* read other parameters */
        if (newpar[SKYSUB] == 0) {
            c_tbcfnd1 (tp, "skysub", &colptr);
            if (colptr == 0) {
                trlerror ("column SKYSUB does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtt (tp, colptr, row, par->sky, ACS_FITS_REC);
        }

        /* CR propagation parameters */
        if (newpar[CRRADIUS] == 0) {
            c_tbcfnd1 (tp, "crradius", &colptr);
            if (colptr == 0) {
                trlerror ("column CRRADIUS does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtr (tp, colptr, row, &par->radius);
        }
        if (newpar[CRTHRESH] == 0) {
            c_tbcfnd1 (tp, "crthresh", &colptr);
            if (colptr == 0) {
                trlerror ("column CRTHRESH does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtr (tp, colptr, row, &par->thresh);
        }

            /* figure out how to do initial comparison image */
        if (newpar[INITGUES] == 0) {
            c_tbcfnd1 (tp, "initgues", &colptr);
            if (colptr == 0) {
                trlerror ("column INITGUES does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtt (tp, colptr, row, par->initgues, ACS_FITS_REC);
        }

        /* read the noise model */
        if (newpar[SCALENSE] == 0) {
            c_tbcfnd1 (tp, "scalense", &colptr);
            if (colptr == 0) {
                trlerror ("column SCALENSE does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegtr (tp, colptr, row, &par->scalense);
        }

        if (newpar[BADINPDQ] == 0) {
            c_tbcfnd1 (tp, "badinpdq", &colptr);
            if (colptr == 0) {
                trlerror ("column BADINPDQ does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegts (tp, colptr, row, &par->badinpdq);
        }

        if (newpar[CRMASK] == 0) {
            c_tbcfnd1 (tp, "crmask", &colptr);
            if (colptr == 0) {
                trlerror ("column CRMASK does not exist in CRREJTAB");
                return (status = COLUMN_NOT_FOUND);
            }
            c_tbegti (tp, colptr, row, &par->mask);
        }

        c_tbtclo (tp);
    }

    PrRefInfo ("crrejtab", par->tbname, "", "", "");
    
    /* parse the sigmas string into numbers */
    *niter = strtor (par->sigmas, sigma);
    if (status != ACS_OK) {
        WhichError (status);
        return (status);
    }
    
    if (*niter > MAX_ITER) {
        sprintf (MsgText,"No more than %d iterations permitted.", MAX_ITER);
        trlerror (MsgText);
        return (status = ERROR_RETURN);
    }
    if (*niter <= 0) {
        trlerror ("Number of iterations is ZERO.");
        return (status = ERROR_RETURN);
    }

    /* other fixed (for now) parameters */
    par->crval = (short) DATAREJECT;
    par->fillval = 0.;
    
    /* print out which parameter are used */
    if (par->verbose) {
        sprintf (MsgText,"\n number of images = %d", nimgs);
        trlmessage (MsgText);
        sprintf (MsgText," CRREJ ref table used: %s", par->tbname);
        trlmessage (MsgText);
        sprintf (MsgText," initial guess method: %s", par->initgues);
        trlmessage (MsgText);
        sprintf (MsgText," total exposure time = %0.1f", exptot);
        trlmessage (MsgText);
        sprintf (MsgText," sigmas used: %s", par->sigmas);
        trlmessage (MsgText);
        sprintf (MsgText," sky subtraction used: %s", par->sky);
        trlmessage (MsgText);
        sprintf (MsgText," rejection radius = %0.1f", par->radius);
        trlmessage (MsgText);
        sprintf (MsgText," propagation threshold = %0.1f", par->thresh);
        trlmessage (MsgText);
        sprintf (MsgText," scale noise = %0.1f%%", par->scalense);
        trlmessage (MsgText);
        sprintf (MsgText," input bad bits value = %d", par->badinpdq);
        trlmessage (MsgText);
        
        if (par->mask == 1) {
            strcpy (maskstr,"YES");
        } else {
            strcpy (maskstr, "NO");
        }
        sprintf (MsgText," reset crmask = %s\n", maskstr);
        trlmessage (MsgText);
    }
    return (status);
}
Exemplo n.º 7
0
int main (int argc, char **argv) {

	/* Local variables */
	char input[CHAR_FNAME_LENGTH+1];
	int printtime = NO;	/* print time after each step? */
	int save_tmp = DUMMY;	/* save temporary files? */
	int verbose = NO;	/* print info during processing? */
	int debug = NO;		/* print debug statements during processing? */
	int quiet = NO;		/* suppress STDOUT messages? */
	int too_many = NO;	/* too many command-line arguments? */
	int onecpu = NO;  /* suppress openmp usage by using only 1 thread?*/
    int i, j;		/* loop indexes */

	/* Function definitions */
	void c_irafinit (int, char **);
	int  CalWf3Run  (char *, int, int, int, int, int);
	void WhichError (int);

	/* Initialize status to OK and MsgText to null */
	status     = WF3_OK;
	MsgText[0] = '\0';
	input[0]   = '\0';

	/* Initialize IRAF environment */
	c_irafinit(argc, argv);
	PtrRegister ptrReg;
	initPtrRegister(&ptrReg);

	/* Command line arguments: 
	 **	0. Check for --version option
	 **	1. input file name
	 **	2. print time?
	 **	3. save intermediate files?
	 **	4. verbose?
	 */
	for (i = 1;  i < argc;  i++) {
		if (!(strcmp(argv[i],"--version"))) {
			printf("%s\n",WF3_CAL_VER_NUM);
			freeOnExit(&ptrReg);
			exit(0);
		}
        if (!(strcmp(argv[i],"--gitinfo")))
        {
            printGitInfo();
            freeOnExit(&ptrReg);
            exit(0);
        }
        if (!(strcmp(argv[i],"--help")))
        {
            printHelp();
            freeOnExit(&ptrReg);
            exit(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] == 's') {
					save_tmp = YES;
				} else if (argv[i][j] == 'r'){
					printf ("Current version: %s\n", WF3_CAL_VER);
					freeOnExit(&ptrReg);
					exit(0);
				} else if (argv[i][j] == 'v') {
					verbose = YES;
				} else if (argv[i][j] == 'd') {
					debug = NO;
				} else if (argv[i][j] == 'q') {
					quiet = YES;
				} else if (argv[i][j] == '1'){
                    onecpu = YES;
                } else {
					printf ("Unrecognized option %s\n", argv[i]);
					printSyntax();
					freeOnExit(&ptrReg);
					exit (ERROR_RETURN);
				}
			}
		} else if (input[0] == '\0') {
			strcpy (input, argv[i]);
		} else {
			too_many = YES;
		}
	}

	if (input[0] == '\0' || too_many) {
	    printSyntax();
	    freeOnExit(&ptrReg);
		exit (ERROR_RETURN);
	}

	/* Initialize the structure for managing trailer file comments */
	InitTrlBuf ();
    addPtr(&ptrReg, &trlbuf, &CloseTrlBuf);
    trlGitInfo();

	/* Copy command-line value for QUIET to structure */
	SetTrlQuietMode (quiet);

	/* Call the CALWF3 main program */
	if (CalWf3Run (input, printtime, save_tmp, verbose, debug, onecpu)) {

		if (status == NOTHING_TO_DO) {
			/* If there is just nothing to do, 
			 ** as for ACQ images, just quit. */
			status = 0;
			sprintf (MsgText, "CALWF3 did NOT process %s", input);
			trlmessage (MsgText);
			freeOnExit(&ptrReg);
			exit(0); 
		} else {
			/* Error during processing */
			sprintf (MsgText, "CALWF3 processing NOT completed for %s",
					input);
			trlerror (MsgText);
			/* Provide interpretation of error for user */
			WhichError (status);
			freeOnExit(&ptrReg);
			exit (ERROR_RETURN);
		}
	}

	/* Successful completion */
	sprintf (MsgText, "CALWF3 completion for %s", input);
	trlmessage (MsgText);


	freeOnExit(&ptrReg);

	/* Exit the program */
	exit (0);
}
Exemplo n.º 8
0
Arquivo: cs8.c Projeto: pllim/hstcal
int main (int argc, char **argv) {

	int status;		/* zero is OK */
	char *input, *output;	/* file names */
	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 */

	c_irafinit (argc, argv);

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

	/* Get names of input and output files. */
	for (i = 1;  i < argc;  i++) {
	    if (argv[i][0] == '-') {
		if (strcmp (argv[i], "--version") == 0) {
		    PrVersion();
		    exit (0);
		}
        if (!(strcmp(argv[i],"--gitinfo")))
        {
            printGitInfo();
            exit(0);
        }
        if (!(strcmp(argv[i],"--help")))
        {
            printHelp();
            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 {
			printf ("ERROR:  Unrecognized option %s\n", argv[i]);
			printSyntax();
			exit (1);
		    }
		}
	    } else if (input[0] == '\0') {
		strcpy (input, argv[i]);
	    } else if (output[0] == '\0') {
		strcpy (output, argv[i]);
	    } else {
		too_many = 1;
	    }
	}
	if (input[0] == '\0' || too_many) {
	    printSyntax();
	    exit (ERROR_RETURN);
	}
	if (output[0] == '\0') {
	    if ((status = MkName (input, "_x2d", "_sx2", output, STIS_LINE)))
		exit (status);
	}

	/* Sum imsets. */
	if ((status = CalStis8 (input, output, printtime, verbose))) {
	    printf ("Error processing %s.\n", input);
	    WhichError (status);
	}
	free (input);
	free (output);

	if (status)
	    exit (ERROR_RETURN);
	else
	    exit (0);
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
int WF3cte (char *input, char *output, CCD_Switch *cte_sw,
        RefFileInfo *refnames, int printtime, int verbose, int onecpu) {

/*
input: filename
output: filename
cte_sw: the calibration flags
refnames: the names of the calibration reference files
onecpu: use parallel processing?

The following are new primary header keywords which will be added to the data
so that they can be updated by the code. They are also specified in the PCTETAB
reference file.

These are taken from the PCTETAB
CTE_NAME - name of cte algorithm
CTE_VER - version number of cte algorithm
CTEDATE0 - date of wfc3/uvis installation in HST, in MJD
CTEDATE1 - reference date of CTE model pinning, in MJD

PCTETLEN - max length of CTE trail
PCTERNOI - readnoise amplitude for clipping
PCTESMIT - number of iterations used in CTE forward modeling
PCTESHFT - number of iterations used in the parallel transfer
PCTENSMD - readnoise mitigation algorithm
PCTETRSH - over-subtraction threshold
PCTEFRAC - cte scaling frac calculated from expstart
PCTERNOI - the readnoise clipping level to use      

#These are taken from getreffiles.c
DRKCFILE is a new dark reference file used only in the CTE branch *_DRC.fits
BIACFILE is a new super-bias reference file used only in the CTE branch *_BIC.fits
PCTETAB is a new reference file FITS table which will contain the software parameter switches for the CTE correction *_CTE.fit

This is the main workhorse function for removing the CTE from WFC3 UVIS images  

Unfortunately this happens before anything else in wfc3, so there's a lot of reading files
at the beginning in order to populate needed information. The rest of the pipeline works
on one chip at a time and the structures are all defined to support that. None of these 
structures are defined until the code enters the single chip loops. This differs from the
CTE correction in ACS which occurs later in the process after basic structures are defined.

*/

    extern int status;

    WF3Info wf3; /*structure with calibration switches and reference files for passing*/
    Hdr phdr; /*primary header for input image, all output information saved here*/
        
    CTEParams cte_pars; /*STRUCTURE HOLDING THE MODEL PARAMETERS*/
    SingleGroup cd; /*SCI 1*/
    SingleGroup ab; /*SCI 2*/
    SingleGroup raz; /* THE LARGE FORMAT COMBINATION OF CDAB*/
    SingleGroup rsz; /* LARGE FORMAT READNOISE CORRECTED IMAGE */
    SingleGroup rsc; /* CTE CORRECTED*/
    SingleGroup rzc; /* FINAL CTE CORRECTED IMAGE */
    SingleGroup chg; /* THE CHANGE DUE TO CTE  */
    SingleGroup raw; /* THE RAW IMAGE IN RAZ FORMAT */
    
    int i,j; /*loop vars*/
    int max_threads=1;
    clock_t begin;
    double  time_spent;
    float hardset=0.0;

    begin = (double)clock();
        
    Bool subarray; /* to verify that no subarray is being used, it's not implemented yet*/

    /*CONTAIN PARALLEL PROCESSING TO A SINGLE THREAD AS USER OPTION*/
#   ifdef _OPENMP
    trlmessage("Using parallel processing provided by OpenMP inside CTE routine");
    if (onecpu){
        omp_set_dynamic(0);
        max_threads=1;
        sprintf(MsgText,"onecpu == TRUE, Using only %i threads/cpu", max_threads);
    } else {
        omp_set_dynamic(0);
        max_threads = omp_get_num_procs(); /*be nice, use 1 less than avail?*/
        sprintf(MsgText,"Setting max threads to %i of %i cpus",max_threads, omp_get_num_procs()); 
    }
    omp_set_num_threads(max_threads);
    trlmessage(MsgText);
#   endif
   

    /* COPY COMMAND-LINE ARGUMENTS INTO WF3. */ 
    WF3Init (&wf3);
    strcpy (wf3.input, input);
    strcpy (wf3.output, output);

    PrBegin ("WFC3CTE");
    if (wf3.printtime)
        TimeStamp("WFC3CTE Started: ",wf3.rootname);

    /* CHECK WHETHER THE OUTPUT FILE ALREADY EXISTS. */
    if (FileExists (wf3.output)){
        WhichError(status);
        return (ERROR_RETURN);
    }

    wf3.pctecorr = cte_sw->pctecorr;
    wf3.darkcorr = cte_sw->darkcorr;
    wf3.biascorr = cte_sw->biascorr;
    wf3.blevcorr = cte_sw->blevcorr;
    wf3.printtime = printtime;
    wf3.verbose = verbose;
    wf3.refnames = refnames;

    PrFileName ("input", wf3.input);
    PrFileName ("output", wf3.output);

    if (wf3.biascorr == COMPLETE){
        trlmessage("BIASCORR complete for input image, CTE can't be performed");
        return(ERROR_RETURN);
    }
    if (wf3.darkcorr == COMPLETE){
        trlmessage("DARKCORR complete for input image, CTE can't be performed");
        return(ERROR_RETURN);
    }
    if (wf3.blevcorr == COMPLETE){
        trlmessage("BLEVCORR complete for input image, CTE can't be performed");
        return(ERROR_RETURN);
    }


    /* DETERMINE THE NAMES OF THE TRAILER FILES BASED ON THE INPUT
       AND OUTPUT FILE NAMES, THEN INITIALIZE THE TRAILER FILE BUFFER
       WITH THOSE NAMES.
       */
    if (initCTETrl (input, output))
        return (status);
    

    /* OPEN INPUT IMAGE IN ORDER TO READ ITS PRIMARY HEADER. */
    if (LoadHdr (wf3.input, &phdr) ){
        WhichError(status);
        return (ERROR_RETURN);
    }

    /* GET KEYWORD VALUES FROM PRIMARY HEADER. */
    if (GetKeys (&wf3, &phdr)) {
        freeHdr (&phdr);
        return (status);
    }

    if (GetCTEFlags (&wf3, &phdr)) {
        freeHdr(&phdr);
        return (status);
    }

    /* OPEN THE INPUT IMAGES AND GET THE  SCIENCE EXTENSIONS  */
    initSingleGroup (&cd);
    getSingleGroup (wf3.input, 1, &cd);
    
    if (hstio_err())
        return (status = OPEN_FAILED);

    /*** MAKE SURE THIS IS NOT A SUBARRAY ***/
    if (GetKeyBool (cd.globalhdr, "SUBARRAY", NO_DEFAULT, 0, &subarray))
        return (status=KEYWORD_MISSING);

    if (subarray) {
        sprintf(MsgText,"**SUBARRAY FOUND!; SUBARRAY images are not yet supported for CTE**");
        trlmessage(MsgText);
        status=ERROR_RETURN;
        return(status);
    }   
    
    initSingleGroup (&ab);
    getSingleGroup (wf3.input, 2, &ab);
    if (hstio_err())
        return (status = OPEN_FAILED);

    if (GetKeyBool (ab.globalhdr, "SUBARRAY", NO_DEFAULT, 0, &subarray))
        return (status=KEYWORD_MISSING);

    if (subarray) {
        sprintf(MsgText,"SUBARRAY FOUND; **SUBARRAY images are not yet supported for CTE**");
        trlmessage(MsgText);
        status=ERROR_RETURN;
        return(status);
    }

    /*READ IN THE CTE PARAMETER TABLE*/
    initCTEParams(&cte_pars);
    if (GetCTEPars (wf3.pctetab.name,&cte_pars))
        return (status);

    if (verbose){
        PrRefInfo ("pctetab", wf3.pctetab.name, wf3.pctetab.pedigree,
                wf3.pctetab.descrip, wf3.pctetab.descrip2);
    }
    
    
    /*SAVE THE PCTETABLE INFORMATION TO THE HEADER OF THE SCIENCE IMAGE
      AFTER CHECKING TO SEE IF THE USER HAS SPECIFIED ANY CHANGES TO THE
      CTE CODE VARIABLES.
    */
    if (CompareCTEParams(&cd, &cte_pars)){
        return (status);
    }    


    /*SET UP THE ARRAYS WHICH WILL BE PASSED AROUND*/  
    initSingleGroup(&raz);
    allocSingleGroup(&raz, RAZ_COLS, RAZ_ROWS);

    initSingleGroup(&rsz);
    allocSingleGroup(&rsz, RAZ_COLS, RAZ_ROWS);

    initSingleGroup(&rsc);
    allocSingleGroup(&rsc, RAZ_COLS, RAZ_ROWS);

    initSingleGroup(&rzc);
    allocSingleGroup(&rzc, RAZ_COLS, RAZ_ROWS);
    
    initSingleGroup(&raw);
    allocSingleGroup(&raw, RAZ_COLS, RAZ_ROWS);
    
    initSingleGroup(&chg);    
    allocSingleGroup(&chg, RAZ_COLS, RAZ_ROWS);

    for (i=0;i<RAZ_COLS;i++){ 
        for(j=0;j<RAZ_ROWS;j++){ 
            Pix(raw.sci.data,i,j)=hardset;
            Pix(rsz.sci.data,i,j)=hardset;
            Pix(raz.sci.data,i,j)=hardset;
            Pix(rsc.sci.data,i,j)=hardset;
            Pix(rzc.sci.data,i,j)=hardset;
            Pix(chg.sci.data,i,j)=hardset;
        }
    }            


    /* SAVE A COPY OF THE RAW IMAGE FOR LATER */
    makesciRAZ(&cd,&ab,&raw);

    /***SUBTRACT THE CTE BIAS FROM BOTH CHIPS IN PLACE***/
    if (doCteBias(&wf3,&cd)){
        freeSingleGroup(&cd);
        return(status);
    }

    
    if (doCteBias(&wf3,&ab)){
        freeSingleGroup(&ab);
        return(status);
    }
      

    /*CONVERT TO RAZ FORMAT AND CORRECT FOR GAIN*/
    if (raw2raz(&wf3, &cd, &ab, &raz))
        return (status);

    /***CALCULATE THE SMOOTH READNOISE IMAGE***/
    trlmessage("CTE: Calculating smooth readnoise image");
    
 
    /***CREATE THE NOISE MITIGATION MODEL ***/
    if (cte_pars.noise_mit == 0) {
        if (raz2rsz(&wf3, &raz, &rsz, cte_pars.rn_amp, max_threads))
            return (status);
    } else {
        trlmessage("Only noise model 0 implemented!");
        return (status=ERROR_RETURN);
    }

    /***CONVERT THE READNOISE SMNOOTHED IMAGE TO RSC IMAGE
        THIS IS WHERE THE CTE GETS CALCULATED         ***/
    if (rsz2rsc(&wf3, &rsz, &rsc, &cte_pars))
        return (status);
       
    /*** SAVE USEFULL HEADER INFORMATION ***/
    if (cteHistory (&wf3, cd.globalhdr))
        return (status);
    
    /*** CREATE THE FINAL CTE CORRECTED IMAGE, PUT IT BACK INTO ORIGNAL RAW FORMAT***/
    for (i=0;i<RAZ_COLS;i++){
        for(j=0; j<RAZ_ROWS; j++){
            Pix(chg.sci.data,i,j) = (Pix(rsc.sci.data,i,j) - Pix(rsz.sci.data,i,j))/wf3.ccdgain;
            Pix(rzc.sci.data,i,j) =  Pix(raw.sci.data,i,j) + Pix(chg.sci.data,i,j);
        }
    }
            
    /*BACK TO NORMAL FORMATTING*/
    undosciRAZ(&cd,&ab,&rzc);
    
    /*UPDATE THE OUTPUT HEADER ONE FINAL TIME*/
    PutKeyDbl(cd.globalhdr, "PCTEFRAC", cte_pars.scale_frac,"CTE scaling fraction based on expstart");
    trlmessage("PCTEFRAC saved to header");
    
    /*SAVE THE NEW RAW FILE WITH UPDATED SCIENCE ARRAYS AND PRIMARY HEADER TO RAC*/
    putSingleGroup(output,cd.group_num, &cd,0);
    putSingleGroup(output,ab.group_num, &ab,0);


    /** CLEAN UP **/    
    freeSingleGroup(&rzc);
    freeSingleGroup(&rsc);
    freeSingleGroup(&chg);
    freeSingleGroup(&raz);
    freeSingleGroup(&rsz);
    freeSingleGroup(&raw);
    
    time_spent = ((double) clock()- begin +0.0) / CLOCKS_PER_SEC;
    if (verbose){
        sprintf(MsgText,"CTE run time: %.2f(s) with %i procs/threads\n",time_spent,max_threads);
        trlmessage(MsgText);
    }

    PrSwitch("pctecorr", COMPLETE);
    if(wf3.printtime)
        TimeStamp("PCTECORR Finished",wf3.rootname);

    return (status);
}
Exemplo n.º 11
0
int initCTETrl (char *input, char *output) {

    extern int status;

    char trl_in[SZ_LINE+1];     /* trailer filename for input */
    char trl_out[SZ_LINE+1];    /* output trailer filename */
    int exist;


    int MkName (char *, char *, char *, char *, char *, int);
    int TrlExists (char *);
    void SetTrlOverwriteMode (int);

    /* Initialize internal variables */
    trl_in[0] = '\0';
    trl_out[0] = '\0';
    exist = EXISTS_UNKNOWN;

	/* Input and output suffixes. */
	char *isuffix[] = {"_raw"};
	char *osuffix[] = {"_rac_tmp"};
	char *trlsuffix[] = {""};

	int nsuffix = 1;


	/* Start by stripping off suffix from input/output filenames */
	if (MkOutName (input, isuffix, trlsuffix, nsuffix, trl_in, SZ_LINE)) {
	    WhichError (status);
	    sprintf (MsgText, "Couldn't determine trailer filename for %s",
		     input);
	    trlmessage (MsgText);
	}
	if (MkOutName (output, osuffix, trlsuffix, nsuffix, trl_out, SZ_LINE)) {
	    WhichError (status);
	    sprintf (MsgText, "Couldn't create trailer filename for %s",
		     output);
	    trlmessage (MsgText);
	}

	/* NOW, CONVERT TRAILER FILENAME EXTENSIONS FROM '.FITS' TO '.TRL' */
    
	if (MkNewExtn (trl_in, TRL_EXTN) ) {
	    sprintf (MsgText, "Error with input trailer filename %s", trl_in);
	    trlerror (MsgText);
	    WhichError (status);
	}
	if (MkNewExtn (trl_out, TRL_EXTN) ) {
	    sprintf (MsgText, "Error with output trailer filename %s", trl_out);
	    trlerror (MsgText);
	    WhichError (status);
	}
    
 	/* If we are working with a RAW file, then see if a TRL file 
	   needs to be overwritten after the generic conversion comments.  */
	if (strstr(input, isuffix[0]) != NULL) {
	    /* Test whether the output file already exists */
	    exist = TrlExists(trl_out);            
	    if (exist == EXISTS_YES) {
		/* The output file exists, so we want to add to them 
		** the new trailer comments.  */
		    SetTrlOverwriteMode (NO);	
	    }
	}
   
    /* Sets up temp trailer file for output and copies input
     ** trailer file into it.  */
    InitTrlFile (trl_in, trl_out);
    
    return(status);
}