1
/*===========================================================================
2
Copyright (C) 1995-2010 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
/*+++++++++++++++++++++ Module SCCA ++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION Module scca.c
32
Holds catalog interfaces:
33
SCCGET, SCCLIS, SCCSHO, SCCFND, SCCSEA
34
.AUTHOR Klaus Banse ESO - Garching
35
.KEYWORDS MIDAS catalogues
36
.ENVIRONMENT independant
38
.VERSION [1.00] 920212: pulled over from scc.c
41
------------------------------------------------------------------------*/
49
#define DEFAULT_LEN 20
55
int SCCLIS(catfile,intval)
57
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59
list contents of catalog file
61
read + display record by record
64
-----------------------------------------------------------------------------*/
66
char *catfile; /* IN: catalog file */
67
int *intval; /* IN: listing interval [low,hi] */
72
stat = outcat(catfile,0,intval);
80
int SCCSHO(catfile,totent,lastent)
82
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84
get total no. of entries and last entry in a catalog
89
-----------------------------------------------------------------------------*/
91
char *catfile; /* IN: catalog file */
92
int *totent; /* OUT: no. of entries */
93
int *lastent; /* OUT: last entry no. */
97
int cattyp, cimno, catid, catlen;
98
int valid, nrec, lasty=0;
100
char catrec[CATREC_LEN+4];
104
*totent = -1; /* initialize to very bad ... */
107
stat = MID_COPN(catfile,&cattyp,&cimno);
108
if (stat != ERR_NORMAL)
110
MID_ERROR("MIDAS","SCCSHO: ",stat,1);
114
catid = CATAL[cimno].FID;
116
stat = rewicat(catid,cimno);
120
MID_ERROR("MIDAS","SCCSHO: ",stat,1);
125
/* loop through catalog + search for record no. `lorec' */
130
catlen = readcat(catid,cimno,catrec,&valid);
131
if (catlen < 0) goto end_of_it; /* EOF reached */
132
if (valid != 0) /* valid (= non-deleted) record read */
134
lasty = CATAL[cimno].RECNO;
143
*lastent = lasty - 1;
151
int outcat(catfile,option,intval)
153
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155
print contents of catalog file in different formats
157
read + display record by record
160
-----------------------------------------------------------------------------*/
162
char *catfile; /* IN: catalog file */
163
int option; /* IN: = 0, normal print out \
164
= 1, just print the filenames */
165
int *intval; /* IN: listing interval [low,hi] */
168
char output[CATREC_LEN+4];
169
char catrec[CATREC_LEN+4];
171
int stat, valid, i, outoff;
172
int cattyp, cimno, catoff, catid, catlen;
179
stat = MID_COPN(catfile,&cattyp,&cimno);
180
if (stat != ERR_NORMAL)
182
MID_ERROR("MIDAS","SCCLIS: ",stat,1);
186
catid = CATAL[cimno].FID;
188
if (lorec < CATAL[cimno].RECNO)
190
stat = rewicat(catid,cimno);
194
MID_ERROR("MIDAS","SCCLIS: ",stat,1);
199
else if (lorec > CATAL[cimno].RECNO)
201
for (i=0; i<99999; i++)
203
catlen = readcat(catid,cimno,catrec,&valid);
204
if (catlen < 0) goto end_of_file; /* EOF reached */
206
if (CATAL[cimno].RECNO == lorec) goto start_of_interval;
211
/* display header line */
216
if (option == 1) goto read_loop; /* skip header lines */
218
if (CATAL[cimno].TYPE == F_TBL_TYPE)
220
(void)sprintf(output,"Table Catalog: %s\n",CATAL[cimno].NAME);
223
strcpy(output, "No Name Ident ");
224
(void)strcat(output," columns rows");
226
else if (CATAL[cimno].TYPE == F_FIT_TYPE)
228
(void)sprintf(output,"FitFile Catalog: %s\n",CATAL[cimno].NAME);
230
(void)strcpy(output, "No Name Ident ");
232
else if (CATAL[cimno].TYPE == F_IMA_TYPE)
235
sprintf(output,"Image Catalog: %s\n--------------",CATAL[cimno].NAME);
238
strcpy(output, "No Name Ident ");
239
(void)strcat(output," Naxis Npix");
243
(void)sprintf(output,"ASCII file Catalog: %s\n",CATAL[cimno].NAME);
245
(void)strcpy(output, "No Name ");
251
/* loop through catalog + search for record no. 'lorec' */
254
if (CATAL[cimno].RECNO > hirec) goto end_of_it;
257
catlen = readcat(catid,cimno,catrec,&valid);
258
if (catlen < 0) goto end_of_it; /* EOF reached */
259
if (valid == 0) goto read_loop;
261
memset((void *)output,32,(size_t)CATREC_LEN);
262
catoff = CGN_INDEXC(catrec,' ');
265
(void) sprintf(output,"#%-4.4d",lorec);
268
(void) strncpy(&output[outoff],catrec,catoff);
269
if (catoff < DEFAULT_LEN)
273
CGN_strcpy(catrec,&catrec[catoff]);
274
catoff = CGN_INDEXC(catrec,'^');
277
output[outoff] = '\0';
280
(void) strncpy(&output[outoff],catrec,catoff);
282
output[outoff++] = ' ';
283
CGN_strcpy(catrec,&catrec[catoff+1]);
284
(void) strcpy(&output[outoff],catrec);
289
(void) strncpy(output,catrec,catoff);
290
output[catoff] = '\0';
303
MID_ERROR("MIDAS","SCCLIS: ",stat,1);
311
int SCCGET(catfile,flag,name,ident,no)
313
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
315
get next entry in catalog
317
return next name + ident of catalog file
318
return a ' ' in name[0], if at EOF
321
------------------------------------------------------------------------- */
323
char *catfile; /* IN: catalog file */
324
int flag; /* IN: = 0 for name only, \
325
= 1 for name + ident */
326
char *name; /* OUT: name of frame in next record of catalog */
327
char *ident; /* OUT: ident of that frame */
328
int *no; /* IN/OUT: current record no. */
331
int catid, catlen, i, stat, cattyp;
334
char catrec[CATREC_LEN+4];
338
stat = MID_COPN(catfile,&cattyp,&cimno);
339
if (stat != ERR_NORMAL)
341
MID_ERROR("MIDAS","SCCGET: ",stat,1);
345
catid = CATAL[cimno].FID;
349
if (CATAL[cimno].RECNO > 1)
351
stat = rewicat(catid,cimno);
352
if (stat < 0) goto osa_error;
357
else if (*no == (CATAL[cimno].RECNO - 1))
360
else if (*no < CATAL[cimno].RECNO)
362
stat = rewicat(catid,cimno);
363
if (stat < 0) goto osa_error;
367
catlen = readcat(catid,cimno,catrec,&valid);
376
i = CATAL[cimno].RECNO - 1;
384
catlen = readcat(catid,cimno,catrec,&valid);
394
if (valid == 0) goto read_loop;
396
*no = CATAL[cimno].RECNO - 1;
398
i = CGN_INDEXC(catrec,' '); /* find end of name */
401
(void) printf("SCCGET: no file delimiter...\n");
404
(void) strncpy(name,catrec,i);
409
CGN_strcpy(catrec,&catrec[i+1]);
410
i = CGN_INDEXC(catrec,'^');
412
(void) strcpy(ident,catrec);
416
(void) strcpy(ident,catrec);
425
MID_ERROR("MIDAS","SCCGET: ",stat,1);
433
int SCCFND(catfile,frmno,frame)
435
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
437
find corresponding frame for given entry no.
439
search for given ntry no. + look up connected frame name
442
---------------------------------------------------------------------*/
444
char *catfile; /* IN: catalog file */
445
int frmno; /* IN: entry no. in catalog */
446
char *frame; /* OUT: corresponding frame name (terminated by \0) */
449
char catrec[CATREC_LEN+4];
453
int cimno, cattyp, valid;
456
stat = MID_COPN(catfile,&cattyp,&cimno);
457
if (stat != ERR_NORMAL)
459
MID_ERROR("MIDAS","SCCFND: ",stat,1);
463
catid = CATAL[cimno].FID;
465
if (frmno < CATAL[cimno].RECNO)
467
stat = rewicat(catid,cimno);
471
MID_ERROR("MIDAS","SCCFND: ",stat,1);
478
if (frmno < CATAL[cimno].RECNO) goto not_found;
480
catlen = readcat(catid,cimno,catrec,&valid);
481
if (catlen < 0) goto not_found; /* EOF reached */
482
if (valid == 0) goto read_loop;
484
n = CATAL[cimno].RECNO - 1;
487
i = CGN_INDEXC(catrec,' '); /* find end of name */
490
(void) printf("SCCFND: no file delimiter...\n");
493
(void) strncpy(frame,catrec,i);
504
MID_ERROR("MIDAS","SCCFND: ",stat,1);