Example #1
0
static int OpenLinTab (char *tname, TblInfo *tabinfo) {

	extern int status;

	tabinfo->tp = c_tbtopn (tname, IRAF_READ_ONLY, 0);
	if (c_iraferr()) {
	    sprintf (MsgText, "MLINTAB `%s' not found.", tname);
	    trlerror (MsgText);
		return (status = OPEN_FAILED);
	}

	tabinfo->nrows = c_tbpsta (tabinfo->tp, TBL_NROWS);

	/* Find the columns. */
	c_tbcfnd1 (tabinfo->tp, "DETECTOR", &tabinfo->cp_det);
	c_tbcfnd1 (tabinfo->tp, "GLOBAL_LIMIT", &tabinfo->cp_global);
	c_tbcfnd1 (tabinfo->tp, "LOCAL_LIMIT", &tabinfo->cp_local);
	c_tbcfnd1 (tabinfo->tp, "TAU", &tabinfo->cp_tau);
	c_tbcfnd1 (tabinfo->tp, "EXPAND", &tabinfo->cp_expand);
	if (tabinfo->cp_det == 0 ||
	    tabinfo->cp_global == 0 ||
	    tabinfo->cp_local == 0 ||
	    tabinfo->cp_tau == 0 ||
	    tabinfo->cp_expand == 0) {
	    trlerror ("Column not found in MLINTAB.");
	    c_tbtclo (tabinfo->tp);
	    return (status = COLUMN_NOT_FOUND);
	}

	/* Pedigree and descrip are optional columns. */
	c_tbcfnd1 (tabinfo->tp, "PEDIGREE", &tabinfo->cp_pedigree);
	c_tbcfnd1 (tabinfo->tp, "DESCRIP", &tabinfo->cp_descrip);

	return (status);
}
Example #2
0
int PrintMissingCols (int missing, int numcols, int *nocol, char *colnames[], char *tabname, IRAFPointer tp) {

/* Parameters:
int missing			i: number of missing columns
int numcols			i: number of columns expected in table
int *nocol			i: array of YES/NO for each column, YES means missing
char **colnames		i: array of colnames
char *tabname		i: name of table columns were read from
IRAFPointer tp		i: pointer to table, close it if necessary
*/

	extern int status;
	int j;
	/* If any columns are missing... */
	if (missing) {
 	    sprintf (MsgText,"%d columns not found in %s.", missing, tabname);
		trlerror (MsgText);
       
		for (j=0; j< numcols; j++) {
			/* Recall which ones were marked missing... */
			if (nocol[j]) {
				/*... and print out that column's name */
	    		sprintf (MsgText,"Column %s not found in %s.", colnames[j], tabname);
				trlerror (MsgText);
			}
		}
	    c_tbtclo (tp);
	    return (status = COLUMN_NOT_FOUND);
	}
	return(status);
}
Example #3
0
int checkGlobalInfo (AsnInfo *asn) {

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

    /* Check instrument = WF3 */
    if (strncmp (asn->instr, "WFC3", 4) != 0 ) {
        sprintf (MsgText, 
                "INSTRUME keyword value \"%s\" not valid in %s",
                asn->instr, asn->filename);
        trlerror (MsgText);
        status = 1;
    }

    /* Check for valid camera number */
    if (asn->detector < 1 || asn->detector > 2) {
        sprintf (MsgText, 
                "CAMERA keyword value \"%d\" not valid in %s",
                asn->detector, asn->filename);
        trlerror (MsgText);
        status = 1;
    }

    return (status);
}
Example #4
0
int CheckDetector (char *image, int detector, char *keyword, int *badtype) {

	extern int status;

	FitsKw key;		/* location of keyword in header */
	IODescPtr im;		/* descriptor for primary header unit */
	Hdr phdr;		/* primary header */

	char keyval[SZ_FITS_REC+1];

	keyval[0] = '\0';
	initHdr (&phdr);

	/* Open the primary header of the reference file. */
	im = openInputImage (image, "", 0);
	getHeader (im, &phdr);
	if (hstio_err())
	    return (status = HEADER_PROBLEM);

	/* Get the DETECTOR keyword. */
	key = findKw (&phdr, keyword);
	if (key == NotFound) {
	    trlkwerr (keyword, image);
	    return (status = KEYWORD_MISSING);
	} else {
	    getStringKw (key, keyval, SZ_FITS_REC);
	    if (hstio_err()) {
		trlkwerr (keyword, image);
		return (status = KEYWORD_MISSING);
	    }
	}

	/* Does the ref file DETECTOR value match the science image? */
	if (detector == IR_DETECTOR) {
	    if (strncmp (keyval, "IR", strlen(keyval)) != 0) {
		sprintf (MsgText, "%s %s='%s' does not match science data",
			 image, keyword, keyval);
		trlerror (MsgText);
		(*badtype)++;
	    }
	} else {
	    if (strncmp (keyval, "UVIS", strlen(keyval)) != 0) {
		sprintf (MsgText, "%s %s='%s' does not match science data",
			 image, keyword, keyval);
		trlerror (MsgText);
		(*badtype)++;
	    }
	}

	/* Close the reference file. */
	closeImage (im);
	freeHdr (&phdr);

	return (status);
}
Example #5
0
int GetSwitch (Hdr *phdr, char *calswitch, int *flag) {

/* arguments:
Hdr *phdr         i: primary header
char *calswitch   i: name of keyword (e.g. FLATCORR)
int *flag         o: value of switch:  PERFORM, OMIT, or COMPLETE
*/

	extern int status;

	FitsKw key;		/* keyword location in header */
	char *word;		/* scratch space for header keyword value */
	int streq_ic (char *, char *);	/* strings equal? (case insensitive) */

	key = findKw (phdr, calswitch);
	if (key == NotFound) {
	    *flag = OMIT;
	    return (status);
	}

	if ((word = (char *) calloc (CHAR_FNAME_LENGTH+1, sizeof(char))) == NULL)
	    return (status = OUT_OF_MEMORY);

	getStringKw (key, word, CHAR_FNAME_LENGTH);
	if (hstio_err()) {
	    free (word);
	    sprintf (MsgText, "Error getting keyword `%s'.", calswitch);
	    trlerror (MsgText);
	    return (status = HEADER_PROBLEM);
	}

	if (streq_ic (word, "perform")) {
	    *flag = PERFORM;
	} else if (streq_ic (word, "complete")) {
	    *flag = COMPLETE;
	} else if (streq_ic (word, "skipped")) {
	    *flag = OMIT;
	} else if (streq_ic (word, "omit")) {
	    *flag = OMIT;
	} else {
	    *flag = OMIT;
	    sprintf (MsgText, "Keyword %s = %s is invalid.", calswitch, word);
	    trlerror (MsgText);
	    free (word);
	    return (status = HEADER_PROBLEM);
	}

	free (word);

	return (status);
}
Example #6
0
static int strcatN (char *outstr, char *instr, int maxch) {

    extern int status;

    if (strlen (instr) + strlen (outstr) > maxch) {
        trlerror ("(MkOutName) strings are too long:");
        sprintf (MsgText, "`%s' + `%s'", outstr, instr);
        trlerror (MsgText);
        status = INVALID_FILENAME;
    } else {
        strcat (outstr, instr);
    }

    return (status);
}
Example #7
0
static int ReadAtoDArray (TblInfo *tabinfo, int row, TblArray *tabarray) {

	extern int status;
	int nret;		/* number of elements actually read */

	/* Find out how many elements there are in the ATOD array,
	   and allocate space for the array to be read from the table.
	*/
	c_tbegti (tabinfo->tp, tabinfo->cp_nelem, row, &tabarray->nelem);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	tabarray->atod = (float *) malloc (tabarray->nelem * sizeof(float));
	if (tabarray->atod == NULL)
	    return (status = OUT_OF_MEMORY);

	nret = c_tbagtr (tabinfo->tp, tabinfo->cp_atod, row,
			tabarray->atod, 1, tabarray->nelem);
	if ( (status = c_iraferr()) )
	    return (status = TABLE_ERROR);

	if (nret < tabarray->nelem) {
	    sprintf (MsgText,
		     "CORRECTION array in row %d of ATODTAB is too short.",
		     row);
	    trlerror (MsgText);
	    free (tabarray->atod);
	    return (status = TABLE_ERROR);
	}

	return (status);
}
Example #8
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);
}
Example #9
0
void CheckTabType (RefTab *table, char *filetype, char *keyword, int *badtype) {

	if (strncmp (table->type, filetype, strlen(filetype)) != 0) {
	    sprintf (MsgText, "%s FILETYPE='%s' is invalid for %s", 
		     table->name, table->type, keyword);
	    trlerror (MsgText);
	    (*badtype)++;
	}
}
Example #10
0
void CheckImgType (RefImage *image, char *filetype, char *keyword, int *badtype) {

	if (strncmp (image->type, filetype, strlen(filetype)) != 0) {
	    sprintf (MsgText, "%s FILETYPE='%s' is invalid for %s", 
		     image->name, image->type, keyword);
	    trlerror (MsgText);
	    (*badtype)++;
	}
}
Example #11
0
/* This function compares the values of CRCORR and RPTCORR from
   the image header with those deduced from the ASN table. */
