# include # include /* for calloc and qsort */ # include # include "../acserr.h" /* for NO_GOOD_DATA */ # include "../acsdq.h" /* for GOODPIXEL */ /* This routine determines the bias level for one line of an image by taking the median of the values in the overscan region. ** NO MAJOR MODIFICATIONS for ACS... */ int FindBlev (SingleGroup *x, int j, int *biassect, short sdqflags, double *biaslevel, int *npix) { /* arguments: SingleGroup *x i: needed for science data and data quality int j i: line of x data to use to get overscan int biassect[2] i: beginning and end of region to use for overscan double *biaslevel o: median bias level for current (j) line int *npix o: number of pixels used to compute bias level */ extern int status; double *over; /* values extracted from overscan region */ int nvals; /* number of good pixels extracted from overscan */ int i; int inplace = 1; /* sort the array in-place */ double MedianDouble (double *, int, int); /* Allocate space for the overscan, and copy out good data. */ over = calloc (biassect[1]-biassect[0]+1, sizeof (double)); nvals = 0; for (i = biassect[0]; i < biassect[1]; i++) { if (DQPix (x->dq.data, i, j) == GOODPIXEL || DQPix (x->dq.data, i, j) & sdqflags) { over[nvals] = Pix (x->sci.data, i, j); nvals++; } } *npix = nvals; if (nvals < 1) { free (over); return (status = NO_GOOD_DATA); } /* Find the median. */ *biaslevel = MedianDouble (over, nvals, inplace); free (over); return (status); }