1
/*===========================================================================
2
Copyright (C) 1995-2006 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
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION fitswmd.c
31
.AUTHOR P.Grosbol ESO/IPG
32
.KEYWORDS MIDAS descriptor, FITS header, keywords
33
.COMMENT write MIDAS descriptor in FITS header
34
.VERSION 1.0 1988-Dec-04 : Creation, PJG
35
.VERSION 1.1 1989-May-26 : Change format - for old-MIDAS, PJG
36
.VERSION 1.2 1989-Jun-12 : Change definition of unit+kunit, PJG
37
.VERSION 1.3 1990-Feb-26 : Change format of char. desc., PJG
38
.VERSION 1.4 1991-Jan-25 : Change include file, PJG
39
.VERSION 1.5 1993-Oct-26 : Update to new SC + prototypes, PJG
40
.VERSION 1.6 1998-Aug-19 : Change format, PJG
41
.VERSION 1.7 2002-Jan-11 : Add logical type, PJG
44
---------------------------------------------------------------------*/
50
#include <midas_def.h>
52
#define MXFHC 80 /* characters in FITS header card */
53
#define MXFCC 70 /* max. char. in FITS comment */
59
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
60
.PURPOSE write MIDAS descriptor to FITS header
61
.RETURN return status 0:OK, -1:error
62
---------------------------------------------------------------------*/
63
int mfd; /* IN: MIDAS file number */
64
char *name; /* IN: name of MIDAS descriptor */
67
char fhc[MXFHC+1], buf[MXFCC+1], chc[MXFHC+1];
69
int ne, nbpe, n, nv, nf, no, epl, null, net;
70
int i, idx, ival[7], unit[2];
71
int SCTMES(), SCDRDL();
81
if (MXMDN <= (int)strlen(name))
83
(void)sprintf(fhc,"Error: descriptor >%s< skipped - name too long",
85
SCTMES(M_RED_COLOR,fhc);
89
if (SCDFND(mfd,name,&type,&ne,&nbpe)) return (-1);
91
nf = 1; /* first element */
93
/* instead of: fitswkc("HISTORY",fhc);
94
we use: dwrite("HISTORY "//fhc,MXFHC); directly */
99
n = sprintf(fhc,"HISTORY '%s','L*%d',1,%d,'35I2'",name,nbpe,ne);
100
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
105
{ /* go through all elements */
106
no = (epl<ne) ? epl : ne;
107
SCDRDL(mfd,name,nf,no,&nv,ival,unit,&null);
108
nf += nv; ne -= nv; n = 0;
109
idx = 9; pc = &fhc[idx]; /* position after 'HISTORY ' */
111
{ /* write one HISTORY card */
112
i = sprintf(pc,"%2d",ival[n]);
116
while (idx<MXFHC) fhc[idx++] = ' '; fhc[idx] = '\0';
122
if (strcmp(name,"SELIDX") == 0) /* Selection Index table */
127
SCDRDI(mfd,"SELIDX",1,1,&nv,ival,unit,&null);
128
ne = ival[0] + 1; /* get actually used size */
129
if (ne < 2) return 0; /* nothing to do... */
131
(void) SCDGETC(mfd,"TSELTABL",1,64,&nv,seltab);
134
n = sprintf(fhc,"HISTORY 'XTSELTABL','C*1',1,%d,'70A1'",nv);
135
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
137
n = sprintf(fhc,"HISTORY %s",seltab);
138
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
143
n = sprintf(fhc,"HISTORY '%s','I*%d',1,%d,'7I10'",name,nbpe,ne);
144
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
149
{ /* go through all elements */
150
no = (epl<ne) ? epl : ne;
151
SCDRDI(mfd,name,nf,no,&nv,ival,unit,&null);
152
nf += nv; ne -= nv; n = 0;
153
idx = 9; pc = &fhc[idx]; /* position after 'HISTORY ' */
155
{ /* write one HISTORY card */
156
i = sprintf(pc,"%10d",ival[n]);
160
while (idx<MXFHC) fhc[idx++] = ' '; fhc[idx] = '\0';
166
n = sprintf(fhc,"HISTORY '%s','R*%d',1,%d,'5E14.7'",name,nbpe,ne);
167
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
172
{ /* go through all elements */
173
no = (epl<ne) ? epl : ne;
174
SCDRDR(mfd,name,nf,no,&nv,fval,unit,&null);
175
nf += nv; ne -= nv; n = 0;
176
idx = 9; pc = &fhc[idx]; /* position after 'HISTORY ' */
178
{ /* write one HISTORY card */
179
i = sprintf(pc,"%14.7E",fval[n]);
183
while (idx<MXFHC) fhc[idx++] = ' '; fhc[idx] = '\0';
189
n = sprintf(fhc,"HISTORY '%s','R*%d',1,%d,'3E23.15'",name,nbpe,ne);
190
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
195
{ /* go through all elements */
196
no = (epl<ne) ? epl : ne;
197
SCDRDD(mfd,name,nf,no,&nv,dval,unit,&null);
198
nf += nv; ne -= nv; n = 0;
199
idx = 9; pc = &fhc[idx]; /* position after 'HISTORY ' */
201
{ /* write one HISTORY card */
202
i = sprintf(pc,"%23.15E",dval[n]);
206
while (idx<MXFHC) fhc[idx++] = ' '; fhc[idx] = '\0';
212
if (strcmp(name,"XTSELTABL") == 0) /* don't write it again... */
217
sprintf(chc,"Warning: descriptor >%s< skipped - too long C*%d",
223
epl = (MXFCC < ne*nbpe) ? MXFCC : ne*nbpe;
224
n = sprintf(fhc,"HISTORY '%s','C*%d',1,%d,'%dA1'",name,nbpe,ne,epl);
225
while (n<MXFHC) fhc[n++] = ' '; fhc[n] = '\0';
228
for (n=0; n<MXFHC; n++) chc[n] = ' '; chc[n] = '\0';
230
n = 1; net = ne*nbpe;
232
{ /* go through all elements */
233
if (nbpe==1) no = (epl<net) ? epl : net; else no = 1;
235
SCDRDC(mfd,name,nbpe,nf,no,&nv,pc,unit,&null);
237
nf += nv; nv *= nbpe; net -= nv;
241
if (c=='\\' || c=='\n')
246
chc[n] = '\0'; fitswkc("HISTORY",chc); n = 1;
248
if (c=='\\') chc[n++] = '\\';
249
else if (c=='\n') chc[n++] = 'n';
251
else if (' '<=c && c<='~')
257
chc[n] = '\0'; fitswkc("HISTORY",chc); n = 1;
263
chc[n] = '\0'; fitswkc("HISTORY",chc);
269
for (n=9; n<MXFHC; n++) fhc[n] = ' '; fhc[n] = '\0';