1
/*===========================================================================
2
Copyright (C) 1989-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
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
.AUTHOR IPG-ESO Garching
33
.CATEGORY table utilities
35
.COMMENTS Interpretation of datatypes and formats.
37
The datatype can be one of the following:
40
\item R[eal], R[eal]*4 - floating point single precision.
41
\item D[ouble], R[eal]*8 - floating point double precision.
42
\item I[nteger], I[nteger]*4 - long integer (4 bytes).
43
\item S[hort], I[nteger]*2 - short integer (2 bytes).
44
\item B[yte], I[nteger]*1 - byte integer (1 byte).
45
\item U[nsigned]*$n$ - Unisgned integer with $n = 1, 2, 4$
46
\item C[haracter]*n - character string.
51
.VERSION 1.0 25-Mar-1989 Definition J.D. Ponz
52
.VERSION 3.0 05-Jul-1990 New version with column arrays F.O.
53
.VERSION 3.1 27-Nov-1990 Merge of tbdecfmt and tbdectyp
54
.VERSION 3.15 04-Feb-1991 length of string = length of field M.P
57
------------------------------------------------------------*/
60
#include <midas_def.h>
61
#include <str.h> /* String Utilities */
62
#include <proto_tbl.h>
69
int tbl_dectyp(etype,type,noelem,form)
71
.PURPOSE Interpret the Type (e.g. R*4) declaration
74
char *etype; /* IN: Text to scan */
75
int *type; /* OUT: Midas data type */
76
int *noelem; /* OUT: Array size */
77
char *form; /* OUT: Default Format */
83
alen = 0; /* ASCII length */
84
i = strloc (etype, '(');
87
if ((l1 < 1) || (l1 > TBL_MAXSIZ)) {
88
sprintf(msg, "****Bad array size in `%s'", etype);
95
l1 = 0; /* decode type */
96
i = strloc (etype, '*');
97
if (etype[i]) l1 = atoi(etype + i + 1);
101
if (!alen) alen = 24;
102
sprintf (form, "D%d.%d", alen, alen-7);
106
if (l1 == 8) goto case_double;
107
if (!alen) alen = 12;
108
sprintf (form, "E%d.%d", alen, alen-6);
113
if (l1 == 1) { *type = D_I1_FORMAT; if (!alen) alen = 4; }
114
else if (l1==2) { *type = D_I2_FORMAT; if (!alen) alen = 6; }
115
else { *type = D_I4_FORMAT; if (!alen) alen = 11;}
116
sprintf (form, "I%d", alen);
121
l1 = *noelem; *noelem = 1;
124
if (l1==2) { *type = D_L1_FORMAT; if (!alen) alen = 4; }
125
else { *type = D_L4_FORMAT; if (!alen) alen = 8;}
126
sprintf (form, "X%d", alen);
131
/* if (*noelem > 1) {
132
sprintf(msg, "**** C*n columns can't be arrays `%s'", etype);
136
if (l1 == 0) l1 = alen;
137
if ((l1 < 1) || (l1 > TBL_MAXSIZ)) {
138
sprintf(msg, "**** Bad character size in `%s'", etype);
142
sprintf(form,"A%d",l1);
147
l1 = 1; goto case_int;
149
l1 = 2; goto case_int;
151
sprintf (msg, "**** Bad datatype %s", etype);
160
int tbl_decfmt(line,i1,i2,type,noelem,form,unit,label)
162
.PURPOSE Decode one line of the FMT file, which looks like
164
{\tt DEFINE/FIELD} [pos1 pos2] type [format] label [unit]
167
.REMARKS If type==0 on return, we've an emtpy line (comment).
168
Beware, the input line IS MODIFIED !!!
170
char *line; /* IN: Line to scan */
171
int *i1; /* OUT: position (1) */
172
int *i2; /* OUT: position (2) */
173
int *type; /* OUT: Element type in midas_def format */
174
int *noelem; /* OUT: Size of array */
175
char *form; /* OUT: Format */
176
char *unit; /* OUT: Unit */
177
char *label; /* OUT: Label (column name) */
179
int status, l1, l2, i,j;
180
char *pf, *pl, *pu, *dtype;
187
*form = *unit = '\0';
191
line[strloc(line, '!')] = '\0'; /* Strip comments */
194
p = line + strskip (line, ' ');
195
if (*p != 'd' && *p != 'D') return(ERR_NORMAL);
196
p += strloc (p, ' ');
199
p += strskip(p, ' ');
201
l1 = atoi(p); p += strloc(p, ' '); p += strskip(p, ' ');
202
l2 = atoi(p); p += strloc(p, ' ');
207
p += strskip(p, ' ');
210
if (*p) *(p++) = '\0';
211
p += strskip(p, ' '); pf = p; p += strloc(p, ' '); if (*p) *(p++) = '\0';
212
p += strskip(p, ' '); pl = p; p += strloc(p, ' '); if (*p) *(p++) = '\0';
213
p += strskip(p, ' '); pu = p; p += strloc(p, ' '); if (*p) *(p++) = '\0';
214
if (! *pl) pl = pf, pf = pu; /* Only 1 string */
215
if (*pf == ':') p = pl, pl = pf+1, pf = p;
216
if (*pu == ':') p = pl, pl = pu+1, pu = p;
217
if (*pf == '"') p = pu, pu = pf, pf = p;
218
i = strloc(dtype,'*');
219
if ((*dtype =='C' || *dtype =='c') && (!dtype[i])) sprintf(pt,"C*%d",l2);
223
while (*dtype!='\0'){
228
status = tbl_dectyp(pt, type, noelem, form);
229
if (status) return(status);
230
if (!pt[i] && (*pt =='C' || *pt =='c')) *noelem = l2;
231
else if (( *pt=='C' || *pt =='c')) {
236
if (*pf) strcpy (form, pf);
237
if (*pu) strcpy (unit, pu);
240
i = (int) strlen(pl);
242
{ /* truncate if necessary */
243
(void) strncpy(label,pl,TBL_LABLEN);
244
label[TBL_LABLEN] = '\0';
245
(void) SCTPUT("(I/W) - column label truncated..");