Skip to content

Commit

Permalink
Merge pull request #106 from jamienoss/infrastructure-changes-from-#101
Browse files Browse the repository at this point in the history
Infrastructure changes, inc. hstio
  • Loading branch information
jamienoss authored May 2, 2017
2 parents 67c346c + 9ae69aa commit 43bc710
Show file tree
Hide file tree
Showing 27 changed files with 566 additions and 154 deletions.
456 changes: 406 additions & 50 deletions hstio/hstio.c

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions hstio/keyword.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static int insertname(FitsKwInfo *kw, char *nm) {
int orig_nlines = 0;

if (kw->hdr->nalloc == 0) {
if (allocHdr(kw->hdr,HdrUnit) != 0)
if (allocHdr(kw->hdr,HdrUnit, True) != 0)
return -1;
}
if (kw->hdr->nlines == kw->hdr->nalloc) {
Expand Down Expand Up @@ -275,7 +275,7 @@ static int addcommentary(Hdr *h, char *text, char *type) {
int nblankline = 0;
char *t;
if (h->nalloc == 0) {
if (allocHdr(h,HdrUnit) != 0)
if (allocHdr(h,HdrUnit, True) != 0)
return -1;
}
if (h->nlines == h->nalloc) {
Expand Down Expand Up @@ -1165,7 +1165,7 @@ FitsKw insertFitsCard(FitsKw kw_, char *card) {

/* make sure we have room */
if (kw->hdr->nalloc == 0) {
if (allocHdr(kw->hdr,HdrUnit) != 0)
if (allocHdr(kw->hdr,HdrUnit, True) != 0)
{ error(NOMEM,""); return NULL; }
}
if (kw->hdr->nlines == kw->hdr->nalloc) {
Expand Down
48 changes: 39 additions & 9 deletions include/hstio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern "C" {
# endif

# include <stdlib.h>

# define HSTIO_VERSION "HSTIO Version 2.6 (11-Mar-2010)"

/*
Expand Down Expand Up @@ -117,8 +119,6 @@ extern "C" {
**
*/

# include <stdlib.h>

/* Below is a general use pointer register (book keeping) to allow easy cleanup upon exit (pseudo C++ destructor)
* Use example:
*
Expand Down Expand Up @@ -166,13 +166,24 @@ enum Bool_ { False = 0, True = 1 };
typedef enum Bool_ Bool;
# endif

enum StorageOrder
{
ROWMAJOR,
COLUMNMAJOR
};

#define SCIEXT 0x01
#define ERREXT 0x02
#define DQEXT 0x04

typedef struct {
short *buffer; /* the pointer to the beg. of the buffer */
int buffer_size; /* the size of the full 2-d array in the */
int tot_nx; /* buffer. */
int tot_ny; /* buffer_size = tot_nx*tot_ny */
int nx; /* The size of the current "view" of the */
int ny; /* full 2-d array. */
enum StorageOrder storageOrder;
short *data; /* The pointer to the beginning of the */
/* subsection of the full 2-d array. */
} ShortTwoDArray;
Expand All @@ -184,6 +195,7 @@ typedef struct {
int tot_ny;
int nx;
int ny;
enum StorageOrder storageOrder;
float *data;
} FloatTwoDArray;

Expand All @@ -208,10 +220,12 @@ typedef struct {
*/

# define Pix(a,i,j) (a).data[(j)*(a).tot_nx + (i)]
# define PixColumnMajor(a,i,j) (a).data[(j)*(a).tot_ny + (i)]
# define DQPix(a,i,j) (a).data[(j)*(a).tot_nx + (i)]
# define DQSetPix(a,i,j,value) (a).data[(j)*(a).tot_nx + (i)] = (value)

# define PPix(a,i,j) (a)->data[(j)*(a)->tot_nx + (i)]
# define PPixColumnMajor(a,i,j) (a)->data[(j)*(a)->tot_ny + (i)]
# define PDQPix(a,i,j) (a)->data[(j)*(a)->tot_nx + (i)]
# define PDQSetPix(a,i,j,value) (a)->data[(j)*(a)->tot_nx + (i)] = (value)

Expand Down Expand Up @@ -251,6 +265,8 @@ typedef struct {
int sx; /* The sizes of the X and Y dimensions */
int sy; /* of the section. */
} DataSection;
void copyDataSection(DataSection * dest, const DataSection * src);


# define HDRSize 81
typedef char HdrArray[HDRSize]; /* Headers are simply an array of fixed */
Expand Down Expand Up @@ -707,12 +723,14 @@ void updateWCS (Hdr *hdr, int xbeg, int ybeg);
*/
# define IFloatData { NULL, 0, 0, 0, 0, 0, NULL }
void initFloatData(FloatTwoDArray *);
int allocFloatData(FloatTwoDArray *, int, int);
int allocFloatData(FloatTwoDArray *, int, int, Bool zeroInitialize);
void freeFloatData(FloatTwoDArray *);
int swapFloatStorageOrder(FloatTwoDArray * target, const FloatTwoDArray * source, enum StorageOrder targetStorageOrder);
# define IShortData { NULL, 0, 0, 0, 0, 0, NULL }
void initShortData(ShortTwoDArray *);
int allocShortData(ShortTwoDArray *, int, int);
int allocShortData(ShortTwoDArray *, int, int, Bool zeroInitialize);
void freeShortData(ShortTwoDArray *);
int swapShortStorageOrder(ShortTwoDArray * target, const ShortTwoDArray * source, enum StorageOrder targetStorageOrder);

# define IFloatLine { NULL, 0 }
void initFloatLine (FloatHdrLine *);
Expand All @@ -729,18 +747,20 @@ int allocDQLine (SingleGroupLine *);

# define IHdr { 0, 0, NULL }
void initHdr(Hdr *);
int allocHdr(Hdr *, int);
int allocHdr(Hdr *, int, Bool zeroInitialize);
int reallocHdr(Hdr *, int);
void freeHdr(Hdr *);
int copyHdr(Hdr *to, Hdr *from);
int copyHdr(Hdr *to, const Hdr *from);

# define IFloatHdrData { NULL, { 0, 0, 0, 0 }, IHdr, IFloatData }
void initFloatHdrData(FloatHdrData *);
int allocFloatHdrData(FloatHdrData *, int, int);
int allocFloatHdrData(FloatHdrData *, int, int, Bool zeroInitialize);
int copyFloatHdrData(FloatHdrData * target, const FloatHdrData * src, enum StorageOrder targetStorageOrder);
void freeFloatHdrData(FloatHdrData *);
# define IShortHdrData { NULL, { 0, 0, 0, 0 }, IHdr, IShortData }
void initShortHdrData(ShortHdrData *);
int allocShortHdrData(ShortHdrData *, int, int);
int allocShortHdrData(ShortHdrData *, int, int, Bool zeroInitialize);
int copyShortHdrData(ShortHdrData * target, const ShortHdrData * src, enum StorageOrder targetStorageOrder);
void freeShortHdrData(ShortHdrData *);

# define IFloatHdrLine { NULL, IHdr, False, 0, NULL }
Expand All @@ -755,13 +775,23 @@ void freeShortHdrLine (ShortHdrLine *);
# define ISingleGroup { NULL, 0, NULL, IFloatHdrData, IFloatHdrData, \
IShortHdrData }
void initSingleGroup(SingleGroup *);
int allocSingleGroup(SingleGroup *, int, int);
int allocSingleGroup(SingleGroup *, int, int, Bool zeroInitialize);
int allocSingleGroupHeader(Hdr ** hdr, Bool zeroInitialize);
int allocSingleGroupExts(SingleGroup *x, int i, int j, unsigned extension, Bool zeroInitialize);
void freeSingleGroup(SingleGroup *);
void setStorageOrder(SingleGroup * group, enum StorageOrder storageOrder);
int copySingleGroup(SingleGroup * target, const SingleGroup * source, enum StorageOrder targetStorageOrder);
void copyOffsetSingleGroup(SingleGroup * output, const SingleGroup * input, unsigned nRows, unsigned nColumns, unsigned outputOffset, unsigned inputOffset, unsigned outputSkipLength, unsigned inputSkipLength);
# define IMultiGroup { 0, NULL }
void initMultiGroup(MultiGroup *);
int allocMultiGroup(MultiGroup *, int);
void freeMultiGroup(MultiGroup *);

int copyFloatData(FloatTwoDArray * target, const FloatTwoDArray * source, enum StorageOrder targetStorageOrder);
void copyOffsetFloatData(float * output, const float * input, unsigned nRows, unsigned nColumns, unsigned outputOffset, unsigned inputOffset, unsigned outputSkipLength, unsigned inputSkipLength);
int copyShortData(ShortTwoDArray * target, const ShortTwoDArray * source, enum StorageOrder targetStorageOrder);
void copyOffsetShortData(short * output, const short * input, unsigned nRows, unsigned nColumns, unsigned outputOffset, unsigned inputOffset, unsigned outputSkipLength, unsigned inputSkipLength);

# define ISingleNicmosGroup { NULL, 0, NULL, IFloatHdrData, IFloatHdrData, \
IShortHdrData, IShortHdrData, IFloatHdrData }
void initSingleNicmosGroup(SingleNicmosGroup *);
Expand Down
18 changes: 12 additions & 6 deletions include/xtables.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void c_imtclose (IRAFPointer imt);
IRAFPointer c_tbtopn (char *tablename, int iomode, IRAFPointer template);
void c_tbtcre (IRAFPointer tp);
void c_tbtclo (IRAFPointer tp);
void c_tbtClose (IRAFPointer * tp);

int c_tbtacc (char *tablename);
void c_tbtnam (IRAFPointer tp, char *tablename, int maxch);
void c_tbfpri (char *intable, char *outtable, int *copied);
Expand All @@ -68,6 +70,7 @@ int c_tbpsta (IRAFPointer tp, int param);
void c_tbcdef1 (IRAFPointer tp, IRAFPointer *cp,
char *colname, char *colunits, char *colfmt, int datatype, int nelem);
void c_tbcfnd1 (IRAFPointer tp, const char *colname, IRAFPointer *cp);
IRAFPointer c_tbcfnd1_retPtr (IRAFPointer tp, const char *colname);
IRAFPointer c_tbcnum (IRAFPointer tp, int colnum);

int c_tbcigi (IRAFPointer cp, int param);
Expand Down Expand Up @@ -102,13 +105,16 @@ void c_tbrcsc (IRAFPointer itp, IRAFPointer otp,
int irow, int orow, int ncols);
void c_tbrudf (IRAFPointer tp, IRAFPointer *cp, int numcols, int row);

void c_tbegtb (IRAFPointer tp, IRAFPointer cp, int rownum, Bool *buffer);
void c_tbegtd (IRAFPointer tp, IRAFPointer cp, int rownum, double *buffer);
void c_tbegtr (IRAFPointer tp, IRAFPointer cp, int rownum, float *buffer);
void c_tbegti (IRAFPointer tp, IRAFPointer cp, int rownum, int *buffer);
void c_tbegts (IRAFPointer tp, IRAFPointer cp, int rownum, short *buffer);
void c_tbegtt (IRAFPointer tp, IRAFPointer cp, int rownum, char *buffer,
void c_tbegtb (const IRAFPointer tp, const IRAFPointer cp, int rownum, Bool *buffer);
void c_tbegtd (const IRAFPointer tp, const IRAFPointer cp, int rownum, double *buffer);
void c_tbegtr (const IRAFPointer tp, const IRAFPointer cp, int rownum, float *buffer);
void c_tbegti (const IRAFPointer tp, const IRAFPointer cp, int rownum, int *buffer);
void c_tbegts (const IRAFPointer tp, const IRAFPointer cp, int rownum, short *buffer);
void c_tbegtt (const IRAFPointer tp, const IRAFPointer cp, int rownum, char *buffer,
int maxch);
int c_tbeGetInt(const IRAFPointer tp, const IRAFPointer cp, int rownum);
double c_tbeGetDouble(const IRAFPointer tp, const IRAFPointer cp, int rownum);

void c_tbeptb (IRAFPointer tp, IRAFPointer cp, int rownum, Bool buffer);
void c_tbeptd (IRAFPointer tp, IRAFPointer cp, int rownum, double buffer);
void c_tbeptr (IRAFPointer tp, IRAFPointer cp, int rownum, float buffer);
Expand Down
2 changes: 1 addition & 1 deletion pkg/acs/calacs/acs2d/doflat.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static int divFlat (SingleGroup *x, char *flatname, ACSInfo *acs2d) {

/* Initialize shifted spot arrays */
initSingleGroup(&outspot);
allocSingleGroup(&outspot, inspot.sci.data.nx, inspot.sci.data.ny);
allocSingleGroup(&outspot, inspot.sci.data.nx, inspot.sci.data.ny, True);

parseObsDate(x->globalhdr, &date);
status = GetSpotTab(acs2d->spot.name, date, &shiftx, &shifty);
Expand Down
2 changes: 1 addition & 1 deletion pkg/acs/calacs/acsrej/acsrej_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int acsrej_loop (IODescPtr ipsci[], IODescPtr ipdq[],
back into the input DQ arrays at the end of processing, while dq
will hold values to write to the output CRJ DQ extension */
initShortData (&dq2);
allocShortData (&dq2, dim_x, dim_y);
allocShortData (&dq2, dim_x, dim_y, True);
for (j = 0; j < dim_y; j++) {
for (i = 0; i < dim_x; i++) {
PDQSetPix(dq,i,j,crflag);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/dobias.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SingleGroup *x io: image to be calibrated; written to in-place
/* First bin the bias image down to the actual size of x. */

initSingleGroup (&z);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny, True);
if ((status = bin2d (&y, x0, y0, rx, ry, avg, &z))) {
printf ("ERROR (biascorr) size mismatch.\n");
return (status);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/doblev.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int *driftcorr o: true means correction for drift along lines was applied
initSingleGroup (out);
allocSingleGroup (out,
in->sci.data.nx - (trimx1 + trimx2),
in->sci.data.ny - (trimy1 + trimy2));
in->sci.data.ny - (trimy1 + trimy2), True);
if (hstio_err())
return (OUT_OF_MEMORY);

Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/dodark.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int sci_extver i: IMSET number in input (science) file
/* Bin the dark image down to the actual size of x. */

initSingleGroup (&z);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny, True);
if ((status = bin2d (&y, x0, y0, rx, ry, avg, &z))) {
printf ("ERROR (darkcorr) size mismatch.\n");
return (status);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/dodqi.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ SingleGroup *x io: image to be calibrated; DQ array written to in-place

if (!in_place) {
/* Allocate space for a scratch array. */
allocShortData (&ydq, snpix[0], snpix[1]);
allocShortData (&ydq, snpix[0], snpix[1], True);
if (hstio_err()) {
printf (
"ERROR (doDQI) couldn't allocate data quality array.\n");
Expand Down
6 changes: 3 additions & 3 deletions pkg/stis/calstis/cs1/doflat.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SingleGroup *x io: image to be calibrated; written to in-place
if (hstio_err())
return (OPEN_FAILED);

allocSingleGroup (&z, y.sci.data.nx, y.sci.data.ny);
allocSingleGroup (&z, y.sci.data.nx, y.sci.data.ny, True);
if (hstio_err())
return (ALLOCATION_PROBLEM);

Expand Down Expand Up @@ -126,7 +126,7 @@ SingleGroup *x io: image to be calibrated; written to in-place
*/
nx = rx * z.sci.data.nx;
ny = ry * z.sci.data.ny;
allocSingleGroup (&y, nx, ny);
allocSingleGroup (&y, nx, ny, True);
if (hstio_err())
return (ALLOCATION_PROBLEM);

Expand Down Expand Up @@ -198,7 +198,7 @@ SingleGroup *x io: image to be calibrated; written to in-place

/* Bin the flat field down to the actual size of x. */

allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny, True);
if ((status = bin2d (&y, x0, y0, rx, ry, avg, &z))) {
printf ("ERROR (doFlat) size mismatch\n");
return (status);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/dolores.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int *done o: true if input image has been binned
if ((out = calloc (1, sizeof (SingleGroup))) == NULL)
return (OUT_OF_MEMORY);
initSingleGroup (out);
allocSingleGroup (out, (in->sci.data.nx) / mx, (in->sci.data.ny) / my);
allocSingleGroup (out, (in->sci.data.nx) / mx, (in->sci.data.ny) / my, True);
if (hstio_err())
return (OUT_OF_MEMORY);

Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs1/doshad.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SingleGroup *x io: image to be calibrated; written to in-place
/* Bin the reference image down to the actual size of x. */

initSingleGroup (&z);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny);
allocSingleGroup (&z, x->sci.data.nx, x->sci.data.ny, True);
if ((status = bin2d (&y, x0, y0, rx, ry, avg, &z))) {
printf ("ERROR (doShad) size mismatch.\n");
return (status);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs4/maketemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static void debugimg (char *dbgfile, CmplxArray *z) {
int i, j;

initFloatHdrData (&x);
allocFloatHdrData (&x, z->nx, z->ny);
allocFloatHdrData (&x, z->nx, z->ny, True);

for (j = 0; j < z->ny; j++) {
for (i = 0; i < z->nx; i++)
Expand Down
4 changes: 2 additions & 2 deletions pkg/stis/calstis/cs6/do1dx.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ StisInfo6 *sts i: calibration switches and info
*/
if (sts->scatter) {
if (allocSingleGroup (&holdraw, in.sci.data.nx,
in.sci.data.ny) == -1)
in.sci.data.ny, True) == ALLOCATION_PROBLEM)
return (OUT_OF_MEMORY);
for (i = 0; i < holdraw.sci.data.nx; i++) {
for (j = 0; j < holdraw.sci.data.ny; j++) {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ StisInfo6 *sts i: calibration switches and info
*/
if (!outw_exists) {
if (allocSingleGroup (&outw, in.sci.data.nx,
in.sci.data.ny) == -1)
in.sci.data.ny, True) == ALLOCATION_PROBLEM)
return (OUT_OF_MEMORY);
outw_exists = 1;
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/stis/calstis/cs6/idtalg/calstis6idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ int bks_order; i: backgr. smoothing polynomial order
return (OUT_OF_MEMORY);
if (ltm[0] > 1.0) {
allocSingleGroup (&win, in.sci.data.nx / 2,
in.sci.data.ny / 2);
in.sci.data.ny / 2, True);
if (RebinData (&in, &win, x1d, wx1d, 2, tabptr.nrows))
return (ERROR_RETURN);
} else {
allocSingleGroup (&win, in.sci.data.nx,
in.sci.data.ny);
in.sci.data.ny, True);
if (RebinData (&in, &win, x1d, wx1d, 1, tabptr.nrows))
return (ERROR_RETURN);
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ int bks_order; i: backgr. smoothing polynomial order
}
remove (temp_ima);
initSingleGroup (&wout);
allocSingleGroup (&wout, win.sci.data.nx, win.sci.data.ny);
allocSingleGroup (&wout, win.sci.data.nx, win.sci.data.ny, True);
for (j = 0; j < wout.sci.data.ny; j++) {
for (i = 0; i < wout.sci.data.nx; i++)
Pix (wout.sci.data, i, j) = im_mod[j][i];
Expand Down Expand Up @@ -1377,7 +1377,7 @@ int bks_order; i: backgr. smoothing polynomial order
initSingleGroup (&wout);
if ((wx1d2 = AllocX1DTable (tabptr.nrows)) == NULL)
return (OUT_OF_MEMORY);
allocSingleGroup (&wout, in.sci.data.nx, in.sci.data.ny);
allocSingleGroup (&wout, in.sci.data.nx, in.sci.data.ny, True);
if (ltm[0] > 1.0) {
if (RebinData (&win, &wout, wx1d, wx1d2, -2, tabptr.nrows))
return (ERROR_RETURN);
Expand Down
2 changes: 1 addition & 1 deletion pkg/stis/calstis/cs7/do2dx.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ StisInfo7 *sts i: calibration switches and info
AddOffsets (sts, &slit);

/* Create output imset. */
allocSingleGroup (out, coord_o->npix[0], coord_o->npix[1]);
allocSingleGroup (out, coord_o->npix[0], coord_o->npix[1], True);
if (hstio_err())
return (OUT_OF_MEMORY);

Expand Down
2 changes: 1 addition & 1 deletion pkg/wfc3/calwf3/lib/dodqi.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ SingleGroup *x io: image to be calibrated; DQ array written to in-place
/* Allocate space for scratch array */
initShortHdrData (&ydq);
if (!in_place) {
allocShortHdrData (&ydq, snpix[0], snpix[1]);
allocShortHdrData (&ydq, snpix[0], snpix[1], True);
if (hstio_err()) {
trlerror ("doDQI couldn't allocate data quality array.");
return (status = OUT_OF_MEMORY);
Expand Down
2 changes: 1 addition & 1 deletion pkg/wfc3/calwf3/wf3ccd/doccd.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ int DoCCD (WF3Info *wf3, int extver) {
sub2full will reset the pixel values
*/
initSingleGroup(&fullarray);
allocSingleGroup(&fullarray,RAZ_COLS/2,RAZ_ROWS);
allocSingleGroup(&fullarray,RAZ_COLS/2,RAZ_ROWS, True);
fullarray.group_num=x.group_num;
CreateEmptyChip(wf3, &fullarray);
if (x.group_num == 2){ /*post blev*/
Expand Down
Loading

0 comments on commit 43bc710

Please sign in to comment.