示例#1
0
int GetProfile (StisInfo6 *sts, int sporder, ProfileArray **profa) {

/* arguments:
StisInfo6 *sts        i: calibration switches and info
int sporder;          i: spectral order number
ProfileArray *profa;  o: list with profile arrays for current sporder
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */

	int CheckProfile (ProfileArray **);
	void FreeProfileArray (ProfileArray **);

	/* Open the profile table. */
	if ((status = OpenProfileTab (sts->pftab.name, &tabinfo)))
	    return (status);

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadProfileTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for matching sporder. */
	    if (SameInt (tabrow.sporder, sporder)) {

	        /* Get pedigree & descrip from the row. */
	        if ((status = RowPedigree (&sts->pftab, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
	            return (status);

	        /* Read profiles into structure. */
	        if ((status = ReadProfileArray (&tabinfo, row, profa,
                                                &(sts->subscale))))
	            return (status);
	    }
	}

	/* Sanity check. */
	if ((status = CheckProfile (profa))) {
	    FreeProfileArray (profa);
	    if (status < 0) {
		printf ("ERROR    Matching row not found in OPROFAB %s\n",
				sts->pftab.name);
		printf ("ERROR    SPORDER %d\n", sporder);
		return (ROW_NOT_FOUND);
	    } else {
		return (status);
	    }
	}

	if ((status = CloseProfileTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#2
0
int GetIntens (StisInfo6 *sts, int sporder, IntensArray *inta) {

/* arguments:
StisInfo6 *sts        i: calibration switches and info
IntensArray *inta     o: description of inta
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int foundit = 0;	/* true if parameters found in table */
	double exptime;		/* exposure time */
	int i;

	/* Open the intensity/wavelength table. */
	exptime = 1.0;
	if ((status = OpenIntensTab (sts->pxtab.name,
                                     &tabinfo, &exptime, sts->fflux)))
	    return (status);

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadIntensTab (&tabinfo, row, &tabrow)))
		return (status);

	    if (!SameInt (tabrow.sporder, sporder))
	        continue;

	    foundit = 1;

	    /* Get pedigree & descrip from the row. */
	    if ((status = RowPedigree (&sts->pxtab, row,
                    tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
	        return (status);

	    /* Read wavelengths and intensities into structure. */
	    if ((status = ReadIntensArray (sts, &tabinfo, row, inta, sporder)))
	        return (status);
	}

            if ((status = CloseIntensTab (&tabinfo)))
	    return (status);

	if (!foundit) {
	    printf ("Warning  Matching row not found in OSPECTAB %s\n",
			sts->pxtab.name);
	    return (ROW_NOT_FOUND);
	}

	/* Convert to counts. */
	for (i = 0;  i < inta->nelem; inta->intens[i++] *= exptime);

	return (0);
}
示例#3
0
int GetAbsPhot (StisInfo7 *sts, int sporder, PhotInfo *phot, int print,
                int *warn) {

/* arguments:
StisInfo *sts   i: calibration switches and info
int sporder     i: current order number
PhotInfo *phot  o: factors to convert to absolute flux
int print	i: if set to zero, turn off error message printing
int *warn	io: if set to zero, turn off blaze shift warning
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int foundit = 0;	/* true if parameters found in table */

	/* Assign the units for the calibrated data. */
	strcpy (phot->bunit, "erg /s /cm**2 /angstrom /arcsec**2");

	/* Open the photometry table. */
	if ((status = OpenPhotTab (sts, &tabinfo, phot, warn)))
	    return (status);

	/* Check each row for a match with keyword values, then read
	   the arrays of wavelength and throughput if there's a match.
	*/

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadPhotTab (&tabinfo, row, &tabrow)))
		return (status);

	    if (sts->obstype == SPECTROSCOPIC_TYPE) {
		if (!SameInt (tabrow.cenwave, sts->cenwave) ||
		    !SameInt (tabrow.sporder, sporder))
		    continue;
	    }

	    if (SameString (tabrow.opt_elem, sts->opt_elem)) {

		foundit = 1;

		/* Get pedigree & descrip from the row. */
		if ((status = RowPedigree (&sts->phottab, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (sts->phottab.goodPedigree == DUMMY_PEDIGREE) {
		    printf ("Warning  DUMMY pedigree in row %d of %s.\n",
			row, sts->phottab.name);
		    sts->x2dcorr_o = DUMMY;
		    ClosePhotTab (&tabinfo);
		    return (0);
		}

		/* Read wavelengths and throughputs into phot. */
		if ((status = ReadPhotData (&tabinfo, row, phot)))
		    return (status);

		break;
	    }
	}

	if ((status = ClosePhotTab (&tabinfo)))
	    return (status);

	if (!foundit) {
	    if (print) {
	        printf ("Warning  Matching row not found in PHOTTAB %s; \\\n",
			 sts->phottab.name);
	        if (sts->obstype == SPECTROSCOPIC_TYPE) {
		    printf ("Warning  OPT_ELEM %s, CENWAVE %d, SPORDER %d.\n",
			    sts->opt_elem, sts->cenwave, sporder);
	        } else {
		    printf ("Warning  OPT_ELEM %s\n", sts->opt_elem);
	        }
	        sts->x2dcorr_o = OMIT;
	    } else
	        return (ROW_NOT_FOUND);
	}

	return (0);
}
示例#4
0
int GetDisp4 (StisInfo4 *sts, DispRelation *disp, char *ref_aper) {

/* arguments:
StisInfo4 *sts       i: calibration switches and info
DispRelation *disp   o: dispersion relation
char *ref_aper       o: name of aperture used to measure dispersion relation
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int best_row;		/* read info from this row */
	double a2diff;		/* difference between A2CENTER and middle */
	double min_a2diff;	/* min value of a2diff */

	/* Open the dispersion coefficients table. */
	if ((status = OpenDSPTab (sts->disptab.name, &tabinfo)))
	    return (status);

	best_row = -1;			/* initial values */
	min_a2diff = 2. * MIDDLE_LINE;

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadDSPTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for a match with opt_elem and cenwave. */

	    if (SameString (tabrow.opt_elem, sts->opt_elem) &&
		SameInt (tabrow.cenwave, sts->cenwave)) {

		a2diff = fabs (tabrow.a2center - MIDDLE_LINE);
		if (a2diff < min_a2diff) {
		    min_a2diff = a2diff;
		    best_row = row;
		}
	    }
	}

	if (best_row < 1) {
	    printf ("Matching row not found in DISPTAB %s:\n",
				sts->disptab.name);
	    printf ("    OPT_ELEM %s, CENWAVE %d\n",
			sts->opt_elem, sts->cenwave);
	    return (TABLE_ERROR);
	}

	/* Read data from the most appropriate row. */
	if ((status = ReadDSPArray (&tabinfo, best_row, disp, ref_aper)))
	    return (status);

	/* Get pedigree & descrip from this row. */
	if ((status = RowPedigree (&sts->disptab, best_row,
                tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
	    return (status);
	if (sts->disptab.goodPedigree == DUMMY_PEDIGREE) {
	    printf ("Warning  DUMMY pedigree in row %d of %s.\n",
		best_row, sts->disptab.name);
	}

	if ((status = CloseDSPTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#5
0
int GetCCDTab (ACSInfo *acs, int dimx, int dimy) {

/* arguments:
ACSInfo *acs     io: calibration switches, etc
int     dimx      i: number of columns in exposure
int     dimy      i: number of lines in exposure
*/

	extern int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int i;
	char amp[5] = "ABCD";
    int samegain;
	
	int foundit;		/* has the correct row been found? */
	int RowPedigree (RefTab *, int, IRAFPointer, IRAFPointer, IRAFPointer);
	int SameInt (int, int);
	int SameFlt (float, float);
	int SameString (char *, char *);

	/* Open the CCD parameters table and find columns. */
	if (OpenCCDTab (acs->ccdpar.name, &tabinfo))
	    return (status);

	/* Check each row for a match with ccdamp, ccdgain, ccdoffst,
	   binaxis1, and binaxis2, and get info from the matching row.
	*/

	foundit = 0;
	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    /* Read the current row into tabrow. */
	    if (ReadCCDTab (&tabinfo, row, &tabrow))
		return (status);

        /* Commanded gain values were int valued pre-SM4 and 
           float valued post-SM4, so we need to check what type
           of ref table we have as input.
        */
        if (tabinfo.intgain == 1) {
            /* Pre-SM4 int valued table */
            samegain = SameInt (tabrow.ccdgaini, (int)acs->ccdgain);
        } else {
            /* Post-SM4 float valued table */
            samegain = SameFlt (tabrow.ccdgainf, acs->ccdgain);
        }

	    if (SameString (tabrow.ccdamp, acs->ccdamp) &&
		samegain &&
		SameInt (tabrow.ccdchip, acs->chip) &&
		SameInt (tabrow.ccdoffset[0], acs->ccdoffset[0]) &&
		SameInt (tabrow.ccdoffset[1], acs->ccdoffset[1]) &&
		SameInt (tabrow.ccdoffset[2], acs->ccdoffset[2]) &&
		SameInt (tabrow.ccdoffset[3], acs->ccdoffset[3])) {

		foundit = 1;
		if (RowPedigree (&acs->ccdpar, row,
			tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip))
		    return (status);
		if (acs->ccdpar.goodPedigree == DUMMY_PEDIGREE) {
		    sprintf (MsgText, "Row %d of CCDTAB is DUMMY.", row);
			trlwarn (MsgText);
		}

		for (i = 0; i < NAMPS; i++){
			/* If the amp is used, keep the value, otherwise set to zero*/
			if (strchr(acs->ccdamp, amp[i]) != NULL) {
				acs->atodgain[i] = tabrow.atodgain[i];
				acs->readnoise[i] = tabrow.readnoise[i];
				acs->ccdbias[i] = tabrow.bias[i];
			} else {
				acs->atodgain[i] = 0.;
				acs->readnoise[i] = 0.;			
				acs->ccdbias[i] = 0.;			
			}
		}

        /* 
            Correct ampx/ampy to match the actual size of the exposure
            This will allow more seamless processing of subarrays.
        */
		acs->ampx = (tabrow.ampx > dimx) ? dimx : tabrow.ampx;
		acs->ampy = tabrow.ampy;		
		acs->saturate = tabrow.saturate;
		break;
	    }
	}

	if (!foundit) {
	    sprintf (MsgText, "Matching row not found in CCDTAB `%s'.", acs->ccdpar.name);
	    trlerror (MsgText);
		sprintf (MsgText, "CCDAMP %s, CCDGAIN %4.1f, CCDOFFST %d,%d,%d,%d.",
		acs->ccdamp, acs->ccdgain, acs->ccdoffset[0], acs->ccdoffset[1],
		acs->ccdoffset[2], acs->ccdoffset[3]);
		trlerror (MsgText);
		
	    CloseCCDTab (&tabinfo);
	    return (status = TABLE_ERROR);
	}

	if (CloseCCDTab (&tabinfo))		/* close the table */
	    return (status);

	return (status);
}
示例#6
0
int GetDisp (StisInfo7 *sts, DispRelation **disp) {

/* arguments:
StisInfo7 *sts       i: calibration switches and info
DispRelation **disp  o: size and coordinate info for output
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int CheckDisp (DispRelation **);
	void FreeDisp (DispRelation **);

	/* Open the dispersion coefficients table. */
	if ((status = OpenDSPTab (sts->disptab.name, &tabinfo)))
	    return (status);

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadDSPTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for a match with opt_elem and cenwave. */

	    if (SameString (tabrow.opt_elem, sts->opt_elem) &&
		SameInt (tabrow.cenwave, sts->cenwave)) {

		/* Get pedigree & descrip from the row. */
		if ((status = RowPedigree (&sts->disptab, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (sts->disptab.goodPedigree == DUMMY_PEDIGREE) {
		    printf ("Warning  DUMMY pedigree in row %d of %s.\n",
			row, sts->disptab.name);
		    sts->x2dcorr_o = DUMMY;
		    CloseDSPTab (&tabinfo);
		    return (0);
		}

		/* Read data from this row. */
		if ((status = ReadDSPArray (&tabinfo, row, disp)))
		    return (status);
	    }
	}

	/* Get for duplicate a2center or non-duplicate ref_aper. */
	if ((status = CheckDisp (disp))) {
	    FreeDisp (disp);
	    if (status < 0) {
		printf ("Warning  Matching row not found in DISPTAB %s; \\\n",
				sts->disptab.name);
		printf ("Warning  OPT_ELEM %s, CENWAVE %d\n",
			sts->opt_elem, sts->cenwave);
		sts->x2dcorr_o = OMIT;
	    } else {
		return (status);
	    }
	}

	if ((status = CloseDSPTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#7
0
int GetSDC6 (StisInfo6 *sts, CoordInfo **coords, int *minorder, int *maxorder)
{

/* arguments:
StisInfo6 *sts             i: calibration switches and info
CoordInfo **coords         o: size and coordinate info for output
int *minorder, *maxorder   o: minimum and maximum values of SPORDER
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int RangeCoord6 (CoordInfo **, int *, int *);

	/* Open the spectroscopic distortion information table. */
	if ((status = OpenSDistTab (sts->distntab.name, &tabinfo)))
	    return (status);

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadSDistTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for a match with opt_elem and cenwave. */
	    if (SameString (tabrow.opt_elem, sts->opt_elem) &&
		SameInt (tabrow.cenwave, sts->cenwave)) {

		/* Get pedigree & descrip from the row. */
		if ((status = RowPedigree (&sts->distntab, row,
                       tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (sts->distntab.goodPedigree == DUMMY_PEDIGREE) {
		    printf ("Warning  DUMMY pedigree in row %d of %s.\n",
			row, sts->distntab.name);
		    sts->x1d_o = DUMMY;
		    CloseSDistTab (&tabinfo);
		    return (0);
		}

		/* Read data from this row. */
		if ((status = ReadSDistArray (&tabinfo, row, coords)))
		    return (status);

		/* This was added because the SDCTAB may contain multiple
		   entries for the CCD pseudo-apertures.  In this case, all
		   matching rows contain the same NPIX2 value, so we can
		   take the value from the first matching row.
		*/
		if ((*coords)->sporder == 1)
		    break;
	    }
	}

	/* Get the range of order numbers. */
	if ((status = RangeCoord6 (coords, minorder, maxorder))) {
	    if (status < 0) {
		printf ("Warning  Matching row not found in SDCTAB %s; \\\n",
				sts->distntab.name);
		printf ("Warning  OPT_ELEM %s, CENWAVE %d.\n",
		    sts->opt_elem, sts->cenwave);
		sts->x1d_o = OMIT;
	    } else {
		return (status);
	    }
	}

	if ((status = CloseSDistTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#8
0
int GetCCDTab (StisInfo1 *sts) {

/* arguments:
StisInfo1 *sts     io: calibration switches, etc
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int foundit;		/* has the correct row been found? */

	/* Open the CCD parameters table and find columns. */
	if ((status = OpenCCDTab (sts->ccdpar.name, &tabinfo)))
	    return (status);

	/* Check each row for a match with ccdamp, ccdgain, ccdoffst,
	   binaxis1, and binaxis2, and get info from the matching row.
	*/

	foundit = 0;
	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    /* Read the current row into tabrow. */
	    if ((status = ReadCCDTab (&tabinfo, row, &tabrow)))
		return (status);

	    if (SameString (tabrow.ccdamp, sts->ccdamp) &&
		SameInt (tabrow.ccdgain, sts->ccdgain) &&
		SameInt (tabrow.ccdoffset, sts->ccdoffset) &&
		SameInt (tabrow.bin[0], sts->binaxis[0]) &&
		SameInt (tabrow.bin[1], sts->binaxis[1])) {

		foundit = 1;
		if ((status = RowPedigree (&sts->ccdpar, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (sts->ccdpar.goodPedigree == DUMMY_PEDIGREE)
		    printf ("Warning  Row %d of CCDTAB is DUMMY.\n", row);
		sts->atodgain = tabrow.atodgain;
		sts->ccdbias = tabrow.ccdbias;
		sts->readnoise = tabrow.readnoise;
		sts->saturate = tabrow.saturate;
		sts->blev_clip = tabrow.blev_clip;
		break;
	    }
	}

	if (!foundit) {
	    printf ("ERROR    Matching row not found in CCDTAB `%s'.\n",
			sts->ccdpar.name);
	    printf (
		"ERROR    CCDAMP %s, CCDGAIN %d, CCDOFFST %d, BINAXIS %d,%d.\n",
		sts->ccdamp, sts->ccdgain, sts->ccdoffset,
		sts->binaxis[0], sts->binaxis[1]);
	    CloseCCDTab (&tabinfo);
	    return (TABLE_ERROR);
	}

	if ((status = CloseCCDTab (&tabinfo)))  /* close the table */
	    return (status);

	return (0);
}
示例#9
0
int GetInang6 (StisInfo6 *sts, RefTab *table, int sporder, InangInfo *iac) {

/* arguments:
StisInfo6 *sts     i: calibration switches and info
RefTab *table      i: inangtab or mofftab
int sporder        i: spectral order number
InangInfo *iac     o: incidence-angle info
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int row;		/* loop index */
	int foundit = 0;

	/* Open the incidence-angle coefficients table. */
	if ((status = OpenIACTab (table->name, &tabinfo)))
	    return (status);

	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadIACTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for a match with opt_elem, cenwave, and sporder. */

	    if (SameString (tabrow.opt_elem, sts->opt_elem) &&
		SameInt (tabrow.cenwave, sts->cenwave) &&
		SameInt (tabrow.sporder, sporder)) {

		foundit = 1;

		/* Get pedigree & descrip from the row. */
		if ((status = RowPedigree (table, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (table->goodPedigree == DUMMY_PEDIGREE) {
		    sts->x1d_o = DUMMY;
		    CloseIACTab (&tabinfo);
		    return (0);
		}

		/* Read data from this row. */
		if ((status = ReadIACArray (&tabinfo, row, iac)))
		    return (status);
	    }
	}

	if (!foundit) {
	    printf ("ERROR    Matching row not found in %s\n", table->name);
	    printf ("ERROR    OPT_ELEM %s, SPORDER %d, CENWAVE %d\n",
		    sts->opt_elem, sporder, sts->cenwave);
	    return (ROW_NOT_FOUND);
	}

	if ((status = CloseIACTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#10
0
文件: doatod.c 项目: jhunkeler/hstcal
int doAtoD (StisInfo1 *sts, SingleGroup *x) {

/* arguments:
StisInfo1 *sts     i: calibration switches, etc
SingleGroup *x    io: image to be calibrated; written to in-place
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */
	TblArray tabarray;	/* correction array read from table row */

	int foundit;		/* row found in table? */
	int row;		/* loop index for row number */
	int row_min;		/* row with closest temperature (min dt) */
	double ref_key_value;	/* value gotten from image header */
	double dt, dt_min;	/* for finding temperature in table */
	int ival;		/* input science data value from x */
	int i, j;
	short dq;		/* a data quality value */

	int no_default = 0;	/* missing keyword is fatal error */

	if (sts->atodcorr != PERFORM)
	    return (0);

	if (sts->ncombine > 1) {
	    printf (
"ERROR    NCOMBINE is already > 1 before ATODCORR has been performed.\n");
	    return (GENERIC_ERROR_CODE);
	}

	/* Open the A-to-D table. */
	if ((status = OpenAtoDTab (sts->atod.name, &tabinfo)))
	    return (status);

	/* Find the row with value closest to the temperature. */

	foundit = 0;
	for (row = 1;  row <= tabinfo.nrows;  row++) {
	    if ((status = ReadAtoDTab (&tabinfo, row, &tabrow)))
		return (status);
	    if (SameString (tabrow.ccdamp, sts->ccdamp) &&
		SameInt (tabrow.ccdgain, sts->ccdgain)) {
		/* Get value from header. */
		if ((status = Get_KeyD (&x->sci.hdr, tabrow.ref_key, no_default,
                                        0., &ref_key_value)))
		    return (status);
		dt = fabs (ref_key_value - tabrow.ref_key_value);
		if (!foundit) {
		    foundit = 1;	/* assign initial values */
		    dt_min = dt;
		    row_min = row;
		} else if (dt < dt_min) {	/* update dt_min */
		    dt_min = dt;
		    row_min = row;
		}
	    }
	}

	if (!foundit) {
	    printf (
	"ERROR    CCD amp %s, gain %d, not found in ATODTAB `%s'.\n",
		sts->ccdamp, sts->ccdgain, sts->atod.name);
	    CloseAtoDTab (&tabinfo);
	    return (TABLE_ERROR);
	}

	/* Get pedigree & descrip from the row. */
	if ((status = RowPedigree (&sts->atod, row_min,
                tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
	    return (status);
	if (sts->atod.goodPedigree == DUMMY_PEDIGREE) {
	    sts->atodcorr = DUMMY;
	    CloseAtoDTab (&tabinfo);
	    return (0);
	}

	/* Reread the appropriate row to get the correction array. */
	if ((status = ReadAtoDArray (&tabinfo, row_min, &tabarray)))
	    return (status);

	/* Apply this correction to each pixel in the image.  At this
	   stage the values should still be integers, so assigning
	   a value to an integer (ival) should not result in truncation.
	*/
	for (j = 0;  j < x->sci.data.ny;  j++) {
	    for (i = 0;  i < x->sci.data.nx;  i++) {
		ival = (int) Pix (x->sci.data, i, j);
		if (ival >= tabarray.nelem) {
		    Pix (x->sci.data, i, j) = tabarray.atod[tabarray.nelem-1];
		    dq = DQPix (x->dq.data, i, j) | SATPIXEL;
		    DQSetPix (x->dq.data, i, j, dq);	/* saturated */
		} else if (ival >= 0) {
		    Pix (x->sci.data, i, j) = tabarray.atod[ival];
		}		/* else if ival < 0, no change */
	    }
	}

	free (tabarray.atod);
	if ((status = CloseAtoDTab (&tabinfo)))
	    return (status);

	return (0);
}
示例#11
0
int FindOverscan (ACSInfo *acs, int nx, int ny, int *overscan) {

/* arguments:
ACSInfo *acs		  i: structure with all values from OSCNTAB 
int nx, ny            i: lengths of first and second image axes
int offsetx, offsety  i: Trim values from LTV1,2
*/

	extern int status;
	int row;
	TblInfo tabinfo;
	TblRow tabrow;
	int foundit;
    
    int cx0, cx1, tx1,tx2;
    int full_nx;

	int SameInt (int, int);
	int SameString (char *, char *);

	/* Open the CCD parameters table and find columns. */
	if (OpenOverTab (acs->oscn.name, &tabinfo))
	    return (status);

	/* Check each row for a match with ccdamp, chip, nx, ny,
	   binx, and biny, and get info from the matching row.
	*/

	foundit = NO;
    *overscan = NO;
	
	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    /* Read the current row into tabrow. */
	    if (ReadOverTab (&tabinfo, row, &tabrow))
		return (status);

	    if (SameString (tabrow.ccdamp, acs->ccdamp) &&
		SameInt (tabrow.chip, acs->chip) &&
        /* The overscan regions only depend on the full chip size...
		SameInt (tabrow.nx, nx) &&
		SameInt (tabrow.ny, ny) &&
		*/
        SameInt (tabrow.bin[0], acs->bin[0]) &&
		SameInt (tabrow.bin[1], acs->bin[1])) {

			foundit = YES;
            *overscan = YES;
                        
            if (acs->subarray == YES) {
                /* We are working with a subarray... */
                /* There is never any virtual overscan. */
                acs->trimy[0] = 0;
                acs->trimy[1] = 0;
			    acs->vx[0] = 0;
			    acs->vx[1] = 0;
			    acs->vy[0] = 0;
			    acs->vy[1] = 0;
                /* Determine whether the subarray extends into the
                    physical overscan regions on either side of the chip */
                tx1 = (int)(nx - acs->offsetx);
                cx1 = tabrow.nx - tabrow.trimx[1] - tabrow.trimx[0];
                cx0 = (int)(tabrow.trimx[0] - acs->offsetx);
                
                if (acs->offsetx > 0) {
                    /* Subarray starts in the first overscan region... */
                    acs->trimx[0] = (acs->offsetx < tabrow.trimx[0])? acs->offsetx : tabrow.trimx[0];
                    /* Check to see if it extends into second overscan region...
                        Fixed 24 July 2001 WJH.
                    */
                    full_nx = tabrow.nx - (tabrow.trimx[0] + tabrow.trimx[1]);
                    tx2 = (int)(nx - acs->trimx[0]) - full_nx;
                    acs->trimx[1] = (tx2 < 0) ? 0 : tx2;
                    acs->biassecta[0] = (tabrow.biassecta[0] - 1 - cx0 > 0) ? (tabrow.biassecta[0] - 1 - cx0) : 0;
                    acs->biassecta[1] = tabrow.biassecta[1] - 1 - cx0;
                    acs->biassectb[0] = 0;
                    acs->biassectb[1] = 0;
                } else if ( tx1 > cx1 && tx1 <= tabrow.nx) {
                    /* ... then the subarray overlaps biassectb... */
                    acs->trimx[0] = 0;
                    acs->trimx[1] = tx1 - cx1;
                    acs->biassecta[0] = 0;
                    acs->biassecta[1] = 0;
                    acs->biassectb[0] = nx - (tx1 - cx1);
                    acs->biassectb[1] = nx - 1;
                     
                } else {
                    /* Subarray doesn't overlap either physical overscan region */
                    acs->trimx[0] = 0;
                    acs->trimx[1] = 0;
                    acs->biassecta[0] = 0;
                    acs->biassecta[1] = 0;
                    acs->biassectb[0] = 0;
                    acs->biassectb[1] = 0;                               
                    *overscan = NO;             
                }
            } else {
                /* We are working with a full chip image... */		
			    acs->trimx[0] = tabrow.trimx[0];
			    acs->trimx[1] = tabrow.trimx[1];
			    acs->trimy[0] = tabrow.trimy[0];
			    acs->trimy[1] = tabrow.trimy[1];
                /* Subtract one from table values to
				    conform to C array indexing... */
			    acs->vx[0] = tabrow.vx[0]-1;
			    acs->vx[1] = tabrow.vx[1]-1;
			    acs->vy[0] = tabrow.vy[0]-1;
			    acs->vy[1] = tabrow.vy[1]-1;
			    acs->biassecta[0] = tabrow.biassecta[0] - 1;
			    acs->biassecta[1] = tabrow.biassecta[1] - 1;
			    acs->biassectb[0] = tabrow.biassectb[0] - 1;
			    acs->biassectb[1] = tabrow.biassectb[1] - 1;
			}

			break;
	    }
	}
	if (foundit == NO) {
		status = ROW_NOT_FOUND;
		sprintf(MsgText, "Could not find appropriate row from OSCNTAB. ");
		trlwarn(MsgText);
	}	
	if(CloseOverTab (&tabinfo))
		return(status);
	
    if (acs->verbose == YES){
        sprintf(MsgText,"Found trim values of: x(%d,%d) y(%d,%d)",acs->trimx[0],acs->trimx[1],acs->trimy[0],acs->trimy[1]);
        trlmessage(MsgText);
    }
    
	return (status);
}
示例#12
0
int GetTrace6 (StisInfo6 *sts, int sporder, SpTrace **trace) {

/* arguments:
StisInfo6 *sts    i: calibration switches and info
int sporder       i: spectral order number
SpTrace **trace   o: size and coordinate info for output
*/

	int status;

	TblInfo tabinfo;	/* pointer to table descriptor, etc */
	TblRow tabrow;		/* values read from a table row */

	int i;
	int found_trace;
	int row;		/* loop index */
	int CheckTrace6 (SpTrace **);
	void FreeTrace6 (SpTrace **);

	/* Open the spectrum trace table. */
	if ((status = OpenTraceTab (sts->sptrctab.name, &tabinfo)))
	    return (status);

	found_trace = 0;
	for (row = 1;  row <= tabinfo.nrows;  row++) {

	    if ((status = ReadTraceTab (&tabinfo, row, &tabrow)))
		return (status);

	    /* Check for a match with opt_elem, cenwave, and sporder. */
	    if (SameString (tabrow.opt_elem, sts->opt_elem) &&
		SameInt (tabrow.cenwave, sts->cenwave) &&
		SameInt (tabrow.sporder, sporder)) {

		/* Get pedigree & descrip from the row. */
		if ((status = RowPedigree (&sts->sptrctab, row,
                        tabinfo.tp, tabinfo.cp_pedigree, tabinfo.cp_descrip)))
		    return (status);
		if (sts->sptrctab.goodPedigree == DUMMY_PEDIGREE) {
		    sts->x1d_o = DUMMY;
		    CloseTraceTab (&tabinfo);
		    return (0);
		}

		/* Read data from this row. */
		if ((status = ReadTraceArray (&tabinfo, row, sts, trace)))
		    return (status);
	        found_trace = 1;
	    }
	}


	/* If nothing found, return silently. */
	if (!found_trace) {
	    if ((status = CloseTraceTab (&tabinfo)))
	        return (status);
	    return (NO_TRACE);
	}

	/* Get for duplicate a2center or non-duplicate a1center.
           An empty trace table is not an error.
        */
	i = CheckTrace6 (trace);
	if (i == NO_TRACE) {
	    if ((status = CloseTraceTab (&tabinfo)))
	        return (status);
	    return (NO_TRACE);
	} else if (i == ERROR_TRACE) {
	    FreeTrace6 (trace);
	    return (ERROR_TRACE);
	}

	if ((status = CloseTraceTab (&tabinfo)))
	    return (status);

	return (0);
}