int CheckCorr (AsnInfo *asn, ACSInfo *acshdr) {

    extern int status;

    if ( (asn->crcorr != acshdr->sci_crcorr) || (asn->rptcorr != acshdr->sci_rptcorr)) {
        trlerror ("CRCORR and/or RPTCORR values not consistent with ASN table!");
        return (status = ERROR_RETURN);
    }
    return (status);
}
Example #12
0
/* Initialize the CalSwitch structure.  This includes information about the
   input and output images, calibration files, and flags to specify which
   calibration steps are to be done.  Get switches and reference file
   names from the primary headers, and check that the files exist.

   Warren Hack, 1998 May 26:
   Initial ACS version
*/
int ACSRefInit (ACSInfo *acs, CalSwitch *sci_sw, RefFileInfo *sciref) {

    /* arguments:
       acs      i: calibration flags and other info
       sci_sw   o: all calibration switches (0 or 1) for science file
       sciref   o: reference file name and info
    */

    extern int status;

    int missing;  /* number of missing reference files */

    int GetSciInfo (ACSInfo *, CalSwitch *, RefFileInfo *);
    void RefExist (RefFileInfo *, int, int *);
    int InsertACSSuffix (ACSInfo *);

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

    /* Get switches and reference file names for science file. */
    if (GetSciInfo (acs, sci_sw, sciref))
        return (status);

    /* Verify that the reference files that we need do exist. */
    missing = 0;  /* initial value */
    RefExist (sciref, acs->detector, &missing);  /* for science file */

    if (missing > 0) {
        if (missing == 1) {
            trlerror ("One reference file was missing.");
        } else {
            sprintf (MsgText, "%d reference files were missing.", missing);
            trlerror (MsgText);
        }
        return (status = CAL_FILE_MISSING);
    }

    return (status);
}
Example #13
0
static int OpenAtoDTab (char *tname, TblInfo *tabinfo) {

	extern int status;

	tabinfo->tp = c_tbtopn (tname, IRAF_READ_ONLY, 0);
	if (c_iraferr()) {
	    sprintf (MsgText, "ATODTAB `%s' not found.", tname);
	    trlerror (MsgText);
	    return (status = OPEN_FAILED);
	}

	tabinfo->nrows = c_tbpsta (tabinfo->tp, TBL_NROWS);

	/* Find the columns. */
	c_tbcfnd1 (tabinfo->tp, "CCDAMP", &tabinfo->cp_amp);
	c_tbcfnd1 (tabinfo->tp, "CCDGAIN", &tabinfo->cp_gain);
	c_tbcfnd1 (tabinfo->tp, "REF_KEY", &tabinfo->cp_key);
	c_tbcfnd1 (tabinfo->tp, "REF_KEY_VALUE", &tabinfo->cp_keyval);
	c_tbcfnd1 (tabinfo->tp, "NELEM", &tabinfo->cp_nelem);
	c_tbcfnd1 (tabinfo->tp, "ATOD", &tabinfo->cp_atod);
	if (tabinfo->cp_amp == 0 ||
	    tabinfo->cp_gain == 0 ||
	    tabinfo->cp_key == 0 ||
	    tabinfo->cp_keyval == 0 ||
	    tabinfo->cp_nelem == 0 ||
	    tabinfo->cp_atod == 0) {
	    trlerror ("Column not found in ATODTAB.");
	    c_tbtclo (tabinfo->tp);
	    return (status = COLUMN_NOT_FOUND);
	}

	/* Pedigree and descrip are optional columns. */
	c_tbcfnd1 (tabinfo->tp, "PEDIGREE", &tabinfo->cp_pedigree);
	c_tbcfnd1 (tabinfo->tp, "DESCRIP", &tabinfo->cp_descrip);

	return (status);
}
Example #14
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);

}
Example #15
0
int CheckGain (char *image, float gain, char *keyword, int *badtype) {

	extern int status;

	FitsKw key;		/* location of keyword in header */
	IODescPtr im;   /* descriptor for primary header unit */
	Hdr phdr;		/* primary header */

	float keyval;

	initHdr (&phdr);

	/* Open the primary header of the reference file. */
	im = openInputImage (image, "", 0);
	getHeader (im, &phdr);
	if (hstio_err())
	    return (status = HEADER_PROBLEM);

	/* Get the CCDGAIN keyword. */
	key = findKw (&phdr, keyword);
	if (key == NotFound) {
	    trlkwerr (keyword, image);
	    return (status = KEYWORD_MISSING);
	} else {
	    keyval = getFloatKw (key);
	    if (hstio_err()) {
		trlkwerr (keyword, image);
		return (status = KEYWORD_MISSING);
	    }
	}

	/* Does the ref file CCDGAIN value match the science image? */
	/* A value of -1 is considered to be OK */
	if ((keyval != -1) && (gain != keyval)) {
	    sprintf (MsgText, "%s %s=%g does not match science data",
		     image, keyword, keyval);
	    trlerror (MsgText);
	    (*badtype)++;
	}

	/* Close the reference file. */
	closeImage (im);
	freeHdr (&phdr);

	return (status);
}
Example #16
0
void multgn1dsub(SingleGroupLine *a, int line, float *gain, float k0, char *ccdamp) {

/* arguments:
SingleGroupLine *a	io: input data; output product
int line		i: line number of input line
int ampx, ampy		i: amp parameters
float *gain		i: atogain parameter
float k0		i: value for scaling image data
			(exptime or flashdur or ...)
            
This uses logic which is good for subarrays    
            
*/
	int i;
	float k;
	int dimx;


	/* Determine k */
	k = 0;
	dimx = a->sci.tot_nx;
            
    /* Since both the science and error arrays operate on the 
        same line of data, we will combine them into one loop over
        X values.
    */
    
    if (strcmp (ccdamp, "A")==0) {   
            k = k0 / gain[AMP_A];
    } else if (strcmp (ccdamp, "B")==0) {   
             k = k0 / gain[AMP_B];
    } else if  (strcmp (ccdamp, "C")==0) {   
             k = k0 / gain[AMP_C];
    } else if  (strcmp (ccdamp, "D")==0) {   
             k = k0 / gain[AMP_D];
    } else {
        trlerror("Bad AMP assignment in multgn1dsub");
    }
             
    /* Apply scale factors  */
    for (i = 0;  i < dimx;  i++) {
	     a->sci.line[i] = k * a->sci.line[i];
	     a->err.line[i] = k * a->err.line[i];        
    }
 
}
Example #17
0
static int checkCCD (Hdr *phdr, WF3Info *wf32d, int *missing) {

/* arguments:
Hdr *phdr        i: primary header
WF3Info *wf32d   i: switches, file names, etc
int *missing     io: incremented if the table is missing
*/

	extern int status;
	int calswitch;			/* returned by GetTabRef and ignored */
	int GetTabRef (RefFileInfo *, Hdr *, char *, RefTab *, int *);
	void MissingFile (char *, char *, int *);
	void CheckTabType (RefTab *, char *, char *, int *);
	int  CheckDetector (char *, int, char *, int *);

	if (GetTabRef (wf32d->refnames, phdr, "CCDTAB", &wf32d->ccdpar,
		       &calswitch))
	    return (status);

	if (wf32d->ccdpar.exists != EXISTS_YES) {

	    MissingFile ("CCDTAB", wf32d->ccdpar.name, missing);

	} else if (wf32d->ccdpar.goodPedigree != GOOD_PEDIGREE) {

	    (*missing)++;
	    sprintf (MsgText, "CCDTAB `%s' is a dummy table.",
		     wf32d->ccdpar.name);
	    trlerror (MsgText);

	} else {

	    /* Is the FILETYPE appropriate for a CCD table? */
	    CheckTabType (&wf32d->ccdpar, "CCD PARAMETERS", "CCDTAB", missing);

	    /* Does it have the correct DETECTOR value? */
	    if (CheckDetector(wf32d->ccdpar.name, wf32d->detector, "DETECTOR",
		missing))
		return (status);
	}

	return (status);
}
/*
 * unmake_amp_array does the opposite of make_amp_array, it takes amp array
 * views and puts them back into the single group in the right order.
 */
