1
/*===========================================================================
2
Copyright (C) 1995,2003 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) 1991 European Southern Observatory
32
.AUTHOR Preben J. Grosbol [ESO/IPG]
33
.KEYWORDS test routines, data conversion
35
.PURPOSE Test routine for data conversion routines
36
.VERSION 1.0 1990-Sep-27 : Creation, PJG
37
.VERSION 1.1 1990-Feb-11 : Add conversion back again, PJG
38
.VERSION 1.2 1990-Feb-12 : Add benchmark test, PJG
41
------------------------------------------------------------------------*/
45
#include <fitsextvals.h>
48
#define MXBUF 2880 /* Max. char. in buffer */
49
#define MXPARM 16 /* Max. no. of parameter */
51
static char *plist[] = {"i+:Input file",
55
"f-:Single precision Floating Point",
56
"d-:Double precision Floating Point",
58
"s-:Short integer", (char *) 0};
65
unsigned char v, *pb, *pv, buf[MXBUF];
66
char c, *pc, mode, *pval[MXPARM];
72
int n, i, to, vrbs, from, xfmt, bmark;
75
dcparm(argc,argv,plist,pval); /* decode parameter list */
76
ifp = (pc=gvparm('i',plist,pval)) ? fopen(pc,"r") : stdin;
78
vrbs = (gvparm('v',plist,pval) != (char *) 0);
79
xfmt = (gvparm('x',plist,pval) != (char *) 0);
80
bmark = (gvparm('b',plist,pval) != (char *) 0);
81
if (gvparm('f',plist,pval)) mode = 'f';
82
else if (gvparm('d',plist,pval)) mode = 'd';
83
else if (gvparm('l',plist,pval)) mode = 'l';
84
else if (gvparm('s',plist,pval)) mode = 's';
86
if (vrbs) printf("Format Mode %c\n\n",mode);
88
cvinit(); to = 1; from = 0;
89
if (bmark) { /* Benchmark test 10000 FITS records */
91
if (vrbs) printf("Benchmark for %d 2880 byte FITS records\n",n);
93
while (i--) *pb++ = 0xff & i;
95
case 'd' : i = MXBUF/8; pd = (double *) buf;
96
while (n--) { cvr8(pd,i,from); cvr8(pd,i,to); }
98
case 'f' : i = MXBUF/4; pf = (float *) buf;
99
while (n--) { cvr4(pf,i,from); cvr4(pf,i,to); }
101
case 'l' : i = MXBUF/4; pl = (long *) buf;
111
case 's' : i = MXBUF/2; ps = (short *) buf;
125
while (fgets((char*) buf,MXBUF,ifp)) {
126
if (vrbs) fputs((char*) buf,stdout);
127
n = 0; pb = buf; pv = buf;
130
if ('0'<=c && c<='9') v = c - '0';
131
else if ('A'<=c && c<='F') v = 10 + c - 'A';
132
else if ('a'<=c && c<='f') v = 10 + c - 'a';
134
if (n++ & 1) *pv++ += v; else *pv = v<<4;
137
case 'd' : i = n/16; pd = (double *) buf;
139
printf("Double %02x%02x%02x%02x %02x%02x%02x%02x > ",
140
buf[0],buf[1],buf[2],buf[3],
141
buf[4],buf[5],buf[6],buf[7]);
143
printf(" %25.17e ",*pd);
144
printf("(%02x%02x%02x%02x %02x%02x%02x%02x)\n",
145
buf[0],buf[1],buf[2],buf[3],
146
buf[4],buf[5],buf[6],buf[7]);
149
printf("-----> %02x%02x%02x%02x %02x%02x%02x%02x\n",
150
buf[0],buf[1],buf[2],buf[3],
151
buf[4],buf[5],buf[6],buf[7]);
154
case 'f' : i = n/8; pf = (float *) buf;
156
printf("Float %02x%02x%02x%02x > ",
157
buf[0],buf[1],buf[2],buf[3]);
159
printf(" %16.7e ",*pf);
160
printf("(%02x%02x%02x%02x)\n",
161
buf[0],buf[1],buf[2],buf[3]);
164
printf("----> %02x%02x%02x%02x\n",
165
buf[0],buf[1],buf[2],buf[3]);
168
case 'l' : i = n/8; pl = (long *) buf;
170
printf("Long %02x%02x%02x%02x > ",
171
buf[0],buf[1],buf[2],buf[3]);
172
if (!same_comp_i4) cvi4(pl,i,from);
173
printf(" %12ld ",*pl);
174
printf("(%02x%02x%02x%02x)\n",
175
buf[0],buf[1],buf[2],buf[3]);
177
if (!same_comp_i4) cvi4(pl,i,to);
178
printf("---> %02x%02x%02x%02x\n",
179
buf[0],buf[1],buf[2],buf[3]);
182
case 's' : i = n/4; ps = (short *) buf;
184
printf("Short %02x%02x > ",buf[0],buf[1]);
185
if (!same_comp_i2) cvi2(ps,i,from);
187
printf("(%02x%02x)\n",buf[0],buf[1]);
189
if (!same_comp_i2) cvi2(ps,i,to);
190
printf("----> %02x%02x\n",buf[0],buf[1]);
198
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199
.COPYRIGHT (c) 1990 European Southern Observatory
202
.AUTHOR Preben J. Grosbol [ESO/IPG]
203
.KEYWORDS parameter decoding, command line
205
.VERSION 1.0 1990-Jul-12 : Creation, PJG
206
.VERSION 1.1 1990-Aug-24 : Add gvparm function, PJG
207
------------------------------------------------------------------------*/
208
static char *cnull = ""; /* pointer to NULL string */
210
int dcparm(argc,argv,plist,pval)
211
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
212
.PURPOSE Decode options and parameters on the command line using
213
standard UNIX syntax.
214
.COMMENT Each option/flag and parameter is defined in a string
215
where the first character is the letter for the flag and
216
the second indicates the type '-' for flag and '+' for
217
addition string expected. After the parameter definition
218
field as comment can be given starting with the delimeter ':'.
219
If a parameter is not given it's value in a NULL popinter.
220
When a flag without string is specified the pointer points
222
Example: command -x -i name -o file
223
A parameter list plist[] = {"x-:Execute flag",
226
"o+:Output file",(char *) 0}
227
would give an output pval[] = {"",(char *) 0,"name","file"}
228
.RETURN Status where 0:OK, -1:Error
229
------------------------------------------------------------------------*/
230
int argc; /* parameter count */
231
char **argv; /* pointers to parameters */
232
char *plist[]; /* pointers to parameter definitions */
233
char *pval[]; /* pointers to parameters strings */
239
pl = cnull; /* initiate variables */
240
for (n=0; plist[n]; n++) pval[n] = (char *) 0;
242
argv++; /* skip over command name */
243
if (--argc != 0) /* decode parameters */
246
if (*pl=='+') { pval[n] = pc; pl = cnull; continue; }
250
while ((pl=plist[n]) && *pl!=c) n++;
252
if (*pl!='+') pval[n] = cnull;
254
if (*pc) { pval[n] = pc; pl = cnull; }
263
char *gvparm(opt,plist,pval)
264
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
265
.PURPOSE Retrieve parameter value for option specified
266
.COMMENT The arrays 'plist' and 'pval' are the same as in
268
.RETURN Pointer to value string, NULL pointer if not available
269
------------------------------------------------------------------------*/
270
char opt; /* option for parameter */
271
char *plist[]; /* pointers to parameter definitions */
272
char *pval[]; /* pointers to parameter strings */
275
while (*plist && **plist!=opt) plist++, pval++;
277
return ((*plist) ? *pval : (char *) 0);