コード例 #1
0
ファイル: getsdc6.c プロジェクト: jhunkeler/hstcal
static int ReadSDistArray (TblInfo *tabinfo, int row, CoordInfo **coords) {

	int status;

	CoordInfo *newrec;
	int NewCoord6 (CoordInfo **, CoordInfo *);

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

	/* Get size info and coordinate parameters. */
	c_tbegti (tabinfo->tp, tabinfo->cp_sporder, row, &newrec->sporder);
	c_tbegtd (tabinfo->tp, tabinfo->cp_a2center, row, &newrec->a2center);
	c_tbegtd (tabinfo->tp, tabinfo->cp_cdelt2, row, &newrec->cdelt2);
	c_tbegti (tabinfo->tp, tabinfo->cp_npix, row, &newrec->npix);
	if (c_iraferr())
	    return (TABLE_ERROR);

	/* Insert in the coords list. */
	if ((status = NewCoord6 (coords, newrec)))
	    return (status);

	free (newrec);

	return (0);
}
コード例 #2
0
ファイル: getlintab.c プロジェクト: jhunkeler/hstcal
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);
}
コード例 #3
0
ファイル: getprofile.c プロジェクト: jhunkeler/hstcal
static int ReadProfileArray (TblInfo *tabinfo, int row, ProfileArray **profa,
                             double *subscale) {
	int status;

	int npts1, npts2;
	ProfileArray *newp;
	int NewProfile (ProfileArray **, ProfileArray *);

	if ((newp = (ProfileArray *) malloc (sizeof (ProfileArray))) == NULL) {
	    printf ("ERROR    Can't allocate memory.\n");
	    return (OUT_OF_MEMORY);
	}
	newp->next = NULL;

	/* Get profile scalar data. */
	c_tbegti (tabinfo->tp, tabinfo->cp_npts,     row, &newp->npts);
	c_tbegti (tabinfo->tp, tabinfo->cp_nptsoff,  row, &newp->nptsoff);
	c_tbegtd (tabinfo->tp, tabinfo->cp_subscale, row, subscale);
	c_tbegtd (tabinfo->tp, tabinfo->cp_minw,     row, &newp->minw);
	c_tbegtd (tabinfo->tp, tabinfo->cp_maxw,     row, &newp->maxw);
	c_tbegti (tabinfo->tp, tabinfo->cp_minp,     row, &newp->minp);
	c_tbegti (tabinfo->tp, tabinfo->cp_maxp,     row, &newp->maxp);
	c_tbegtr (tabinfo->tp, tabinfo->cp_sn,       row, &newp->sn);

	/* Alloc array memory. */
	newp->profoff = (double *) malloc (newp->nptsoff * sizeof (double));
	newp->prof    = (double *) malloc (newp->npts * sizeof (double));
	if (newp->profoff == NULL || newp->prof == NULL) {
	    printf ("ERROR    Can't allocate memory.\n");
	    return (OUT_OF_MEMORY);
	}

	/* Get profile array data. */
	npts1 = c_tbagtd (tabinfo->tp, tabinfo->cp_profoff, row,
			 newp->profoff, 1, newp->nptsoff);
	if (c_iraferr())
	    return (TABLE_ERROR);
	npts2 = c_tbagtd (tabinfo->tp, tabinfo->cp_prof, row,
			 newp->prof, 1, newp->npts);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (npts1 != newp->nptsoff) {
	    c_tbtclo (tabinfo->tp);
	    printf ("ERROR    Inconsistent array info in OPROFTAB\n");
	    return (TABLE_ERROR);
	}

	/* Insert newp into the profile list. */
	if ((status = NewProfile (profa, newp)))
	    return (status);

	free (newp->profoff);
	free (newp->prof);
	free (newp);

	return (0);
}
コード例 #4
0
ファイル: getdisp4.c プロジェクト: brechmos-stsci/hstcal
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);
}
コード例 #5
0
ファイル: gettrace6.c プロジェクト: brechmos-stsci/hstcal
static int ReadTraceArray (TblInfo *tabinfo, int row, StisInfo6* sts, SpTrace **trace) {

	int status;

	int nelem;		/* number of elements read from table */
	double mjd;             /* MJD */
	double degperyr;        /* rate of trace rotation */

	SpTrace *newd;
	int NewTrace6 (SpTrace **, SpTrace *);

	if ((newd = (SpTrace *) malloc (sizeof (SpTrace))) == NULL) {
	    printf ("ERROR    Can't allocate memory.\n");
	    return (OUT_OF_MEMORY);
	}
	newd->next = NULL;

	/* Get spectrum trace and other info. */
	c_tbegtd (tabinfo->tp, tabinfo->cp_a1center, row, &newd->a1center);
	c_tbegtd (tabinfo->tp, tabinfo->cp_a2center, row, &newd->a2center);

	c_tbegti (tabinfo->tp, tabinfo->cp_nelem, row, &newd->nelem);
	if (newd->nelem > MAX_SP_TRACE) {
	    printf ("ERROR    Spectrum trace in SPTRCTAB is too large.\n");
	    return (TABLE_ERROR);
	}
	nelem = c_tbagtd (tabinfo->tp, tabinfo->cp_a2displ, row,
			newd->a2displ, 1, newd->nelem);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (tabinfo->cp_mjd != 0) {
	    c_tbegtd (tabinfo->tp, tabinfo->cp_mjd, row, &mjd);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_degperyr, row, &degperyr);
	    sts->trace_rotation = rotatetrace(sts->expstart, mjd, degperyr, newd->a2displ, nelem);
	}

	/* Convert a1center and a2center to zero-indexed. */
	newd->a1center--;
	newd->a2center--;

	if (nelem < newd->nelem) {
	    c_tbtclo (tabinfo->tp);
	    printf ("ERROR    Not all elements were read from SPTRCTAB\n");
	    return (TABLE_ERROR);
	}

	/* Insert newd into the SpTrace list. */
	if ((status = NewTrace6 (trace, newd)))
	    return (status);

	free (newd);

	return (0);
}
コード例 #6
0
ファイル: getapoffset6.c プロジェクト: jhunkeler/hstcal
static int ReadApTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

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

	return (0);
}
コード例 #7
0
ファイル: gettdccorr.c プロジェクト: brechmos-stsci/hstcal
static int ReadTdcTab (TblInfo *tabinfo, int row, TblRow *tabrow) {

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

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

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

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

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

	return 0;
}
コード例 #8
0
ファイル: getdisp.c プロジェクト: jhunkeler/hstcal
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);
}
コード例 #9
0
ファイル: getdisp4.c プロジェクト: brechmos-stsci/hstcal
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);

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

	return (0);
}
コード例 #10
0
ファイル: doatod.c プロジェクト: jhunkeler/hstcal
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);
}
コード例 #11
0
ファイル: doatod.c プロジェクト: jhunkeler/hstcal
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);
}
コード例 #12
0
ファイル: getabsphot.c プロジェクト: brechmos-stsci/hstcal
static int ReadPhotData (TblInfo *tabinfo, int row, PhotInfo *phot) {

	int nwl, nthru;		/* number of elements actually read */

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

	phot->wl = (double *) malloc (phot->nelem * sizeof(double));
	phot->thru = (double *) malloc (phot->nelem * sizeof(double));
	if (phot->wl == NULL || phot->thru == NULL)
	    return (OUT_OF_MEMORY);

	nwl = c_tbagtd (tabinfo->tp, tabinfo->cp_wl, row,
			phot->wl, 1, phot->nelem);
	if (c_iraferr())
	    return (TABLE_ERROR);

	nthru = c_tbagtd (tabinfo->tp, tabinfo->cp_thru, row,
			phot->thru, 1, phot->nelem);
	if (c_iraferr())
	    return (TABLE_ERROR);

	if (nwl < phot->nelem || nthru < phot->nelem) {
	    c_tbtclo (tabinfo->tp);
	    free (phot->wl);
	    free (phot->thru);
	    printf ("ERROR    Not all elements were read from PHOTTAB.\n");
	    return (TABLE_ERROR);
	}

	phot->allocated = 1;			/* set flag */

	if (phot->blazecorr == PERFORM) {

	    c_tbegti (tabinfo->tp, tabinfo->cp_mref, row, &phot->mref);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_wref, row, &phot->wref);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_yref, row, &phot->yref);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_mjd,  row, &phot->mjd);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_mx,   row, &phot->mx);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_my,   row, &phot->my);
	    c_tbegtd (tabinfo->tp, tabinfo->cp_mt,   row, &phot->mt);
	    if (tabinfo->cp_m0 == 0)
		phot->m0 = 0.;
	    else
		c_tbegtd (tabinfo->tp, tabinfo->cp_m0, row, &phot->m0);

	    if (c_iraferr()) {
	        free (phot->wl);
	        free (phot->thru);
	        free (phot->error);
	        return (TABLE_ERROR);
	    }

	    /* Reference data is 1-indexed ! */
	    phot->yref -= 1.0;
	}

	return (0);
}
コード例 #13
0
ファイル: c_tbegt.c プロジェクト: jhunkeler/hstcal
double c_tbeGetDouble (const IRAFPointer tp, const IRAFPointer cp, int row)
{
	double ret = 0;
	c_tbegtd(tp, cp, row, &ret);
	return ret;
}
コード例 #14
0
ファイル: echscatread.c プロジェクト: brechmos-stsci/hstcal
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);
}
コード例 #15
0
ファイル: echscatread.c プロジェクト: brechmos-stsci/hstcal
static int GetPSF (char *name, Hdr *phdr, double xsize, double ysize,
                   ScatterFunctions *scf,
                   Image *psf1, Image *psf2, Image *psf3) {

/*
char *name;             i: name of TELTAB reference file
Hdr *phdr               i: primary header
double xsize, ysize;    i: aperture size in arcsec
ScatterFunctions *scf;  o: data structure with scattering functions
Image *psf1,2,3;        o: PSF images, previously initialized
*/
        IRAFPointer tp;
        IRAFPointer cp_refwave, cp_pscale, cp_psfdim, cp_telepsf;
        int row, nrows, psfdim;
        double rw, psfscale;
        Image ospsf;
        Image imtemp, psf;
        char keyword[STIS_CBUF];
        double xplate, yplate;
        double sbox, lbox;
        double rstart, rstop;
        double frac1, frac2;
        float fhold;
        double sum;
        int i, j, k, kk, ms, ml, ns, nl, s, l;
        int ns2, nl2, s1, s2, l1, l2;
        int istart, istop;
        int status;

        int Alloc1DImage (Image *, int);
        int Alloc2DImage (Image *, int, int);
        void InitImage (Image *);
        void FreeImage (Image *);

        /* Define plate scale. */

        if (streq_ic (scf->opt_elem, "E140M"))
            xplate = 0.036;
        else if (streq_ic (scf->opt_elem, "E140H"))
            xplate = 0.0466;
        else if (streq_ic (scf->opt_elem, "E230M"))
            xplate = 0.033;
        else if (streq_ic (scf->opt_elem, "E230H"))
            xplate = 0.0466;
        else {
            printf ("Non supported grating.\n");
            return (ERROR_RETURN);
        }
        yplate = 0.029;

        /* Truncate the aperture size if it extends beyond the borders
           of an image.
        */

        /* See if uniformly illuminated aperture was used. */

        if ((status = Get_KeyS (phdr, "SCLAMP", 0, "", keyword, STIS_CBUF)))
            return (status);
        if (!streq_ic (keyword, "NONE")) {
            ml = (int)floor (ysize / yplate);
            if (ml % 2) {
                status  = Alloc1DImage (psf1, ml+1);
                status |= Alloc1DImage (psf2, ml+1);
                status |= Alloc1DImage (psf3, ml+1);
                if (status)
                    return (status);
                for (i = 1; i < ml; i++) {
                    psf1->pix[i] = 1.0 / ml;
                    psf2->pix[i] = 1.0 / ml;
                    psf3->pix[i] = 1.0 / ml;
                }
                psf1->pix[0]  = 0.5 / ml;
                psf1->pix[ml] = 0.5 / ml;
                psf2->pix[0]  = 0.5 / ml;
                psf2->pix[ml] = 0.5 / ml;
                psf3->pix[0]  = 0.5 / ml;
                psf3->pix[ml] = 0.5 / ml;
            } else {
                status  = Alloc1DImage (psf1, ml);
                status |= Alloc1DImage (psf2, ml);
                status |= Alloc1DImage (psf3, ml);
                if (status)
                    return (status);
                for (i = 0; i < ml; i++) {
                    psf1->pix[i] = 1.0 / ml;
                    psf2->pix[i] = 1.0 / ml;
                    psf3->pix[i] = 1.0 / ml;
                }
            }
            return (STIS_OK);
        }

        /* Scan reference file and process each PSF. */

        tp = c_tbtopn (name, IRAF_READ_ONLY, 0);
        if (c_iraferr()) {
            printf ("ERROR    TELTAB `%s' not found\n", name);
            return (OPEN_FAILED);
        }
        nrows = c_tbpsta (tp, TBL_NROWS);
        c_tbcfnd1 (tp, "PSFWAVE", &cp_refwave);
        c_tbcfnd1 (tp, "PSCALE",  &cp_pscale);
        c_tbcfnd1 (tp, "PSFDIM",  &cp_psfdim);
        c_tbcfnd1 (tp, "TELEPSF", &cp_telepsf);
        if (cp_refwave == 0 || cp_psfdim  == 0 ||
            cp_pscale  == 0 || cp_telepsf == 0) {
            printf( "ERROR    Column not found in TELTAB\n");
            c_tbtclo (tp);
            return (COLUMN_NOT_FOUND);
        }

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

            c_tbegtd (tp, cp_refwave, row, &rw);
            if (c_iraferr())
                return (TABLE_ERROR);

            /* Matching reference wavelenghts. */

            if (rw == scf->psfw[kk]) {

                /* Read PSF image and associated data. */

                c_tbegtd (tp, cp_pscale, row, &psfscale);
                c_tbegti (tp, cp_psfdim, row, &psfdim);

                InitImage (&imtemp);
                if ((status = Alloc2DImage (&imtemp, psfdim, psfdim)))
                    return (status);
                i = c_tbagtr (tp, cp_telepsf, row, imtemp.pix, 1,
                              imtemp.npix);
                if (c_iraferr())
                    return (TABLE_ERROR);

                /* Find peak. */

                ns = imtemp.nx;
                nl = imtemp.ny;
                fhold = -FLT_MAX;
                for (i = 0; i < ns; i++) {
                    for (j = 0; j < nl; j++) {
                        if (PIX (imtemp, i, j) > fhold) {
                            s = i;
                            l = j;
                            fhold = PIX (imtemp, i, j);
                        }
                    }
                }

                /* Determine portion of PSF that made it through aperture. */

                ns2 = ((int)NINT (xsize / psfscale)) / 2;
                nl2 = ((int)NINT (ysize / psfscale)) / 2;
                s1  = ((s - ns2) >= 0) ? (s - ns2) : 0;
                s2  = ((s + ns2) <= (ns - 1)) ? (s + ns2) : (ns - 1);
                l1  = ((l - nl2) >= 0) ? (l - nl2) : 0;
                l2  = ((l + nl2) <= (nl - 1)) ? (l + nl2) : (nl - 1);

                /* Extract sub-image. */

                InitImage (&ospsf);
                if ((status = Alloc2DImage (&ospsf, s2 - s1 + 1, l2 - l1 + 1)))
                    return (status);
                k = 0;
                /* location of braces looks like a typo, but harmless */
                for (j = l1; j <= l2; j++)
                    for (i = s1; i <= s2; i++) {
                        ospsf.pix[k++] = PIX (imtemp, i, j);
                }
                FreeImage (&imtemp);
                ns = ospsf.nx;
                nl = ospsf.ny;

                /* # of STIS pixels (ms*ml) illuminated by aperture. */

                /* modified on 2013 Nov 13 by PEH
                   xplate / psfscale and yplate / psfscale are the factors
                   by which the PSF in the _tel.fits file are oversampled.
                */
                ms = (NINT (ns / (xplate / psfscale))) / 2;
                ml = (NINT (nl / (yplate / psfscale))) / 2;
                ms = 2 * ms + 1;
                ml = 2 * ml + 1;

                /* Bin oversampled PSF to STIS pixel scale. */

                /* Bin columns. */

                if ((status = Alloc2DImage (&imtemp, ms, nl)))
                    return (status);
                sbox = ns / (double)ms;
                for (i = 0; i < ms; i++) {
                    rstart = i     * sbox;
                    rstop  = (i+1) * sbox;
                    istart = (int) floor (rstart);
                    istop  = (int) floor (rstop);
                    istop = (istop < ns) ? istop : ns-1;
                    frac1 = rstart - istart;
                    frac2 = 1.0 - (rstop - istop);
                    for (j = 0; j < nl; j++) {
                        for (k = istart+1; k < istop;
                            PIX (imtemp, i, j) += PIX (ospsf, k++, j));
                        PIX (imtemp, i, j) += PIX (ospsf, istart, j) *
                                              (1.0 - frac1);
                        PIX (imtemp, i, j) += PIX (ospsf, istop,  j) *
                                              (1.0 - frac2);
                    }
                }
                FreeImage (&ospsf);

                /* Bin rows. */

                InitImage (&psf);
                if ((status = Alloc2DImage (&psf, ms, ml)))
                    return (status);
                lbox = nl / (double)ml;
                for (j = 0; j < ml; j++) {
                    rstart = j     * lbox;
                    rstop  = (j+1) * lbox;
                    istart = (int) floor (rstart);
                    istop  = (int) floor (rstop);
                    istop = (istop < nl) ? istop : nl-1;
                    frac1 = rstart - istart;
                    frac2 = 1.0 - (rstop - istop);
                    for (i = 0; i < ms; i++) {
                        for (k = istart+1; k < istop;
                             PIX (psf, i, j) += PIX (imtemp, i, k++));
                        PIX (psf, i, j) += PIX (imtemp, i, istart) *
                                            (1.0 - frac1);
                        PIX (psf, i, j) += PIX (imtemp, i, istop) *
                                            (1.0 - frac2);
                    }
                }
                FreeImage (&imtemp);

                /* Normalize PSF to unit area. */

                sum = 0.0;
                for (i = 0; i < psf.npix; sum += psf.pix[i++]);
                for (i = 0; i < psf.npix; psf.pix[i++] /= sum);

                /* This awful code is a consequence of the
                   change in reference file format that took place
                   after the original code was completed.
                */
                switch (kk) {
                case 0:
                    if ((status = Alloc2DImage (psf1, psf.nx, psf.ny)))
                        return (status);
                    for (i= 0 ; i < psf1->npix; i++)
                        psf1->pix[i] = psf.pix[i];
                    break;
                case 1:
                    if ((status = Alloc2DImage (psf2, psf.nx, psf.ny)))
                        return (status);
                    for (i= 0 ; i < psf2->npix; i++)
                        psf2->pix[i] = psf.pix[i];
                    break;
                case 2:
                    if ((status = Alloc2DImage (psf3, psf.nx, psf.ny)))
                        return (status);
                    for (i= 0 ; i < psf3->npix; i++)
                        psf3->pix[i] = psf.pix[i];
                    break;
                default:
                    break;
                }

                FreeImage (&psf);
                kk++;
            }
        }

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

        c_tbtclo (tp);
        return (STIS_OK);
}
コード例 #16
0
ファイル: c_tbegt.c プロジェクト: jhunkeler/hstcal
void c_tbegtt (const IRAFPointer tp, const IRAFPointer cp, int row, char *buffer,
                int maxch) {

/* Read a string value from a table column.
arguments:
IRAFPointer tp          i: table descriptor
IRAFPointer cp          i: column descriptor
int row                 i: row number (one indexed)
char *buffer            o: value read from table
int maxch               i: maximum length of the string (not incl NULL)
*/

        TableDescr *tbl_descr;
        ColumnDescr *col_descr;
        int anynul=0;
        long firstelem=1, nelem=1;
        char *value;
        int len;
        int status = 0;

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

        if (col_descr->datatype < 0) {
            if (col_descr->width >= maxch)
                len = col_descr->width;
            else
                len = maxch;
        } else {
            len = SZ_FITS_STR;
        }
        value = (char *)calloc (len+1, sizeof(char));

        if (col_descr->datatype == IRAF_BOOL) {
            Bool b_value;
            c_tbegtb (tp, cp, row, &b_value);
            if (b_value == True)
                strcpy (value, "yes");
            else
                strcpy (value, "no");

        } else if (col_descr->datatype == IRAF_DOUBLE) {
            double d_value;
            c_tbegtd (tp, cp, row, &d_value);
            if (d_value == IRAF_INDEFD)
                strcpy (value, "INDEF");
            else
                sprintf (value, "%.16g", d_value);

        } else if (col_descr->datatype == IRAF_REAL) {
            float r_value;
            c_tbegtr (tp, cp, row, &r_value);
            if (r_value >= 0.99999 * IRAF_INDEFR &&
                r_value <= 1.00001 * IRAF_INDEFR) {
                strcpy (value, "INDEF");
            } else {
                sprintf (value, "%.7g", r_value);
            }

        } else if (col_descr->datatype == IRAF_INT) {
            int i_value;
            c_tbegti (tp, cp, row, &i_value);
            if (i_value == IRAF_INDEFI)
                strcpy (value, "INDEF");
            else
                sprintf (value, "%d", i_value);

        } else if (col_descr->datatype == IRAF_SHORT) {
            short si_value;
            c_tbegts (tp, cp, row, &si_value);
            if (si_value == IRAF_INDEFS)
                strcpy (value, "INDEF");
            else
                sprintf (value, "%hd", si_value);

        } else {

            /* fits_read_col_str = ffgcvs */
            fits_read_col_str (tbl_descr->fptr, col_descr->colnum,
                (long)row, firstelem, nelem, "INDEF",
                &value, &anynul, &status);
            if (status != 0)
                setError (status, "c_tbegtt:  error reading element");
        }

        copyString (buffer, value, maxch);

        free (value);
}
コード例 #17
0
ファイル: gettdccorr.c プロジェクト: brechmos-stsci/hstcal
static int postSM4TdcCorr(StisInfo1 *sts, double mean_dark,
                          double *factor) {

/* arguments:
StisInfo1 *sts          i: calibration switches, etc
double mean_dark        i: mean of good pixels of dark reference image
                           (binned to 1024x1024 pixels in size)
double *factor          o: NUV correction factor for dark image
*/
        /*int status;*/

	IRAFPointer tp;			/* pointer to table descriptor */
	/* column descriptors */
	IRAFPointer cp_date0, cp_temp0,
		cp_a1, cp_d1, cp_a2, cp_d2, cp_ta, cp_tb, cp_tc;
	int nrows;			/* number of rows in table */
	/* values read from a table row */
	double date0;			/* reference date */
	double temp0;			/* reference temperature */
	double a1;
	double d1;
	double a2;
	double d2;
	double ta;
	double tb;
	double tc;
	int row;			/* loop index for row number */
	int read_this_row = -1;		/* number of row of table to read */
	double min_date0 = 0.;		/* min value of data0 */
	double best_date0 = 0.;		/* date0 in row to use */
	double d_date;			/* expstart - date0 */
	double d_temp;			/* temperature - temp0 */
	double count_rate;		/* computed count rate at EXPSTART */

	tp = c_tbtopn(sts->tdctab.name, IRAF_READ_ONLY, 0);
	if (c_iraferr()) {
	    printf("ERROR    Can't open TDCTAB `%s'.\n", sts->tdctab.name);
	    return OPEN_FAILED;
	}
	nrows = c_tbpsta(tp, TBL_NROWS);
	if (nrows < 1) {
	    printf("ERROR    TDCTAB %s is empty.\n", sts->tdctab.name);
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	/* Look for all of the columns we require. */
	c_tbcfnd1(tp, "DATE0", &cp_date0);
	c_tbcfnd1(tp, "TEMP0", &cp_temp0);
	c_tbcfnd1(tp, "A1", &cp_a1);
	c_tbcfnd1(tp, "D1", &cp_d1);
	c_tbcfnd1(tp, "A2", &cp_a2);
	c_tbcfnd1(tp, "D2", &cp_d2);
	c_tbcfnd1(tp, "TA", &cp_ta);
	c_tbcfnd1(tp, "TB", &cp_tb);
	c_tbcfnd1(tp, "TC", &cp_tc);
	if (cp_date0 == 0 || cp_temp0 == 0 ||
	    cp_a1 == 0 || cp_d1 == 0 ||
	    cp_a2 == 0 || cp_d2 == 0 ||
	    cp_ta == 0 || cp_tb == 0 || cp_tc == 0) {
	    printf("ERROR    Column not found in TDCTAB.\n");
	    c_tbtclo(tp);
	    return COLUMN_NOT_FOUND;
	}

	/* Find the minimum value in the DATE0 column. */
	for (row = 1;  row <= nrows;  row++) { /* row number is one-indexed */
	    c_tbegtd(tp, cp_date0, row, &date0);
	    if (c_iraferr()) {
		c_tbtclo(tp);
		return TABLE_ERROR;
	    }
	    if (row == 1)
		min_date0 = date0;
	    else if (date0 < min_date0)
		min_date0 = date0;
	}
	if (sts->expstart < min_date0) {
	    printf("ERROR    Exposure start time precedes earliest date "
	           "in TDCTAB.\n");
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	/* Select the row such that DATE0 is less than but closest to
	   the exposure start time.
	*/
	best_date0 = min_date0;			/* initial value */
	for (row = 1;  row <= nrows;  row++) {
	    c_tbegtd(tp, cp_date0, row, &date0);
	    if (c_iraferr()) {
		c_tbtclo(tp);
		return TABLE_ERROR;
	    }
	    if (date0 < sts->expstart && (row == 1 || date0 > best_date0)) {
		best_date0 = date0;
		read_this_row = row;
	    }
	}
	if (read_this_row < 1) {
	    c_tbtclo(tp);
	    printf("Warning:  No valid row found in TDCTAB %s\n",
	           sts->tdctab.name);
	    *factor = 1.;
	    return 0;
	}

	c_tbegtd(tp, cp_date0, read_this_row, &date0);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}
	d_date = sts->expstart - date0;

	c_tbegtd(tp, cp_temp0, read_this_row, &temp0);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}
	d_temp = sts->detector_temp - temp0;

	c_tbegtd(tp, cp_a1, read_this_row, &a1);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_d1, read_this_row, &d1);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_a2, read_this_row, &a2);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_d2, read_this_row, &d2);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_ta, read_this_row, &ta);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_tb, read_this_row, &tb);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbegtd(tp, cp_tc, read_this_row, &tc);
	if (c_iraferr()) {
	    c_tbtclo(tp);
	    return TABLE_ERROR;
	}

	c_tbtclo(tp);

	count_rate = a1 * exp(-d_date / d1) +
	             a2 * exp(-d_date / d2) +
	             ta + tb * d_temp +
	                  tc * d_temp * d_temp;

	if (count_rate > 100.) {
	    printf("Warning  TDC dark count rate = %.6g\n", count_rate);
	}
	*factor = count_rate / mean_dark;
	if (fabs(*factor) > 100. || fabs(*factor) < 0.01) {
	    printf("Warning  TDC correction factor = %.6g.\n", *factor);
	}

	return 0;
}
コード例 #18
0
ファイル: getgrpinfo4.c プロジェクト: brechmos-stsci/hstcal
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");
}