/* @(#)scd.c 17.1.1.1 (ESO-DMD) 01/25/02 17:36:25 */ /*=========================================================================== Copyright (C) 1995 European Southern Observatory (ESO) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. Correspondence concerning ESO-MIDAS should be addressed as follows: Internet e-mail: midas@eso.org Postal address: European Southern Observatory Data Management Division Karl-Schwarzschild-Strasse 2 D 85748 Garching bei Muenchen GERMANY ===========================================================================*/ /*++++++++++++++++++++++++++++ SC interface module SCD +++++++++++++++++++++++ .LANGUAGE C .IDENTIFICATION Module SCD .AUTHOR K. Banse ESO - Garching .KEYWORDS standard interfaces, descriptors .ENVIRONMENT VMS and UNIX .COMMENTS holds SCDRDx (x=C,D,I,R,L, Z,X) .VERSION [2.00] 871125: new and hopefully final version ... 011126 last modif ----------------------------------------------------------------------------*/ #include #include #include #define DISK_REC 512 static char realdescr[52], help[72]; static int dsclen; /* */ int SCDRDC(imno,descr,noelm,felem,maxvals,actvals,values,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a character descriptor and its extensions .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int noelm /* IN : no. of "elements" in type, i.e. CHAR*noelm */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; char *values /* OUT: array for descriptor data */; int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int mm, kk, koff; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ dtype[0] = 'C'; if (fcbp->DSCFLAG == 'Y') status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); else if (fcbp->DSCFLAG == 'Z') status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); else status = MID_DSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) goto end_of_it; mm = noelem * bytelem; /* real size of descr. */ koff = (felem-1) * noelm; /* requested offset */ kk = mm - koff; /* size available */ /* check parameters */ if ( (felem <= 0) || (noelm < 1) || (kk < noelm) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } kk /= noelm; /* no. of elements/values available */ /* now go + get the data */ first = koff + 1; /* first byte to access */ if (kk > maxvals) kk = maxvals; /* minimize no. of data */ mm = kk * noelm; snull = -1; (void) MID_RDSCRC(chanl,dblock,dindx,first,mm,values,&snull); *null = snull; *actvals = kk; *unit = dunit; return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDRDD(imno,descr,felem,maxvals,actvals,values,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a double precision descriptor and its extensions .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; double *values /* OUT: array of type 'type' buffer for descriptor data */; int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int actv, n, *ipntr; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { /* all except START goes to father */ if (strcmp(realdescr,"START") == 0) goto next_step; imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } next_step: fcbp = fctpntr->FZP; chanl = fctpntr->IOCHAN; /* find descriptor in directory */ dtype[0] = 'D'; if (fcbp->DSCFLAG == 'Y') { status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); } } else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } } if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ actv = noelem - felem + 1; /* max. no. of values */ if (actv > maxvals) actv = maxvals; *actvals = actv; /* now go + get the data - type D is handled via integer descriptors... */ snull = -1; if (dtype[0] == 'R') { float *rvals; char *mypntr; n = sizeof(float) * actv; mypntr = malloc((unsigned int) n); if (mypntr == (char *) 0) { status = ERR_MEMOUT; goto end_of_it; } rvals = (float *)mypntr; (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,rvals,&snull); for (n=0; n= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { /* all except NAXIS, NPIX => father */ if (strcmp(realdescr,"NAXIS") == 0) goto next_step; else if (strcmp(realdescr,"NPIX") == 0) goto next_step; imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } next_step: chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ dtype[0] = 'L'; if (fcbp->DSCFLAG == 'Y') /* logical descriptors are new... */ status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); else status = ERR_INPINV; if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ *actvals = noelem - felem + 1; /* max. no. of values */ if (*actvals > maxvals) *actvals = maxvals; /* now go + get the data */ snull = -1; (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull); iptr = values; for (nr=0; nr<*actvals; nr++) { if (*iptr != 0) *iptr = 1; /* enforce 0/1 as only output */ iptr++; } *null = snull; *unit = dunit; return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDRDI(imno,descr,felem,maxvals,actvals,values,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of an integer descriptor and its extensions .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; int *values /* OUT: array of type 'type' buffer for descriptor data */; int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { /* all except NAXIS, NPIX => father */ if (strcmp(realdescr,"NAXIS") == 0) goto next_step; else if (strcmp(realdescr,"NPIX") == 0) goto next_step; imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } next_step: chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ dtype[0] = 'I'; if (fcbp->DSCFLAG == 'Y') status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); else if (fcbp->DSCFLAG == 'Z') status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); else status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ *actvals = noelem - felem + 1; /* max. no. of values */ if (*actvals > maxvals) *actvals = maxvals; /* now go + get the data */ snull = -1; (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull); *null = snull; *unit = dunit; return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDRDR(imno,descr,felem,maxvals,actvals,values,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a real descriptor and its extensions .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; float *values /* OUT: array of type 'type' buffer for descriptor data */; int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int n, actv; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) /* check imno */ { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ dtype[0] = 'R'; if (fcbp->DSCFLAG == 'Y') { status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,help); } } else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } } if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ actv = noelem - felem + 1; /* max. no. of values */ if (actv > maxvals) actv = maxvals; *actvals = actv; /* now go + get the data - type D is handled via integer descriptors... */ snull = -1; if (dtype[0] == 'D') { int *ipntr; double *dvals; char *mypntr; n = sizeof(double) * actv; mypntr = malloc((unsigned int) n); /* allocate space for */ if (mypntr == (char *) 0) /* for double temp data */ { status = ERR_MEMOUT; goto end_of_it; } dvals = (double *)mypntr; n = DD_SIZE / II_SIZE; /* double stuff is stored */ first = n*felem - 1; /* integer data */ actv *= n; ipntr = (int *)mypntr; (void) MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull); for (n=0; n= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ *actvals = 0; fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory noelm/bytelem = 1 for HELP descriptors */ dtype[0] = 'H'; if (fcbp->DSCFLAG == 'Y') { dtype[0] = ' '; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,values); kk = (int) strlen(values); if (kk < 1) *totvals = -1; else *totvals = *actvals = kk; return status; } else if (fcbp->DSCFLAG == 'Z') status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); else status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { *totvals = -1; return (ERR_NORMAL); } koff = felem - 1; /* requested offset */ kk = noelem - koff; /* no. of elements/values available */ *totvals = noelem; /* total size */ /* check parameters */ if ( (felem <= 0) || (kk < 1) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* now go + get the data */ first = felem; /* first byte to access */ if (kk > maxvals) kk = maxvals; /* minimize no. of data */ snull = -1; (void) MID_RDSCRC(chanl,dblock,dindx,first,kk,values,&snull); *actvals = kk; return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDRDZ(imno,dirsize,direlem) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE display the descriptor directory .ALGORITHM use MID_DSCDIR to do the job .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; int *dirsize /* OUT : no. of chars. used by descr-directory */; int *direlem /* OUT : no. of descr. (incl. directory) */; { int dblock, dindx, dunit; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { int status; status = ERR_INPINV; MID_E2(6,imno,"Z-DIRECORY.MIDAS",status,1); return status; } fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } fcbp = fctpntr->FZP; if (fcbp->DSCFLAG == 'Y') (void) MID_YDSCDIR(imno,'Z',dtype,dtype,dirsize,direlem, &dunit,&dblock,&dindx,help); else { int mm; mm = 0; (void) MID_ZDSCDIR(imno,'Z',dtype,mm,dtype,dirsize,direlem, &dunit,&dblock,&dindx); } return ERR_NORMAL; } /* */ int SCDRDX(imno,flag,name,type,bytelem,noelem,hnc) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE in 1. step get complete descriptor directory next return descriptor info like SCDINF .ALGORITHM use MID_DSCDIR to do the job .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno; /* IN: imno of data frame */ int flag; /* IN: action flag = 0, free space again = 1, read in complete descr. directory = 2, as 1 and also return total no. of descriptors = 10, return descr. info of next descr. */ char *name; /* OUT: name of next descr. = ' ' if no more descr. */ char *type; /* OUT: type of next descr. */ int *bytelem; /* OUT: no. of bytes per element */ int *noelem; /* OUT: no. of elements */ int *hnc; /* OUT: no. of help text chars */ { int status, mm, chanl, nullo; static int dirbytes, dirlen, nlen, myimno=-1; char *dscpntr; static char *cpt, *xdscdir = (char *) 0; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; static int koko=0; char *klaus; fctpntr = FCT.ENTRIES + imno; if (flag == 0) { if (xdscdir != (char *) 0) { free (xdscdir); xdscdir = (char *) 0; } return ERR_NORMAL; } if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status= ERR_INPINV; /* wrong argument `npos' */ goto end_of_it; } fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* use father frame */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; if (fcbp->DSCFLAG == 'Y') { dscpntr = (char *) &YDSCDIR_ENTRY; if (flag != 10) { myimno = imno; dirlen = fcbp->DFILLED; if (xdscdir != (char *) 0) (void)free (xdscdir); xdscdir = (char *) malloc((unsigned int) (dirlen+4)); nullo = -1; (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,1,dirlen,xdscdir,&nullo); cpt = xdscdir; /* for flag = 2, we have to go through directory once */ if (flag == 2) { register int nr, npos; nr = 0; npos = 0; while (nr < dirlen) { if (*cpt != '\0') npos ++; /* test if deleted descr. */ cpt += fcbp->DIRENTRY; nr += fcbp->DIRENTRY; } *noelem = npos; cpt = xdscdir; /* set back to start */ } cpt += fcbp->DIRENTRY; /* skip directory itself */ nlen = fcbp->DIRENTRY; /* set to already used length */ } else { if (myimno != imno) /* no call with flag=1 before... */ { status = ERR_INPINV; goto end_of_it; } dYloop: if (nlen < dirlen) { if (*cpt == '\0') /* test if deleted entry */ { cpt += fcbp->DIRENTRY; nlen += fcbp->DIRENTRY; goto dYloop; } else (void) memcpy(dscpntr,cpt,(size_t)fcbp->DIRENTRY); cpt += fcbp->DIRENTRY; nlen += fcbp->DIRENTRY; /* follow with pointer */ } else { if (xdscdir != (char *) 0) { (void)free (xdscdir); xdscdir = (char *) 0; } *name = ' '; *noelem = -1; /* mark the end */ return ERR_NORMAL; } (void) memcpy(name,YDSC_PNTR->NAMESTR,(size_t)YDSC_PNTR->NAMELEN); /* passed param `type' must be at least 4 chars */ (void) MID_TYPINFO(1,YDSC_PNTR->TYPE,YDSC_PNTR->BYTELEM,type,4); *noelem = YDSC_PNTR->NOELEM; *bytelem = YDSC_PNTR->BYTELEM; *hnc = YDSC_PNTR->HELPLEN; } } else if (fcbp->DSCFLAG == 'Z') { dscpntr = (char *) &ZDSCDIR_ENTRY; if (flag != 10) { myimno = imno; dirlen = fcbp->DFILLED; mm = 1; if (xdscdir != (char *) 0) (void)free (xdscdir); xdscdir = malloc((unsigned int) (dirlen+4)); nullo = -1; (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,1,dirlen,xdscdir,&nullo); cpt = xdscdir; /* for flag = 2, we have to go through directory once */ if (flag == 2) { register int nr, npos; nr = 0; npos = 0; while (nr < dirlen) { if (*cpt == '3') mm = 3; else if (*cpt == '2') mm = 2; else mm = 1; dirbytes = mm * fcbp->DIRENTRY; if (*(cpt+1) != '_') npos ++; /* test if just fill_in block */ cpt += dirbytes; nr += dirbytes; } *noelem = npos; cpt = xdscdir; /* set back to start */ } if (*cpt == '3') /* skip directory itself */ mm = 3; else if (*cpt == '2') mm = 2; dirbytes = mm * fcbp->DIRENTRY; cpt += dirbytes; nlen = dirbytes; /* follow with pointer */ } else { if (myimno != imno) /* no call with flag=1 before... */ { status = ERR_INPINV; goto end_of_it; } dZloop: if (nlen < dirlen) { if (*cpt == '2') mm = 2; else if (*cpt == '3') mm = 3; else mm = 1; dirbytes = mm * fcbp->DIRENTRY; if (*(cpt+1) == '_') /* test if just fill_in block */ { cpt += dirbytes; nlen += dirbytes; goto dZloop; } else CGN_COPYALL(dscpntr,cpt,dirbytes); cpt += dirbytes; nlen += dirbytes; /* follow with pointer */ } else { if (xdscdir != (char *) 0) { (void)free (xdscdir); xdscdir = (char *) 0; } *name = ' '; *noelem = -1; /* mark the end */ return ERR_NORMAL; } (void) strcpy(name,ZDSC_PNTR->NAME); /* type must be at least 4 chars */ (void) MID_TYPINFO(1,ZDSC_PNTR->TYPE,ZDSC_PNTR->BYTELEM,type,4); *noelem = ZDSC_PNTR->NOELEM; *bytelem = ZDSC_PNTR->BYTELEM; *hnc = ZDSC_PNTR->HNOELEM; } } else { dscpntr = (char *) &DSCDIR_ENTRY; if (flag != 10) { myimno = imno; dirlen = fcbp->DFILLED; mm = 1; if (xdscdir != (char *) 0) (void)free (xdscdir); xdscdir = malloc((unsigned int) (dirlen+4)); nullo = -1; (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,1,dirlen,xdscdir,&nullo); cpt = xdscdir; /* for flag = 2, we have to go through directory once */ if (flag == 2) { register int nr, npos; nr = 0; npos = 0; while (nr < dirlen) { if (*cpt != '\0') npos ++; /* test if deleted descr. */ cpt += fcbp->DIRENTRY; nr += fcbp->DIRENTRY; } *noelem = npos; cpt = xdscdir; /* set back to start */ } cpt += fcbp->DIRENTRY; /* skip directory itself */ nlen = fcbp->DIRENTRY; /* set to already used length */ } else { if (myimno != imno) /* no call with flag=1 before... */ { status = ERR_INPINV; goto end_of_it; } dloop: if (nlen < dirlen) { if (*cpt == '\0') /* test if deleted entry */ { cpt += fcbp->DIRENTRY; nlen += fcbp->DIRENTRY; goto dloop; } else CGN_COPYALL(dscpntr,cpt,fcbp->DIRENTRY); cpt += fcbp->DIRENTRY; nlen += fcbp->DIRENTRY; /* follow with pointer */ } else { if (xdscdir != (char *) 0) { (void)free (xdscdir); xdscdir = (char *) 0; } *name = ' '; *noelem = -1; /* mark the end */ return ERR_NORMAL; } (void) strncpy(name,DSC_PNTR->NAME,15); name[15] = '\0'; *noelem = DSC_PNTR->NOELEM; *bytelem = DSC_PNTR->BYTELEM; *type = DSC_PNTR->TYPE; *hnc = 0; /* help didn't exist then ... */ } } return ERR_NORMAL; end_of_it: MID_E2(6,imno,"descriptor.directory",status,1); return status; } /* */ int SCDHRC(imno,descr,noelm,felem,maxvals,actvals,values,htxt,hmax,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a character descriptor and its help text .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int noelm /* IN : no. of "elements" in type, i.e. CHAR*noelm */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; char *values /* OUT: array for descriptor data */; char *htxt; /* OUT: help text */ int hmax; /* OUT: max. no. of chars in help text */ int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data will only be applied, if not -1 */; { int mm, kk, koff; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first, hnoelem, hbytelem, hblock, hindx; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ htxt[0] = '\0'; dtype[0] = 'C'; if (fcbp->DSCFLAG == 'Y') status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); (void) MID_ZDSCDIR(imno,'H',realdescr,dsclen,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status == ERR_NORMAL) { dtype[0] = 'H'; status = MID_DSCDIR(imno,'F',descr,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } } if (status != ERR_NORMAL) goto end_of_it; mm = noelem * bytelem; /* real size of descr. */ koff = (felem-1) * noelm; /* requested offset */ kk = mm - koff; /* size available */ /* check parameters */ if ( (felem <= 0) || (noelm < 1) || (kk < noelm) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } kk /= noelm; /* no. of elements/values available */ /* now go + get the data */ first = koff + 1; /* first byte to access */ if (kk > maxvals) kk = maxvals; /* minimize no. of data */ mm = kk * noelm; snull = -1; (void) MID_RDSCRC(chanl,dblock,dindx,first,mm,values,&snull); *null = snull; *actvals = kk; *unit = dunit; /* now we process the help text */ if (fcbp->DSCFLAG != 'Y') { if (hnoelem > 0) { if (hnoelem >= hmax) hnoelem = hmax - 1; (void) MID_RDSCRC(chanl,hblock,hindx,1,hnoelem,htxt,&snull); htxt[hnoelem] = '\0'; } } return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDHRD(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a double precision descriptor and its help text .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; double *values /* OUT: array of type 'type' buffer for descriptor data */; char *htxt; /* OUT: help text */ int hmax; /* IN : max. no. of chars. for help text */ int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int actv, n, *ipntr; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first, hnoelem, hbytelem, hblock, hindx; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { /* all except START goes to father */ if (strcmp(realdescr,"START") == 0) goto next_step; imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } next_step: fcbp = fctpntr->FZP; chanl = fctpntr->IOCHAN; /* find descriptor in directory */ htxt[0] = '\0'; dtype[0] = 'D'; if (fcbp->DSCFLAG == 'Y') { status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); } } else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } (void) MID_ZDSCDIR(imno,'H',realdescr,dsclen,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if real descr instead */ dtype[0] = 'R'; status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } if (status == ERR_NORMAL) { dtype[0] = 'H'; status = MID_DSCDIR(imno,'F',descr,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } } if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ actv = noelem - felem + 1; /* max. no. of values */ if (actv > maxvals) actv = maxvals; *actvals = actv; /* now go + get the data - type D is handled via integer descriptors... */ snull = -1; if (dtype[0] == 'R') { float *rvals; char *mypntr; n = sizeof(float) * actv; mypntr = malloc((unsigned int) n); if (mypntr == (char *) 0) { status = ERR_MEMOUT; goto end_of_it; } rvals = (float *)mypntr; (void) MID_RDSCRR(chanl,dblock,dindx,felem,actv,rvals,&snull); for (n=0; nDSCFLAG != 'Y') { if (hnoelem > 0) { if (hnoelem >= hmax) hnoelem = hmax - 1; (void) MID_RDSCRC(chanl,hblock,hindx,1,hnoelem,htxt,&snull); htxt[hnoelem] = '\0'; } } return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDHRL(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a logical descriptor and its help text .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; int *values /* OUT: array of type 'type' buffer for descriptor data */; char *htxt; /* OUT: help text */ int hmax; /* IN : max. no. of chars. for help text */ int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, hnoelem, hbytelem, hblock, hindx; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ htxt[0] = '\0'; dtype[0] = 'L'; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ *actvals = noelem - felem + 1; /* max. no. of values */ if (*actvals > maxvals) *actvals = maxvals; /* now go + get the data */ snull = -1; (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull); *null = snull; *unit = dunit; return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDHRI(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of an integer descriptor and its help text .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; int *values /* OUT: array of type 'type' buffer for descriptor data */; char *htxt; /* OUT: help text */ int hmax; /* IN : max. no. of chars. for help text */ int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, hnoelem, hbytelem, hblock, hindx; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) { /* all except NAXIS, NPIX => father */ if (strcmp(realdescr,"NAXIS") == 0) goto next_step; else if (strcmp(realdescr,"NPIX") == 0) goto next_step; imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } next_step: chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ htxt[0] = '\0'; dtype[0] = 'I'; if (fcbp->DSCFLAG == 'Y') status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); (void) MID_ZDSCDIR(imno,'H',realdescr,dsclen,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status == ERR_NORMAL) { dtype[0] = 'H'; status = MID_DSCDIR(imno,'F',descr,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } } if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ *actvals = noelem - felem + 1; /* max. no. of values */ if (*actvals > maxvals) *actvals = maxvals; /* now go + get the data */ snull = -1; (void) MID_RDSCRI(chanl,dblock,dindx,felem,*actvals,values,&snull); *null = snull; *unit = dunit; /* now we process the help text */ if (fcbp->DSCFLAG != 'Y') { if (hnoelem > 0) { if (hnoelem >= hmax) hnoelem = hmax - 1; (void) MID_RDSCRC(chanl,hblock,hindx,1,hnoelem,htxt,&snull); htxt[hnoelem] = '\0'; } } return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; } /* */ int SCDHRR(imno,descr,felem,maxvals,actvals,values,htxt,hmax,unit,null) /*++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE read the contents of a real descriptor and its help text .ALGORITHM 'actval' will be set to the actual no. of values returned .RETURNS return status ( 0 = o.k. ) --------------------------------------------------*/ int imno /* IN : no. of data frame */; char *descr /* IN : descriptor name */; int felem /* IN : position of 1st element to be accessed */; int maxvals /* IN : max. no. of values to be returned */; int *actvals /* OUT: actual no. of values returned */; float *values /* OUT: array of type 'type' buffer for descriptor data */; char *htxt; /* OUT: help text */ int hmax; /* IN : max. no. of chars. for help text */ int *unit /* OUT: unit pointer */; int *null /* OUT: no. of null values in data \ will only be applied, if not -1 */; { int n, actv; int status, chanl, bytelem, noelem, dblock, dindx; int dunit, snull, first, hnoelem, hbytelem, hblock, hindx; char dtype[4]; struct FCB_STRUCT *fcbp; struct FCT_STRUCT *fctpntr; if ( (imno < 0) || (imno >= FCT.MAXENT) ) /* check imno */ { status = ERR_INPINV; goto end_of_it; } dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */ fctpntr = FCT.ENTRIES + imno; if (fctpntr->LINK[0] >= 2) /* if son, use father's imno */ { imno = fctpntr->LINK[1]; fctpntr = FCT.ENTRIES + imno; } chanl = fctpntr->IOCHAN; fcbp = fctpntr->FZP; /* find descriptor in directory */ htxt[0] = '\0'; dtype[0] = 'R'; if (fcbp->DSCFLAG == 'Y') { status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx,htxt); } } else if (fcbp->DSCFLAG == 'Z') { status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_ZDSCDIR(imno,'F',realdescr,dsclen,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } (void) MID_ZDSCDIR(imno,'H',realdescr,dsclen,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } else { status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); if (status != ERR_NORMAL) { /* see if double descr instead */ dtype[0] = 'D'; status = MID_DSCDIR(imno,'F',descr,dtype,&bytelem, &noelem,&dunit,&dblock,&dindx); } if (status == ERR_NORMAL) { dtype[0] = 'H'; status = MID_DSCDIR(imno,'F',descr,dtype,&hbytelem, &hnoelem,&dunit,&hblock,&hindx); } } if (status != ERR_NORMAL) goto end_of_it; /* check parameters */ if ( (felem <= 0) || (felem > noelem) || (maxvals <= 0) ) { status = ERR_INPINV; /* invalid input parameters */ goto end_of_it; } /* minimize no. of data */ actv = noelem - felem + 1; /* max. no. of values */ if (actv > maxvals) actv = maxvals; *actvals = actv; /* now go + get the data - type D is handled via integer descriptors... */ snull = -1; if (dtype[0] == 'D') { int *ipntr; double *dvals; char *mypntr; n = sizeof(double) * actv; mypntr = malloc((unsigned int) n); /* allocate space for */ if (mypntr == (char *) 0) /* for double temp data */ { status = ERR_MEMOUT; goto end_of_it; } dvals = (double *)mypntr; n = DD_SIZE / II_SIZE; /* double stuff is stored */ first = n*felem - 1; /* integer data */ actv *= n; ipntr = (int *)mypntr; (void) MID_RDSCRI(chanl,dblock,dindx,first,actv,ipntr,&snull); for (n=0; nDSCFLAG != 'Y') { if (hnoelem > 0) { if (hnoelem >= hmax) hnoelem = hmax - 1; (void) MID_RDSCRC(chanl,hblock,hindx,1,hnoelem,htxt,&snull); htxt[hnoelem] = '\0'; } } return status; end_of_it: /* here for errors */ MID_E2(6,imno,descr,status,1); return status; }