Exemplo n.º 1
0
void PrRefInfo (char *keyword, char *filename,
	char *pedigree, char *descrip, char *descrip2) {

/* arguments:
char *keyword   i: keyword name for reference file
char *filename  i: name of reference file (image or table)
char *pedigree  i: pedigree for image file, table header, or table row
char *descrip   i: first descrip, from image or table header
char *descrip2  i: second descrip, if any, from table row
*/
	void UpperAll (char *, char *, int);

	UpperAll (keyword, buf, SCRATCH_SIZE);

	sprintf (MsgText,"%s %s", buf, filename);
	trlmessage (MsgText);

	if (pedigree[0] != '\0') {
	    sprintf (MsgText, "%s PEDIGREE=%s", buf, pedigree);
	    trlmessage (MsgText);
	}
	
	if (descrip[0] != '\0') {
	    sprintf (MsgText, "%s DESCRIP =%s", buf, descrip);
	    trlmessage (MsgText);
	}
	
	if (descrip2[0] != '\0') {
	    sprintf (MsgText, "%s DESCRIP =%s", buf, descrip2);
	    trlmessage (MsgText);
	}
}
Exemplo n.º 2
0
void PrHdrInfo (char *aperture, char *filter, char *detector) {

	sprintf (MsgText, "APERTURE %s", aperture);
	trlmessage (MsgText);
	sprintf (MsgText, "FILTER   %s", filter);
	trlmessage (MsgText);
	sprintf (MsgText, "DETECTOR %s", detector);
	trlmessage (MsgText);
}
Exemplo n.º 3
0
int LoadAsn (AsnInfo *asn) {

    /* Arguments:
     **  input		 i: Name of input file or image
     **  asn			io: Association info structure
     */

    extern int status;
    void printInfo (AsnInfo *);
    int SetInput (AsnInfo *);
    int SetAsnSingle (AsnInfo *);
    int GetAsnTable (AsnInfo *);
    int GetGlobalInfo (AsnInfo *);

    /* Determine whether input is a single file, an association table,
     ** or an entry from an association table. */
    if (SetInput (asn))
        return (status);

    if (asn->process == FULL) {
        sprintf (MsgText,"LoadAsn:  Processing FULL Association");
    } else if (asn->process == PARTIAL) {
        sprintf (MsgText,"LoadAsn:  Processing PART of Association");
    } else {
        sprintf (MsgText,"LoadAsn:  Processing SINGLE exposure");
    }
    trlmessage (MsgText);

    /* Read in global info from ASN table's primary header */	
    if (GetGlobalInfo (asn)) {
        trlerror (" Problem getting primary header information.");
        return (status);
    }


    /* Read in ASN table, and load appropriate members info into memory */
    if (asn->process == SINGLE) {
        /* Set ASN structure values to process a single exposure */
        if (SetAsnSingle (asn))
            return (status);
    } else {
        if (GetAsnTable (asn))
            return (status);
    }

    if (asn->debug) { 
        sprintf (MsgText,"LoadAsn:  Read in ASN table %s ", asn->asn_table);
        trlmessage (MsgText);
    }


    /* Print a summary of information about the association */
    if (asn->verbose)
        printInfo (asn);

    return (status);
}
Exemplo n.º 4
0
void PrEnd (char *label) {

	char *GetDateTime (void);

	sprintf (MsgText, "End      %s", GetDateTime());
	trlmessage (MsgText);
	trlmessage ("");
	sprintf (MsgText,"*** %s complete ***", label);
	trlmessage (MsgText);
}
Exemplo n.º 5
0
void PrBegin (char *label) {

	char *GetDateTime (void);

	trlmessage ("\n");
	sprintf (MsgText,"%s*** %s -- Version %s ***",TRL_PREFIX, label,
		 WF3_CAL_VER);
	trlmessage (MsgText);
	sprintf (MsgText,"Begin    %s", GetDateTime());
	trlmessage (MsgText);
}
Exemplo n.º 6
0
void PrGrpEnd (char *label, int n) {

/* arguments:
char *label  i: to be printed at beginning of line (e.g. "Imset" or "Order")
int n        i: number to be printed following label, if n > 0
*/
	char *GetTime (void);
	void Upper1 (char *, char *, int);
	
	if (strlen (label) > PAD_SIZE)
	    strcpy (buf, "*****");
	else if (n > 0)
	    sprintf (buf, "%s %d", label, n);
	else
	    sprintf (buf, "%s", label);

	Upper1 (buf, buf, SCRATCH_SIZE);

	if (strlen (buf) > PAD_SIZE && n > 0) {
	    sprintf (buf, "%s%d", label, n);	/* too long; delete the space */
	    Upper1 (buf, buf, SCRATCH_SIZE);
	}

	sprintf (MsgText, "%s End %s", buf, GetTime());
	trlmessage (MsgText);
}
Exemplo n.º 7
0
void PrSwitch (char *keyword, int value) {

/* arguments:
char *keyword  i: keyword name of calibration switch
int value      i: value of switch (OMIT, PERFORM, etc)
*/

	void UpperAll (char *, char *, int);

	
	UpperAll (keyword, buf, SCRATCH_SIZE);

	sprintf (MsgText,"%s", buf);
		
	if (value == OMIT)
	    strcat (MsgText," OMIT");
	else if (value == PERFORM)
	    strcat (MsgText, " PERFORM");
	else if (value == DUMMY)
	    strcat (MsgText, " SKIPPED");
	else if (value == SKIPPED)
	    strcat (MsgText, " SKIPPED");
	else if (value == COMPLETE)
	    strcat (MsgText, " COMPLETE");
	else
	    strcat (MsgText, " unknown");
		
	trlmessage (MsgText);
}
Exemplo n.º 8
0
int doNoisIR (WF3Info *wf3, MultiNicmosGroup *input) {

/* Arguments:
**	wf3	 i: WFC3 info structure
**	input	io: input image
*/

	/* Function definitions */
	int noiscalc (WF3Info *, SingleNicmosGroup *);
	int OmitStep (int);
	void PrSwitch (char *, int);

	/* Do the noise calculation for each group */
	if (wf3->noiscorr == PERFORM) {

	    for (wf3->group=wf3->ngroups; wf3->group >= 1; wf3->group--) {
		 if (noiscalc (wf3, &(input->group[wf3->group-1]))) {
		     PrSwitch ("noiscorr", SKIPPED);
		     return (status=0);
		 }
	    }
	}

	/* Print status to trailer */
	if (!OmitStep (wf3->noiscorr))
	    trlmessage ("Uncertainty array initialized.");
	PrSwitch ("noiscorr", COMPLETE);

	/* Successful return */
	return (status = 0);
}
Exemplo n.º 9
0
void PrGrpBegin (char *label, int n) {

/* arguments:
char *label  i: to be printed at beginning of line (e.g. "Imset" or "Order")
int n        i: number to be printed following label, if n > 0
*/
	char *GetTime (void);
	void Upper1 (char *, char *, int);
		
	if (strlen (label) > PAD_SIZE){
	    /* The label was longer than the buffer! */
	    strcpy (buf, "*****");
   	} else if (n > 0)
	    sprintf (buf, "%s %d", label, n);
	else
	    sprintf (buf, "%s", label);

	Upper1 (buf, buf, SCRATCH_SIZE);

	/* Is PAD_SIZE too small for the label and number? */
	if (strlen (buf) > PAD_SIZE && n > 0) {
	    sprintf (buf, "%s%d", label, n);	/* delete the space */
	    Upper1 (buf, buf, SCRATCH_SIZE);
	}

	sprintf (MsgText, "%s Begin %s", buf, GetTime());
	trlmessage (MsgText);
}
Exemplo n.º 10
0
static int UpdateHdr (char *output) {

    extern int status;

    Hdr phdr;               /* primary header */
    IODescPtr im;		/* descriptor for output image */

    int PutKeyBool (Hdr *, char *, Bool, char *);

    sprintf(MsgText, "Trying to open %s...",output);
    trlmessage (MsgText);

    initHdr (&phdr);

    /* Open input image in order to read its primary header. */
    im = openUpdateImage (output, "", 0, &phdr);				
    if (hstio_err()) {
        trlopenerr (output);
        closeImage(im);
        return (status = OPEN_FAILED);
    }

    if (PutKeyBool (&phdr, "ASN_PROD", True, "") ) {
        freeHdr (&phdr);
        trlerror ("Couldn't update ASN_PROD keyword in ASN table header");
        return(status = KEYWORD_MISSING);
    }

    /* write out primary header */
    if (putHeader (im))
        status = HEADER_PROBLEM;	
    if (hstio_err() || status) {
        trlreaderr (output);
        closeImage (im);
        return (status = OPEN_FAILED);
    }

    closeImage (im);
    /* Close the ASN table's primary header. */
    freeHdr (&phdr);

    sprintf(MsgText, "Updated Global Header for %s...",output);
    trlmessage (MsgText);

    return (status);

}
Exemplo n.º 11
0
void printInfo (AsnInfo *asn) {

    int i, j, k;
    int numprod;

    trlmessage("");

    if (asn->dthcorr == DUMMY) {
        numprod = 0;
    } else {
        numprod = asn->numprod;
    }
    sprintf (MsgText,
            "NUMBER of MEMBERS in TABLE: %d  PRODUCTS: %d  SUB-PRODUCTS: %d",
            asn->numasn, numprod, asn->numsp);
    trlmessage (MsgText);

    if (asn->process != SINGLE) {
        for (i=0; i < asn->numprod; i++) {
            if (asn->dthcorr != DUMMY || asn->dthcorr != OMIT) {
                sprintf (MsgText,
                        "Product-- Member %3d: %s  Product: %2d  Type: %s",
                        i+1, asn->product[i].name, asn->product[i].prodid,
                        asn->product[i].mtype);
                trlmessage (MsgText);
            }

            for (j = 1; j <= asn->numsp; j++) {
                sprintf (MsgText,
                        "Sub-Product-- Member %3d: %s  Posn: %2d  Type: %s",
                        j, asn->product[i].subprod[j].name, 
                        asn->product[i].subprod[j].posid,
                        asn->product[i].subprod[j].mtype);
                trlmessage (MsgText);

                for (k = 1; k <= asn->spmems[j]; k++) {
                    sprintf (MsgText,
                            "Exposure-- Member %3d: %s  Type: %s",
                            k, asn->product[i].subprod[j].exp[k].name, 
                            asn->product[i].subprod[j].exp[k].mtype);
                    trlmessage (MsgText);
                }
            }
        }

    } else {

        /* Print out info for SINGLE exposure ... */
        sprintf (MsgText, "Exposure-- Processing SINGLE Exposure %s ",
                asn->filename);
        trlmessage (MsgText);
    }

    trlmessage ("");
}
Exemplo n.º 12
0
void PrFileName (char *label, char *filename) {

/* arguments:
char *label     i: e.g. "Input" or "Output"
char *filename  i: name of input or output file
*/
	void Upper1 (char *, char *, int);
	
	Upper1 (label, buf, SCRATCH_SIZE);

	sprintf (MsgText,"%s %s", buf, filename);
	trlmessage (MsgText);
}
Exemplo n.º 13
0
int LoadHdr (char *input, Hdr *phdr) {

	extern int status;
	
	IODescPtr im;		/* descriptor for input image */
   	
	sprintf(MsgText, "Trying to open %s...",input);
	trlmessage (MsgText);

	/* Open input image in order to read its primary header. */
	im = openInputImage (input, "", 0);				

	if (hstio_err()) {
		trlopenerr (input);
	    return (status = OPEN_FAILED);
	}
		
    initHdr (phdr);	

	/* get primary header */
	if (getHeader (im, phdr) )
		status = HEADER_PROBLEM;	
	if (hstio_err() || status) {
		trlreaderr (input);
		closeImage (im);
		freeHdr (phdr);
	    return (status = OPEN_FAILED);
	}
	
	closeImage (im);
    
	sprintf(MsgText, "Read in Primary header from %s...",input);
	trlmessage (MsgText);

	return (status);
}	
Exemplo n.º 14
0
/* Find the median vaue in the array. Handles odd and even number of inputs. */
float findRMedian (float *arr, int npts) {

	int i;
	float *tarr;
	float median;
    
	int sort (float *, int);  /* sort the given array*/

	median = 0.;

	/* Check for trivial cases */
	if (npts == 0) {
	    return(0.0);

	} else if (npts == 1) {
	    return(arr[0]);

	} else {
        
	    /*create a temporary array to sort the values*/
	    tarr = (float *) calloc(npts, sizeof(float));
	    if (tarr == NULL) {
		sprintf (MsgText, "Memory allocation failure in resistmean");
		trlmessage (MsgText);
		return (0.0);
	    }
    	    for (i=0; i<npts; i++)
        	tarr[i]=arr[i];
        
	    /* Sort the array of values */
	    if (sort(tarr-1, npts))
		return (0.0);

	    /* Find the median */
	    if ((npts % 2) == 0)
		median = 0.5 * (tarr[npts/2-1] + tarr[npts/2]);
	    else
		median = tarr[npts/2];

	    free(tarr);
	}

	return (median);
}
Exemplo n.º 15
0
static int DriftFit (void) {

	double d;
	double xmean, ymean;	/* mean values of column and value */

	if (sums[0] < 1.)
	    return (-1);

	d = sums[4] - sums[1] * sums[1] / sums[0];
	if (d == 0.)
	    return (-2);

	xmean = sums[1] / sums[0];
	ymean = sums[2] / sums[0];

	slope = (sums[3] - xmean * ymean * sums[0]) / d;

        sprintf (MsgText, "Computed a parallel fit with slope of %g", slope);
        trlmessage (MsgText);

	return (0);
}
Exemplo n.º 16
0
int GetSingle (AsnInfo *asn, ACSInfo *acs) {

/* arguments:
AsnInfo *asn      	i: calibration flags and other info
ACSInfo *acs		o: exposure specific flags and info
*/
	extern int status;
	char rootname[CHAR_FNAME_LENGTH];
	*rootname = '\0';
	void FindAsnRoot (const char *, char *);
	
	const char * outroot = asn->filename;
	
	/* Make sure we are only passing a rootname, and not a full filename.*/
	FindAsnRoot (outroot, rootname);
	strcpy (acs->outroot, rootname);
	strcpy (acs->rootname, rootname);
	
	if (asn->debug) {
		sprintf (MsgText, "GetSingle: Rootname: %s, Output rootname: %s",rootname, outroot);
		trlmessage (MsgText);
	}

	/* Check to see that this value of rootname is what we really need... */
	strcpy (acs->asn_table, asn->asn_table);	
	strcpy (acs->rawfile, asn->filename);
	
	/* Set sci_* flags for acs */	
	acs->sci_crcorr = asn->crcorr;
	acs->sci_dthcorr = asn->dthcorr;
	acs->sci_rptcorr = asn->rptcorr;
	acs->detector = asn->detector;
	acs->nimages = 1;

    /* Set MemType appropriate for output */
    acs->mtype[0] = '\0';

	return (status);
}
Exemplo n.º 17
0
int GetGlobalInfo (AsnInfo *asn) {

    /* Arguments:
     **	asn	io: association info structure
     */
    extern int status;
    Hdr phdr;               /* primary header */

    char detector[SZ_FITS_REC+1];

    /* Function definitions */
    int GetKeyStr (Hdr *, char *, int, char *, char *, int);
    int LoadHdr (char *, Hdr *);
    /*	int GetSwitch (Hdr *, char *, int *); */

    if (asn->debug) {
        trlmessage ("GetGlobalInfo: Ready to open primary header... ");
    } 

    if (asn->debug) {
        sprintf(MsgText, "GetGlobalInfo: asn_table is %s",asn->asn_table);
        trlmessage (MsgText);
    }

    /* Read primary header of ASN file into phdr. */
    if (LoadHdr (asn->asn_table, &phdr)) {
        sprintf (MsgText, "Could not load header from table %s",
                asn->asn_table);
        trlerror (MsgText);
        return (status);
    }
    if (asn->debug) {
        trlmessage ("GetGlobalInfo: Read in header from Image");
    }	

    /* Get the observing mode keyword values from header */
    asn->instr[0] = '\0';
    if (GetKeyStr (&phdr, "INSTRUME", 0, "", asn->instr, SZ_FITS_REC)) {
        trlkwerr ("INSTRUME", asn->asn_table);
        return (status = KEYWORD_MISSING);
    }

    asn->detector = 0;
    detector[0]   = '\0';
    if (GetKeyStr (&phdr, "DETECTOR", 0, "", detector, SZ_FITS_REC)) {
        trlkwerr ("DETECTOR", asn->asn_table);
        return (status = KEYWORD_MISSING);
    }

    /* Convert detector string to usable value */
    if (strncmp (detector, "UVIS", 4) == 0) {
        asn->detector = CCD_DETECTOR;
    } else if (strncmp (detector, "IR", 2) == 0) {
        asn->detector = IR_DETECTOR;
    } else {
        asn->detector = UNKNOWN_DETECTOR;
        return (status = HEADER_PROBLEM);
    }

    checkGlobalInfo(asn);

    /* You can NOT create a summed image with only 1 input */
    if (asn->process == SINGLE) {
        asn->rptcorr = OMIT;
    }

    /* If we are not processing an entire association, then
     ** we will not have the inputs necessary for a DTHCORR. */
    /*	if (dthcorr == PERFORM) { */
    if (asn->process == SINGLE) {
        asn->dthcorr = DUMMY;
    }
    /*	} */

    /* Otherwise, leave asn->dthcorr as set by reading ASN table itself */

    /* Close the ASN table's primary header here. */
    freeHdr (&phdr);



    if (asn->debug) {
        trlmessage ("GetGlobalInfo: Detector and Instrument determined");
    }	

    /* Successful return */
    return (status);
}
Exemplo n.º 18
0
/* GETASNMEMBER: Copy information from association table structure
**	to a single image structure for use by the remainder of the 
**	processing tasks.
*/
int GetAsnMember (AsnInfo *asn, int prodid, int posid, int expid, ACSInfo *acs) {

/* arguments:
AsnInfo *asn      	i: calibration flags and other info
int prodid			i: product id for exposure
int posid			i: sub-product id for exposure 
int expid			i: id of exposure within sub-product
ACSInfo *acs		o: exposure specific flags and info
*/
	extern int status;
	
	char rootname[CHAR_FNAME_LENGTH+1];
	char mtype[SZ_STRKWVAL+1];
    int mlen;
	void FindAsnRoot (const char *, char *);
    void UpperAll (char *, char *, int);
    
	/* find out if the member we want exists... */	
	if (asn->product[prodid].subprod[posid].exp[expid].name[0] == '\0') {
		sprintf(MsgText,"Couldn't find exposure %d of sub-product %d for product %d. ", expid, posid, prodid);
		trlerror (MsgText);
		return (status = NO_GOOD_DATA);
	}

	/* Initialize local strings... */
	rootname[0] = '\0';
    mtype[0] = '\0';

    const char * outroot = asn->product[prodid].subprod[posid].name;
	
	/* Make sure we are only passing a rootname, and not a full filename.*/
	FindAsnRoot (outroot, rootname);
	strcpy (acs->outroot, rootname);
					
	strcpy (acs->rootname, asn->product[prodid].subprod[posid].exp[expid].name);
	strcpy (acs->crj_root, asn->product[prodid].subprod[posid].spname);

	/* Make sure we are only passing a rootname, and not a full filename.*/
	FindAsnRoot (acs->rootname, rootname);
	strcpy (acs->rootname, rootname);
	
	if (asn->debug){
		sprintf (MsgText, "GetAsnMember: Rootname: %s, Output rootname: %s",rootname, outroot);
		trlmessage (MsgText);
	}
	/* Check to see that this value of rootname is what we really need... */
	strcpy (acs->asn_table, asn->asn_table);	
	strcpy (acs->rawfile, asn->product[prodid].subprod[posid].exp[expid].expname);
	
	/* Set sci_* flags for acs */	
	acs->sci_crcorr = asn->crcorr;
	acs->sci_dthcorr = asn->dthcorr;
	acs->sci_rptcorr = asn->rptcorr;
	acs->detector = asn->detector;
	acs->nimages = asn->spmems[posid];

    /* Set MemType appropriate for output */
    if (!strncmp (rootname, acs->asn_table, 8) ) {
        mlen = strlen(acs->mtype);
        UpperAll (acs->mtype, mtype, mlen);
        strcpy(mtype, asn->product[prodid].subprod[posid].mtype);
    }
    
	return (status);
}
Exemplo n.º 19
0
int GetAsnTable (AsnInfo *asn) {

    /* Arguments:
     **	asn		o: Association info structure
     */
    extern int status;

    /* Local variables */
    int i;				/* loop index */
    int nrows;			/* number of rows in ASNTAB */
    int col, row;			/* loop indexes */
    IRAFPointer tp;			/* ASNTAB table pointer */
    IRAFPointer colptr[NCOLS];	/* ASNTAB column pointers */
    int numsp;			/* number of sub-products in asn */
    int	posid;			/* id of sub-product */
    RowInfo *exp;		/* Internal structure for table information */
    int *spmems, *expmem;	/* number of EXP for each sub-product */
    int poslen;		/* Length of memtype string minus POSID */
    int prodid;		/* id of product 	*/
    int expid;
    int defid;		/* default position id for exposures */
    int procprod;
    int maxspmems;		/* max number of sub-product members */
    char *word;
    Bool proddth;
    char spname_ext[SZ_CBUF+1];	/* Extension for sub-product */
    char spname_ext_cte[SZ_CBUF+1];	/* Extension for sub-product */
    char memtype[SZ_COLNAME+1];
    char memsubtype[SZ_COLNAME+1];

    /* ASNTAB column names */
    char colname[NCOLS][SZ_COLNAME+1] = {
        "MEMNAME",
        "MEMTYPE",
        "MEMPRSNT"
    };

    /* Function definitions */
    void freeAsnInfo (AsnInfo *);
    int  allocAsnInfo (AsnInfo *, int, int *);
    void trlopenerr (char *);
    void trlwarn (char *);
    char *lowcase (char *, char *);
    int  MkName (char *, char *, char *, char *, char *, int);
    void initRowInfo (RowInfo *);
    int  streq_ic (char *, char *);  /* strings equal? (case insensitive) */

    if (asn->debug) {
        sprintf (MsgText, "GetAsnTable: ASN_TABLE is %s",asn->asn_table);
        trlmessage (MsgText); 
    }

    /* Open the ASN table */
    tp = c_tbtopn (asn->asn_table, IRAF_READ_ONLY, 0);
    if (c_iraferr()) {
        trlopenerr (asn->asn_table);
        return (status = TABLE_ERROR);
    }

    /* Get pointers to columns in ASNTAB */
    for (col=0; col < NCOLS; col++) {
        c_tbcfnd1 (tp, colname[col], &(colptr[col]));
        if (c_iraferr() || colptr[col] == 0) {
            sprintf (MsgText, "Can't find column %s in %s", colname[col],
                    asn->asn_table);
            trlerror (MsgText);
            c_tbtclo (tp);
            return (status = COLUMN_NOT_FOUND);
        }
    }

    /* Find out how many rows are in ASNTAB */
    nrows = 0;
    nrows = c_tbpsta (tp, TBL_NROWS);
    if (nrows <= 0) {
        sprintf (MsgText, "Invalid number of rows in %s", asn->asn_table);
        trlerror (MsgText);
        c_tbtclo (tp);
        return (status = TABLE_ERROR);
    }

    /* Initialize total number of members based on number of
     ** rows in table */
    asn->numasn = nrows;
    poslen = 0;

    /* Allocate space for internal variables */
    exp = NULL;
    exp = (RowInfo *)calloc(nrows, sizeof(RowInfo));
    for (row = 0; row < nrows; row++)
        initRowInfo (&(exp[row]));

    /* Read each row of ASNTAB into a local structure */
    for (row = 0; row < nrows; row++) {

        /* Get the MEMBER NAME in this row */
        c_tbegtt (tp, colptr[0], row+1, exp[row].memname, SZ_CBUF);
        if (c_iraferr()) {
            sprintf (MsgText, "Can't read %s in row %d in %s", colname[0],
                    row+1, asn->asn_table);
            trlerror (MsgText);
            c_tbtclo (tp);
            free (exp);
            return (status = ELEMENT_NOT_FOUND);
        }

        /* Convert to lowercase for use as a file name */
        for (i = 0; i < strlen(exp[row].memname); i++)
            exp[row].memname[i] = tolower(exp[row].memname[i]);

        /* Get the TYPE in this row */
        c_tbegtt (tp, colptr[1], row+1, exp[row].mtype, SZ_CBUF);
        if (c_iraferr()) {
            sprintf (MsgText, "Can't read %s in row %d in %s", colname[1],
                    row+1, asn->asn_table);
            trlerror (MsgText);
            c_tbtclo (tp);
            free (exp);
            return (status = ELEMENT_NOT_FOUND);
        }

        /* Convert to lowercase for use later in routine.
         ** Also, if a value of MEMTYPE contains a UNDERLINE, then 
         ** record conversion to DASH in trailer file and warn
         ** user to correct the value. */
        lowcase (exp[row].type, exp[row].mtype);
        for (i = 0; i < strlen(exp[row].type); i++) {
            if (exp[row].type[i] == UNDERLINE_CHAR) {       
                exp[row].type[i] = DASH_CHAR;
                sprintf(MsgText, "MEMTYPE %s in row %d was INVALID and needs to be corrected.",
                        exp[row].mtype, row+1);
                trlwarn(MsgText);
            }
        }

        /* Get the STATUS in this row */
        c_tbegtb (tp, colptr[2], row+1, &(exp[row].prsnt));
        if (c_iraferr()) {
            sprintf (MsgText, "Can't read %s in row %d in %s", colname[2],
                    row+1, asn->asn_table);
            trlerror (MsgText);
            c_tbtclo (tp);
            free (exp);
            return (status = ELEMENT_NOT_FOUND);
        }
        if (asn->debug) {
            sprintf (MsgText, "GetAsnTable: Read in row %d from ASN table",
                    row);
            trlmessage (MsgText);
        }
    }

    /*  
     ** Determine whether CRCORR or RPTOBS processing will be required
     ** by searching for MEMTYPE of EXP_CR* or EXP_RPT*, respectively.
     ** Once it is determined, go on to next step...
     */
    for (row = 0; row < nrows; row++) {

        /* Check to see if we need to do CR-SPLIT combination ... */
        if (strstr (exp[row].type, "-cr") != NULL) {
            asn->crcorr = PERFORM;
            asn->rptcorr = OMIT;
            poslen = CRLEN;
            break;

            /* ... or REPEAT-OBS combination ... 	*/
        } else if (strstr (exp[row].type, "-rp") != NULL) { 
            asn->rptcorr = PERFORM;
            asn->crcorr = OMIT;
            poslen = RPTLEN;
            break;

            /* ... or neither at all	*/
        } else {
            asn->rptcorr = OMIT;
            asn->crcorr = OMIT;
            poslen = DTHLEN;
        }	
    }

    /* Default to always perform DRIZCORR step */
    asn->dthcorr = PERFORM;

    if (asn->debug) {
        sprintf (MsgText, "GetAsnTable: CRCORR = %d, RPTCORR = %d",
                asn->crcorr,asn->rptcorr);
        trlmessage (MsgText);
    }

    /* Sort through the list figuring out which are input vs. output
     ** files, and see if any input files are missing. */
    /* Initialize local variables */
    numsp   = 0;
    posid   = 0;
    prodid  = 0;
    proddth = False;
    defid   = 1;

    /* Find out how many products/sub-products are in the association
     ** and determine the posid for each member. */	
    for (row = 0; row < nrows; row++) {
        memtype[0] = '\0';
        memsubtype[0] = '\0';

        /* As long as this is not the final product,
         ** count number of members in each product/sub-product...*/
        if (strstr(exp[row].type,"prod-dth") != NULL) {
            exp[row].posid = 0;	
            posid = 0;	

            /* If we have a dither product listed, we want to eventually
             ** perform dither combining step... */	
            prodid++;
            proddth = True;

            /* We always want to produce a product, but if
             ** not set to PERFORM, then create an empty product... */
            if (asn->dthcorr == OMIT) 
                asn->dthcorr = DUMMY;

        } else {

            strcpy(memtype,exp[row].type);	
            /* Let's start by breaking up the MEMTYPE string */
            word = strtok(memtype,"-");
            strcpy(memsubtype,word);
            /* The end of this second part of MEMTYPE has the POSID */
            word = strtok(NULL,"\n");

            /* If the last character of the memtype is a number or letter, 
             ** convert to an integer value...  */
            if (streq_ic(word,"crj") || streq_ic(word,"rpt") || streq_ic(word,"crc") ) {
                posid = 1;
            } else {
                if (exp[row].prsnt || streq_ic(memsubtype,"prod")) {

                    if (isalnum(word[poslen])) {
                        /* Interpret the POSID from the second part
                         ** of MEMTYPE */
                        posid=(int)strtol(&word[poslen],(char **)NULL,10);
                    } else {
                        /* Otherwise, assume it is a different pointing
                         ** and assign an incremented position ID. After
                         ** all, it is NOT a CR-SPLIT or RPT-OBS exposure.*/
                        posid = defid;
                        defid++;
                    }
                }
            }

            /* Keep track of how many sub-products there are based on
             ** POSID from MEMTYPE values */

            if (posid > numsp) {
                if ((exp[row].prsnt && (strstr(memtype,"exp") != NULL)) ||
                        strstr(memtype,"prod") != NULL) {
                    numsp++;
                }
            }

            exp[row].posid = posid;		
        }

        if (asn->debug) {
            sprintf (MsgText, "GetAsnTable: Posid = %d for row %d",posid,
                    row);
            trlmessage (MsgText);
        }	

        /* If the member is missing, give a warning */
        /* This implies that MEMPRSNT must be set to YES for EXP_*
         ** This is not fatal for WF3.  Simply decrement tmembers. */
        if (!exp[row].prsnt && strncmp(exp[row].type, "prod-",5) != 0) {
            sprintf (MsgText, "Member \"%s\" is not present",
                    exp[row].memname);
            trlwarn (MsgText);		 
            asn->numasn--;
            /* Now flag row as being absent so it doesn't get passed
             ** along for further processing... */
            exp[row].posid = MEMABSENT;
        }
    }

    if (asn->debug) {
        sprintf (MsgText, "GetAsnTable: NUMSP = %d, PRODID = %d",numsp,
                prodid);
        trlmessage (MsgText);
    }

    /* Check for existence of enough data to process */
    if (asn->numasn < 1) {
        trlerror ("No data available for given assoc. table");
        freeAsnInfo (asn);
        return (status = ERROR_RETURN);
    }

    /* Record the number of products found in association */
    if (proddth) {
        asn->numprod = prodid;
    } else {
        /* If there are no PROD-DTH entries in ASN table, set
         ** numprod to 1 */
        asn->numprod = prodid + 1;
    }

    /* Determine what elements should be processed based on
     ** initial input, either FULL or PARTIAL processing.  */
    procprod = 0;
    if (asn->process != FULL) {
        for (row=0; row < nrows; row++){
            /* Look for entry with same name as input */
            if (streq_ic(exp[row].memname, asn->rootname)) {
                /* We only want to process this product	*/
                procprod = exp[row].posid;
                numsp = 1;
            }	
        }
    }

    /* Allocate space to count number of exposures per sub-product
     ** with spmems[0] being reserved for final output product
     ** since POSID starts indexing at 1. */
    spmems = (int *)calloc(numsp+1,sizeof(int));
    expmem = (int *)calloc(numsp+1,sizeof(int));

    /* Initialize arrays */
    for (i=0; i <= numsp; i++) {
        spmems[i] = 0;
        expmem[i] = 0;
    }

    /* For each sub-product,
     ** identify each EXP that belongs to that posid and 
     ** is present to be processed. */
    for (row=0; row < nrows; row++) {
        if (strstr(exp[row].type, "exp-") && exp[row].posid > MEMABSENT) {

            if ((asn->process != FULL && exp[row].posid == procprod) ||
                    asn->process == FULL) {

                spmems[exp[row].posid]++;
                /* Exposure IDs will start at 1 to be consistent 
                 ** with POSID numbering. Initialize here, count later. */
                expmem[exp[row].posid] = 1;
            }
        }
    }

    /* Allocate slots for all members in ASN info structure */
    if (allocAsnInfo (asn, numsp, spmems)) {
        return (status = TABLE_ERROR);
    }

    asn->product[prodid].prodid = prodid;

    /* Reset prodid for filling ASN table */
    prodid = 0;

    /* Copy summary information about ASN relationships to ASN structure. */
    maxspmems = 0;
    asn->numsp = numsp;
    for (i=0; i <= numsp; i++) {
        asn->spmems[i] = spmems[i];
        if (spmems[i] > maxspmems)
            maxspmems = spmems[i];
    }

    /* If there aren't any sub-products with more than 1 member, then
     ** omit crcorr/rptcorr processing */
    if ((maxspmems < 2) && asn->crcorr == PERFORM) {
        sprintf (MsgText,
                "No sub-product with more than 1 member; CRCORR will be skipped");
        trlwarn (MsgText);
        asn->crcorr = DUMMY;
    } else if ((maxspmems < 2) && asn->rptcorr == PERFORM) {
        sprintf (MsgText,
                "No sub-product with more than 1 member; RPTCORR will be skipped");
        trlwarn (MsgText);
        asn->rptcorr = DUMMY;
    }

    /* Copy information read-in into ASN structure now... */
    for (row = 0; row < nrows; row++) {
        if (exp[row].posid != MEMABSENT) {
            if ((asn->process != FULL && exp[row].posid == procprod) ||
                    asn->process == FULL) {	  
                posid = exp[row].posid;

                /* Is this row the final product entry? */
                if (strstr(exp[row].type, "prod-dth") != NULL) {
                    strcpy (asn->product[prodid].name, exp[row].memname);
                    strcpy (asn->product[prodid].mtype, exp[row].type);
                    asn->product[prodid].prsnt = exp[row].prsnt;
                    asn->product[prodid].numsp = numsp;
                    asn->product[prodid].asnrow = row+1;

                    /* Create full file name for this image */
                    if (MkName (exp[row].memname, "_raw", "_drz", "",
                                asn->product[prodid].prodname, SZ_LINE)){
                        strcpy(asn->product[prodid].prodname,
                                exp[row].memname);
                        strcat (asn->product[prodid].prodname,
                                "_drz.fits");
                    }
                    
                    /* Create full file name for this CTE image */
                    if (MkName (exp[row].memname, "_rac_tmp", "_drc", "",
                                asn->product[prodid].prodname_cte, SZ_LINE)){
                        strcpy(asn->product[prodid].prodname_cte,
                                exp[row].memname);
                        strcat (asn->product[prodid].prodname_cte,
                                "_drc.fits");
                    }
                    

                    /* Or, is this row an input exposure? */
                } else if (strstr(exp[row].type, "exp-") != NULL) {

                    if (exp[row].posid > MEMABSENT) {

                        /* Internal counter for which exposure we want for
                         ** a position */
                        expid = expmem[posid];
                        strcpy(asn->product[prodid].subprod[posid].exp[expid].name,
                                exp[row].memname);		
                        strcpy(asn->product[prodid].subprod[posid].exp[expid].mtype,
                                exp[row].type);
                        asn->product[prodid].subprod[posid].exp[expid].prsnt =
                            exp[row].prsnt;
                        asn->product[prodid].subprod[posid].exp[expid].asnrow=
                            row+1;

                        /* Create full file name for this image */
                        if (MkName (exp[row].memname, "_raw", "_raw", "",
                                    asn->product[prodid].subprod[posid].exp[expid].expname,
                                    SZ_LINE)) {

                            strcpy(asn->product[prodid].subprod[posid].exp[expid].expname,
                                    exp[row].memname);
                            strcat(asn->product[prodid].subprod[posid].exp[expid].expname,
                                    "_raw.fits");
                        }

                        /* Fill-in sub-product information for EXP-DTH
                         ** exposures which don't create sub-products */
                        if (strstr(exp[row].type, "exp-dth") != NULL) {
                            if (!MkName (exp[row].memname, "_raw", "_flt", "",
                                        asn->product[prodid].subprod[posid].spname,
                                        SZ_LINE) ) {

                                strcpy(asn->product[prodid].subprod[posid].name,
                                        exp[row].memname);
                                strcpy(asn->product[prodid].subprod[posid].mtype,
                                        exp[row].type);
                                asn->product[prodid].subprod[posid].posid =
                                    exp[row].posid;
                            }
                        }

                        /* Increment that counter for next exposure's id
                         ** for this posid */
                        expmem[posid]++;
                    }

                    /* If neither, it must be a sub-product */
                } else {

                    if (spmems[posid] > 0) {

                        strcpy(asn->product[prodid].subprod[posid].name,
                                exp[row].memname);
                        strcpy(asn->product[prodid].subprod[posid].mtype,
                                exp[row].type);
                        asn->product[prodid].subprod[posid].prsnt =
                            exp[row].prsnt;
                        asn->product[prodid].subprod[posid].asnrow = row+1;


                        /* Create full file name for this image for 
                         ** DTHCORR input */
                        spname_ext[0] = '\0';
                        spname_ext_cte[0] = '\0';
                        if (asn->crcorr || asn->rptcorr) {
                            strcpy (spname_ext, "_crj");
                            strcpy (spname_ext_cte,"_crc");
                        } else {
                            strcpy (spname_ext, "_sfl");
                            strcpy (spname_ext_cte, "_sfl");
                        }

                        if (MkName (exp[row].memname, "_raw", spname_ext, "",
                                    asn->product[prodid].subprod[posid].spname,
                                    SZ_LINE)) {

                            strcpy(asn->product[prodid].subprod[posid].spname,
                                    exp[row].memname);
                            strcat(asn->product[prodid].subprod[posid].spname,
                                    spname_ext);		
                            strcat(asn->product[prodid].subprod[posid].spname,
                                    ".fits");		
                                    
                        }
                        if (MkName (exp[row].memname, "_raw", spname_ext_cte, "",
                                    asn->product[prodid].subprod[posid].spname_cte,
                                    SZ_LINE)) {

                            strcpy(asn->product[prodid].subprod[posid].spname_cte,
                                    exp[row].memname);
                            strcat(asn->product[prodid].subprod[posid].spname_cte,
                                    spname_ext_cte);		
                            strcat(asn->product[prodid].subprod[posid].spname_cte,
                                    ".fits");		
                                    
                        }

                        asn->product[prodid].subprod[posid].numexp =
                            spmems[posid];
                        asn->product[prodid].subprod[posid].posid = posid;

                    }
                }
            }
        } /* Process only those exposures where MEMPRSNT == YES */
    }

    /* Close the ASN table.  We are done reading it in. */
    c_tbtclo (tp);



    /* Clean up memory usage as well. */
    free (spmems);
    free (expmem);
    free (exp);

    if (asn->debug) {
        trlmessage ("GetAsnTable: Info from ASN read into memory.");
    }

    /* Successful return */
    return (status);
}
Exemplo n.º 20
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.º 21
0
static int SumGrps (AcsSumInfo *acs, char *mtype) {

    extern int status;
    SingleGroup x;                /* first imset */
    SingleGroupLine y;            /* line from Nth imset */
    double exptime;                /* exposure time of current image */
    double sumexptime = 0.;        /* accumulated exposure time */
    char *message;                 /* for printtime info */
    int extver;                    /* imset number */
    int i;                    /* counter for current image */
    int chip, ychip;            /*Chip being summed */
    int extchip;            /* Extension of chip being summed */
    int line;                /* Line of chip being summed */
    char        uroot[CHAR_FNAME_LENGTH];   /* Upper case version of rootname */

    int doStat (SingleGroup *, short);
    void TimeStamp (char *, char *);
    void PrGrpBegin (char *, int);
    void PrGrpEnd (char *, int);
    void PrSwitch (char *, int);
    void UCalVer (Hdr *);
    void UFilename (char *, Hdr *);
    void UMemType (char *, Hdr *);
    void UExpname (char *, Hdr *);
    int DetCCDChip (char *, int, int, int *);
    void    UpperAll (char *, char *, int);

    int GetKeyInt (Hdr *, char *, int, int, int *);
    int GetKeyDbl (Hdr *, char *, int, double, double *);
    int PutKeyStr (Hdr *, char *, char *, char *);

    initSingleGroup (&x);
    initSingleGroupLine (&y);

    if (acs->printtime) {
        if ((message = calloc (CHAR_LINE_LENGTH+1, sizeof (char))) == NULL)
            return (status = OUT_OF_MEMORY);
    }

    for (extver = 1;  extver <= acs->nimsets;  extver++) {

        PrGrpBegin ("imset", extver);

        getSingleGroup (acs->input[0], extver, &x);
        if (hstio_err())
            return (status = OPEN_FAILED);
        if (acs->printtime)
            TimeStamp ("first imset read", acs->input[0]);

        /* get from x */
        if (GetKeyInt (&x.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &chip))
            return (status);
        if (GetKeyDbl (x.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend))
            return (status);

        sumexptime = acs->exptime;

        /* Square the errors to convert to variance. */
        SquareErr (&x);                /* operate on x */

        /* For each imset/extver, loop over all images */
        for (i = 1; i < acs->nimages; i++) {

            /* Determine which extension corresponds to desired chip
            ** for the remainder of the images.
            */
            extchip = 0;

            if (DetCCDChip(acs->input[i], chip, acs->nimsets, &extchip) ) {
                return (status);
            }

            /* Get the first line of bias image data. */
            openSingleGroupLine (acs->input[i], extchip, &y);
            if (hstio_err())
                return (status = OPEN_FAILED);

            /* Update exposure time info. */
            /* get from y */

            if (GetKeyInt (&y.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &ychip))
                return (status);
            if (GetKeyDbl (y.globalhdr, "EXPTIME", NO_DEFAULT, 0., &exptime))
                return (status);
            if (GetKeyDbl (y.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend))
                return (status);

            sumexptime += exptime;

            /*Loop over lines in each subsequent image */
            for (line = 0; line < x.sci.data.ny; line++) {
                status = getSingleGroupLine (acs->input[i], line, &y);
                if (status) {
                    sprintf(MsgText,"Could not read line %d from image %d.",line+1,i+1);
                    trlerror(MsgText);
                    return (status = OPEN_FAILED);
                }

                SquareErrLine (&y);                /* operate on y */

                /* Add current imset to sum (i.e. add y to x).  This differs
                    from add2d in that RptSum adds variances, rather than
                    adding errors in quadrature.
                */
                if (RptSumLine (&x, line, &y))
                    return (status);

            } /*End loop over lines */

            if (acs->printtime) {
                if (i == 1)
                    strcpy (message, "1st imset added");
                else if (i == 2)
                    strcpy (message, "2nd imset added");
                else if (i == 3)
                    strcpy (message, "3rd imset added");
                else
                    sprintf (message, "%dth imset added", i);

                TimeStamp (message, acs->input[i]);
            }

            closeSingleGroupLine (&y);
        } /* End loop over images */

        freeSingleGroupLine (&y);

        /* Take the square root of variance to convert back to errors. */
        SqrtErr (&x);

        /* Compute statistics and update keywords in output headers. */
        trlmessage ("\n");
        if (doStat (&x, acs->sdqflags))
        return (status);
        if (acs->printtime)
            TimeStamp ("Image statistics computed", acs->rootname);
        /* Update header info in output. */
        if (PutSumHdrInfo (&x, sumexptime, acs->expend, acs->nimages, acs->nimsets))
            return (status);

        /* Update CAL_VER and FILENAME, then write output file.
            EXPNAME values modified for all extensions in a SingleGroup.
                    WJH 7 July 1999
        */
        UCalVer (x.globalhdr);
        UFilename (acs->output, x.globalhdr);
        UMemType (mtype, x.globalhdr);
        UExpname (acs->rootname, &x.sci.hdr);
        UExpname (acs->rootname, &x.err.hdr);
        UExpname (acs->rootname, &x.dq.hdr);
        UpperAll (acs->rootname, uroot, strlen(acs->rootname)+1 );

        PutKeyStr (x.globalhdr, "ROOTNAME", uroot,"Rootname of the observation set");

        putSingleGroup (acs->output, extver, &x, 0);
        if (hstio_err())
                return (status = 1001);
        freeSingleGroup (&x);

        PrGrpEnd ("imset", extver);

        if (acs->printtime)
            TimeStamp ("Output written to disk", acs->rootname);
    } /* End loop over imsets */

    if (acs->printtime)
        free (message);
    return (status);
}
Exemplo n.º 22
0
int doDark (ACSInfo *acs2d, SingleGroup *x, float *meandark) {
  
  /* arguments:
   ACSInfo *acs     i: calibration switches, etc
   SingleGroup *x    io: image to be calibrated; written to in-place
   float *meandark    o: mean of dark image values subtracted
   */
  
  extern int status;

  const float darkscaling = 3.0;  /* Extra idle time */
  
  SingleGroupLine y, z;	/* y and z are scratch space */
  int extver = 1;		/* get this imset from dark image */
  int rx, ry;		/* for binning dark down to size of x */
  int x0, y0;		/* offsets of sci image */
  int same_size;		/* true if no binning of ref image required */
  int avg = 0;		/* bin2d should sum values within each bin */
  int scilines; 			/* number of lines in science image */
  int i, j;
  float mean, dark;
  float weight, wdark;    /* weights for line averages */
  int update;
  float darktime;
  
  int FindLine (SingleGroup *, SingleGroupLine *, int *, int *, int *, int *, int *);
  int sub1d (SingleGroup *, int, SingleGroupLine *);
  int trim1d (SingleGroupLine *, int, int, int, int, int, SingleGroupLine *);
  int DetCCDChip (char *, int, int, int *);
  void AvgSciValLine (SingleGroupLine *, short, float *, float *);
  int multk1d (SingleGroupLine *, float);
  
  
	initSingleGroupLine (&y);
	
	scilines = x->sci.data.ny;

  /* Compute DARKTIME */
  /* SBC does not have FLASH keywords */
  if (acs2d->detector == MAMA_DETECTOR)
    darktime = acs2d->exptime;
  else {
    darktime = acs2d->exptime + acs2d->flashdur;

    /* Post-SM4 non-BIAS WFC only */
    /* TARGNAME unavailable, assume EXPTIME=0 means BIAS */
    if (acs2d->detector == WFC_CCD_DETECTOR && acs2d->expstart > SM4MJD && acs2d->exptime > 0)
      darktime += darkscaling;
  }
  
	/* Compute correct extension version number to extract from
   reference image to correspond to CHIP in science data.
   */
	if (acs2d->pctecorr == PERFORM) {
    if (DetCCDChip (acs2d->darkcte.name, acs2d->chip, acs2d->nimsets, &extver) )
      return (status);
  } else {
    if (DetCCDChip (acs2d->dark.name, acs2d->chip, acs2d->nimsets, &extver) )
      return (status);
  }
	
	if (acs2d->verbose) {
		sprintf(MsgText,"Performing dark subtraction on chip %d in imset %d",acs2d->chip, extver);
		trlmessage(MsgText);
	}
  
	/* Get the dark image data. */
  if (acs2d->pctecorr == PERFORM) {
    openSingleGroupLine (acs2d->darkcte.name, extver, &y);
  } else {
    openSingleGroupLine (acs2d->dark.name, extver, &y);
  }
	if (hstio_err())
    return (status = OPEN_FAILED);
  
  
	/* Compare binning of science image and reference image;
   get same_size and high_res flags, and get info about
   binning and offset for use by bin2d.
   */
	if (FindLine (x, &y, &same_size, &rx, &ry, &x0, &y0))
    return (status);
  
  if (rx != 1 || ry != 1) {
		sprintf(MsgText,"Reference image and input are not binned to the same pixel size!");
		trlmessage(MsgText);
  }
	if (acs2d->verbose){
		sprintf(MsgText,"Image has an offset of %d,%d",x0,y0);
		trlmessage(MsgText);
	}
  
	mean = 0.0;
  weight = 0.0;
  
	/* Bin the dark image down to the actual size of x. */
  
	initSingleGroupLine (&z);
	allocSingleGroupLine (&z, x->sci.data.nx);
	for (i=0, j=y0; i < scilines; i++,j++) { 
    
    /* We are working with a sub-array and need to apply the
     proper section from the reference image to the science image.
     */
		if (acs2d->pctecorr == PERFORM) {
      getSingleGroupLine (acs2d->darkcte.name, j, &y);
    } else {
      getSingleGroupLine (acs2d->dark.name, j, &y);
    }
    
    /*
     rx = 1;
     */
    update = NO;
    
    if (trim1d (&y, x0, y0, rx, avg, update, &z)) {
			trlerror ("(darkcorr) size mismatch.");
			return (status);
    }
    
    multk1d(&z, darktime);
    
    AvgSciValLine (&z, acs2d->sdqflags, &dark, &wdark);
    
		/* Sum the contribution from each line */			
		mean += dark * wdark;
		weight += wdark;
    
    status = sub1d (x, i, &z);
		if (status)
			return (status);
	}
	freeSingleGroupLine (&z);			/* done with z */
  
  /*	} */
  
	closeSingleGroupLine (&y);
	freeSingleGroupLine (&y);
  
	/* Compute the mean for the entire image */	
	if (scilines > 0) 
		*meandark = mean / weight; 
	else 
		*meandark = 0.;
	
	return (status);
}
Exemplo n.º 23
0
int doDark (WF3Info *wf32d, SingleGroup *x, float *meandark) {

/* arguments:
WF3Info *wf3       i: calibration switches, etc
SingleGroup *x    io: image to be calibrated; written to in-place
float *meandark	   o: mean of dark image values subtracted
*/

    extern int status;

    SingleGroupLine y, z;	/* y and z are scratch space */
    int extver = 1;		/* get this imset from dark image */
    int rx, ry;			/* for binning dark down to size of x */
    int x0, y0;			/* offsets of sci image */
    int same_size;		/* true if no binning of ref image required */
    int avg = 0;		/* bin2d should sum values within each bin */
    int scilines; 		/* number of lines in science image */
    int i, j;
    float mean, dark;
    float weight, wdark;    	/* weights for line averages */
    int update;
    float gain[NAMPS];
    float rn2[NAMPS];       	/* only need this to call get_nsegn */

    int FindLine (SingleGroup *, SingleGroupLine *, int *, int *, int *,
		  int *, int *);
    int sub1d (SingleGroup *, int, SingleGroupLine *);
    int trim1d (SingleGroupLine *, int, int, int, int, int, SingleGroupLine *);
    int DetCCDChip (char *, int, int, int *);
    void get_nsegn (int, int, int, int, float *, float*, float *, float *);
    void AvgSciValLine (SingleGroupLine *, short, float *, float *);
    void multgn1d (SingleGroupLine *, int, int, int, float *, float);


	initSingleGroupLine (&y);
	
	scilines = x->sci.data.ny;

	/* Compute correct extension version number to extract from
	   reference image to correspond to CHIP in science data.  */
	if (DetCCDChip(wf32d->dark.name, wf32d->chip, wf32d->nimsets, &extver))
	    return (status);	
	
	if (wf32d->verbose) {
	    sprintf (MsgText,
		     "Performing dark subtraction on chip %d in imset %d",
		     wf32d->chip, extver);
	    trlmessage(MsgText);
	}

	/* Get the dark image data. */
	openSingleGroupLine (wf32d->dark.name, extver, &y);
	if (hstio_err())
	    return (status = OPEN_FAILED);

	/* Compare binning of science image and reference image;
	   get same_size flag, and get info about binning and offset
	   for use by bin2d.
	*/
	if (FindLine (x, &y, &same_size, &rx, &ry, &x0, &y0))
	    return (status);
    
	/* Return with error if reference data not binned same as input */
	if (rx != 1 || ry != 1) {
	    closeSingleGroupLine (&y);
	    freeSingleGroupLine (&y);
	    sprintf (MsgText,
	    "DARK image and input are not binned to the same pixel size!");
	    trlerror(MsgText);
	    return (status = SIZE_MISMATCH);
	}
	if (wf32d->verbose){
	    sprintf(MsgText,"Image has an offset of %d,%d",x0,y0);
	    trlmessage(MsgText);
	}

	mean = 0.0;
	weight = 0.0;
    
	/* Multiply the dark image by the exposure time and divide by the
	   atodgain (or just by exposure time for the MAMAs), and
	   subtract it from x.
	*/
    
	for (i = 0; i < NAMPS; i++) {
	     gain[i] = 0.;
	     rn2[i] = 0.;
	}
	get_nsegn (wf32d->detector, wf32d->chip, wf32d->ampx, wf32d->ampy,
		   wf32d->atodgain, wf32d->readnoise, gain, rn2);

	initSingleGroupLine (&z);
	allocSingleGroupLine (&z, x->sci.data.nx);
	for (i=0, j=y0; i < scilines; i++,j++) { 

	     /* We are working with a sub-array and need to apply the
		proper section from the reference image to the science image.
	     */
	     getSingleGroupLine (wf32d->dark.name, j, &y);

             update = NO;

	     if (trim1d (&y, x0, y0, rx, avg, update, &z)) {
		 trlerror ("(darkcorr) size mismatch.");
		 return (status);
	     }

	     multgn1d(&z, j, wf32d->ampx, wf32d->ampy, gain, wf32d->exptime[0]);

	     AvgSciValLine (&z, wf32d->sdqflags, &dark, &wdark);

	     /* Sum the contribution from each line */			
	     mean += dark * wdark;
	     weight += wdark;

	     status = sub1d (x, i, &z);
	     if (status)
		 return (status);
	}
	freeSingleGroupLine (&z);			/* done with z */

	closeSingleGroupLine (&y);
	freeSingleGroupLine (&y);

	/* Compute the mean for the entire image */	
	if (scilines > 0) 
	    *meandark = mean / weight; 
	else 
	    *meandark = 0.;
	
	return (status);
}
Exemplo n.º 24
0
int GetCCDInfo (WF3Info *wf3, CCD_Switch *sci_sw, RefFileInfo *sciref) {

/* arguments:
WF3Info *wf3          i: calibration flags and other info
CCD_Switch *sci_sw    o: all calibration switches (0 or 1) for science file
RefFileInfo *sciref  io: list of keyword,filename pairs for science file
*/

	extern int status;

	IODescPtr im;		/* descriptor for an image */
	Hdr phdr;		/* primary header */
	int nextend;		/* number of FITS extensions in rawfile */

	int GetKeyInt (Hdr *, char *, int, int, int *);
	int GetKeyFlt (Hdr *, char *, int, float, float *);
	int GetCCDSws (CCD_Switch *, Hdr *);
	int GetCCDRef (WF3Info *, CCD_Switch *, Hdr *, RefFileInfo *);
	
	/* Open input raw data file. */
	initHdr (&phdr);
	im = openInputImage (wf3->rawfile, "", 0);
	if (hstio_err()) {
	    sprintf (MsgText, "Member \"%s\" is not present", wf3->rawfile);
	    trlerror (MsgText);
        freeHdr(&phdr);
	    return (status = OPEN_FAILED);
	}

	/* Read primary header into pdhr. */
	getHeader (im, &phdr);
	if (hstio_err()) {
	    sprintf (MsgText, "Could not open PRIMARY header for \"%s\" ",
		     wf3->rawfile);
	    trlmessage (MsgText);
        closeImage(im);
        freeHdr(&phdr);
	    return (status = OPEN_FAILED);
	}
	closeImage (im);
	
	/* Get generic parameters: */

	/* Find out how many extensions there are in this file. */
	if (GetKeyInt (&phdr, "NEXTEND", USE_DEFAULT, EXT_PER_GROUP, &nextend)){
        freeHdr(&phdr);
        closeImage(im);
	    return (status = KEYWORD_MISSING);
    }
        
	wf3->nchips = nextend / EXT_PER_GROUP;

	/* Get binning and gain info.  We really only need this for the CCD. */
	if (GetKeyInt (&phdr, "BINAXIS1", USE_DEFAULT, 1, &wf3->scibin[0])) {
        closeImage(im);
        freeHdr(&phdr);
	    return (status = KEYWORD_MISSING);
    }
	if (GetKeyInt (&phdr, "BINAXIS2", USE_DEFAULT, 1, &wf3->scibin[1])){
        closeImage(im);
        freeHdr(&phdr);
	    return (status = KEYWORD_MISSING);
    }
	if (GetKeyFlt (&phdr, "CCDGAIN",  USE_DEFAULT, 1.5, &wf3->scigain)){
        closeImage(im);
        freeHdr(&phdr);
	    return (status = KEYWORD_MISSING);
    }
    
	wf3->samebin = 1;	/* default */

	/* Get calibration switches, and check that reference files exist. */
	if (GetCCDSws (sci_sw, &phdr))
	    return (status = KEYWORD_MISSING);
	if (GetCCDRef (wf3, sci_sw, &phdr, sciref))
	    return (status = CAL_FILE_MISSING);

	freeHdr (&phdr);
	return (status);
}
Exemplo n.º 25
0
int SetInput (AsnInfo *asn) {

    /* Arguments:
     **  asn			io: Association info structure
     */	
    extern int status;

    /* Local Variables */
    char filename[SZ_FNAME+1];	
    int exist;			/* EXISTS_YES or EXISTS_NO */
    int in_dot;
    char linput[SZ_FNAME+1];	/* Lower case version of input */
    int incase;			/* What kind of input do we have? */

    int  DoesFileExist (char *);
    char *lowcase (char *, char *);
    int  GetAsnName (char *, char *);
    void FindAsnRoot (char *, char *);

    /* Initialize internal variables here... */
    filename[0] = '\0';

    /* convert input to lowercase for use only in looking for extensions */
    lowcase (linput, asn->input);

    /* Determine what kind of input: root only, 
     **				 root + suffix, or 
     **				 root + suffix + extension
     ** We will look for '.fit' or '.fits' extensions.
     */

    /* First, let's complete the input filename with a FITS extension.*/
    if (strstr(linput, ".fit") == NULL) {
        strcpy (filename, asn->input);
        strcat (filename, ".fits");
    } else {
        strcpy (filename, asn->input);
        strcat (filename, "\0");
    } 		

    /* Initialize local variable */
    incase = 0;

    /* Now, we find out what kind of input name was provided... */
    if (strstr(linput, "_asn") != NULL){
        incase = 0;
    } else if (strstr(linput, "_raw") != NULL ) {
        incase = 1;
    } else if (!IsProduct (linput)) {
        /* Not a sub-product/intermediate product... */
        incase = 2;
    } else {
        /* treat as if it was only a rootname (plus '.fits') */
        incase = 3;
    }

    if (asn->debug) {
        sprintf (MsgText, "GetAsnTable: incase = %d",incase);
        trlmessage (MsgText);
    }

    /* Given this full filename for a file which exists, 
     ** copy out just the rootname. */
    FindAsnRoot(filename, asn->rootname);

    /* Can we find the file as it is input? */
    exist = DoesFileExist(filename);

    /* Treat filename according to what was input... */
    switch (incase) {

        case 0:  /* We have an ASN file explicitly specified */

            if (exist == EXISTS_YES) {

                /* Found an ASN file:  Set values in ASN structure */
                asn->process = FULL;
                strcpy(asn->asn_table, filename);
                strcpy(asn->filename, filename);

                if (asn->verbose) {
                    trlmessage ("Processing FULL ASN table...");
                }			

            } else {

                /* Couldn't find specified ASN file... */
                sprintf (MsgText, "File %s not found for processing",
                        filename);
                trlerror (MsgText);
                return (status = OPEN_FAILED);			
            }
            break;

        case 1:  /* We have a RAW file explicitly specified */

            if (exist == EXISTS_YES) {

                /* Found a RAW file: Set values in ASN structure */
                strcpy (asn->filename, filename);
                strcpy (asn->asn_table, filename);
                strcat (asn->asn_table, "\0");

                if (asn->verbose) {
                    sprintf (MsgText, "Processing SINGLE image %s...",
                            asn->filename);
                    trlmessage (MsgText);
                }
                asn->process = SINGLE;

            } else {

                /* Couldn't find specified RAW file... */
                sprintf (MsgText,"File %s not found for processing",
                        filename);
                trlerror (MsgText);
                return (status = OPEN_FAILED);			
            }
            break;

        case 2:  /* We have a sub-product/intermediate file specified
                  ** for re-processing. They should really just run the
                  ** stand-alone tasks separately by hand, but...  */

            if (exist == EXISTS_YES) {
                strcpy (asn->filename, filename);

                /* Look for ASN_TAB in file's header, and copy to
                 ** ASN->asn_table if it is found. */
                if (!GetAsnName (filename, asn->asn_table) ) {

                    /* No ASN table listed, process as a
                     ** SINGLE exposure */
                    asn->process = SINGLE;				
                    if (asn->verbose) {
                        trlmessage 
                            ("Re-Processing a SINGLE image from ASN table...");
                    }
                } else {

                    /* ASN table given in file, PARTIALLY process
                     ** table */ 	
                    asn->process = PARTIAL;	
                    if (asn->verbose) {
                        trlmessage 
                            ("Re-Processing PART of ASN table...");
                    }
                }

            } else {

                /* Couldn't find specified file... */
                sprintf (MsgText,"File %s not found for re-processing",
                        filename);
                trlerror (MsgText);
                return (status = OPEN_FAILED);			
            }
            break;

        case 3:  /* We only have a rootname (with .fits extension)
                  ** specified */
        default:		

            if (exist == EXISTS_YES) {
                strcpy (asn->filename, filename);

                /* Look for ASN_TAB in file's header, and copy to
                 ** ASN->asn_table if it is found. */
                if (!GetAsnName (filename, asn->asn_table)) {

                    /* No ASN table listed, process as a SINGLE
                     ** exposure */
                    asn->process = SINGLE;				
                    if (asn->verbose) {
                        trlmessage 
                            ("Processing a SINGLE image from ASN table...");
                    }
                } else {

                    /* ASN table given in file, PARTIALLY process
                     ** table */ 	
                    asn->process = PARTIAL;	
                    if (asn->verbose) {
                        trlmessage ("Processing PART of ASN table...");
                    }
                }			

            } else {

                /* Let's start fresh, shall we?  At this point we only
                 ** have as rootname and (maybe) a .fits extension... 

                 in_dot = strcspn (filename, ".fit");
                 */	
                in_dot = strlen(filename) -
                    strlen(strstr (filename, ".fit"));

                if (asn->debug){
                    sprintf (MsgText, "For file %s, in_dot = %d",
                            filename, in_dot);
                    trlmessage (MsgText);
                }

                /* Truncate extension off of filename */
                filename[in_dot] = '\0';

                /* Create full ASN table name from input rootname */
                strcat (filename, "_asn.fits");
                exist = DoesFileExist (filename);

                if (exist == EXISTS_YES) {
                    strcat (filename, "\0");
                    /* If a name was specified, the file must exist. */
                    strcpy (asn->asn_table, filename);
                    if (asn->verbose) {
                        trlmessage 
                            ("Found and processing FULL ASN table...");
                    }
                    asn->process = FULL;
                } else {

                    /* Couldn't find ASN file, so
                     ** trim off suffix previously tested. */
                    in_dot = strlen (filename) - 
                        strlen (strstr(filename, "_asn")) ;
                    filename[in_dot] = '\0';

                    /* ... and look for RAW file */
                    strcat (filename, "_raw.fits");
                    exist = DoesFileExist (filename);

                    if (exist == EXISTS_YES) {

                        /* Found a RAW file;
                         ** Set values in ASN structure */
                        strcat (filename, "\0");
                        strcpy (asn->asn_table, filename);
                        if (asn->verbose) {
                            trlmessage 
                                ("Processing a SINGLE image from ASN table...");
                        }
                        asn->process = SINGLE;

                    } else {

                        /* Is INPUT the rootname of a product which
                         ** hasn't been created yet? */
                        /* Extract just the rootname plus last character
                         ** of rootname (which may be the subproduct ID*/
                        in_dot = strlen (filename) - 
                            strlen (strstr (filename, "_raw"));
                        filename[in_dot -1] = '\0';

                        /* Replace last character of filename with
                         ** 0_asn.fits	*/
                        strcat (filename, "0_asn.fits");
                        exist = DoesFileExist (filename);

                        if (exist == EXISTS_YES) {
                            strcpy (asn->asn_table, filename);
                            if (asn->verbose) {
                                trlmessage 
                                    ("PARTIAL processing of ASN table...");
                            }
                            asn->process = PARTIAL;
                        } else {
                            /* We can't find a matching file or ASN
                             ** table to process */
                            sprintf (MsgText,
                                    "File %s not found for processing",
                                    filename);
                            trlerror (MsgText);
                            return (status = OPEN_FAILED);
                        }
                    }
                }			
            } /* End of Exists ELSE statement for this case */

            break; /* End of Case 3 and DEFAULT case */
    } /* End of switch statement */

    if (asn->debug) {
        trlmessage 
            ("SetInput: Determined what ASN table to process and how.");
    }

    return (status);
} 
Exemplo n.º 26
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.º 27
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.º 28
0
Arquivo: sink.c Projeto: sosey/hstcal
int SinkDetect(WF3Info *wf3, SingleGroup *x){

    extern int status;
    int i,j, jj;
    short dqval=0;
    float scipix; /*to save the value of the science pixel*/
    float refdate=50000.;
    int keep_going=1;
    
    sprintf(MsgText,"\nPerforming SINK pixel detection for imset %i",x->group_num);
    trlmessage(MsgText);
    

    /*THE SCIENCE IMAGE*/
    SingleGroup raz; /*quad rotated image to work with*/    

    /* INIT THE SCIENCE INPUT  */
    initSingleGroup (&raz);
    allocSingleGroup (&raz,RAZ_COLS/2, RAZ_ROWS);
        
    /*CONVERT DQ DATA TO RAZ FORMAT FOR SCIENCE FILE*/
    makedqRAZ(x, &raz);
    makeSciSingleRAZ(x, &raz);

	/* GET THE SINK FILE REFERENCE IMAGE FROM SINKFILE AND INITIALIZE */
    FloatHdrData sinkref;
    initFloatHdrData(&sinkref);
    getFloatHD(wf3->sink.name,"SCI",x->group_num,&sinkref);
                 
    /*NOW TURN THE SINK REFERENCE IMAGES INTO RAZ FORMAT*/
    FloatTwoDArray sinkraz;    
    initFloatData(&sinkraz); /*float 2d arrays*/
    allocFloatData(&sinkraz,RAZ_COLS/2, RAZ_ROWS);     

    makeFloatRaz(&sinkref.data,&sinkraz,x->group_num);

       
    /*THE MJD OF THE SCIENCE EXPOSURE IS THE COMPARISON DATE
     THE FOLLOWING TRANSLATION TAKEN FROM ISR WFC3-2014-22.PDF */
    
    scipix=0.;
    for (i=0;i<(RAZ_COLS/2);i++){
        for (j=0; j<RAZ_ROWS; j++){
        
            if (  (PPix(&sinkraz,i,j) > refdate)  &&  ( wf3->expstart > PPix(&sinkraz,i,j))  ){
                keep_going=1;
                
                /*FLAG THE PRIMARY SINK PIXEL*/
                dqval = TRAP | DQPix (raz.dq.data, i, j);
                DQSetPix (raz.dq.data, i, j, dqval);
                scipix = Pix(raz.sci.data,i,j);
                
                /*FLAG THE DOWNSTREAM PIXEL*/
                if (PPix(&sinkraz,i,j-1) < 0 ){
                    dqval = TRAP | DQPix (raz.dq.data, i, j-1);
                    DQSetPix (raz.dq.data, i, j-1, dqval);
                }

                /*FLAG THE UPSTREAM PIXELS*/
                for (jj=j+1; jj<RAZ_ROWS; jj++){
                    if ((int) PPix(&sinkraz,i,jj) == 0)
                        keep_going=0;
                    if ( PPix(&sinkraz,i,jj) > refdate)
                        keep_going=0;
                    if ( 0. < PPix(&sinkraz,i,jj) &&  PPix(&sinkraz,i,jj) < 1000. && keep_going){
                        if (scipix <= PPix(&sinkraz,i,jj) ){
                           dqval = TRAP | DQPix (raz.dq.data, i, jj);
                           DQSetPix (raz.dq.data, i, jj, dqval);
                        }                
                    } else {
                        keep_going=0;
                    }
                }                
            } /*end if*/ 
        } /*end j*/
    }/*end i*/   

    
    /*format the dq data back to expected orientation*/
    undodqRAZ(x,&raz);

    freeSingleGroup(&raz);
    freeFloatData(&sinkraz);
    freeFloatHdrData(&sinkref);
    trlmessage("Sink pixel flagging complete");
    return(status);
}
Exemplo n.º 29
0
int AcsSum (char *input, char *output, char *mtype, int printtime, int verbose)
{

    extern int status;

    IRAFPointer tpin;

    AcsSumInfo acs;
    IODescPtr im;        /* descriptor for input image */
    Hdr phdr;        /* primary header for input image */
    int nimgs;
    int i;
    char acs_input[CHAR_FNAME_LENGTH];

    int          FileExists (char *);
    void         TimeStamp (char *, char *);
    void         PrBegin (char *);
    void         PrEnd (char *);
    void         PrFileName (char *, char *);
    void         PrHdrInfo (char *, char *, char *, char *);
    int          MkName (char *, char *, char *, char *, char *, int);
    void         WhichError (int);
    void         InitSumTrl (char *input, char *output);
    void         FindAsnRoot (char *, char *);
    int          mkNewSpt (char *, char *, char *);

    /* Determine input and output trailer files, then initialize
        output file by combining inputs into output file */
    InitSumTrl (input, output);

    PrBegin ("ACSSUM");
    nimgs = 0;

    if (printtime)
        TimeStamp ("ACSSUM started", "");

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

    nimgs = c_imtlen(tpin);

    /* Initialize structure containing acssum information. */
    AcsInit (&acs,nimgs);

    /* Copy command-line arguments into acs. */
    for (i = 0; i < nimgs; i++) {
        c_imtgetim (tpin, acs.input[i], CHAR_FNAME_LENGTH);
        PrFileName ("input", acs.input[i]);
    }

    /* close file template */
    c_imtclose (tpin);

    strcpy (acs.output, output);
    acs.printtime = printtime;
    acs.verbose = verbose;

    PrFileName ("output", acs.output);
    FindAsnRoot (output, acs.rootname);

    initHdr (&phdr);

    /* Check whether the output file already exists. */
    if (FileExists (acs.output)) {
        FreeAcsInput (acs.input, nimgs);
        return (status);
    }
    strcpy(acs_input,acs.input[0]);

    /* Open input image in order to read its primary header. */
    im = openInputImage (acs_input, "", 0);

    if (hstio_err()) {
        FreeAcsInput (acs.input, nimgs);
        return (status = OPEN_FAILED);
    }

    getHeader (im, &phdr);        /* get primary header */
    if (hstio_err()) {
        FreeAcsInput (acs.input, nimgs);
        return (status = OPEN_FAILED);
    }
    closeImage (im);

    /* Get keyword values from primary header. */
    if (GetSumKeyInfo (&acs, &phdr)) {
        FreeAcsInput (acs.input, nimgs);
        return (status);
    }
    freeHdr (&phdr);

    /* Print information about this image. */
    PrHdrInfo (acs.aperture, acs.filter1, acs.filter2, acs.det);

    if (acs.printtime)
        TimeStamp ("Begin processing", acs.rootname);

    /* Sum all imsets. */
    if (SumGrps (&acs,mtype)){
        FreeAcsInput (acs.input, nimgs);
        return (status);
    }

    /* create new SPT file for output product */
    if (mkNewSpt (input, mtype, output)) {
        return(status);
    }

    /* Done... */
    trlmessage ("\n");
    PrEnd ("ACSSUM");

    if (acs.printtime)
        TimeStamp ("ACSSUM completed", acs.rootname);

    /* Write out temp trailer file to final file */
    WriteTrlFile ();

    FreeAcsInput (acs.input, nimgs);
    return (status);
}
Exemplo n.º 30
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);
}