Debian Codegraph @

libsrc/st/midfct.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2011 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 MIDFCT +++++++++++++++++++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module midfct.c
31 .AUTHOR Klaus Banse
32 .KEYWORDS Midas utility routines.
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds MID_ACCFRM, MID_ACCFITS,
36 MID_CREFRE, MID_FINDFR, MID_INITFR, MID_RETNAM
37 MID_FCTCTRL
38 .VERSION [1.50] 871110: new repartition KB
39
40 110310 last modif
41 ------------------------------------------------------------------------*/
42
43
44 #include <fileexts.h> /* includes all others: e.g. <midas_def.h> */
45 #include <computer.h>
46 #include <fsydef.h>
47 #include <osparms.h>
48 #include <osyparms.h>
49
50 #include <fcntl.h>
51 #include <stdlib.h>
52 #include <unistd.h>
53 #include <string.h>
54 #include <libgen.h>
55
56
57 #define BIT_0 0x1
58
59 #define READ 0
60 #define WRITE 1
61 #define READ_WRITE 2
62 #define APPEND 3
63
64
65 static int swapshort = SWAPSHORT;
66 static int swapint = SWAPINT;
67 static int floatfmt = FLOATFMT;
68
69 /*
70 from 900606 on: VERS_005 not supported after 04SEP
71 from 921006 on: VERS_006 "
72 from 950712 on: VERS_007 "
73 from 961030 on: VERS_010 not supported after 07SEP
74 from 010308 on: VERS_100
75 from 020313 on: VERS_101
76 from 030120 on: VERS_105
77 from 060601 on: VERS_110
78 from 090401 on: VERS_120
79 */
80
81 static char Midvers[] = "VERS_";
82
83 static struct FCT_STRUCT *fctpntr;
84
85 static int compress_flag;
86
87 /*
88
89 */
90
91 int MID_ACCFITS(name,flag,extensio,entrx)
92
93 /*++++++++++++++++++++++++++++++++++++++++++++++++++
94 .KEYWORDS
95 frame control table, FITS file access
96 .PURPOSE
97 access a FITS file and convert the FITS header to Midas descr. format
98 .ALGORITHM
99 Build internal name FITZ`orig-name' and use MID_fitsin to convert
100 FITS header to Midas descr. format
101 .RETURNS
102 status: int return status
103 --------------------------------------------------*/
104
105 char *name; /* IN : complete frame name */
106 int flag; /* IN : control flag:
107 0 - open an existing FITS file,
108 1 - open an existing FITS file again,
109 2 - create new entry + open (existing) FITS file
110 for 1. time */
111 int extensio; /* IN : extension no. */
112 int *entrx; /* OUT: FCT entry number */
113
114 {
115 int kstat, last_compress, first_time, mm;
116 int lennam;
117
118 char work[84], bname[160];
119 char *myname;
120
121 struct FCB_STRUCT *fcbp;
122
123
124
125
126 /*
127 FITS files are handled directly in Midas as follows:
128 The FITS file abc.xyz is read in as any FITS file in Midas, thereby
129 converted to the Midas format, and stored in virtual memory, only.
130 This file is internally renamed to FITZabc.xyz if it's a single
131 image/table FITS file.
132 FITS extensions are counted with the prime header regarded as
133 extension 0. So, a FITS file with two extensions would have a primary
134 header ("empty", i.e. NAXIS=0, if ext. 1 is a table), and ext. 1 and
135 ext. 2.
136 The extension no. is appended to the name, e.g. extension 3 of abc.xyz
137 would have the internal name FITZabc.xyz003.
138 Therefore, FITS files with max. 999 extensions can be processed
139 directly in Midas, currently.
140 */
141
142
143
144 /* FITS files must be in current dir. */
145
146 mm = CGN_JNDEXC(name,FSY_DIREND);
147 if (mm > -1)
148 { /* we have a FITS file with a dir. */
149 char curdir[1024];
150
151 if (getcwd(curdir,(size_t)1024) != NULL)
152 {
153 char *dirc, *dirnam;
154
155 dirc = strdup((const char*) name);
156 dirnam = dirname(dirc); /* extract dir. path only */
157 kstat = strcmp(curdir,dirnam);
158 free(dirc);
159
160 if (kstat == 0)
161 { /* o.k. - file path = current dir. */
162 myname = name + mm + 1; /* take off path */
163 goto move_on;
164 }
165 }
166
167 (void) strcpy(curdir,
168 "direct access to FITS files only possible in current working dir...");
169 MID_LOG('G',curdir,(int)strlen(curdir));
170 printf("%s\n",curdir); /* avoid using STTPUT() ... */
171 return (ERR_INPINV);
172 }
173 else
174 myname = name;
175
176 move_on:
177 (void) strcpy(bname,"FITZ");
178 (void) strcpy(&bname[4],myname);
179 lennam = (int)strlen(bname);
180
181 if (extensio > -1)
182 {
183 (void) sprintf(work,"%3.3d",extensio);
184 (void) strcat(bname,work);
185 }
186
187 last_compress = compress_flag; /* save flag from previous ACCFRM call */
188
189 kstat = MID_ACCFRM(bname,flag,entrx,&mm); /* maybe already there... */
190 if (kstat != ERR_NORMAL)
191 { /* NO - we have to create new frame */
192 MID_POPERR(); /* pop errors message from ACCFRM */
193 kstat = /* convert FITS to Midas */
194 MID_fitsin(1,myname,extensio,bname,work,entrx,&mm);
195 /* this goes via SCFCRE ... */
196 if (kstat != 0)
197 {
198 if (kstat == -9)
199 return (ERR_FITEXT);
200 else
201 return (ERR_VERNOR);
202 }
203 first_time = 1;
204 }
205 else
206 first_time = 0;
207
208
209 /* indicate FITS format */
210
211 fctpntr = FCT.ENTRIES + (*entrx);
212 fctpntr->COMPRESS = last_compress; /* in case ACCFRM compressed... */
213 fcbp = fctpntr->FZP;
214 fctpntr->SIZE = fcbp->FITSINF1; /* use that as nopix ... */
215 fctpntr->O_NAMLEN = lennam;
216
217 if (first_time == 1)
218 fctpntr->FILTYP = mm; /* FITS format > 0 */
219
220 return (ERR_NORMAL);
221 }
222 /*
223
224 */
225
226 int MID_ACCFRM(name,flag,entrx,aux)
227
228 /*++++++++++++++++++++++++++++++++++++++++++++++++++
229 .KEYWORDS
230 frame control table, access
231 .PURPOSE
232 Access the frame control table to retrieve all necessary
233 information concerning data frames
234 .ALGORITHM
235 Search the FCT for an existing frame entry of the same name.
236 If a FCT entry does not exist, it is created and a bulk
237 data file is physically opened. This operation returns
238 the I/O channel assigned to the file and (for VMS) other useful info.
239 Finally read in the FCB.
240 .RETURNS
241 status: int return status
242 --------------------------------------------------*/
243
244 char *name; /* IN : complete frame name */
245 int flag; /* IN : control flag:
246 0 - open an existing disk file,
247 1 - open an existing disk file again,
248 2 - create new entry + open (existing) disk file
249 for 1. time */
250 int *entrx; /* OUT: FCT entry number */
251 int *aux; /* OUT: additional info:
252 [0] = 0 - file was not already in FCT
253 [0] = 1 - yes, file was already in FCT */
254
255 {
256 int entrx1, n, mm, status;
257 int ioch, fid, fidcount;
258
259 #if vms
260 int vmsfida, vmsfidb;
261 static char c1='_', c2='G', c3='Z';
262
263 #else
264 static char c1='.', c2='g', c3='z';
265 #endif
266
267 char strbuf[8], work[168], *nampntr;
268
269 struct FCB_STRUCT *fcbp;
270
271 struct FCT_STRUCT *fctpntro;
272
273 struct LDB_STRUCT *ldbp;
274
275 extern char DATA_PATH[328];
276
277
278
279
280 status = ERR_NORMAL;
281 strbuf[0] = 'M'; /* make sure, it's initialized */
282 strbuf[1] = '\0';
283
284 compress_flag = 0;
285 mm = *entrx; /* maybe value should be reused */
286
287 if (flag == 2) goto new_entry;
288
289
290 /* flag = 0 or 1 -> first, search for existing entry in FCT */
291
292 entrx1 = MID_FINDFR(name);
293
294 if (entrx1 < 0) /* if not found, test more */
295 {
296 ioch = (int)strlen(name) - 2;
297 if ((name[ioch] == c1) && (name[ioch+1] == 'Z'))
298 compress_flag = 1;
299 else if ((name[ioch-1] == c1) && (name[ioch] == c2)
300 && (name[ioch+1] == c3))
301 {
302 ioch --; /* keep pointed to '.' */
303 compress_flag = 2;
304 }
305 else
306 goto new_entry;
307
308
309 /* we have a compressed frame here */
310
311 name[ioch] = '\0'; /* name.typ.Z => name.typ */
312 entrx1 = MID_FINDFR(name); /* try again */
313 if (entrx1 < 0) /* still not found, so do it ... */
314 {
315 char *Nullptr = (char *) 0;
316
317 #if vms
318 if (compress_flag == 1)
319 (void) snprintf(work,(size_t) 160,"compress -d %s_Z",name);
320 else
321 (void) snprintf(work,(size_t) 160,"gzip -d %s_GZ",name);
322
323 #else
324 if (compress_flag == 1)
325 (void) snprintf(work,(size_t) 160,"uncompress %s.Z",name);
326 else
327 (void) snprintf(work,(size_t) 160,"gzip -d %s.gz",name);
328 #endif
329
330 oshcmd(work,Nullptr,Nullptr,Nullptr);
331 goto new_entry;
332 }
333 }
334
335 fctpntr = FCT.ENTRIES + entrx1;
336
337 if (flag == 1) /* open frame again */
338 {
339 register int mr;
340
341 fctpntro = fctpntr; /* save entry of that match */
342 entrx1 = MID_CREFRE(name,-1); /* create one more entry */
343 fctpntr = FCT.ENTRIES + entrx1; /* copy entry */
344 fctpntr->IOCHAN = fctpntro->IOCHAN;
345
346 #if vms
347 fctpntr->FILEIDA = fctpntro->FILEIDA;
348 fctpntr->FILEIDB = fctpntro->FILEIDB;
349 (void) strcpy(fctpntr->DEVICE,fctpntro->DEVICE);
350 #else
351 fctpntr->FILEID = fctpntro->FILEID;
352 #endif
353
354 for (mr=0; mr<4; mr++)
355 fctpntr->KAUX[mr] = fctpntro->KAUX[mr];
356 fctpntr->SIZE = fctpntro->SIZE;
357 fctpntr->PROT = fctpntro->PROT;
358 fctpntr->COMPRESS = fctpntro->COMPRESS;
359 fctpntr->NOBYTE = fctpntro->NOBYTE;
360 fctpntr->FORMAT = fctpntro->FORMAT;
361 fctpntr->DATTYP = fctpntro->DATTYP;
362 fctpntr->PIXPBL = fctpntro->PIXPBL;
363 fctpntr->STBLOK = fctpntro->STBLOK;
364 fctpntr->FILTYP = fctpntro->FILTYP;
365 fctpntr->FITSEXT = fctpntro->FITSEXT;
366 fctpntr->LINK[0] = fctpntro->LINK[0];
367 fctpntr->LINK[1] = fctpntro->LINK[1];
368 fctpntr->CR_FLAG = fctpntro->CR_FLAG;
369 fctpntr->O_NAMLEN = fctpntro->O_NAMLEN;
370 for (mr=0; mr<3; mr++)
371 fctpntr->FITSADDR[mr] = fctpntro->FITSADDR[mr];
372 fctpntr->FITSOUT = fctpntro->FITSOUT;
373 fctpntr->CATALOG[0] = fctpntro->CATALOG[0];
374 fctpntr->CATALOG[1] = fctpntro->CATALOG[1];
375 fctpntr->FZP = fctpntro->FZP;
376 }
377
378 *aux = 1; /* indicate that frame already in FCT */
379 *entrx = entrx1;
380 return ERR_NORMAL;
381
382
383
384 /* build up new entry in FCT */
385
386 new_entry: /* create new entry in FCT */
387 *aux = 0; /* indicate that frame is new in FCT */
388 nampntr = name;
389 fidcount = 0;
390 entrx1 = MID_CREFRE(name,mm); /* try to create one more entry */
391
392 if (unlikely(entrx1 < 0)) /* filename too long */
393 {
394 MID_ERROR("MIDAS","MID_ACCFRM:",status,0);
395 return ERR_FILNAM;
396 }
397
398 fctpntr = FCT.ENTRIES + entrx1; /* o.k. */
399 fctpntr->COMPRESS = compress_flag;
400
401
402 open_file: /* open bulk data file */
403
404 #if vms
405 FSY_OPNBDF(nampntr,fctpntr->NAMLEN,&ioch,&vmsfida,&vmsfidb,
406 fctpntr->DEVICE,&status);
407 if ((status & BIT_0) == 0 )
408 fid = -1;
409 else
410 {
411 fid = 0;
412 fctpntr->FILEIDA = vmsfida;
413 fctpntr->FILEIDB = vmsfidb;
414 fctpntr->DEVICE[16] = '\0';
415 fctpntr->IOCHAN = ioch;
416 status = ERR_NORMAL;
417 }
418
419 #else
420 fid = open(nampntr,O_RDWR);
421 if (fid == -1) /* if not o.k. for READ+WRITE, try to open READ only */
422 {
423 fid = open(nampntr,O_RDONLY);
424 if (fid > -1) fctpntr->PROT = 2; /* set read only flag */
425 }
426
427 fctpntr->FILEID = fid;
428 fctpntr->IOCHAN = fid; /* the same in Unix */
429 #endif
430
431
432 if (fid < 0)
433 {
434 if (fidcount < 4)
435 {
436 n = fidcount*80;
437 (void) strncpy(work,&DATA_PATH[n],80);
438 if (work[0] != '^')
439 {
440 work[80] = ' ';
441 n = CGN_INDEXC(work,' ');
442 (void) strcpy(&work[n],name); /* use new path */
443 nampntr = work;
444 fidcount ++;
445 goto open_file;
446 }
447 }
448
449 fctpntr->NAME[0] = ' '; /* clear entrx1 again */
450 free(fctpntr->FZP);
451 MID_ERROR("FSY","MID_ACCFRM:",ERR_FRMNAC,0);
452 return ERR_FRMNAC;
453 }
454
455
456 fcbp = fctpntr->FZP; /* pointer to individual FCB */
457 if (flag != 2)
458 { /* get FCB + check compatibility with host */
459 status = OSY_RVB(fctpntr->IOCHAN,(char *)fcbp,OUR_BLOCK_SIZE,1);
460 if (unlikely(status != ERR_NORMAL))
461 {
462 status = ERR_FRMNAC;
463 (void) strcpy(strbuf,"OSY");
464 goto error_return;
465 }
466
467 if (strncmp(fcbp->VERSION,Midvers,5) == 0) /* compare only "VERS_" */
468 {
469 if (swapshort == 12)
470 {
471 if (unlikely(fcbp->SWPSHORT != '=')) goto error_return_0;
472 }
473 else /* if (swapshort == 21) */
474 {
475 if (unlikely(fcbp->SWPSHORT != 's')) goto error_return_0;
476 }
477
478 if (swapint == 1234)
479 {
480 if (unlikely(fcbp->SWPINT != '=')) goto error_return_0;
481 }
482 else if (swapint == 4321)
483 {
484 if (unlikely(fcbp->SWPINT != 's')) goto error_return_0;
485 }
486 else if (swapint == 2143)
487 {
488 if (unlikely(fcbp->SWPINT != 'h')) goto error_return_0;
489 }
490 else /* if (swapint == 3412) */
491 {
492 if (unlikely(fcbp->SWPINT != 'w')) goto error_return_0;
493 }
494
495 if (floatfmt == IEEEFLOAT)
496 {
497 if (unlikely(fcbp->FLOTFMT != '=')) goto error_return_0;
498 }
499
500 #if vms
501 else if (floatfmt == VAXFLOAT)
502 {
503 if (fcbp->FLOTFMT != 'V')
504 {
505 if (fcbp->FLOTFMT != 'G') goto error_return_0;
506 SCTPUT("Warning: data is VAX Gfloat instead of Float...");
507 }
508 }
509 else if (floatfmt == VAXGFLOAT)
510 {
511 if (fcbp->FLOTFMT != 'G')
512 {
513 if (fcbp->FLOTFMT != 'V') goto error_return_0;
514 SCTPUT("Warning: data is VAX Float instead of Gfloat...");
515 }
516 }
517 #endif
518
519 else if (floatfmt == HPFLOAT)
520 {
521 if (unlikely(fcbp->FLOTFMT != 'H')) goto error_return_0;
522 }
523 }
524
525 else
526 {
527 status = ERR_VERNOR; /* version not recognizable... */
528 goto error_return; /* tell caller, to try FITS access */
529 }
530
531 fctpntr->SIZE = fcbp->NDVAL;
532 fctpntr->NOBYTE = fcbp->NOBYT;
533 fctpntr->FORMAT = fcbp->DFORMAT;
534 fctpntr->PIXPBL = fcbp->PIXPBL;
535 fctpntr->STBLOK = fcbp->D1BLOCK;
536 fctpntr->CATALOG[0] = fcbp->BDTYPE[0];
537
538 /* also read first LDB from disk */
539 status = cacheLDB(1,fctpntr->IOCHAN,fcbp->PTRLDB,&ldbp);
540 if (unlikely(status != ERR_NORMAL))
541 {
542 (void) strcpy(strbuf,"MIDAS");
543 goto error_return;
544 }
545 }
546
547 fctpntr->CATALOG[1] = 'N';
548 *entrx = entrx1;
549 return status;
550
551
552
553 /* here for errors */
554
555 error_return_0:
556 status = ERR_FMTBAD;
557 (void) strcpy(strbuf,"MIDAS");
558
559 error_return:
560 if ((char *)fctpntr->FZP != (char *) 0) free ((char *)fctpntr->FZP);
561 OSY_DASSGN(entrx1,mm);
562
563 fctpntr->NAME[0] = ' '; /* clear FCT entry again */
564 fctpntr->NAME[1] = '\0';
565 MID_ERROR(strbuf,"MID_ACCFRM:",status,0);
566 return status;
567 }
568 /*
569
570 */
571
572 int MID_CREFRE(name,wanted)
573
574 /*++++++++++++++++++++++++++++++++++++++++++++++++++
575 .KEYWORDS
576 frame control table
577 .PURPOSE
578 create an entry in the frame control table (FCT) for
579 specified name + access flag and return the entry no.
580 if no room, return status = 0, else status = 1
581 .ALGORITHM
582 straight forward
583 .RETURNS
584 entrx: I*4 FCT entry no. (>= 0)
585 or -2 if filename too long
586 --------------------------------------------------*/
587
588 char *name; /* IN : complete name of bulk data frame */
589 int wanted; /* IN : if in [0,FCT.MAXENT[, it is interpreted \
590 as wanted index and we try our best at it */
591 {
592 int lna, mm, nr;
593
594
595
596 #if vms
597 char upname[FCT_NAME_LEN];
598 int nll;
599
600
601 nll = FCT_NAME_LEN-1;
602 CGN_UPCOPY(upname,name,nll); /* for VMS use upper case names */
603 #endif
604
605
606
607
608 for (nr=0; nr<FCT_NAME_LEN; nr++) /* check name length */
609 {
610 if (name[nr] == '\0')
611 {
612 lna = nr;
613 goto start_ok;
614 }
615 }
616 return (-2); /* name too long! */
617
618
619 start_ok:
620 if ((wanted >= 0) && (wanted < FCT.MAXENT)) /* if wanted in valid range */
621 { /* try to fill that entry */
622 nr = wanted;
623 fctpntr = FCT.ENTRIES + nr;
624 if (fctpntr->NAME[0] == ' ') goto do_it;
625 }
626
627
628 /* look for empty slot in FCT table */
629
630 look:
631 fctpntr = FCT.ENTRIES;
632 for (nr=0; nr<FCT.MAXENT; nr++)
633 {
634 if (fctpntr->NAME[0] == ' ') goto do_it;
635 fctpntr ++;
636 }
637
638
639 /* no more space in FCT - we have to extend it */
640
641 mm = FCT.MAXENT + 8; /* increase in chunks of 8 */
642 MID_FCTIN(mm); /* update also FCT.MAXENT there */
643 goto look; /* and search again */
644
645 do_it:
646 #if vms
647 (void) strcpy(fctpntr->NAME,upname); /* copy 'upname' + init entry */
648 #else
649 (void) strcpy(fctpntr->NAME,name); /* copy 'name' + init entry */
650 #endif
651
652 fctpntr->NAMLEN = lna;
653 fctpntr->BDADDR[0] = (char *) 0;
654 fctpntr->BDADDR[1] = (char *) 0;
655 fctpntr->PNTR = (char *) 0;
656 fctpntr->PROT = 3; /* default to read_write */
657 fctpntr->COMPRESS = 0;
658 fctpntr->CATALOG[1] = 'N';
659 fctpntr->KAUX[0] = 0;
660 fctpntr->KAUX[1] = 0;
661 fctpntr->KAUX[2] = 0;
662 fctpntr->LINK[0] = 0;
663 fctpntr->LINK[1] = 0;
664 fctpntr->ACCESS = 'I';
665 fctpntr->CR_FLAG = 0;
666 fctpntr->O_NAMLEN = 0;
667 fctpntr->DATTYP = D_OLD_FORMAT;
668 fctpntr->FILTYP = 0; /* default to Midas file type */
669 fctpntr->FITSEXT = 0;
670 fctpntr->FZP =
671 (struct FCB_STRUCT *) malloc((unsigned int) sizeof(struct FCB_STRUCT));
672 fctpntr->FITSADDR[0] = (char *) 0;
673 fctpntr->FITSADDR[1] = (char *) 0;
674 fctpntr->FITSADDR[2] = (char *) 0;
675 fctpntr->FITSOUT = ' ';
676
677 return (nr); /* return entry into FCT */
678 }
679 /*
680
681 */
682
683 int MID_FINDFR(name)
684
685 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
686 .KEYWORDS
687 Frame Control Table, bulk data frames
688 .PURPOSE
689 get the entry in the FCT of a bulk data frame
690 .ALGORITHM
691 search the FCT for given name + access flag and return its entry
692 if not found return -1
693 .RETURNS
694 entry_no in FCT
695 -------------------------------------------------------------*/
696
697 char *name; /* IN : complete name of bulk data frame */
698
699 {
700 int nr;
701
702
703 #if vms
704 char upname[FCT_NAME_LEN];
705 int nll;
706
707 nll = FCT_NAME_LEN-1;
708 CGN_UPCOPY(upname,name,nll); /* for VMS use upper case names */
709 #endif
710
711
712 fctpntr = FCT.ENTRIES;
713 for (nr=0; nr<FCT.MAXENT; nr++) /*loop through FCT and compare name */
714 {
715 #if vms
716 if ( strcmp(fctpntr->NAME,upname) == 0 ) return nr;
717 #else
718 if ( strcmp(fctpntr->NAME,name) == 0 ) return nr;
719 #endif
720
721 fctpntr ++;
722 }
723
724 return (-1);
725 }
726 /*
727
728 */
729
730 int MID_FCTCTRL(flag,id,values)
731
732 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
733 .KEYWORDS
734 Frame Control Table, bulk data frames
735 .PURPOSE
736 access/control the FCT contents of a frame from high level code
737 .ALGORITHM
738 function depends on flag
739 .RETURNS
740 if o.k. return 0, else != 0
741 -------------------------------------------------------------*/
742
743 int flag; /* IN: action flag */
744 int id; /* IN: FCT entry no. */
745 int *values; /* IN/OUT: data array, depends on flag */
746
747
748 {
749 if ((id < 0) || (id >= FCT.MAXENT)) return (-1);
750 fctpntr = FCT.ENTRIES + id;
751
752 if (flag == 1)
753 {
754 fctpntr->KAUX[2] = *values;
755 }
756
757 return 0;
758 }
759 /*
760
761 */
762
763 int MID_RETNAM(id,name,lnam)
764
765 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
766 .KEYWORDS
767 Frame Control Table, bulk data frames
768 .PURPOSE
769 get the FCT name of a file id (imno in SCF modules)
770 .ALGORITHM
771 return the name in given FCT_entry
772 if internal FITS file, remove leading FITZ and cut off extens. no's
773 .RETURNS
774 if not found return -1, if name buffer not large enough return -2
775 else 0
776 -------------------------------------------------------------*/
777
778 int id; /* IN: FCT entry no. */
779 char *name; /* OUT: complete name of bulk data frame */
780 int lnam; /* IN: max. length of name */
781
782 {
783 int ilen;
784
785
786
787 if ((id < 0) || (id >= FCT.MAXENT)) return (-1);
788
789
790 fctpntr = FCT.ENTRIES + id;
791 if (fctpntr->NAME[0] == ' ') return (-1); /* file already closed */
792
793 if (fctpntr->O_NAMLEN > 0) /* internal FITS file */
794 { /* FITZorigname... */
795 ilen = fctpntr->O_NAMLEN - 4;
796 if (lnam <= ilen) return (-2); /* name too long */
797
798 (void) strcpy(name,fctpntr->NAME+4);
799 name[ilen] = '\0'; /* cut off ext no's ... */
800 }
801 else
802 {
803 if (lnam <= fctpntr->NAMLEN) return (-2); /* name too long */
804 (void) strcpy(name,fctpntr->NAME);
805 }
806
807 return (0);
808 }
809