1
/*===========================================================================
2
Copyright (C) 1995-2007 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
/*+++++++++++++++++++ CGN interfaces part A +++++++++++++++++++++++++++++++
30
.IDENTIFICATION Module CGNA
32
holds CLEANF, INDEXC, INDEXS
33
.AUTHOR K. Banse ESO - Garching
35
name translation, parsing, filling
36
.ENVIRONMENT VMS and UNIX
38
.VERSION [1.40] 870715: C-version
41
-----------------------------------------------------------------------------*/
54
int CGN_CLEANF(infile,deftypno,outfile,lout,namtype,ext_flg)
56
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
translate file name and append default type, if required.
59
also indicate, if extracted file is wanted
60
cleaned filename is terminated by \0
62
straight forward via CGN_INDEXC
63
we have to use FSYDEF.H, which defines file-system dependant values !!
65
return status = 0, if all o.k.
67
------------------------------------------------------------------------*/
69
char *infile; /* IN : (complete) file name (terminated by \0) */
70
int deftypno; /* IN : default_type_no. 0 = file type will decide
72
3 = table (.tbl), 4 = fit file (.fit)
76
int lout; /* IN : max length of outfile */
77
char *outfile; /* OUT: "cleaned" file name */
78
int *namtype; /* OUT: type of frame:
79
1 = image (.bdf), 2 = any (.any)
80
3 = table (.tbl), 4 = fit file (.fit)
81
5 = logfile (.log), 6 = procedure (.prg)
82
7 = catalog (.cat), 8 = test (.tst)
84
0 = if something wrong... */
85
int *ext_flg; /* OUT: = 0, if none;
86
> 0 if index of '[' or '@'
87
< 0 if index of [extens] */
91
int k, tt, inlen, typeno;
105
if ((cr == ' ') || (cr == '\0')) return (-2);
107
if ((deftypno < 1) || (deftypno > 7))
110
typeno = deftypno - 1;
112
inlen = (int)strlen(infile);
116
/* check if name is enclosed in special char. XFNAMC (currently = ")
117
then we just strip them off ... */
121
if (infile[k] == XFNAMC) /* it's "name" */
126
k --; /* new length of string */
127
(void) memcpy(outfile,&infile[1],(size_t)k);
129
*namtype = 99; /* we don't check ... */
135
/* first look for file[... : ...] or file[extens] */
138
if (infile[k] == ']')
140
for (nr=(k-1); nr>0; nr--)
142
if (infile[nr] == '[')
152
(void) memcpy(work,infile,(size_t)k);
156
for (nr=(k+1); nr<inlen; nr++)
158
if (infile[nr] == ':') goto get_logname;
160
*ext_flg = -k; /* we have a FITS extension */
163
/* now check for file@plane/line/pixel */
167
k = CGN_INDEXC(infile,'@');
171
(void) memcpy(work,infile,(size_t)k);
178
CGN_LOGNAM(cpntr,outfile,lout); /* returns outfile with \0 */
180
tt = CGN_APPNDTYP(outfile,typeno);
186
cpntr = outfile + tt;
187
for (nr=0; nr<9; nr++)
189
if (strcmp(cpntr,FSY_DEFPNTR[nr]) == 0)
196
*namtype = 1; /* default to images */
211
int CGN_APPNDTYP(char *s, int typeno)
213
int CGN_APPNDTYP(s, typeno)
218
/* ++++++++++++++++++++++++++++++++++++++++++++++
220
a) append correct file type if not set yet
221
b) return index of .filetype if any
223
----------------------------------------------- */
229
char work[24], *defpntr;
236
for (nr=k; nr>0; nr--)
238
if (s[nr] == FSY_TYPMARK) /* now, look for type */
240
tt = nr; /* we found no dir_specs before */
243
else if (s[nr] == FSY_DIREND) /* and directory endmarker */
249
defpntr = FSY_DEFPNTR[typeno]; /* point to correct deftype */
250
if (KIWORDS[OFF_AUX+12] == 1)
251
{ /* we work with FITS, */
253
if (typeno == 0) /* so look for default */
254
{ /* image/table types */
255
(void) SCKGETC("MID$TYPES",1,8,&inlen,work+1);
258
else if (typeno == 2)
260
(void) SCKGETC("MID$TYPES",9,8,&inlen,work+1);
265
(void) strcpy(s+k,defpntr); /* append def type to file */
275
int CGN_INDEXC(char *s, char t)
278
/*++++++++++++++++++++++++++++++++++++++++++++++++++
280
returns position of single character in input string
282
returns position of single character in input string,
283
-length(s) if not there
284
--------------------------------------------------*/
286
char *s; /* input string */
287
char t; /* test character */
297
for (i=0; *cp != '\0'; i++)
299
if (t == *cp++) return (i);
302
return (-1); /* not found, return length of string (negative) */
311
/*++++++++++++++++++++++++++++++++++++++++++++++++++
313
find position of substring in input string.
316
returns index of substring in input string (= 0,1,2,...),
317
-length(s) if not there
318
--------------------------------------------------*/
320
char *s; /* input string */
321
char *t; /* substring */
328
/* library routine strstr() returns pointer to substring or NULL */
332
if (ptr == (char *) 0)
341
int CGN_FILINFO(file,size,time,prot)
343
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
349
return status = 0, if all o.k.
350
= -1, if file could not be accessed
351
------------------------------------------------------------------------*/
353
long int *size, *time;
359
struct filestatus fstat;
363
n = osfinfo(file,&fstat);
364
if (n != 0) return (-1);
366
*size = fstat.filesize;
367
*time = (long int) fstat.date;
368
*prot = fstat.protection;