static int unmake_amp_array(const int arr_rows, const int arr_cols, SingleGroup *im,
                            int amp, double * array) {

  extern int status;

  /* iteration variables */
  int i, j;

  /* variables for the image row/column we want */
  int r,c;

  for (i = 0; i < arr_rows; i++) {
    for (j = 0; j < arr_cols; j++) {
      if (amp == AMP_A) {
        r = im->sci.data.ny - i - 1;
        c = j;
      } else if (amp == AMP_B) {
        r = im->sci.data.ny - i - 1;
        c = im->sci.data.nx - j - 1;
      } else if (amp == AMP_C) {
        r = i;
        c = j;
      } else if (amp == AMP_D) {
        r = i;
        c = im->sci.data.nx - j -1;
      } else {
        trlerror("Amp number not recognized, must be 0-3.");
        status = ERROR_RETURN;
        return status;
      }

      Pix(im->sci.data, c, r) = (float) array[i*arr_cols + j];
    }
  }

  return status;
}
Example #19
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);
}
Example #20
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);
}
Example #21
0
void InitSumTrl (char *input, char *output) {

    extern int status;
    IRAFPointer    tpin;
    int n;

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

    int trl_len;

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

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

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

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

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

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


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

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

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

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

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

    }

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

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

    /* Deallocate memory */
    free(trl_in);
    c_imtclose (tpin);
}
Example #22
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);
}
Example #23
0
static int GetSumKeyInfo (AcsSumInfo *acs, Hdr *phdr) {

/* arguments:
AcsSumInfo *acs  io: calibration switches and info
Hdr *phdr       i: primary header
*/

    extern int status;
    int sdqflags;            /* "serious" data quality flags */
    int nextend;            /* number of FITS extensions */
    int nrptexp;            /* number of exposures */
    int no_def = 0;            /* missing keyword is fatal error */

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

    /* Have the data been converted from counts to absolute flux? */

    if (GetKeyStr (phdr, "APERTURE", no_def, "", acs->aperture, ACS_CBUF))
        return (status);

    if (GetKeyStr (phdr, "DETECTOR", no_def, "", acs->det, ACS_CBUF))
        return (status);
    if (strcmp (acs->det, "SBC") == 0) {
        acs->detector = MAMA_DETECTOR;
    } else if (strcmp (acs->det, "HRC") == 0) {
        acs->detector = HRC_CCD_DETECTOR;
    } else if (strcmp (acs->det, "WFC") == 0) {
        acs->detector = WFC_CCD_DETECTOR;
    } else {
        sprintf (MsgText, "DETECTOR = %s is invalid", acs->det);
        trlerror (MsgText);
        return (status = HEADER_PROBLEM);
    }

    /* Filter names. */
    if (GetKeyStr (phdr, "FILTER1", USE_DEFAULT, "", acs->filter1, ACS_CBUF))
        return (status);
    if (GetKeyStr (phdr, "FILTER2", USE_DEFAULT, "", acs->filter2, ACS_CBUF))
        return (status);

    if (GetKeyDbl (phdr, "EXPTIME", NO_DEFAULT, 0., &acs->exptime))
        return (status);

    if (GetKeyInt (phdr, "SDQFLAGS", USE_DEFAULT, MAX_DQ, &sdqflags))
        return (status);
    acs->sdqflags = sdqflags;

    /* Find out how many extensions there are in this file. */
    if (GetKeyInt (phdr, "NEXTEND", USE_DEFAULT, EXT_PER_GROUP, &nextend))
        return (status);

    /* Convert number of extensions to number of SingleGroups. */
    acs->nimsets = nextend / EXT_PER_GROUP;

    /* Get NRPTEXP and compare with nimages. */
    if (GetKeyInt (phdr, "NRPTEXP", no_def, 0, &nrptexp))
        return (status);

    if (nrptexp != acs->nimages) {
        sprintf (MsgText, "%d exposures will be summed, however, NRPTEXP was %d.",
            acs->nimages, nrptexp);
        trlwarn (MsgText);
    }

    if (acs->nimages <= 1) {
        trlwarn ("ACSSUM: Can not continue. There is only one input image!");
        return (status = NOTHING_TO_DO);
    }

    return (status);
}
Example #24
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);
} 
Example #25
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);
}
Example #26
0
/*
Description:
------------
If using the exposure time, the scaling factors are normalized to ratios 
relative to the max exposure. 

    Date            Author      Description
    ----            ------      -----------
    24-Sep-1998     W.J. Hack   Initial Version
    18-Mar-1999     W.J. Hack   Revised to read EXPTIMEs from Primary headers
                                using image-template list directly
    20-Oct-1999     W.J. Hack   Revised to compute number of good input images
                                and insure they are less than MAX_FILES.
    14-Apr-2000     W.J. Hack   Revised to also return final EXPEND appropriate
                                for output CR-combined product
    14-Mar-2002     W.J. Hack   Added computation of cumulative DARKTIME
    4-Apr-2002      W.J. Hack   added initialization of 'totd'
   24-Apr-2002      W.J. Hack   removed darktime altogether, find initial EXPSTART
*/
int cr_scaling (char *expname, IRAFPointer tpin, float efac[], int *nimgs, double *expend, double *expstart)
{
    extern int status;

    Hdr         prihdr;
    int         nzero, k;
    char        fdata[CHAR_FNAME_LENGTH + 1];
    IODescPtr   ip;
    int         numimgs;        /* How many good input images are there? */

    double     end, keyend, keystart, start;

    int         GetKeyFlt (Hdr *, char *, int, float, float *);
    int         GetKeyDbl (Hdr *, char *, int, double, double *);
    /* -------------------------------- begin ---------------------------------- */

    /* Rewind the image template pointer */
    c_imtrew(tpin);

    *nimgs = c_imtlen(tpin);
    end = 0.0;
    keyend = 0.0;
    start = 1e+10;
    keystart = 0.0;

    
    /* Check to make sure there are not too many images to work with... */
    if (*nimgs > MAX_FILES) {
        trlerror("There are too many input images to combine. "); 
        return(status = NOTHING_TO_DO);
    }

    /* if the parameter scaling is null, all images have equal weight. 
        If no keyword name is given for the exposure time, assume equal
        weights of 1 for all images.
    */
    if (expname[0] == '\0') {
        return (status);
    }

    /* Use exposure time as scaling factor */
    nzero = 0;	
     
    /* loop all input files counting how many usable inputs there are */
    numimgs = 0;
    for (k = 0; k < *nimgs; ++k) {

        /* read the next input image name in the template list */
        c_imtgetim (tpin, fdata, CHAR_FNAME_LENGTH);

        /* open the primary header */
        ip = openInputImage (fdata, "", 0);
        if (hstio_err()) {
            sprintf (MsgText, "Cannot open data file '%s'", fdata);
            trlerror (MsgText);
            return (status = OPEN_FAILED);
        }

        initHdr (&prihdr);

        /* read in primary header from image */
        getHeader (ip, &prihdr);

        if (GetKeyFlt (&prihdr, expname, USE_DEFAULT, 0., &efac[k]) != 0) {
            sprintf (MsgText, "cannot read '%s' from the primary header of '%s'", expname, fdata);
            trlerror (MsgText);
            freeHdr (&prihdr);
            return(status = KEYWORD_MISSING);
        }
        
        if (efac[k] < 0.) {
            sprintf (MsgText, "exposure time of file '%s' is negative", fdata);
            trlerror (MsgText);
            freeHdr (&prihdr);
            return(status = INVALID_VALUE);
        }
        if (efac[k] == 0.) {
            nzero++;
        }
        
        numimgs++;
        if (GetKeyDbl (&prihdr, "EXPEND", USE_DEFAULT, 0., &keyend) != 0) {
            sprintf (MsgText, "cannot read 'EXPEND' from the primary header of '%s'", fdata);
            trlerror (MsgText);
            freeHdr (&prihdr);
            return(status = KEYWORD_MISSING);
        }
        if (GetKeyDbl (&prihdr, "EXPSTART", USE_DEFAULT, 0., &keystart) != 0) {
            sprintf (MsgText, "cannot read 'EXPSTART' from the primary header of '%s'", fdata);
            trlerror (MsgText);
            freeHdr (&prihdr);
            return(status = KEYWORD_MISSING);
        }
        
        end = (keyend > end) ? keyend: end;
        start = (keystart < start) ? keystart : start;
        closeImage (ip);
        freeHdr (&prihdr);
    }
    
    if (nzero > 0 && nzero < *nimgs) {
        trlwarn ("Some (but not all) input imsets have zero exposure time.");
        trlwarn ("Final product will be compromised!");
        
        /* This type of error will need to be handled differently in order
            to allow pipeline processing of this type of dataset. 
        return (status = INVALID_VALUE);
        */
    }
    
    /* Only return the number of valid input images,
        initial EXPSTART and final EXPEND value
    */
    *nimgs = numimgs;
    *expend = end;
    *expstart = start;
    
    return (status);
}
Example #27
0
int updateAsnTable (AsnInfo *asn, int prodid, int posid) {

    /* Arguments:
     **	asn		    i: association info structure
     **	prodid		i: product id for member that needs to be updated
     **	posid		i: position id for member that needs to be updated
     */
    extern int status;

    /* Local variables */
    int col;			/* loop index */
    IRAFPointer asn_tp;		/* table pointers */
    IRAFPointer colptr[NCOLS];	/* ASN table column pointers */
    Bool prsnt;

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

    /* Initialize the table column pointers */
    for (col = 0; col < NCOLS; col++)
        colptr[col] = 0;

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

    /* Find the columns in the ASN table */
    for (col=0; col < NCOLS; col++) {
        if (colptr[col] == 0) {
            c_tbcfnd1 (asn_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 (asn_tp);
                return (status = 1);
            }
        }
    }

    /* Value MEMPRSNT will be updated to... */
    prsnt = True;

    /* Are we working with a Product or a subproduct... */
    if (posid == 0) {

        /* Write the updated info for PRODUCT to the ASN table */
        c_tbeptb (asn_tp, colptr[2], asn->product[prodid].asnrow, prsnt);

    } else {

        /* Write the updated info for SUB-PRODUCT to the ASN table */
        c_tbeptb (asn_tp, colptr[2],
                asn->product[prodid].subprod[posid].asnrow, prsnt);
    }

    /* Close the ASN table */
    c_tbtclo (asn_tp);

    /* Update ASN_PROD keyword to TRUE to signal successful
     ** creation of product/sub-product. */
    if (UpdateHdr (asn->asn_table) ) {    
        trlerror ("Couldn't update ASN table header");
        return(status = KEYWORD_MISSING);
    }

    /* Successful return */
    return (status);
}
Example #28
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);
}
Example #29
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);
}
Example #30
0
int allocAsnInfo (AsnInfo *asn, int numsp, int *spmems) {

    extern int status;

    /* Local variables */
    int i;		/* loop index */
    int prodid = 0;	/* product ID: for looping over products later */
    int j;		/* loop index for EXPs */
    int numexp;	

    /* Function definitions */
    void initAsnProduct (ProdInfo *, int);
    void initAsnSubProd (SubProdInfo *, int);
    void initAsnExp (ExpInfo *);

    void freeAsnInfo (AsnInfo *);
    void initAsnExp (ExpInfo *);

    /* Free the structure if necessary */
    if (asn->product != NULL)
        freeAsnInfo(asn);

    /* Allocate the member structures */
    asn->spmems  = (int *)calloc(numsp+1,sizeof(int));
    asn->product = (ProdInfo *)calloc(1,sizeof(ProdInfo ));

    /* Initialize each member structure */
    for (i=0; i < asn->numprod; i++) {
        initAsnProduct (&(asn->product[i]), numsp+1);
    }

    asn->product[prodid].subprod =
        (SubProdInfo *)calloc(numsp+1, sizeof(SubProdInfo));

    for (i=0; i <= numsp; i++) {
        if (spmems[i] > 0) 
            numexp = spmems[i];
        else
            numexp = 1;

        initAsnSubProd(&(asn->product[prodid].subprod[i]), numexp);
    }

    for (i=0; i <= numsp; i++) {
        asn->product[0].subprod[i].exp =
            (ExpInfo *)calloc(spmems[i]+1, sizeof(ExpInfo));
        for (j=0; j <= spmems[i]; j++)
            initAsnExp (&(asn->product[prodid].subprod[i].exp[j]));	
    }

    /* Check for error during allocation */
    if (asn->product == NULL) {
        asn->numprod = 0;
        asn->numasn = 0;
        trlerror ("Insufficient memory to allocate ASN structure");
        return (status = 1);
    }

    /* Succesful return */
    return (status);
}