1
/*===========================================================================
2
Copyright (C) 1995-2008 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 MIDDSCA +++++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION MIDDSCA.C
31
.AUTHOR Klaus Banse ESO - Garching
33
holds INITDS, WDSCRI, WDSCRR, WDSCRC, RDSCRI, RDSCRR, RDSCRC,
35
.KEYWORDS MIDAs Descriptors
36
.ENVIRONMENT VMS and UNIX
37
.VERSION [1.30] 861110: creation from FORTRAN version
38
.VERSION [2.50] 910718: initialize some variables in the next_descr branch
42
------------------------------------------------------------------------*/
59
int MID_CLONEDS(fcbp,iochan,fctpntri)
61
/*++++++++++++++++++++++++++++++++++++++++++++++++++
63
clone the descr. blocks (LDBs) of imnoa to imnob
67
status: I*4 return status
68
--------------------------------------------------*/
70
struct FCB_STRUCT *fcbp; /* IN: pointer to FCB of result frame */
71
int iochan; /* IN: channel of frame */
72
struct FCT_STRUCT *fctpntri; /* IN: pointer to FCT of source data frame */
81
struct LDB_STRUCT *ldbp;
83
struct FCB_STRUCT *fcbpi;
87
status = cacheLDB(22,iochan,fcbp->PTRLDB,&ldbp); /* create cache */
89
ichan = fctpntri->IOCHAN;
90
fcbpi = fctpntri->FZP;
92
fcbp->DIRENTRY = YENTRY_SIZE; /* entry in descr. direc. = 100 chars */
93
fcbp->DIREXT = 6000; /* one extension = 60 entries (6000 chars) */
95
fcbp->INLDB[0] = fcbpi->INLDB[0];
96
fcbp->INLDB[1] = fcbpi->INLDB[1];
97
fcbp->ENDLDB = fcbpi->ENDLDB;
98
fcbp->ENDLDB_OFF = fcbpi->ENDLDB_OFF;
99
fcbp->DSIZE = fcbpi->DSIZE;
100
fcbp->DFILLED = fcbpi->DFILLED;
102
cptr = (char *) ldbp;
103
nr = mr = fcbp->PTRLDB;
108
status = OSY_RVB(ichan,cptr,LDB_SIZE,nr);
109
if (status != ERR_NORMAL) goto end_of_it;
110
nr = ldbp->NEXT; /* -> next source LDB */
113
status = OSY_WVB(iochan,cptr,LDB_SIZE,ldbp->BLKNUM);
114
if (status != ERR_NORMAL) goto end_of_it;
120
printf("%d LDBs cloned\n",count);
123
fcbp->CLONY = 1; /* descr. were cloned */
125
/* move 1st LDB into cache */
127
ldbp->BLKNUM = fcbp->PTRLDB;
128
status = OSY_RVB(iochan,cptr,LDB_SIZE,ldbp->BLKNUM);
129
status = cacheLDB(3,iochan,ldbp->BLKNUM,&ldbp); /* write to disk */
130
if (status == ERR_NORMAL) return ERR_NORMAL;
135
MID_ERROR("MIDAS","MID_CLONEDS:",status,0);
143
int MID_INITDS(fcbp,iochan)
145
/*++++++++++++++++++++++++++++++++++++++++++++++++++
147
initialize the descr. directory + update the FCB accordingly
149
set up the descr. directory exactly like any other descriptor
150
reserve already LDB's (= 12 blocks) for directory + standard descriptors
152
status: I*4 return status
153
--------------------------------------------------*/
155
struct FCB_STRUCT *fcbp; /* IN: pointer to FCB of frame */
156
int iochan; /* IN: channel of frame */
159
int kldb, nn, dscdsiz;
163
char *cpntrb, *dscpntr;
165
struct LDB_STRUCT *ldbp;
169
status = cacheLDB(22,iochan,fcbp->PTRLDB,&ldbp); /* create cache */
171
dscdsiz = fcbp->DBEGIN;
172
kldb = fcbp->INLDB[0]; /* no. of LDBs needed for dscdir */
173
mm = (kldb * LDB_DATA); /* size in bytes */
174
n = mm - dscdsiz; /* space left in `kldb' LDBs */
175
nn = (kldb << 2) - 2; /* (*4 - 2), so blockno.s like 2, 6, 10, 14 */
178
/* set up endpointers to include already 1. entry of descr. directory */
182
fcbp->ENDLDB = nn; /* dscdir fits with extra space */
183
mm -= LDB_DATA; /* no_bytes in full first blocks */
184
n = (dscdsiz - mm) / II_SIZE; /* move to 4-byte words */
185
fcbp->ENDLDB_OFF = n + 1; /* offset is in 4-byte words ... */
189
fcbp->ENDLDB = nn + 4; /* dscdir fits with no extra space */
190
fcbp->ENDLDB_OFF = 1;
193
fcbp->DSIZE = dscdsiz - 12; /* just drop the 12 byte header stuff */
196
/* calculate initial no. of LDBs and initialize them */
198
ldbp->LDBWORDS.IWORD[0] = fcbp->DSIZE;
199
ldbp->LDBWORDS.IWORD[1] = -1; /* indicate that it's contiguous */
200
ldbp->LDBWORDS.IWORD[2] = 0; /* no index into extension block, yet */
202
fcbp->CLONY = 0; /* descr. are created from scratch */
205
/* handle decriptor directory entries */
207
fcbp->DIRENTRY = YENTRY_SIZE; /* entry in descr. direc. = 100 chars */
208
fcbp->DIREXT = 6000; /* one extension = 60 entries (6000 chars) */
211
(short int) CGN_COPY(YDSC_PNTR->NAMESTR,"DESCRIPTOR.DIRECTORY");
212
YDSC_PNTR->TYPE = 'C'; /* type of descr. */
213
YDSC_PNTR->HELPLEN = (short int) 0; /* no help text */
214
YDSC_PNTR->UNIT = (short int) 0;
215
YDSC_PNTR->BYTELEM = (short int) 1;
216
YDSC_PNTR->NOELEM = fcbp->DSIZE;
217
YDSC_PNTR->START = fcbp->PTRLDB; /* start in 1. LDB (block 2) */
218
YDSC_PNTR->INDEX = 1; /* in first data word */
219
dscpntr = (char *) &YDSCDIR_ENTRY;
222
fcbp->DFILLED = nn; /* first entry used for direc. itself */
224
cpntrb = (char *) &ldbp->LDBWORDS;
225
cpntrb += (3*II_SIZE); /* skip 3 integers (= LDB.LDBWORDS.CWORD[12]) */
226
CGN_COPYALL(cpntrb,dscpntr,nn); /* put chardata into word 4,5,6,... */
230
already reserve + link the first LDBs together from no. 2 on
231
remember, 4 blocks form an LDB and block 1 = FCB
232
the descr directory is included
235
nn = fcbp->INLDB[0] + fcbp->INLDB[1]; /* total no. of inital LDBs */
237
ldbp->BLKNUM = fcbp->PTRLDB;
238
for (nr=1; nr<nn; nr++)
240
ldbp->NEXT = ldbp->BLKNUM + 4;
241
status = cacheLDB(3,iochan,ldbp->BLKNUM,&ldbp); /* write to disk */
242
if (status != ERR_NORMAL) goto end_of_it;
243
ldbp->BLKNUM = ldbp->NEXT; /* chain LDBs */
246
ldbp->NEXT = 0; /* mark end of LDB list */
247
status = cacheLDB(3,iochan,ldbp->BLKNUM,&ldbp); /* write last LDB to disk */
248
if (status == ERR_NORMAL)
249
return (status); /* that's it folks... */
252
/* store error codes */
256
MID_ERROR("MIDAS","MID_INITDS:",status,0);
264
int MID_RDSCRC(iochan,start_block,start_indx,first,total,cvals,nullo)
266
/*++++++++++++++++++++++++++++++++++++++++++++++++++
268
read the contents of a descriptor and its extensions as
269
integer/real/character data
271
The values of a descriptor are returned as integer/real/char. data.
272
No more than MAXVAL values will be returned, but ACTVAL will
273
be set to the actual no. of values associated with the
274
descriptor, starting from the position which is specified as 1. element
277
--------------------------------------------------*/
279
int iochan /* IN : channel of frame */;
280
int start_block /* IN : start block no. of descriptor */;
281
int start_indx /* IN : start index in that block */;
282
int first /* IN : position of 1. element to be accessed */;
283
int total /* IN : no. of values to return */;
284
char *cvals /* OUT: array to hold descriptor data */;
285
int *nullo /* IO : no. of null values in data */;
288
int bldb, ildb, extens[2];
289
int off, begin, end, tval, rval;
294
struct LDB_STRUCT *ldbp;
300
begin, end point to begin + end of descr. data
301
off points to offset within descr. data */
307
status = cacheLDB(1,iochan,bldb,&ldbp); /* get starting LDB in */
310
/* 1. loop - look for start descriptor element */
313
LDBinfo(iochan,ldbp,ildb,&rval,extens);
315
begin = end + 1; /* keep start index */
316
end += rval; /* update end */
321
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
322
if (bldb != ldbp->BLKNUM)
323
status = cacheLDB(1,iochan,bldb,&ldbp);
328
/* 2. loop - fill data with descriptor data */
331
off = first - begin + 1;
335
nulflag = *nullo; /. save null flag, -1 means do not check... ./
337
feature not implemented yet
340
register char *kpntr;
345
if (bldb != ldbp->BLKNUM)
346
status = cacheLDB(1,iochan,bldb,&ldbp);
349
(void) MID_RDcLDB(iochan,ldbp,ildb,cpntra,off,&rval,extens);
351
kpntr = cpntra; /. handle NULL checks ./
352
for (nr=0; nr<rval; nr++)
354
if (*kpntr++ == NUL_CVAL) (*nullo) ++;
358
cpntra += rval; /. update pointers ./
360
ildb = extens[1] - 1;
371
if (bldb != ldbp->BLKNUM)
372
status = cacheLDB(1,iochan,bldb,&ldbp);
375
(void) MID_RDcLDB(iochan,ldbp,ildb,cpntra,off,&rval,extens);
378
cpntra += rval; /* update pointers */
380
ildb = extens[1] - 1;
395
int MID_RDSCRI(iochan,start_block,start_indx,first,total,ivals,nullo)
397
/*++++++++++++++++++++++++++++++++++++++++++++++++++
399
read the contents of a descriptor and its extensions as
400
integer/real/character data
402
The values of a descriptor are returned as integer/real/char. data.
403
No more than MAXVAL values will be returned, but ACTVAL will
404
be set to the actual no. of values associated with the
405
descriptor, starting from the position which is specified as 1. element
408
--------------------------------------------------*/
410
int iochan /* IN : channel of frame */;
411
int start_block /* IN : start bldb no. of descriptor */;
412
int start_indx /* IN : start index in that bldb */;
413
int first /* IN : position of 1. element to be accessed */;
414
int total /* IN : no. of values to return */;
415
int *ivals /* OUT: array to hold descriptor data */;
416
int *nullo /* IO : no. of null values in data */;
419
int bldb, ildb, extens[2];
420
int off, begin, end, tval, rval;
426
struct LDB_STRUCT *ldbp;
432
begin, end point to begin + end of descr. data
433
off points to offset within descr. data */
439
status = cacheLDB(1,iochan,bldb,&ldbp);
442
/* 1. loop - look for start descriptor element */
445
LDBinfo(iochan,ldbp,ildb,&rval,extens);
447
begin = end + 1; /* keep start index */
448
end += rval; /* update end */
453
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
454
if (bldb != ldbp->BLKNUM)
455
status = cacheLDB(1,iochan,bldb,&ldbp);
460
/* 2. loop - fill data with descriptor data */
463
off = first - begin + 1;
467
nulflag = *nullo; /. save null flag, -1 means do not check... ./
469
feature not implemented yet
477
if (bldb != ldbp->BLKNUM)
478
status = cacheLDB(1,iochan,bldb,&ldbp);
481
(void) MID_RDLDB(iochan,ldbp,ildb,1,ipntr,&rdummy,off,
485
for (nr=0; nr<rval; nr++)
487
if (*hpntr++ == NUL_IVAL) (*nullo) ++;
491
ipntr += rval; /. update pointers ./
493
ildb = extens[1] - 1;
503
if (bldb != ldbp->BLKNUM) status = cacheLDB(1,iochan,bldb,&ldbp);
506
(void) MID_RDLDB(iochan,ldbp,ildb,1,ipntr,&rdummy,off,
512
ipntr += rval; /* update pointers */
514
ildb = extens[1] - 1;
530
int MID_RDSCRR(iochan,start_block,start_indx,first,total,rvals,nullo)
532
/*++++++++++++++++++++++++++++++++++++++++++++++++++
534
read the contents of a descriptor and its extensions as
535
integer/real/character data
537
The values of a descriptor are returned as integer/real/char. data.
538
No more than MAXVAL values will be returned, but ACTVAL will
539
be set to the actual no. of values associated with the
540
descriptor, starting from the position which is specified as 1. element
543
--------------------------------------------------*/
545
int iochan /* IN : channel of frame */;
546
int start_block /* IN : start bldb no. of descriptor */;
547
int start_indx /* IN : start index in that bldb */;
548
int first /* IN : position of 1. element to be accessed */;
549
int total /* IN : no. of values to return */;
550
float *rvals /* OUT: array to hold descriptor data */;
551
int *nullo /* IO : no. of null values in data */;
554
int bldb, ildb, extens[2];
555
int off, begin, end, tval, rval;
560
struct LDB_STRUCT *ldbp;
566
begin, end point to begin + end of descr. data
567
off points to offset within descr. data */
573
status = cacheLDB(1,iochan,bldb,&ldbp);
576
/* 1. loop - look for start descriptor element */
579
LDBinfo(iochan,ldbp,ildb,&rval,extens);
581
begin = end + 1; /* keep start index */
582
end += rval; /* update end */
587
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
588
if (bldb != ldbp->BLKNUM)
589
status = cacheLDB(1,iochan,bldb,&ldbp);
594
/* 2. loop - fill data with descriptor data */
597
off = first - begin + 1;
601
nulflag = *nullo; /. save null flag, -1 means do not check... ./
603
feature not implemented yet
607
register float *fpntr;
611
if (bldb != ldbp->BLKNUM)
612
status = cacheLDB(1,iochan,bldb,&ldbp);
615
(void) MID_RDLDB(iochan,ldbp,ildb,2,&idummy,rpntr,
619
for (nr=0; nr<rval; nr++)
621
if (*fpntr++ == NUL_RVAL) (*nullo) ++;
625
rpntr += rval; /. update pointers ./
627
ildb = extens[1] - 1;
637
if (bldb != ldbp->BLKNUM) status = cacheLDB(1,iochan,bldb,&ldbp);
640
(void) MID_RDLDB(iochan,ldbp,ildb,2,&idummy,rpntr,off,
646
rpntr += rval; /* update pointers */
648
ildb = extens[1] - 1;
664
int MID_WDSCRI(iochan,start_block,start_indx,ivals,conflg,first,nval)
666
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
668
Write a descriptor + its values as integer/real/character data
671
Descriptor data is written into atoms which are already created -
672
so no checks for overflow are necessary.
675
------------------------------------------------------------------*/
677
int iochan /* IN : channel no of frame */;
678
int start_block /* IN : start LDB no */;
679
int start_indx /* IN : starting index in bldb */;
680
int *ivals /* IN : integer descriptor data */;
681
int conflg /* IN : constant flag = 1/0 (Yes/No) */;
682
int first /* IN : pos. of 1st desc. value to be accessed \
683
if 1st = -1, desc. values are appended \
685
int nval /* IN : no. of data values */;
689
int bldb, ildb, extens[2];
690
int off, begin, end, tval, rval;
697
struct LDB_STRUCT *ldbp;
702
/* get starting LDB */
708
status = cacheLDB(1,iochan,bldb,&ldbp);
711
/* 1. loop - look for start descriptor element */
714
LDBinfo(iochan,ldbp,ildb,&rval,extens);
716
begin = end + 1; /* keep start index */
717
end += rval; /* update end */
722
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
723
if (bldb != ldbp->BLKNUM)
724
status = cacheLDB(1,iochan,bldb,&ldbp);
729
/* 2. loop - fill descriptor data */
732
off = first - begin + 1;
736
if (bldb != ldbp->BLKNUM) status = cacheLDB(1,iochan,bldb,&ldbp);
739
(void) MID_WRLDB(iochan,ldbp,ildb,1,ipntr,&rdummy,cdummy,
740
conflg,off,&rval,extens);
745
if (conflg == 0) ipntr += rval; /* update pointer */
747
ildb = extens[1] - 1;
759
int MID_WDSCRR(iochan,start_block,start_indx,rvals,conflg,first,nval)
761
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
763
Write a descriptor + its values as integer/real/character data
766
Descriptor data is written into atoms which are already created -
767
so no checks for overflow are necessary.
770
--------------------------------------------------------------------------*/
772
int iochan /* IN : channel no of frame */;
773
int start_block /* IN : start LDB no */;
774
int start_indx /* IN : starting index in bldb */;
775
float *rvals /* IN : real descriptor data */;
776
int conflg /* IN : constant flag = 1/0 (Yes/No) */;
777
int first /* IN : pos. of 1st desc. value to be accessed \
778
if 1st = -1, desc. values are appended \
780
int nval /* IN : no. of data values */;
783
int bldb, ildb, extens[2];
784
int off, begin, end, tval, rval;
791
struct LDB_STRUCT *ldbp;
796
bldb = start_block; /* get starting LDB */
800
status = cacheLDB(1,iochan,bldb,&ldbp);
803
/* 1. loop - look for start descriptor element */
806
LDBinfo(iochan,ldbp,ildb,&rval,extens);
808
begin = end + 1; /* keep start index */
809
end += rval; /* update end */
814
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
815
if (bldb != ldbp->BLKNUM)
816
status = cacheLDB(1,iochan,bldb,&ldbp);
821
/* 2. loop - fill descriptor data */
824
off = first - begin + 1;
828
if (bldb != ldbp->BLKNUM) status = cacheLDB(1,iochan,bldb,&ldbp);
831
(void) MID_WRLDB(iochan,ldbp,ildb,2,&idummy,rpntr,cdummy,
832
conflg,off,&rval,extens);
837
if (conflg == 0) rpntr += rval; /* update pointer */
839
ildb = extens[1] - 1;
851
int MID_WDSCRC(iochan,start_block,start_indx,cvals,conflg,first,nval)
853
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
855
Write a descriptor + its values as integer/real/character data
858
Descriptor data is written into atoms which are already created -
859
so no checks for overflow are necessary.
862
-------------------------------------------------------------------*/
864
int iochan /* IN : channel no of frame */;
865
int start_block /* IN : start LDB no */;
866
int start_indx /* IN : starting index in bldb */;
867
char *cvals /* IN : character descriptor data */;
868
int conflg /* IN : constant flag = 1/0 (Yes/No) */;
869
int first /* IN : pos. of 1st desc. value to be accessed \
870
if 1st = -1, desc. values are appended \
872
int nval /* IN : no. of data values */;
875
int bldb, ildb, extens[2];
876
int off, begin, end, tval, rval;
883
struct LDB_STRUCT *ldbp;
888
/* get starting LDB */
894
status = cacheLDB(1,iochan,bldb,&ldbp);
897
/* 1. loop - look for start descriptor element */
900
LDBinfo(iochan,ldbp,ildb,&rval,extens);
902
begin = end + 1; /* keep start index */
903
end += rval; /* update end */
908
ildb = extens[1] - 1; /* indices are counted in FORTRAN */
909
if (bldb != ldbp->BLKNUM)
910
status = cacheLDB(1,iochan,bldb,&ldbp);
915
/* 2. loop - fill descriptor data */
918
off = first - begin + 1;
922
if (bldb != ldbp->BLKNUM) status = cacheLDB(1,iochan,bldb,&ldbp);
925
(void) MID_WRLDB(iochan,ldbp,ildb,3,&idummy,&rdummy,cpntra,
926
conflg,off,&rval,extens);
931
if (conflg == 0) cpntra += rval; /* update pointer */
933
ildb = extens[1] - 1;