Debian Codegraph @

libsrc/st/scca.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2010 European Southern Observatory (ESO)
3
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.
8
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.
13
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,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++ Module SCCA ++++++++++++++++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module scca.c
31 .COMMENTS
32 Holds catalog interfaces:
33 SCCGET, SCCLIS, SCCSHO, SCCFND, SCCSEA
34 .AUTHOR Klaus Banse ESO - Garching
35 .KEYWORDS MIDAS catalogues
36 .ENVIRONMENT independant
37
38 .VERSION [1.00] 920212: pulled over from scc.c
39
40 100616 last modif
41 ------------------------------------------------------------------------*/
42
43 #include <fileexts.h>
44 #include <fsydef.h>
45
46 #include <stdio.h>
47 #include <string.h>
48
49 #define DEFAULT_LEN 20
50
51 /*
52
53 */
54
55 int SCCLIS(catfile,intval)
56
57 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58 .PURPOSE
59 list contents of catalog file
60 .ALGORITHM
61 read + display record by record
62 .RETURNS
63 int return status
64 -----------------------------------------------------------------------------*/
65
66 char *catfile; /* IN: catalog file */
67 int *intval; /* IN: listing interval [low,hi] */
68
69 {
70 int stat;
71
72 stat = outcat(catfile,0,intval);
73 return stat;
74 }
75
76 /*
77
78 */
79
80 int SCCSHO(catfile,totent,lastent)
81
82 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
83 .PURPOSE
84 get total no. of entries and last entry in a catalog
85 .ALGORITHM
86 straight forward
87 .RETURNS
88 int return status
89 -----------------------------------------------------------------------------*/
90
91 char *catfile; /* IN: catalog file */
92 int *totent; /* OUT: no. of entries */
93 int *lastent; /* OUT: last entry no. */
94
95 {
96 int stat;
97 int cattyp, cimno, catid, catlen;
98 int valid, nrec, lasty=0;
99
100 char catrec[CATREC_LEN+4];
101
102
103
104 *totent = -1; /* initialize to very bad ... */
105 *lastent = -1;
106
107 stat = MID_COPN(catfile,&cattyp,&cimno);
108 if (stat != ERR_NORMAL)
109 {
110 MID_ERROR("MIDAS","SCCSHO: ",stat,1);
111 return stat;
112 }
113
114 catid = CATAL[cimno].FID;
115
116 stat = rewicat(catid,cimno);
117 if (stat < 0)
118 {
119 stat = ERR_CATBAD;
120 MID_ERROR("MIDAS","SCCSHO: ",stat,1);
121 return stat;
122 }
123
124
125 /* loop through catalog + search for record no. `lorec' */
126
127 nrec = 0;
128
129 read_loop:
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 */
133 {
134 lasty = CATAL[cimno].RECNO;
135 nrec ++;
136 }
137
138 goto read_loop;
139
140
141 end_of_it:
142 *totent = nrec;
143 *lastent = lasty - 1;
144 return ERR_NORMAL;
145
146 }
147 /*
148
149 */
150
151 int outcat(catfile,option,intval)
152
153 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154 .PURPOSE
155 print contents of catalog file in different formats
156 .ALGORITHM
157 read + display record by record
158 .RETURNS
159 int return status
160 -----------------------------------------------------------------------------*/
161
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] */
166
167 {
168 char output[CATREC_LEN+4];
169 char catrec[CATREC_LEN+4];
170
171 int stat, valid, i, outoff;
172 int cattyp, cimno, catoff, catid, catlen;
173 int lorec, hirec;
174
175
176 lorec = intval[0];
177 hirec = intval[1];
178
179 stat = MID_COPN(catfile,&cattyp,&cimno);
180 if (stat != ERR_NORMAL)
181 {
182 MID_ERROR("MIDAS","SCCLIS: ",stat,1);
183 return stat;
184 }
185
186 catid = CATAL[cimno].FID;
187
188 if (lorec < CATAL[cimno].RECNO)
189 {
190 stat = rewicat(catid,cimno);
191 if (stat < 0)
192 {
193 stat = ERR_CATBAD;
194 MID_ERROR("MIDAS","SCCLIS: ",stat,1);
195 return stat;
196 }
197 }
198
199 else if (lorec > CATAL[cimno].RECNO)
200 {
201 for (i=0; i<99999; i++)
202 {
203 catlen = readcat(catid,cimno,catrec,&valid);
204 if (catlen < 0) goto end_of_file; /* EOF reached */
205
206 if (CATAL[cimno].RECNO == lorec) goto start_of_interval;
207 }
208 }
209
210
211 /* display header line */
212
213 start_of_interval:
214 lorec --;
215
216 if (option == 1) goto read_loop; /* skip header lines */
217
218 if (CATAL[cimno].TYPE == F_TBL_TYPE)
219 {
220 (void)sprintf(output,"Table Catalog: %s\n",CATAL[cimno].NAME);
221 SCTPUT(output);
222 (void)
223 strcpy(output, "No Name Ident ");
224 (void)strcat(output," columns rows");
225 }
226 else if (CATAL[cimno].TYPE == F_FIT_TYPE)
227 {
228 (void)sprintf(output,"FitFile Catalog: %s\n",CATAL[cimno].NAME);
229 SCTPUT(output);
230 (void)strcpy(output, "No Name Ident ");
231 }
232 else if (CATAL[cimno].TYPE == F_IMA_TYPE)
233 {
234 (void)
235 sprintf(output,"Image Catalog: %s\n--------------",CATAL[cimno].NAME);
236 SCTPUT(output);
237 (void)
238 strcpy(output, "No Name Ident ");
239 (void)strcat(output," Naxis Npix");
240 }
241 else
242 {
243 (void)sprintf(output,"ASCII file Catalog: %s\n",CATAL[cimno].NAME);
244 SCTPUT(output);
245 (void)strcpy(output, "No Name ");
246 }
247
248 SCTPUT(output);
249
250
251 /* loop through catalog + search for record no. 'lorec' */
252
253 read_loop:
254 if (CATAL[cimno].RECNO > hirec) goto end_of_it;
255
256 lorec ++;
257 catlen = readcat(catid,cimno,catrec,&valid);
258 if (catlen < 0) goto end_of_it; /* EOF reached */
259 if (valid == 0) goto read_loop;
260
261 memset((void *)output,32,(size_t)CATREC_LEN);
262 catoff = CGN_INDEXC(catrec,' ');
263 if (option == 0)
264 {
265 (void) sprintf(output,"#%-4.4d",lorec);
266 output[5] = ' ';
267 outoff = 6;
268 (void) strncpy(&output[outoff],catrec,catoff);
269 if (catoff < DEFAULT_LEN)
270 outoff = 25;
271 else
272 outoff += catoff;
273 CGN_strcpy(catrec,&catrec[catoff]);
274 catoff = CGN_INDEXC(catrec,'^');
275
276 if (catoff < 1)
277 output[outoff] = '\0';
278 else
279 {
280 (void) strncpy(&output[outoff],catrec,catoff);
281 outoff = 63;
282 output[outoff++] = ' ';
283 CGN_strcpy(catrec,&catrec[catoff+1]);
284 (void) strcpy(&output[outoff],catrec);
285 }
286 }
287 else
288 {
289 (void) strncpy(output,catrec,catoff);
290 output[catoff] = '\0';
291 }
292
293 SCTPUT(output);
294
295 goto read_loop;
296
297
298 end_of_it:
299 return ERR_NORMAL;
300
301 end_of_file:
302 stat = ERR_INPINV;
303 MID_ERROR("MIDAS","SCCLIS: ",stat,1);
304 return stat;
305 }
306
307 /*
308
309 */
310
311 int SCCGET(catfile,flag,name,ident,no)
312
313 /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
314 .PURPOSE
315 get next entry in catalog
316 .ALGORITHM
317 return next name + ident of catalog file
318 return a ' ' in name[0], if at EOF
319 .RETURNS
320 int return status
321 ------------------------------------------------------------------------- */
322
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. */
329
330 {
331 int catid, catlen, i, stat, cattyp;
332 int cimno, valid;
333
334 char catrec[CATREC_LEN+4];
335
336
337
338 stat = MID_COPN(catfile,&cattyp,&cimno);
339 if (stat != ERR_NORMAL)
340 {
341 MID_ERROR("MIDAS","SCCGET: ",stat,1);
342 return stat;
343 }
344
345 catid = CATAL[cimno].FID;
346
347 if (*no < 1)
348 {
349 if (CATAL[cimno].RECNO > 1)
350 {
351 stat = rewicat(catid,cimno);
352 if (stat < 0) goto osa_error;
353 }
354 goto read_loop;
355 }
356
357 else if (*no == (CATAL[cimno].RECNO - 1))
358 goto read_loop;
359
360 else if (*no < CATAL[cimno].RECNO)
361 {
362 stat = rewicat(catid,cimno);
363 if (stat < 0) goto osa_error;
364 }
365
366 forward:
367 catlen = readcat(catid,cimno,catrec,&valid);
368 if (catlen < 0)
369 {
370 *name = ' ';
371 *(name+1) = '\0';
372 *no = -1;
373 return ERR_NORMAL;
374 }
375
376 i = CATAL[cimno].RECNO - 1;
377 if (i == *no)
378 goto read_loop;
379 else
380 goto forward;
381
382
383 read_loop:
384 catlen = readcat(catid,cimno,catrec,&valid);
385 if (catlen < 0)
386 {
387 *name = ' ';
388 *(name+1) = '\0';
389 *no = -1;
390 }
391
392 else
393 {
394 if (valid == 0) goto read_loop;
395
396 *no = CATAL[cimno].RECNO - 1;
397
398 i = CGN_INDEXC(catrec,' '); /* find end of name */
399 if (i < 1)
400 {
401 (void) printf("SCCGET: no file delimiter...\n");
402 i = 1;
403 }
404 (void) strncpy(name,catrec,i);
405 name[i] = '\0';
406
407 if (flag > 0)
408 {
409 CGN_strcpy(catrec,&catrec[i+1]);
410 i = CGN_INDEXC(catrec,'^');
411 if (i < 0)
412 (void) strcpy(ident,catrec);
413 else
414 {
415 catrec[i] = '\0';
416 (void) strcpy(ident,catrec);
417 }
418 }
419 }
420
421 return ERR_NORMAL;
422
423 osa_error:
424 stat = ERR_CATBAD;
425 MID_ERROR("MIDAS","SCCGET: ",stat,1);
426 return stat;
427 }
428
429 /*
430
431 */
432
433 int SCCFND(catfile,frmno,frame)
434
435 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
436 .PURPOSE
437 find corresponding frame for given entry no.
438 .ALGORITHM
439 search for given ntry no. + look up connected frame name
440 .RETURNS
441 int return status
442 ---------------------------------------------------------------------*/
443
444 char *catfile; /* IN: catalog file */
445 int frmno; /* IN: entry no. in catalog */
446 char *frame; /* OUT: corresponding frame name (terminated by \0) */
447
448 {
449 char catrec[CATREC_LEN+4];
450
451 int catid, catlen;
452 int i, n, stat;
453 int cimno, cattyp, valid;
454
455
456 stat = MID_COPN(catfile,&cattyp,&cimno);
457 if (stat != ERR_NORMAL)
458 {
459 MID_ERROR("MIDAS","SCCFND: ",stat,1);
460 return stat;
461 }
462
463 catid = CATAL[cimno].FID;
464
465 if (frmno < CATAL[cimno].RECNO)
466 {
467 stat = rewicat(catid,cimno);
468 if (stat < 0)
469 {
470 stat = ERR_CATBAD;
471 MID_ERROR("MIDAS","SCCFND: ",stat,1);
472 return stat;
473 }
474 }
475
476
477 read_loop:
478 if (frmno < CATAL[cimno].RECNO) goto not_found;
479
480 catlen = readcat(catid,cimno,catrec,&valid);
481 if (catlen < 0) goto not_found; /* EOF reached */
482 if (valid == 0) goto read_loop;
483
484 n = CATAL[cimno].RECNO - 1;
485 if (frmno == n)
486 {
487 i = CGN_INDEXC(catrec,' '); /* find end of name */
488 if (i < 1)
489 {
490 (void) printf("SCCFND: no file delimiter...\n");
491 i = 1;
492 }
493 (void) strncpy(frame,catrec,i);
494 frame[i] = '\0';
495 }
496
497 else
498 goto read_loop;
499
500 return ERR_NORMAL;
501
502 not_found:
503 stat = ERR_INPINV;
504 MID_ERROR("MIDAS","SCCFND: ",stat,1);
505 return stat;
506 }