/* @(#)fitsrdm.c 17.1.1.1 (ES0-DMD) 01/25/02 17:39:09 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, MA 02139, USA. Corresponding concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .COPYRIGHT (c) 1994 European Southern Observatory .IDENT fitsrdm.c .LAUGUAGE C .AUTHOR P.Grosbol ESO/IPG .KEYWORDS FITS data matrix, decode, read .COMMENT read the prime data matrix of FITS file .VERSION 1.0 1988-Dec-10 : Creation, PJG .VERSION 1.1 1989-Oct-08 : Save Group parm. in table, PJG .VERSION 1.2 1989-Oct-24 : Check of data to store, PJG .VERSION 1.3 1990-Feb-04 : Change call-seq. for cv-routine, PJG .VERSION 1.4 1991-Feb-14 : Correct pointer error, PJG .VERSION 2.0 1991-Feb-24 : Change call-seq. structures, PJG .VERSION 2.1 1991-Mar-23 : Compute min/max if not given, PJG .VERSION 2.2 1993-Sep-23 : Check overflow in cut values, PJG .VERSION 2.3 1993-Dec-02 : Update to new SC + prototypes, PJG .VERSION 2.4 1994-May-09 : Cast variable for ANSI-C, PJG .VERSION 2.5 1994-Jun-28 : Include UI2 as bitpix=-16, PJG .VERSION 2.6 1994-Sep-07 : Add explicit cast for unsigned, PJG .VERSION 2.7 1997-Jan-08 : Only warning on wrong record size, PJG ---------------------------------------------------------------------*/ #include /* computer specific constants */ #include /* general data definitions */ #include /* basic FITS definitions */ #include /* MIDAS definitions */ #define MXFB 2880 /* max. size of scaling buffer */ #ifdef __STDC__ int fitsrdm(int mfd , BFDEF * bfdef , int size , int mfdt , char fmt, int Midas_flag) #else int fitsrdm(mfd,bfdef,size,mfdt,fmt,Midas_flag) /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Read prime data matrix in FITS .RETURN error code - 0: OK, -1: error ---------------------------------------------------------------------*/ int mfd; /* IN: MIDAS file descriptor */ BFDEF *bfdef; /* IN: pointer to FITS header parm's */ int size; /* IN: size of data matrix (bytes) */ int mfdt; /* IN: MIDAS file desc. Groups table */ char fmt; /* IN: data format Original/Float */ int Midas_flag; /* IN: = 0, `usual' mode = 1, `internal FITS access' */ #endif { register int bf, k; unsigned char uc, *pb; short s, *ps; unsigned short u, *pu; int fpf, dno, gno, pno, npix, n, fmm; int dn, pn, ndata, dfmt, nb, pcnt, dsf, unit[4]; int felem, i, *pi, mnvi, mxvi; float *pf, cuts[2]; double fac, zero, d, *pd, mnvd, mxvd; PDEF *pp; union { float f[2*MXFB]; double d[MXFB]; } buf; union { unsigned char *b; char *c; short *s; unsigned short *u; int *i; float *f; double *d; } p; int option; mnvd = mxvd = 0.0; pno = bfdef->pcount; pcnt = 0; /* initiate counters */ pp = bfdef->parm; gno = 0; bf = bfdef->bflag; dfmt = bfdef->bitpix; nb = (dfmt<0) ? -dfmt/8 : dfmt/8; ndata = size/(nb*bfdef->gcount) - pno; dno = ndata; fac = bfdef->bscale; zero = bfdef->bzero; felem = 1; fmm = ((bfdef->mflag != 3) && (0sflag || dfmt!=-32) ; dsf = ((bfdef->sflag && dfmt!=-64) || fmt=='F') ? -32 : dfmt; while (0pscal * (*(p.b++)) + pp->pzero; break; case -16 : case 16 : d = pp->pscal * (*(p.s++)) + pp->pzero; break; case 32 : d = pp->pscal * (*(p.i++)) + pp->pzero; break; case -32 : d = pp->pscal * (*(p.f++)) + pp->pzero; break; case -64 : d = pp->pscal * (*(p.d++)) + pp->pzero; break; } pcnt++; pp++; if (0<=mfdt) TCEWRD(mfdt,gno+1,pcnt,&d); } } if (!pno && 0sflag) { switch (dfmt) { case 8 : pf = buf.f; uc = bfdef->blank; for (k=0; kblank; for (k=0; kblank; for (k=0; kblank; for (k=0; kblank; for (k=0; kblank; for (k=0; kblank; for (k=0; kblank; ps = p.s; for (k=0; kblank; for (k=0; kblank; for (k=0; ksflag) ? buf.d : p.d - dn; if (felem==1) mnvd = mxvd = *pd; for (k=0; kpcount; pcnt = 0; pp = bfdef->parm; dno = ndata; } } } while (npix && gnogcount); } if (fmm) { /* save computed min/max values */ if (dsf > -32) { cuts[0] = mnvi; cuts[1] = mxvi; /* handle also UI2 here */ } else { if (MAXFLOAT