Exemple #1
0
static int CheckPedigree (TblInfo *tabinfo, int row, int *pedigree) {

	char *str_pedigree;

	if (tabinfo->cp_pedigree > 0) {

	    if ((str_pedigree = (char *) calloc (STIS_LINE+1,
                                         sizeof(char))) == NULL) {
		printf ("ERROR    Out of memory.\n");
		return (OUT_OF_MEMORY);
	    }
	    c_tbegtt (tabinfo->tp, tabinfo->cp_pedigree, row,
			str_pedigree, STIS_LINE);
	    if (c_iraferr())
		return (TABLE_ERROR);

	    if (strncmp (str_pedigree, "DUMMY", 5) == 0)
		*pedigree = DUMMY_PEDIGREE;
	    else
		*pedigree = GOOD_PEDIGREE;
	    free (str_pedigree);

	} else {

	    *pedigree = GOOD_PEDIGREE;
	}

	return (0);
}
Exemple #2
0
static int ReadLinTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	extern int status;

	c_tbegtt (tabinfo->tp, tabinfo->cp_det, row,
			tabrow->detector, ACS_CBUF-1);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtd (tabinfo->tp, tabinfo->cp_global, row, &tabrow->global_limit);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtd (tabinfo->tp, tabinfo->cp_local, row, &tabrow->local_limit);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtd (tabinfo->tp, tabinfo->cp_tau, row, &tabrow->tau);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_expand, row, &tabrow->expand);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	return (status);
}
Exemple #3
0
void c_tbegts (const IRAFPointer tp, const IRAFPointer cp, int row, short *buffer) {

/* Read a short integer value from a table column.
arguments:
IRAFPointer tp          i: table descriptor
IRAFPointer cp          i: column descriptor
int row                 i: row number (one indexed)
short *buffer           o: value read from table
*/

        TableDescr *tbl_descr;
        ColumnDescr *col_descr;
        int anynul=0;
        long firstelem=1, nelem=1;
        short nulval=IRAF_INDEFS;
        int status = 0;

        tbl_descr = (TableDescr *)tp;
        col_descr = (ColumnDescr *)cp;

        if (col_descr->datatype < 0) {
            char *value;
            int maxch;
            maxch = col_descr->width + 5;
            value = (char *)calloc (maxch, sizeof(char));
            c_tbegtt (tp, cp, row, value, maxch);
            if (strcmp (value, "INDEF") == 0)
                *buffer = IRAF_INDEFS;
            else
                *buffer = atoi (value);
            free (value);

        } else if (col_descr->datatype == IRAF_BOOL) {
            Bool b_value;
            c_tbegtb (tp, cp, row, &b_value);
            if (b_value)
                *buffer = 1;
            else
                *buffer = 0;

        } else if (col_descr->datatype == IRAF_INT) {
            int i_value;
            c_tbegti (tp, cp, row, &i_value);
            if (i_value == IRAF_INDEFI)
                *buffer = IRAF_INDEFS;
            else
                *buffer = (short)i_value;

        } else {

            /* fits_read_col_sht = ffgcvi */
            fits_read_col_sht (tbl_descr->fptr, col_descr->colnum,
                (long)row, firstelem, nelem, nulval,
                buffer, &anynul, &status);
            if (status != 0)
                setError (status, "c_tbegts:  error reading element");
        }
}
Exemple #4
0
void c_tbegtd (const IRAFPointer tp, const IRAFPointer cp, int row, double *buffer) {

/* Read a value of type double from a table column.
arguments:
IRAFPointer tp          i: table descriptor
IRAFPointer cp          i: column descriptor
int row                 i: row number (one indexed)
double *buffer          o: value read from table
*/

        TableDescr *tbl_descr;
        ColumnDescr *col_descr;
        int anynul=0;
        long firstelem=1, nelem=1;
        double nulval=IRAF_INDEFD;
        int status = 0;

        tbl_descr = (TableDescr *)tp;
        col_descr = (ColumnDescr *)cp;

        if (col_descr->datatype < 0) {
            char *value;
            int maxch;
            maxch = col_descr->width + 5;
            value = (char *)calloc (maxch, sizeof(char));
            c_tbegtt (tp, cp, row, value, maxch);
            if (strcmp (value, "INDEF") == 0)
                *buffer = IRAF_INDEFD;
            else
                *buffer = atof (value);
            free (value);

        } else if (col_descr->datatype == IRAF_INT) {
            int i_value;
            c_tbegti (tp, cp, row, &i_value);
            if (i_value == IRAF_INDEFI)
                *buffer = IRAF_INDEFD;
            else
                *buffer = i_value;

        } else if (col_descr->datatype == IRAF_SHORT) {
            short si_value;
            c_tbegts (tp, cp, row, &si_value);
            if (si_value == IRAF_INDEFS)
                *buffer = IRAF_INDEFD;
            else
                *buffer = si_value;

        } else {

            /* fits_read_col_dbl = ffgcvd */
            fits_read_col_dbl (tbl_descr->fptr, col_descr->colnum,
                (long)row, firstelem, nelem, nulval,
                buffer, &anynul, &status);
            if (status != 0)
                setError (status, "c_tbegtd:  error reading element");
        }
}
Exemple #5
0
static int ReadDSPArray (TblInfo *tabinfo, int row,
		DispRelation *disp, char *ref_aper) {

	int ncoeff;		/* number of coefficients read from table */
	int i;

	for (i = 0;  i < MAX_DISP_COEFF;  i++)
	    disp->coeff[i] = 0.;

	/* Get name of aperture used to measure dispersion relation. */
	c_tbegtt (tabinfo->tp, tabinfo->cp_ref_aper, row, ref_aper, STIS_CBUF);

	/* Number of coefficients in dispersion relation. */
	c_tbegti (tabinfo->tp, tabinfo->cp_ncoeff, row, &disp->ncoeff);
	if (disp->ncoeff > MAX_DISP_COEFF) {
	    printf ("Too many dispersion coefficients %d in DISPTAB.\n",
		disp->ncoeff);
	    return (TABLE_ERROR);
	}

	/* Get the coefficients themselves. */
	ncoeff = c_tbagtd (tabinfo->tp, tabinfo->cp_coeff, row,
			disp->coeff, 1, disp->ncoeff);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (ncoeff < disp->ncoeff) {
	    c_tbtclo (tabinfo->tp);
	    printf ("Not all coefficients were read from DISPTAB.\n");
	    return (TABLE_ERROR);
	}

	/* Get the a4corr info. */
	if (tabinfo->cp_a4corr == 0) {
	    disp->mref = 0;
	    disp->yref = 0.;
	    disp->a4corr = 0.;
	} else {
	    double yref;

	    c_tbegti (tabinfo->tp, tabinfo->cp_mref, row, &disp->mref);
	    if (c_iraferr())
		return (TABLE_ERROR);

	    c_tbegtd (tabinfo->tp, tabinfo->cp_yref, row, &yref);
	    if (c_iraferr())
		return (TABLE_ERROR);
	    /* convert to zero-indexing */
	    disp->yref = yref - 1.;

	    c_tbegtd (tabinfo->tp, tabinfo->cp_a4corr, row, &disp->a4corr);
	    if (c_iraferr())
		return (TABLE_ERROR);
	}

	return (0);
}
Exemple #6
0
static int ReadApTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	c_tbegtt (tabinfo->tp, tabinfo->cp_aperture, row,
			tabrow->aperture, STIS_CBUF);
	c_tbegtd (tabinfo->tp, tabinfo->cp_offset, row, &tabrow->offset);
	if (c_iraferr())
	    return (TABLE_ERROR);

	return (0);
}
Exemple #7
0
static int ReadAtoDTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	c_tbegtt (tabinfo->tp, tabinfo->cp_amp, row,
			tabrow->ccdamp, STIS_CBUF);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_gain, row, &tabrow->ccdgain);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtt (tabinfo->tp, tabinfo->cp_key, row,
			tabrow->ref_key, STIS_CBUF);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtd (tabinfo->tp, tabinfo->cp_keyval, row, &tabrow->ref_key_value);
	if (c_iraferr())
	    return (TABLE_ERROR);

	return (0);
}
Exemple #8
0
static int ReadDSPTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	c_tbegtt (tabinfo->tp, tabinfo->cp_opt_elem, row,
			tabrow->opt_elem, STIS_CBUF);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_cenwave, row, &tabrow->cenwave);
	if (c_iraferr())
	    return (TABLE_ERROR);

	return (0);
}
Exemple #9
0
static int ReadCCDTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	c_tbegtt (tabinfo->tp, tabinfo->cp_amp, row,
			tabrow->ccdamp, STIS_CBUF);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_ccdgain, row, &tabrow->ccdgain);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_ccdoffset, row, &tabrow->ccdoffset);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_bin1, row, &tabrow->bin[0]);
	if (c_iraferr())
	    return (TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_bin2, row, &tabrow->bin[1]);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_atodgain, row, &tabrow->atodgain);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_bias, row, &tabrow->ccdbias);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_readnoise, row, &tabrow->readnoise);
	if (c_iraferr())
	    return (TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_saturate, row, &tabrow->saturate);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (tabinfo->cp_blev_clip == 0) {
	    tabrow->blev_clip = DEFAULT_BLEV_CLIP;
	} else {
	    c_tbegtr (tabinfo->tp, tabinfo->cp_blev_clip, row,
			&tabrow->blev_clip);
	    if (c_iraferr())
		return (TABLE_ERROR);
	}

	return (0);
}
Exemple #10
0
static int ReadAtoDTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	extern int status;

	c_tbegtt (tabinfo->tp, tabinfo->cp_amp, row,
			tabrow->ccdamp, SZ_CBUF);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_gain, row, &tabrow->ccdgain);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtt (tabinfo->tp, tabinfo->cp_key, row,
			tabrow->ref_key, SZ_CBUF);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtd (tabinfo->tp, tabinfo->cp_keyval, row, &tabrow->ref_key_value);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	return (status);
}
Exemple #11
0
static int ReadDSPArray (TblInfo *tabinfo, int row, DispRelation **disp) {

	int status;

	int ncoeff;		/* number of coefficients read from table */
	DispRelation *newrec;
	int NewDisp (DispRelation **, DispRelation *);

	if ((newrec = malloc (sizeof (DispRelation))) == NULL) {
	    printf ("ERROR    (GetDisp) can't allocate memory.\n");
	    return (OUT_OF_MEMORY);
	}
	newrec->next = NULL;

	/* Get dispersion coefficients and other info. */
	c_tbegtd (tabinfo->tp, tabinfo->cp_a2center, row, &newrec->a2center);
	c_tbegtt (tabinfo->tp, tabinfo->cp_ref_aper, row, newrec->ref_aper,
		STIS_CBUF);
	c_tbegti (tabinfo->tp, tabinfo->cp_ncoeff, row, &newrec->ncoeff);
	if (newrec->ncoeff > MAX_DISP_COEFF) {
	    printf (
	"ERROR    Too many dispersion coefficients %d in DISPTAB.\n",
		newrec->ncoeff);
	    return (TABLE_ERROR);
	}
	ncoeff = c_tbagtd (tabinfo->tp, tabinfo->cp_coeff, row,
			newrec->coeff, 1, newrec->ncoeff);
	if (c_iraferr())
	    return (TABLE_ERROR);

	/* Convert a2center to zero-indexed. */
	newrec->a2center--;

	if (ncoeff < newrec->ncoeff) {
	    c_tbtclo (tabinfo->tp);
	    printf ("ERROR    Not all coefficients were read from DISPTAB.\n");
	    return (TABLE_ERROR);
	}

	/* Insert newrec into the disp list. */
	if ((status = NewDisp (disp, newrec)))
	    return (status);

	free (newrec);

	return (0);
}
Exemple #12
0
static int ReadBpixTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	/* OPT_ELEM is an optional column. */
	if (tabinfo->cp_opt_elem == 0) {
	    strcpy (tabrow->opt_elem, "ANY");
	} else {
	    c_tbegtt (tabinfo->tp, tabinfo->cp_opt_elem, row,
			tabrow->opt_elem, STIS_CBUF);
	    if (c_iraferr())
		return (TABLE_ERROR);
	}

	c_tbegti (tabinfo->tp, tabinfo->cp_xstart, row, &tabrow->xstart);
	if (c_iraferr())
	    return (TABLE_ERROR);
	tabrow->xstart--;
	c_tbegti (tabinfo->tp, tabinfo->cp_ystart, row, &tabrow->ystart);
	if (c_iraferr())
	    return (TABLE_ERROR);
	tabrow->ystart--;
	c_tbegti (tabinfo->tp, tabinfo->cp_length, row, &tabrow->length);
	if (c_iraferr())
	    return (TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_axis, row, &tabrow->axis);
	if (c_iraferr())
	    return (TABLE_ERROR);
	c_tbegts (tabinfo->tp, tabinfo->cp_flag, row, &tabrow->flag);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (tabrow->axis !=1 && tabrow->axis != 2) {
	    printf ("ERROR    Axis = %d in BPIXTAB, but it must be 1 or 2.\n",
			tabrow->axis);
	    c_tbtclo (tabinfo->tp);
	    return (TABLE_ERROR);
	}
	if (tabrow->length <= 0) {
	    printf (
	"ERROR    Length = %d in BPIXTAB, but it must be positive.\n",
		    tabrow->length);
	    c_tbtclo (tabinfo->tp);
	    return (TABLE_ERROR);
	}

	return (0);
}
Exemple #13
0
static int GetXDisp (char *name, ScatterFunctions *scf) {

/* arguments
char *name;             i: name of CDSTAB reference file
ScatterFunctions *scf;  o: data structure with scattering functions
*/
        IRAFPointer tp;
        IRAFPointer cp_optelem, cp_nelem, cp_cdscat;
        char opt_elem[STIS_CBUF];
        int row, nrows, i;

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    CDSTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        nrows = c_tbpsta (tp, TBL_NROWS);
        c_tbcfnd1 (tp, "OPT_ELEM", &cp_optelem);
        c_tbcfnd1 (tp, "NELEM",    &cp_nelem);
        c_tbcfnd1 (tp, "CDSCAT",   &cp_cdscat);
        if (cp_optelem == 0 || cp_nelem == 0 || cp_cdscat == 0) {
            printf( "ERROR    Column not found in CDSTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

        for (row = 1; row <= nrows ; row++) {
            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);
            if (streq_ic (opt_elem, scf->opt_elem)) {
                c_tbegti (tp, cp_nelem, row, &(scf->nxdisp));
                scf->xdisp = (float *) calloc (scf->nxdisp, sizeof (float));
                if (scf->xdisp == NULL )
                    return (OUT_OF_MEMORY);
                i = c_tbagtr (tp, cp_cdscat, row, scf->xdisp, 1, scf->nxdisp);
                if (c_iraferr())
                    return (TABLE_ERROR);
                c_tbtclo (tp);
                return (STIS_OK);
            }
        }

        printf( "ERROR    Row with %s optical element not found in CDSTAB\n",
                 opt_elem);
        c_tbtclo (tp);
        return (ROW_NOT_FOUND);
}
Exemple #14
0
static int ReadPhotTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	c_tbegtt (tabinfo->tp, tabinfo->cp_opt_elem, row,
			tabrow->opt_elem, STIS_CBUF);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (tabinfo->cp_cenwave != 0) {
	    c_tbegti (tabinfo->tp, tabinfo->cp_cenwave, row, &tabrow->cenwave);
	    if (c_iraferr())
		return (TABLE_ERROR);
	    c_tbegti (tabinfo->tp, tabinfo->cp_sporder, row, &tabrow->sporder);
	    if (c_iraferr())
		return (TABLE_ERROR);
	} else {
	    tabrow->cenwave = 0;
	    tabrow->sporder = 0;
	}

	return (0);
}
Exemple #15
0
static int GetScatter (char *name, ScatterFunctions *scf) {

/* arguments
char *name;             i: name of ECHSCTAB reference file
ScatterFunctions *scf;  o: data structure with scattering functions
*/
        IRAFPointer tp;
        IRAFPointer cp_optelem, cp_sporder, cp_nelem, cp_scat;
        char opt_elem[STIS_CBUF];
        int row, nrows, i;

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    ECHSCTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        nrows = c_tbpsta (tp, TBL_NROWS);
        c_tbcfnd1 (tp, "OPT_ELEM", &cp_optelem);
        c_tbcfnd1 (tp, "NELEM",    &cp_nelem);
        c_tbcfnd1 (tp, "SPORDER",  &cp_sporder);
        c_tbcfnd1 (tp, "ECHSCAT",  &cp_scat);
        if (cp_optelem == 0 || cp_nelem == 0 ||
            cp_sporder == 0 || cp_scat  == 0) {
            printf( "ERROR    Column not found in ECHSCTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

        /* This creates some small amount of unused memory but the
           cost is negligible.
        */
        scf->scfunc = (ScFunc *) calloc (nrows , sizeof (ScFunc));
        scf->nsc = 0;

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

            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);

            if (streq_ic (opt_elem, scf->opt_elem)) {

                c_tbegti (tp, cp_sporder, row,
                          &(scf->scfunc[(scf->nsc)].sporder));
                if (c_iraferr())
                    return (TABLE_ERROR);
                c_tbegti (tp, cp_nelem, row, &(scf->scfunc[(scf->nsc)].nelem));
                if (c_iraferr())
                    return (TABLE_ERROR);
                scf->scfunc[(scf->nsc)].values = (double *) calloc (
                                                 scf->scfunc[(scf->nsc)].nelem,
                                                 sizeof (double));
                i = c_tbagtd (tp, cp_scat, row,
                                           scf->scfunc[(scf->nsc)].values, 1,
                                           scf->scfunc[(scf->nsc)].nelem);
                if (c_iraferr())
                    return (TABLE_ERROR);

                (scf->nsc)++;
            }
        }

        c_tbtclo (tp);

        if (scf->nsc == 0) {
            printf( "ERROR    Row not found in ECHSCTAB\n");
            return (ROW_NOT_FOUND);
        }

        return (STIS_OK);
}
Exemple #16
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);
}
Exemple #17
0
static void GetSDC (StisInfo4 *sts) {

	IRAFPointer tp;
	IRAFPointer cp_opt_elem;
	IRAFPointer cp_a2center, cp_cdelt2;
	IRAFPointer cp_pedigree, cp_descrip;
	char opt_elem[STIS_CBUF+1];		/* grating or prism name */
	int nrows, row;
	int foundit;

	/* default values */
	sts->crpix[1] = PRISM_CRPIX2 - 1.;	/* zero indexed */
	sts->cdelt[1] = PRISM_CDELT2;		/* degrees per pixel */
	sts->crpix[0] = 0.;		/* the rest are not used */
	sts->cdelt[0] = 0.;
	sts->crval[0] = 0.;
	sts->crval[1] = 0.;

	tp = c_tbtopn (sts->sdctab.name, IRAF_READ_ONLY, 0);
	if (c_iraferr()) {
	    printf ("Warning  SDCTAB `%s' not found; default values used.\n",
		sts->sdctab.name);
	    clear_cvoserr();
	    return;
	}
	nrows = c_tbpsta (tp, TBL_NROWS);

	c_tbcfnd1 (tp, "OPT_ELEM", &cp_opt_elem);
	c_tbcfnd1 (tp, "A2CENTER", &cp_a2center);
	c_tbcfnd1 (tp, "CDELT2", &cp_cdelt2);
	if (cp_opt_elem == 0 || cp_a2center == 0 || cp_cdelt2 == 0) {
	    printf ("Warning  Column(s) not found in SDCTAB; defaults used.\n");
	    c_tbtclo (tp);
	    return;
	}
	c_tbcfnd1 (tp, "PEDIGREE", &cp_pedigree);
	c_tbcfnd1 (tp, "DESCRIP", &cp_descrip);

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

	    c_tbegtt (tp, cp_opt_elem, row, opt_elem, STIS_CBUF);
	    if (c_iraferr()) {
		strcpy (opt_elem, "dummy");
		clear_cvoserr();
	    }

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

		foundit = 1;
		c_tbegtd (tp, cp_a2center, row, &sts->crpix[1]);
		c_tbegtd (tp, cp_cdelt2, row, &sts->cdelt[1]);
		sts->crpix[1] -= 1.;		/* zero indexed */
		sts->cdelt[1] /= 3600.;		/* degrees per pixel */

		RowPedigree (&sts->sdctab, row, tp, cp_pedigree, cp_descrip);

		break;
	    }
	}

	c_tbtclo (tp);

	if (!foundit)
	    printf ("Warning  PRISM not found in SDCTAB; defaults used.\n");
}
Exemple #18
0
static int ReadCCDTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	extern int status;

	c_tbegtt (tabinfo->tp, tabinfo->cp_amp, row,
			tabrow->ccdamp, ACS_CBUF-1);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_ccdchip, row, &tabrow->ccdchip);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
        
    if (tabinfo->intgain == 1){
	    c_tbegti (tabinfo->tp, tabinfo->cp_ccdgain, row, &tabrow->ccdgaini);
    } else {
	    c_tbegtr (tabinfo->tp, tabinfo->cp_ccdgain, row, &tabrow->ccdgainf);
	}        
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_bin1, row, &tabrow->bin[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_bin2, row, &tabrow->bin[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_ccdoffset[0], row, &tabrow->ccdoffset[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);		
	c_tbegti (tabinfo->tp, tabinfo->cp_ccdoffset[1], row, &tabrow->ccdoffset[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_ccdoffset[2], row, &tabrow->ccdoffset[2]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);		
	c_tbegti (tabinfo->tp, tabinfo->cp_ccdoffset[3], row, &tabrow->ccdoffset[3]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_bias[0], row, &tabrow->bias[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_bias[1], row, &tabrow->bias[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_bias[2], row, &tabrow->bias[2]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_bias[3], row, &tabrow->bias[3]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
		
	c_tbegtr (tabinfo->tp, tabinfo->cp_atodgain[0], row, &tabrow->atodgain[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_atodgain[1], row, &tabrow->atodgain[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_atodgain[2], row, &tabrow->atodgain[2]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_atodgain[3], row, &tabrow->atodgain[3]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegtr (tabinfo->tp, tabinfo->cp_readnoise[0], row, &tabrow->readnoise[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_readnoise[1], row, &tabrow->readnoise[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_readnoise[2], row, &tabrow->readnoise[2]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegtr (tabinfo->tp, tabinfo->cp_readnoise[3], row, &tabrow->readnoise[3]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_ampx, row, &tabrow->ampx);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_ampy, row, &tabrow->ampy);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
		
	c_tbegtr (tabinfo->tp, tabinfo->cp_saturate, row, &tabrow->saturate);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	return (status);
}
Exemple #19
0
static int GetRefWave (Hdr *phdr, char *name, ScatterFunctions *scf) {

/* arguments
Hdr *phdr               i: primary header
char *name;             i: name of SRWTAB reference file
ScatterFunctions *scf;  o: data structure with reference wavelengths
*/
        IRAFPointer tp;
        IRAFPointer cp_optelem, cp_cenwave, cp_nrw, cp_hrwlist, cp_prwlist;
        char opt_elem[STIS_CBUF];
        int row, nrows, i, cenwave, status;
        double holdh[10], holdp[10];   /* holds a maximum of 10 wavelengths */

        /* This is necessary to avoid rui warnings from the debugger. */
        for (i = 0; i < 10; i++) {
            holdh[i] = 0.0;
            holdp[i] = 0.0;
        }
        for (i = 0; i <= NREFWAVE; i++) {
            scf->kernw[i] = 0.0;
            scf->psfw[i] = 0.0;
        }

        /* get reference CENWAVE. */

        if ((status = Get_KeyI (phdr, "CENWAVE", 0, 0, &cenwave)))
            return (status);

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    SRWTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        nrows = c_tbpsta (tp, TBL_NROWS);
        c_tbcfnd1 (tp, "OPT_ELEM",  &cp_optelem);
        c_tbcfnd1 (tp, "CENWAVE",   &cp_cenwave);
        c_tbcfnd1 (tp, "NRW",       &cp_nrw);
        c_tbcfnd1 (tp, "HALOWAVES", &cp_hrwlist);
        c_tbcfnd1 (tp, "PSFWAVES",  &cp_prwlist);
        if (cp_optelem == 0 || cp_cenwave == 0 ||
            cp_nrw     == 0 || cp_hrwlist == 0 || cp_prwlist == 0) {
            printf( "ERROR    Column not found in SRWTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

        scf->nwave = 0;
        for (row = 1; row <= nrows ; row++) {

            c_tbegti (tp, cp_cenwave, row, &i);
            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);
            if (c_iraferr())
                return (TABLE_ERROR);
            if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem))) {

                c_tbegti (tp, cp_nrw, row, &(scf->nwave));
                if (c_iraferr())
                    return (TABLE_ERROR);
                i = c_tbagtd (tp, cp_hrwlist, row, holdh, 1, scf->nwave);
                if (c_iraferr())
                    return (TABLE_ERROR);
                i = c_tbagtd (tp, cp_prwlist, row, holdp, 1, scf->nwave);
                if (c_iraferr())
                    return (TABLE_ERROR);
                c_tbtclo (tp);

                scf->kernw[0] = holdh[0];
                scf->psfw[0]  = holdp[0];
                if (scf->nwave > 1) {
                    scf->kernw[1] = holdh[1];
                    scf->psfw[1]  = holdp[1];
                }
                if (scf->nwave > 2) {
                    scf->kernw[2] = holdh[2];
                    scf->psfw[2]  = holdp[2];
                }

                return (STIS_OK);
            }
        }

        printf( "ERROR    Row not found in SRWTAB\n");
        c_tbtclo (tp);
        return (ROW_NOT_FOUND);
}
Exemple #20
0
static int GetRipple (Hdr *phdr, char *name, ScatterFunctions *scf) {

/* arguments
Hdr *phdr               i: primary header
char *name;             i: name of RIPTAB  reference file
ScatterFunctions *scf;  o: data structure with ripple functions
*/
        IRAFPointer tp;
        IRAFPointer cp_optelem, cp_cenwave, cp_sporder, cp_wave,
                    cp_nelem, cp_ripple;
        char opt_elem[STIS_CBUF];
        int row, nrows, i, k, cenwave, status;

        /* get reference CENWAVE. */

        if ((status = Get_KeyI (phdr, "CENWAVE", 0, 0, &cenwave)))
            return (status);

        /* Open table and get column pointers. */

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    RIPTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        c_tbcfnd1 (tp, "OPT_ELEM",   &cp_optelem);
        c_tbcfnd1 (tp, "CENWAVE",    &cp_cenwave);
        c_tbcfnd1 (tp, "SPORDER",    &cp_sporder);
        c_tbcfnd1 (tp, "NELEM",      &cp_nelem);
        c_tbcfnd1 (tp, "WAVELENGTH", &cp_wave);
        c_tbcfnd1 (tp, "RIPPLE",     &cp_ripple);
        if (cp_cenwave == 0 || cp_sporder == 0 ||
            cp_wave    == 0 || cp_ripple  == 0 ||
            cp_nelem   == 0 || cp_optelem == 0) {
            printf( "ERROR    Column not found in RIPTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

        /* Get # of matching rows. */

        nrows = c_tbpsta (tp, TBL_NROWS);
        scf->nrp = 0;
        for (row = 1; row <= nrows; row++) {
            c_tbegti (tp, cp_cenwave, row, &i);
            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);
            if (c_iraferr())
                return (TABLE_ERROR);

            if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem)))
                (scf->nrp)++;
        }
        if (scf->nrp == 0) {
            printf ("ERROR    No matching rows in RIPTAB `%s'\n", name);
            return (TABLE_ERROR);
        }

        /* Alloc memory. */

        scf->rpfunc = (RippleFunc *) calloc (scf->nrp, sizeof (RippleFunc));
        if (scf->rpfunc == NULL)
            return (OUT_OF_MEMORY);

        /* Ingest data from matching rows. */

        k = 0;
        for (row = 1; row <= nrows ; row++) {

            c_tbegti (tp, cp_cenwave, row, &i);
            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);
            if (c_iraferr())
                return (TABLE_ERROR);

            if ((i == cenwave) && (streq_ic (opt_elem, scf->opt_elem))) {

                c_tbegti (tp, cp_sporder, row, &(scf->rpfunc[k].sporder));
                if (c_iraferr())
                    return (TABLE_ERROR);
                scf->rpfunc[k].nelem = c_tbcigi (cp_ripple,
                                                 TBL_COL_LENDATA);
                scf->rpfunc[k].wavelengths = (double *) calloc (
                                             scf->rpfunc[k].nelem,
                                             sizeof (double));
                if (scf->rpfunc[k].wavelengths == NULL)
                    return (OUT_OF_MEMORY);
                scf->rpfunc[k].values = (double *) calloc (
                                         scf->rpfunc[k].nelem,
                                         sizeof (double));
                if (scf->rpfunc[k].values == NULL)
                    return (OUT_OF_MEMORY);
                i = c_tbagtd (tp, cp_wave, row, scf->rpfunc[k].wavelengths,
                              1, scf->rpfunc[k].nelem);
                if (c_iraferr())
                    return (TABLE_ERROR);
                i = c_tbagtd (tp, cp_ripple, row, scf->rpfunc[k].values,
                              1, scf->rpfunc[k].nelem);
                if (c_iraferr())
                    return (TABLE_ERROR);

                k++;
            }
        }

        c_tbtclo (tp);

        return (STIS_OK);
}
Exemple #21
0
static int GetHalo (char *name, ScatterFunctions *scf,
                    Image *halo1, Image *halo2, Image *halo3) {

/*
char *name;             i: name of HALOTAB reference file
ScatterFunctions *scf;  o: data structure with scattering functions
Image *halo1,2,3;       o: halo images, previously initialized
*/

        IRAFPointer tp;
        IRAFPointer cp_optelem, cp_refwave, cp_haldim, cp_halo;
        char opt_elem[STIS_CBUF];
        int row, nrows, i, status, k, haldim;
        double rw;

        int Alloc2DImage (Image *, int, int);

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    HALOTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        nrows = c_tbpsta (tp, TBL_NROWS);
        c_tbcfnd1 (tp, "OPT_ELEM", &cp_optelem);
        c_tbcfnd1 (tp, "HALOWAVE", &cp_refwave);
        c_tbcfnd1 (tp, "HALDIM",   &cp_haldim);
        c_tbcfnd1 (tp, "HALO",     &cp_halo);
        if (cp_optelem == 0 || cp_refwave == 0 ||
            cp_haldim  == 0 || cp_halo    == 0) {
            printf( "ERROR    Column not found in HALOTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

        k = 0;
        for (row = 1; row <= nrows ; row++) {

            c_tbegtt (tp, cp_optelem, row, opt_elem, STIS_CBUF-1);
            c_tbegtd (tp, cp_refwave, row, &rw);
            if (c_iraferr())
                return (TABLE_ERROR);

            if ((rw == scf->kernw[k]) &&
                (streq_ic (opt_elem, scf->opt_elem))) {

                c_tbegti (tp, cp_haldim, row, &haldim);

                /* This awful code is a consequence of the
                   change in reference file format that took place
                   after the original code was completed.
                */
                switch (k) {
                case 0:
                    if ((status = Alloc2DImage (halo1, haldim, haldim)))
                        return (status);
                    i = c_tbagtr (tp, cp_halo, row, halo1->pix, 1, halo1->npix);
                    if (c_iraferr())
                        return (TABLE_ERROR);
                    break;
                case 1:
                    if ((status = Alloc2DImage (halo2, haldim, haldim)))
                        return (status);
                    i = c_tbagtr (tp, cp_halo, row, halo2->pix, 1, halo2->npix);
                    if (c_iraferr())
                        return (TABLE_ERROR);
                    break;
                case 2:
                    if ((status = Alloc2DImage (halo3, haldim, haldim)))
                        return (status);
                    i = c_tbagtr (tp, cp_halo, row, halo3->pix, 1, halo3->npix);
                    if (c_iraferr())
                        return (TABLE_ERROR);
                    break;
                default:
                    break;
                }

                k++;
            }
        }

        if (k == 0) {
            printf ("ERROR    No matching rows in HALOTAB `%s'\n", name);
            return (TABLE_ERROR);
        }

        c_tbtclo (tp);
        return (STIS_OK);
}
Exemple #22
0
static int ReadOverTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

	extern int status;

	c_tbegtt (tabinfo->tp, tabinfo->cp_amp, row,
			tabrow->ccdamp, ACS_CBUF-1);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_chip, row, &tabrow->chip);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
		
	c_tbegti (tabinfo->tp, tabinfo->cp_binx, row, &tabrow->bin[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);		
	c_tbegti (tabinfo->tp, tabinfo->cp_biny, row, &tabrow->bin[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
		
	c_tbegti (tabinfo->tp, tabinfo->cp_nx, row, &tabrow->nx);
	if (c_iraferr())
	    return (status = TABLE_ERROR);	
	c_tbegti (tabinfo->tp, tabinfo->cp_ny, row, &tabrow->ny);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_trimx1, row, &tabrow->trimx[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_trimx2, row, &tabrow->trimx[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_trimy1, row, &tabrow->trimy[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_trimy2, row, &tabrow->trimy[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_vx1, row, &tabrow->vx[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_vx2, row, &tabrow->vx[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_vy1, row, &tabrow->vy[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);
	c_tbegti (tabinfo->tp, tabinfo->cp_vy2, row, &tabrow->vy[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_biassecta1, row, &tabrow->biassecta[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_biassecta2, row, &tabrow->biassecta[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_biassectb1, row, &tabrow->biassectb[0]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);

	c_tbegti (tabinfo->tp, tabinfo->cp_biassectb2, row, &tabrow->biassectb[1]);
	if (c_iraferr())
	    return (status = TABLE_ERROR);


	return (status);
}
Exemple #23
0
/*  rejpar_in -- Read parameters either from user input or table.

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

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


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

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

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

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

    crsplit_in = nimgs;

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

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

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

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

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

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

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

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

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

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

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

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

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

        c_tbtclo (tp);
    }

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

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

/* Read a boolean value from a table column.
arguments:
IRAFPointer tp          i: table descriptor
IRAFPointer cp          i: column descriptor
int row                 i: row number (one indexed)
Bool *buffer            o: value (True or False) read from table
*/

        TableDescr *tbl_descr;
        ColumnDescr *col_descr;
        int anynul=0;
        long firstelem=1, nelem=1;
        int nulval=0;
        char s_value[11]={'\0'};
        int status = 0;

        tbl_descr = (TableDescr *)tp;
        col_descr = (ColumnDescr *)cp;

        if (col_descr->datatype < 0) {
            char *value;
            int maxch;
            maxch = col_descr->width + 5;
            value = (char *)calloc (maxch, sizeof(char));
            c_tbegtt (tp, cp, row, value, maxch);
            str_lower (value, value);
            if (strcmp (value, "1") == 0) {
                *buffer = True;
            } else if (strcmp (value, "0") == 0) {
                *buffer = False;
            } else if (strncmp (value, "yes", 3) == 0 ||
                       strncmp (value, "true", 4) == 0) {
                *buffer = True;
            } else {
                *buffer = False;
            }
            free (value);

        } else if (col_descr->datatype == IRAF_INT) {
            int i_value;
            c_tbegti (tp, cp, row, &i_value);
            if (i_value == IRAF_INDEFI)
                *buffer = False;
            else if (i_value)
                *buffer = True;
            else
                *buffer = False;

        } else if (col_descr->datatype == IRAF_SHORT) {
            short si_value;
            c_tbegts (tp, cp, row, &si_value);
            if (si_value == IRAF_INDEFS)
                *buffer = False;
            else if (si_value)
                *buffer = True;
            else
                *buffer = False;

        } else {

            /* fits_read_col_log = ffgcvl */
            fits_read_col_log (tbl_descr->fptr, col_descr->colnum,
                (long)row, firstelem, nelem, nulval,
                s_value, &anynul, &status);
            if (status != 0)
                setError (status, "c_tbegtb:  error reading element");
            if (s_value[0])
                *buffer = True;
            else
                *buffer = False;
        }
}