1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
.COPYRIGHT (c) 1995-2009 European Southern Observatory
32
.AUTHOR P.Grosbol ESO/IPG
33
.KEYWORDS MIDAS frames, information
34
.COMMENT get informations from MIDAS frames
35
.VERSION 1.0 1991-Mar-23 : Creation, PJG
36
.VERSION 1.1 1991-May-15 : Check for SCFGET return, PJG
37
.VERSION 1.2 1991-Jun-03 : Always set bfac and bzero, PJG
38
.VERSION 1.3 1991-Sep-24 : Get NULL's for tables, PJG
39
.VERSION 1.4 1992-Aug-07 : Correct format for C*n table columns, PJG
40
.VERSION 1.5 1993-Apr-12 : Correct MIN/MAX computation, PJG
41
.VERSION 1.6 1993-Sep-17 : Correct fitstbl because of TCBGET
42
.VERSION 1.7 1993-Oct-26 : Update to new TC + prototypes, PJG
43
.VERSION 1.8 1995-Jan-23 : Do not update LHCUTS, correct check, PJG
44
.VERSION 1.9 1996-Jun-24 : Exchange MAXLONG with 2147483645.0, PJG
45
.VERSION 2.0 1998-Mar-09 : use existing BSCALE, BZERO if FITS file already
46
.VERSION 2.1 1998-Apr-22 : Use I2 format of I1 table columns, PJG
49
---------------------------------------------------------------------*/
59
#include <midas_def.h>
63
#define BSIZE 10240 /* size of internal buffer */
64
#define MXLB 81 /* max. char. in line buffer */
66
static int fpexc; /* fp- exception flag */
68
static SDEF sdef; /* Image scaling information */
69
static TXDEF txdef; /* table definitions */
70
static FDEF fdef[MXF]; /* information on columns */
75
SDEF *fitsbdf(mfd,mff,mfn,outflg)
76
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
.PURPOSE compute scaling information MIDAS image
78
.COMMENT if mfd<0 the pointer is returned directly!
79
.RETURN return pointer to scaling structure, on error NULL pointer
80
---------------------------------------------------------------------*/
81
int mfd; /* IN: MIDAS file number */
82
int mff; /* IN: MIDAS file data format */
83
char *mfn; /* IN: name of MIDAS file */
84
int *outflg; /* OUT: 99, if BSCALE, BZERO are used
85
0, if LHCUTS was set or computed */
88
int mmm, ioff, null, naxis;
89
int nax[MXDIM], unit[4];
91
float *f, *fb, cuts[2];
96
if (mfd<0) return &sdef;
98
SCDRDI(mfd,"NAXIS",1,1,&nv,&naxis,unit,&null);
99
sdef.dsize = (naxis) ? 1 : 0;
100
SCDRDI(mfd,"NPIX",1,MXDIM,&nv,nax,unit,&null);
101
for (i=0; i<naxis; i++) sdef.dsize *= nax[i];
103
cuts[0] = cuts[1] = 0.0;
104
SCDRDR(mfd,"LHCUTS",3,2,&nv,cuts,unit,&null);
105
lcut = cuts[0]; hcut = cuts[1];
107
if (nv!=2 || hcut<=lcut)
108
{ /* compute max/min cuts of data */
109
struct FCT_STRUCT *fctpntr;
113
fctpntr = FCT.ENTRIES + mfd;
114
if (fctpntr->CR_FLAG == 1) /* we work on a created FITS file */
115
{ /* take cuts as they are */
116
sdef.dmin = sdef.dmax = 0.0;
122
if (fctpntr->FILTYP > 0)
123
{ /* take FITS header as it is */
124
istat = SCDRDR(mfd,"BSCALE",1,1,&i,&bscale,unit,&null);
125
if (istat == ERR_NORMAL)
126
istat = SCDRDR(mfd,"BZERO",1,1,&i,&bzero,unit,&null);
127
if (istat == ERR_NORMAL)
138
if (nv == 2) /* in first if-test: low, hi cuts were equal */
140
sdef.dmin = sdef.dmax = 0.0;
148
fb = (float *)osmmget(BSIZE); /* get internal buffer */
151
SCTPUT("Error: cannot allocate internal buffer");
152
SCFCLO(mfd); return (SDEF *) 0;
155
osscatch(SIGFPE,fpeh); fpexc = 0; /* catch fp-exception */
157
ioff = 1; nb = BSIZE >> 2; /* = BSIZE/4 */
159
if (mff!=D_R4_FORMAT)
160
{ /* we need data in floating point format */
162
SCFOPN(mfn,D_R4_FORMAT,0,F_IMA_TYPE,&mmm);
167
while (ioff<=sdef.dsize)
168
{ /* find max/min values in data */
170
n = (sdef.dsize-ioff<nb) ? sdef.dsize-ioff+1 : nb;
171
SCFGET(mmm, ioff, n, &ns, (char *) f);
172
if (ioff == 1) lcut = hcut = *f;
174
if (ns<n) ioff = sdef.dsize + 1; /* to force exit of loop */
178
if (!isNULLFLOAT(*f))
182
if (*f<lcut) lcut = *f;
183
else if (hcut<*f) hcut = *f;
190
if (mff!=D_R4_FORMAT)
191
{ /* reopen in original data format */
193
SCFOPN(mfn,mff,0,F_IMA_TYPE,&mfd);
195
osmmfree((char *) fb);
200
sdef.bfac = 0.5 * (hcut-lcut)/2147483645.0;
201
if (sdef.bfac==0.0) sdef.bfac = 1.0;
202
sdef.boff = 0.5 * (hcut + lcut);
210
TXDEF *fitstbl(mfd,ffmt,cut)
211
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
212
.PURPOSE get table information
213
.COMMENT if mfd<0 the pointer is returned directly!
214
.RETURN return pointer to Table structure
215
---------------------------------------------------------------------*/
216
int mfd; /* IN: MIDAS file number */
217
int ffmt; /* IN: file format B/O/X */
218
int cut; /* IN: cut flag */
224
int bytes, items, null;
229
if (mfd<0) return &txdef;
231
TCIGET(mfd,&(txdef.tfields),&(txdef.nrow),&ns,&ns,&ns);
232
if (txdef.tfields > MXF)
235
(void) sprintf(tbuf,"no. of columns (%d) > max. supported columns (%d)",
238
return 0; /* that should always break it... */
241
txdef.mxrow = 0; txdef.mxcol = 0; txdef.col = fdef;
244
for (i=1; i<=txdef.tfields; i++, fd++) { /* get info. for columns */
245
TCFGET(mfd,i,fd->tdisp,&len,&dtype);
246
TCBGET(mfd,i,&dtype,&items,&bytes);
248
while (*pc && *pc!=' ') pc++;
250
if (ffmt == 'B') fd->trepn = (dtype!=D_C_FORMAT) ? 1 : bytes;
251
else fd->trepn = (dtype!=D_C_FORMAT) ? items : bytes;
252
strcpy(fd->tform,fd->tdisp);
253
dcffmt(fd->tform,&fr,&fc,&fw,&fm);
254
TCLGET(mfd,i,fd->ttype);
255
TCUGET(mfd,i,fd->tunit);
260
if (ffmt!='B') fd->twdth = 4*items;
262
if (fc=='I') fd->tdfmt = 'I';
265
else { strcpy(fd->tform,"E15.8"); fd->twdth = 15; }
269
if (ffmt!='B') fd->twdth = 8*items;
270
else if (cut=='C') fd->twdth = fw;
272
strcpy(fd->tform,"D24.16"); fd->twdth = 24;
277
if (ffmt!='B') fd->twdth = bytes;
278
else if (cut=='C') fd->twdth = fw;
280
sprintf(fd->tform,"A%d",bytes); fd->twdth = bytes;
285
if (ffmt!='B') fd->twdth = 2*items;
286
else if (cut=='C') fd->twdth = fw;
288
strcpy(fd->tform,"I4"); fd->twdth = 4;
290
TBL_toNULL((TBL_D_I2<<TBL_D_BITS)|1, (char *) &snull);
295
if (ffmt!='B') fd->twdth = 2*items;
296
else if (cut=='C') fd->twdth = fw;
298
strcpy(fd->tform,"I6"); fd->twdth = 6;
300
TBL_toNULL((TBL_D_I2<<TBL_D_BITS)|1, (char *) &snull);
305
if (ffmt!='B') fd->twdth = 4*items;
306
else if (cut=='C') fd->twdth = fw;
308
strcpy(fd->tform,"I11"); fd->twdth = 11;
310
TBL_toNULL((TBL_D_I4<<TBL_D_BITS)|1, (char *) &null);
314
txdef.mxrow += fd->twdth;
315
if (txdef.mxcol<fd->twdth) txdef.mxcol = fd->twdth;
323
void fpeh(s) /* fp-exception handler */
326
osscatch(SIGFPE,fpeh);