CHAPTER 11    PROGRAM INTERFACE TO SAD





            11.1 INTRODUCTION



                 This description assumes a knowledge of the structure of the

            standard  data format as described in "Standard Astronomical Data

            Format for use by  The  Anglo-Australian  Observatory  and  Mount

            Stromlo and Siding Spring Observatories "(DKW 29/5/79).

                 Throughout this discussion, the  following  conventions  are

            observed:  bytes are eight bits, words are 16 bits, longwords are

            32 bits.

                 To distinguish parameters which start counting at  one  from

            those  which  count  from  zero,  the  terms  index  and  offset,

            respectively, are used.  All pointers, whether  byte  or  record,

            are  offsets  from  the appropriate reference location.  That is,

            the first byte is record number zero.

                 Arguments which have meaning in an application  sense,  e.g.

            row  number,  count  from  one.   Purely computational parameters

            usually count from zero.

                 All parameters, such  as  status  codes,  array  dimensions,

            array  indices and offsets, are defined symbolically.  This gives

            a degree of resilience to changes in the format and all  programs

            should be written in terms of symbols rather than their numerical

            equivalents.  Conventions for  naming  parameters  are  given  in

            Appendix  A.   Combining  precision  and  readability  in the one

            symbol has led to long names.  It is suggested  that,  where  the

            meaning  is clear, application programs equate shorter symbols to

            the longer named symbols once per program  and  use  the  shorter

            name  throughout  the  program.   On  the  Mount  Stromlo VAX the

            standard  parameter  file  can  be  accessed  using  an  'INCLUDE

            LBY:SADPAR.FOR' in the Fortran source program.


                                                                Page 2





            11.2 NODE/IMAGE CONTROL ARRAYS



                 The first argument of each  subroutine  call  is  a  control

            array  which  plays  the  part  of  a  logical  unit  number in a

            conventional Fortran read or  write.   It  carries  pointers  and

            other  information  needed  to access the data efficiently.  When

            reading or writing an existing image  or  node,  the  application

            program  has to do nothing to this array other than dimension it.

            Information about the image is available to the program  in  this

            array.  Before creating a new image, the application program must

            first set up some mandatory parameters in the control array.

                 A control array may be node or image control array depending

            on  context.  Node and image control arrays are similar and it is

            not necessary to know before the initial access to a node whether

            a node or image will be encountered.  This can be determined from

            the  subroutine  status  return  or  the  control  array   itself

            subsequent  to the access.  Consequently, it is not necessary for

            a program to know the structure of a data tree prior to accessing

            it.

                 As each level of node is accessed,  when  climbing  a  tree,

            relevant  parameters  are copied from the previous level array so

            that only one array need be specified  in  subsequent  reads  and

            writes to that level.

                 Multiple files, nodes and images may be held open for access

            by specifying separate control arrays.

                 Details of Node/Image Control Arrays are given  in  Appendix

            B.


                                                                Page 3





            11.3 SUBROUTINES



                 The general call to a standard format access subroutine is:



            CALL SUBROUTINE(CA,other arguments,ISTAT)



            where CA is the relevant control array  and  ISTAT  is  a  status

            return.  ISTAT is defined so that it will be .TRUE.  on a logical

            test if the operation was successful.  Other  status  values  are

            defined in the parameter definition file.

                 Where character string  arguments  are  specified  in  these

            definitions,  they  follow the conventions applied to the parsing

            of literal strings in subroutine calls.  On the VAX this  implies

            a CHARACTER data type.

                 Nodes and images may be  accessed  by  name  or  number.   A

            positive image number indicates an access by number.  If the node

            image number is D$P_SEQACS, the next node or image in sequence is

            accessed.   If  it  is  D$P_NAMACS, a named search is done.  In a

            search by number, the name is returned; in a search by name,  the

            number  is returned; in a sequential search, both name and number

            are returned.  Numbering in this context starts at one.

                 Phase 1 implementation at  Mt.   Stromlo  will  not  support

            deletion  of nodes or images, nor the extensible comments feature

            of the data format standard.

                 In the subroutine descriptions that follow, the letters  "C"

            or "R" after a subroutine argument denote whether the argument is

            to be defined  at  the  time  of  call  to  or  return  from  the

            subroutine.


                                                                Page 4





            11.3.1 File Level Subroutines



            1.  SFOPNF SUBROUTINE



                 This subroutine opens  a  disk  file  and  opens  the  first

            node/image within that file.



            Call:



                  CALL SFOPNF(CA,FILE_NAME,ACSTYP,ISTAT,LU)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array.  No information  need

                                  be  provided  for  an  existing file.  When

                                  creating a new file, the following elements

                                  must  be  supplied:   In the case of a node

                                  array only the TAG and NAME fields need  be

                                  entered   but   for   an  image  array  the

                                  following   additional   fields   must   be

                                  supplied:  DATFMT, NELS, NROWS, NPLNS, EL1,

                                  ELZ,  ROW1,  ROWZ,   PLN1,   PLNZ,   FLOOR,

                                  CEILING, NULLDAT.



            FILE_NAME  C    CHAR  is the file specification.



            ACSTYP     C    CHAR  is the access type  :   'U'  (update),  'R'

                                  (read), 'W' (write).



            ISTAT      R    I4    is the return status.



            LU         C    I4    is the logical unit to  be  used  for  I/O.

                                  This  is  the one occasion when an argument

                                  comes  after  ISTAT.   It  is  placed  here

                                  because  it is expected to become redundant

                                  in later implementations of the package.



            Status Returns:



            D$S_IMAGE             The top node in the file was an image.



            D$S_NODE              The top node in the file was a node.



            D$S_ILLNCA            The  control  array  contains  an   illegal

                                  field.



            D$S_NONMULT           The record size of the SAD file  is  not  a

                                  multiple  of  the size of a data element as

                                  defined in the DATFMT field.



            D$S_ILFORM            The specified data format is illegal.



            D$S_UNSUPFMT          The specified data format is not  supported

                                  by the current SAD software.


                                                                Page 5





            Operating system supplied status.



            2.  SFCLOS SUBROUTINE



                 This subroutine closes the SAD disk file.



            Call:



                  CALL SFCLOS(CA,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array.   Any  control  array

                                  which  has  been used in accessing the file

                                  may be used in the call.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILLNCA            The  control  array  contains  an   illegal

                                  field.



            Operating system supplied status.


                                                                Page 6





            11.3.2 Node Level Subroutines



            1.  SFOPNN SUBROUTINE.



                 This subroutine opens a node/image.



            Call:



                  CALL SFOPNN(CA1,CA2,NODE_NAME,NODE_NO,ACSTYP,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA1       C/R   I4    is the node control array of  level  higher

                                  than  that  being  opened.  This array will

                                  have been  set  up  by  the  routine  which

                                  opened the node.



            CA2       C/R   I4    is the control array of node being  opened.

                                  No  information  need  be  provided  for an

                                  existing node.  When creating  a  new  node

                                  the following fields must be supplied :  In

                                  the case of a node array only the  TAG  and

                                  NAME  fields  need  be  entered, but for an

                                  image array the following additional fields

                                  must  be  supplied  :  DATFMT, NELS, NROWS,

                                  NPLNS, EL1, ELZ, ROW1,  ROWZ,  PLN1,  PLNZ,

                                  FLOOR, CEILING, NULLDAT.



            NODE_NAME C/R   CHAR  is the node name.



            NODE_NO   C/R   I4    is the node number.



            ACSTYP     C    CHAR  is the access type  :   'U'  (update),  'R'

                                  (read), 'W' (write).



            ISTAT      C    I4    is the return Status.



            Status Returns:



            D$S_IMAGE             The node opened was an image.



            D$S_NODE              The node was a node.



            D$S_ILOPIM            Illegal operation attempted  on  an  image.

                                  CA1  is  probably  an  image  control array

                                  rather than a node control array.



            D$S_ILLNCA            One  of  the  control  arrays  contains  an

                                  illegal field.



            D$S_WRPROT            The node associated with CA1  is  not  open

                                  for writing.



            D$S_NXNODE            The specified node does not exist.


                                                                Page 7





            D$S_ILNODENO          The NODE_NO parameter was invalid.



            D$S_NONMULT           The record size of the SAD file  is  not  a

                                  multiple  of  the size of a data element as

                                  defined in the DATFMT field.



            D$S_ILFORM            The specified data format is illegal.



            D$S_UNSUPFMT          The specified data format is not  supported

                                  by the current SAD software.



            Operating system supplied status.


                                                                Page 8





            2.  SFWNC/SFRNC SUBROUTINES



                 These subroutines Read/write comments to a node header.



            Calls:



                  CALL SFWNCM(CA,COMNTS,ISTCHR,LSTCHR,ISTAT)

                  CALL SFRNCM(CA,COMNTS,ISTCHR,LSTCHR,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the node control array.  This array will

                                  have  been  set  up  by  the  routine which

                                  opened the node.



            COMNTS    C/R   CHAR  are comments.



            ISTCHR     C    I4    is the position of the first  character  to

                                  be read/ written.



            LSTCHR     C    I4    is the position of the last character to be

                                  read/ written.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILLNCA            The  control  array  contains  an   illegal

                                  field.



            D$S_NOCOMMENT         The    character    positions     specified

                                  (ISTCHR,LSTCHR)  do  not  fall  within  the

                                  bounds of the comments field.



            D$S_WRPROT            Attempt  to  write  comments  to  a   write

                                  protected node.



            Operating system supplied status.


                                                                Page 9





            11.3.3 Image level subroutines



            1.  SFWKWD SUBROUTINE



                 This subroutine writes a keyword and  associated  values  to

            the keyword subdivison of an image header.



            Call:



                  CALL SFWKWD(CA,KEYWD,VALUE,FORMAT,COMNTS,DUPFLG,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array of  the  image.   This

                                  array  will have been set up by the routine

                                  which opened the node.



            KEYWD      C    CHAR  is the keyword.



            VALUE      C    I4    is the array containing the value(s) to  be

                                  written for this Keyword.



            FORMAT     C    CHAR  specifies the format in which the  value(s)

                                  are  to  be  written.   The general form is

                                  'nnnX'.  'X'  can  be  'I',  'F',  or   'A'

                                  signifying  integer, real or character data

                                  respectively.  'nnn' is a count, specifying

                                  the  number  of  values to be written.  Eg.

                                  the format '3I' means three integer  values

                                  are  written,  '180A' means a string of 180

                                  characters is written.



            COMNTS     C    CHAR  are comments to be written after the "/" in

                                  the keyword entry .



            DUPFLG     C    LOG   is the flag which  determines  whether  the

                                  keyword   is  to  be  duplicated.   If  the

                                  keyword  already  exists  and   DUPFLG   is

                                  .FALSE.,  the old entry is overwritten.  If

                                  DUPFLG  is  .TRUE.,  the   old   entry   is

                                  preserved  and  another  entry  made.  This

                                  allows,  for  example,  multiple  'COMMENT'

                                  keywords to be defined.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_ILSUBDIV          A  subdivision  other  than   the   keyword

                                  subdivision was encountered.


                                                               Page 10





            Operating system supplied status.





            2.  VALUE/IVALUE/CVALUE FUNCTIONS



                 Three FUNCTION subroutines  are  provided  to  read  keyword

            values.   VALUE,  IVALUE,  and  CVALUE  return  real, integer and

            character values respectively from the keyword subdivision of  an

            image header.



            Calls:



                  VALUE= VALUE(CA,KEYWD,NVAL,NKEY,ISTAT)

                  IVAL = IVALUE(CA,KEYWD,NVAL,NKEY,ISTAT)

                  CVAL = CVALUE(CA,KEYWD,NCHARS,NKEY,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array of  the  image.   This

                                  array  will have been set up by the routine

                                  which opened the node.



            KEYWD      C    CHAR  is the keyword.



            NKEY       C    I4    is the occurrence  of  the  keyword  to  be

                                  read.    This   allows   access   to   each

                                  occurrence of a multiply defined keyword.



            NVAL       C    I4    is the number of the value to be  returned;

                                  eg.,  the  keyword  'RA'  might  have three

                                  values defined (hours,  minutes,  seconds).

                                  Setting  NVAL  to 2 will return the minutes

                                  field as the value of the function.



            NCHARS     R    I4    is the number of characters extracted  from

                                  the keyword entry on return from the CVALUE

                                  routine.



            ISTAT      R    I4    is the return Status.



            Status returns:



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_ILSUBDIV          A  subdivision  other  than   the   keyword

                                  subdivision was encountered.



            D$S_UNDEFKYWD         The keyword was not found.



            D$S_NOVAL             Fewer than NVAL values are in the entry.



            D$S_NOTCHARKEY        The keyword requested  is  not  written  in

                                  character format.


                                                               Page 11





            Operating system supplied status.


                                                               Page 12





            3.  COMMENT FUNCTION



                 This function returns the comments which occur after the "/"

            in a keyword.



            Call:



                  COMNT = COMMENT(CA,KEYWD,NCHARS,NKEY,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array of  the  image.   This

                                  array  will have been set up by the routine

                                  which opened the node.



            KEYWD      C    CHAR  is the keyword.



            NKEY       C    I4    is the occurrence  of  the  keyword  to  be

                                  read.    This   allows   access   to   each

                                  occurrence of a multiply defined keyword.



            NCHARS     R    I4    On return from the routine, NCHARS  is  the

                                  number  of  characters  extracted  from the

                                  keyword entry.



            ISTAT      R    I4    is the return Status.



            Status returns:



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_ILSUBDIV          A  subdivision  other  than   the   keyword

                                  subdivision was encountered.



            D$S_UNDEFKYWD         The keyword was not found.



            D$S_NOVAL             Fewer than NVAL values are in the entry.



            Operating system supplied status.








                                                               Page 13





            4.  SFKEYR/SFKEYW SUBROUTINES



                 These subroutines read/write an entire keyword card from the

            keyword subdivision of an image header.



            Calls:



                  CALL SFKEYR(CA,KEYWDNO,KEYCARD,ISTAT)

                  CALL SFKEYW(CA,KEYWDNO,KEYCARD,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA         C    I4    is the control array of  the  image.   This

                                  arrray will have been set up by the routine

                                  which opened the node.



            KEYWDNO    C    I4    is the number of  the  keyword  to  access.

                                  For   SFKEYR,   if   KEYWDNO  is  equal  to

                                  D$P_SEQACCS the next keyword  is  returned,

                                  otherwise keyword access is by number.  For

                                  SFKEYW, if KEYWDNO is equal to  D$P_SEQACCS

                                  the  keyword  is  written at the end of the

                                  subdivision  (preserving  all  the  current

                                  keywords)  , otherwise the current keywords

                                  are  erased  and  the  subdivision  started

                                  afresh.



            KEYCARD    R    CHAR  is the  keyword  card;  80  characters  are

                                  allowed.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_ISUBDIV           A  subdivision  other  than   the   keyword

                                  subdivision was encountered.



            D$S_UNDEFKYWD         The requested keyword was not found.   This

                                  status is returned by SFKEYR when there are

                                  fewer than KEYNUM  keywords,  or  when  the

                                  "END="  keyword  is  encountered  during  a

                                  sequential access.



            Operating system supplied status.








                                                               Page 14





            5.  SFRXYZ/SFWXYZ SUVROUTINES



                 These subroutines  transfer  a  cube  of  data  between  the

            program array and the SAD image.



            Calls:



                  CALL SFRXYZ(CA,ARRAY,NAX,NAY,NAZ,IX,IY,IZ,NX,NY,NZ,ISTAT)

                  CALL SFWXYZ(CA,ARRAY,NAX,NAY,NAZ,IX,IY,IZ,NX,NY,NZ,ISTAT)



            where:



            NAME         I/O  TYPE      DESCRIPTION

            CA           C/R   I4   is the control array of the image.   This

                                    array  will  have  been  set  up  by  the

                                    routine which opened the node.



            ARRAY        C/R   BYTE is the array receiving/containing data



            NAX,NAY,NAZ   C    I4   are the dimensions of array.



            IX,IY,IZ      C    I4   are the coordinates  of  start  of  cube.

                                    (N.B.    coordinates   are   relative  to

                                    complete  data  array  not  active   data

                                    array)



            NX, NY, NZ    C    I4   are the sizes of the cube.



            ISTAT         C    I4   is the return status.



            Status returns:



            D$S_ILOPND              Illegal  operation  on  a  node.   CA  is

                                    probably a node control array rather than

                                    an image control array.



            D$S_ILLICA              The CA defined in  the  call  was  not  a

                                    legal image control array.



            D$S_INSARR              The array is too small to contain a  cube

                                    of the specified size.



            D$S_DATLOB              The data cube specified lies outside  the

                                    limits declared in the image header.



            D$S_WRPROT              Attempt to write  to  a  write  protected

                                    image.



            D$S_ILFORM              The specified data format is illegal.



            D$S_UNSUPFMT            The  specified   data   format   is   not

                                    supported by the current SAD software.



            Operating system supplied status.


                                                               Page 15





            6.  SFRPLN/SFWPLN SUBROUTINES



                 These subroutines transfer an entire plane of  data  between

            the program array and the SAD image.



            Calls:



                  CALL SFRPLN(CA,ARRAY,NAX,NAY,NPLANE,ISTAT)

                  CALL SFWPLN(CA,ARRAY,NAX,NAY,NPLANE,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array of  the  image.   This

                                  array  will have been set up by the routine

                                  which opened the node.



            ARRAY     C/R   BYTE  is the array receiving/containing data.



            NAX,NAY    C    I4    are the dimensions of array.



            NPLANE     C    I4    is the plane number.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILOPND            Illegal  operation  on  a  node.    CA   is

                                  probably  a  node control array rather than

                                  an image control array.



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_INSARR            The array is too small to contain  a  plane

                                  of the specified size.



            D$S_DATLOB            The plane specified lies outside the limits

                                  declared in the image header.



            D$S_WRPROT            Attempt  to  write  to  a  write  protected

                                  image.



            D$S_ILFORM            The specified data format is illegal.



            D$S_UNSUPFMT          The specified data format is not  supported

                                  by the current SAD software.



            Operating system supplied status.








                                                               Page 16





            7.  SFRROW/SRWROW SUBROUTINES



                 These subroutines transfer an entire row of data between the

            program array and the SAD image.



            Calls:



                  CALL SFRROW(CA,ARRAY,NAX,NROW,NPLANE,ISTAT)

                  CALL SFWROW(CA,ARRAY,NAX,NROW,NPLANE,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            CA        C/R   I4    is the control array of  the  image.   This

                                  array  will have been set up by the routine

                                  which opened the node.



            ARRAY     C/R   BYTE  is the array receiving/containing data.



            NAX        C    I4    is the dimension of array.



            NROW       C    I4    is the row number.



            NPLANE     C    I4    is the plane number.



            ISTAT      R    I4    is the return status.



            Status returns:



            D$S_ILOPND            Illegal  operation  on  a  node.    CA   is

                                  probably  a  node control array rather than

                                  an image control array.



            D$S_ILLICA            The CA defined in the call was not a  legal

                                  image control array.



            D$S_INSARR            The array is too small to contain a row  of

                                  the specified size.



            D$S_DATLOB            The row specified lies outside  the  limits

                                  declared in the image header.



            D$S_WRPROT            Attempt  to  write  to  a  write  protected

                                  image.



            D$S_ILFORM            The specified data format is illegal.



            D$S_UNSUPFMT          The specified data format is not  supported

                                  by the current SAD software.



            Operating system supplied status.








                                                               Page 17





            11.3.4.  Miscellaneous Routines



            1.  SDPFMT SUBROUTINE



                 This subroutine sets the data format in which  the  programs

            will  work.  Translation is performed between this format and the

            format in which the data is stored on disk.



            Call:



                  CALL SDPFMT(FORMAT,ISTAT)



            where:



            NAME      I/O  TYPE         DESCRIPTION

            FORMAT     C   CHAR   is the format to be used  in  the  program.

                                  Legal values are 'I1', 'I2', 'I4' (one, two

                                  and four byte integer), 'R4', 'R8'  (single

                                  and   double   precision  real),  and  'C8'

                                  (complex).    The   only    format    fully

                                  supported,  however, is 'R4'.  The 'R8' and

                                  'C8' formats are partially supported  -  if

                                  the  disk format is the same as the program

                                  format the read/write  data  routines  will

                                  accept  them, otherwise the read/write data

                                  routines  will  return   the   D$S_UNSUPFMT

                                  status.



            ISTAT      R   I4     is the return status.



            Status returns:



            D$S_ILFORM            The specified data format is illegal.



            D$S_UNSUPFMT          The specified data format is not  supported

                                  by the current SAD software.



            Operating system supplied status.








                                                               Page 18





            11.4 SAD LOW LEVEL ROUTINES



                 These routines provide the low level I/O  and  handling  for

            the SAD I/O package.  This document should be read in association

            with the listings.





            1.  BUFFER STRUCTURE



                 Buffers  are  contained  in  the  common  SF$BUF   and   the

            particular  buffer  to  be  used is identified by a buffer number

            which is passed as an argument in subroutine calls.

                 Buffer characteristics are determined by  parameters  MAXREC

            and NBUFFERS which are the maximum record length in bytes and the

            number of buffers.  Currently MAXREC = 2048 and NBUFFERS = 8



                 See SF$LOWLEVEL for the buffer definitions.



            2.  MODULES





            Module       Subroutines         Function



            SF$LOWLEVEL    SF$RDBUF     Reads one record

                           SF$RQBUF     Requests a buffer for writing.



                           SF$WRBUF     Writes out a buffer



                           SF$RLBUF     Releases a requested  buffer  without

                                        writing.    N.B.,  SF$RQBUF  prevents

                                        further use of a buffer until  it  is

                                        either written or released.



            SF$VERYLOW     SF$READW     Reads   record    and    waits    for

                                        completion.



                           SF$WAITR     Waits for read to complete.



                           SF$FIND      Initiates access to record.



                           SF$WRITEW    Writes record, waits for completion.



            SF$INIT        SF$INIT      Initializes buffer queue.



            SF$QUEUE       SF$GETQ      Finds first available buffer.



                           SF$BOTQ      Moves a buffer to the bottom  of  the

                                        queue.



                           SF$TOPQ      Moves a buffer  to  the  top  of  the

                                        queue.





            Note:  only SF$LOWLEVEL routines  should  be  called  externally.

            The remaining three modules are called by SF$LOWLEVEL.


                                                               Page 19





            3.  BUFFER HEADER STRUCTURE



            Buffer headers are kept in a two  dimensional  array  the  second

            dimension  corresponding  to  buffer  number.  Length of a single

            buffer header is  determined  by  the  parameter.   LENHDR.   The

            contents of a header are:



            BHDRS(CHANNEL,.)      I/O channel no.  currently associated  with

                                  this buffer.



            BHDRS(RECORD,.)       Number of record currently in buffer .



            BHDRS(RECSIZE,.)      Size (in  bytes)  of  record  currently  in

                                  buffer.



            BHDRS(FLAGS,.)        Control flags associated with  the  buffer.

                                  If  any  flag is set, buffer cannot be used

                                  by SF$GETQ.  Currently  defined  flags  are

                                  FLG$LOCK(buffer  locked  by  SF$RQBUF)  and

                                  FLG$FILL(buffer is being used in  lookahead

                                  I/O).



            BHDRS(QNEXT,.)        Number of next buffer in queue.



            BHDRS(QPREV,.)        Number of previous buffer in queue.








                                                               Page 20





            4.  QUEUE STRUCTURE



                 When a buffer is required, the queue is  searched  from  the

            top  and the first unflagged buffer used.  When a buffer is used,

            it is placed at the bottom of the queue.   This  assumes  that  a

            buffer will stay in memory the maximum possible time.

                 There are two overall  queue  pointers:   QFIRST  and  QLAST

            which   point  to  the  first  and  last  buffers  in  the  queue

            respectively.  (Note:  first buffer, top of  queue  and  head  of

            queue are synonimous).

                 For a buffer at the head of the queue the header pointer  to

            the  previous  buffer  is  zero.   For  a buffer at the tail, the

            pointer to the next buffer is zero.



            5.  MODULES CONTAINING DEFINITIONS



            These notes indicate the modules which must be modified if  there

            is any change in definitions:





            Buffers               SF$LOWLEVEL, higher level routines.



            NBUFFERS              SF$LOWLEVEL, SF$INIT, SF$QUEUE



            Buffer Headers        SF$LOWLEVEL, SF$INIT, SF$QUEUE



            Queue Headers         SF$LOWLEVEL, SF$INIT, Used but not  defined

                                  in SF$QUEUE.



            6.  POTENTIAL ENHANCEMENTS



            (i)    Introduce a no wait version of writing.

            (ii)   Separate read and write queues,  generally  a  read  queue

                   will be longer than a write queue.

            (iii)  Introduce lower level I/O in SF$VERYLOW.


                                                               Page 21





                                       APPENDIX A



                                CONVENTIONS FOR DEFINING



                            PARAMETER NAMES AND STATUS VALUES



                             FOR STANDARD DATA I/O ROUTINES



                                       ON THE VAX 







            A.1 Parameter Names







                 The format of a parameter name is:





                 D$cc_dddddd(_tt)



            where:



            cc =      Category of parameter:



                      S  =  Status code.

                      P  =  Parameter (e.g.  default  record  size  or  array

                            dimensions)

                      T  =  Tree header

                      IC =  Image control array

                      NC =  Node control array

                      II =  Image control subdivision (interchange format)

                      IA =  Image control subdivision (access format)

                      N  =  Node control subdivision

                      ND =  Node directory entry

                      A  =  Astronomical subdivision.





            dddddd =  Parameter  description  or  field  name.   In  case  of

                      astronomical  subdivision,  this  is  broken  into  two

                      parts:  aaa_bbb , where aaa identifies  the  particular

                      subdivision and bbb identifies the parameter.





            tt =      Parameter type (only included where multiple types  are

                      possible):





                      I  =  Array index (assuming 4 byte elements)

                      B  =  Byte offset

                      W  =  Word offsets

                      L  =  Longword offset

                      NB =  Number of bytes in parameter field






                                                               Page 22









                      NW =  Number of words in parameter field

                      NL =  Number of longwords in parameter field



            Example:



            D$IC_NAME_I =   Image control array index (counting from 1  )  of

                  image name.



            D$IC_NAME_B =   Byte offset (counting from 0) of the  image  name

                  from the start of the image control array.







            A.2 Status Values







                 Status values follow the conventions  for  condition  values

            defined  in  Appendix C of the "VAX 11/780 Architecture Handbook"

            as follows:



              31 30              16 15  14                3  2   0

            ______________________________________________________

            !   !                  !   !                    !     !

            !   !                  !   !                    !     !

            ______________________________________________________









                       < 2:0> = Severity level code



                       <14:3> = Message number obtained from Fortran ,

                  operating  system  , or defined specifically for the

                  standard data routines



                       <15> = 1 for messages specific to the  standard

                  data routines 0 otherwise.



                       <30:16> =  Facility  number  of  standard  data

                  routines currently 2)



                       <31> = 1 always







                 Bits <31:16> of status returns from standard  data  routines

            should  contain  the  standard  routine  identifier  (D$S_SAD)  ,

            regardless of whether the status value originated in the routines

            themselves  or  in  some system utility.  (That is, if the status

            value is defined as as an INTEGER*2  array  of  dimension  2  the

            second  word  should  be  set to D$S_SAD) .  The one exception to

            this rule is the SS$_NORMAL return.


                                                               Page 23













                                       APPENDIX B



                             NODE/IMAGE CONTROL ARRAY LAYOUT









                 The fields which comprise the node and image control  arrays

            are  described  below.   The  name  of  the field (as used in the

            standard parameter descriptions , Appendix  A)  ,  the  code  and

            length  of  the  field  (in  bytes),  and a brief description are

            given.







            B.1 Parameters contained in both Image and Node control arrays





            TAG       Character   4     Two character tag ('ND' or 'IM') plus

                                        a   two   character   version  number

                                        (derived from header or disc)



            NAME      Character   12    Node/Image name



            LUFL      Integer     4     Logical unit  number (I*2)/Flags  (16

                                        bits)  (the  only flag so far defined

                                        is write enable)



            RECLEN    Integer     4     Length of random access record



            HDPTR     Integer     4     Record pointer to node/image header







            B.2 Parameters contained in Node control array only





            NSUBND    Integer     4     Number of subnodes.



            NLSTND    Integer     4     Number of last node accessed.







            B.3 Parameters contained in Image control array only





            DATPTR    Integer     4     Record pointer to data.



            COMPTR    Integer     4     Record pointer to comments chain.



            DATFMT    Character   8     Format of data:  


                                                               Page 24







                                        byte 1 - A(SCII) ,R(eal) or I(nteger)



                                        byte 2 - number of bytes per value in

                                        non-ASCII formats



                                        bytes 3-8 - format for ASCII formats



                                        bytes 3-4 - system code for non-ASCII









                                        formats



                                        e.g.    PDP-11   REAL*4   would    be

                                        "R4PD    "  , F10.2 ASCII would be "A

                                        F10.2 ".



            NELS      Integer     4     Number of elements per row (including

                                        inactive region)



            NROWS     Integer     4     number of rows per  plane  (including

                                        inactive region)



            NPLNS     Integer     4     Number of planes per image (including

                                        inactive region)



            EL1       Integer     4     Number of first active element in row



            ELZ       Integer     4     Number of last active element in row



            ROW1      Integer     4     Number of first active row in plane



            ROWZ      Integer     4     Number of last active row in plane



            PLN1      Integer     4     Number of first active plane in image



            PLNZ      Integer     4     Number of last active plane in image



            FLOOR     ###         4     Floor data value (in  specified  data

                                        format)  -  usually  set at about the

                                        threshold.  Any data below the  floor

                                        are ignored.  Not supported for ASCII

                                        data   and   only    allows    single

                                        precision.



            CEILING   ###         4     Ceiling data value (in specified data

                                        format)    -   usually   related   to

                                        instrument  saturation.    Any   data

                                        value  above the ceiling is ignored .

                                        Not supported for ASCII data and only

                                        allows single precision.



            NULLDAT   ###         4     Null  datum  code.   Used  to  denote


                                                               Page 25





                                        undefined  data.   Not  supported for

                                        ASCII data  and  only  allows  single

                                        precision.



            LSTEL     Integer     4     Number of last element accessed



            LSTROW    Integer     4     Number of last row accessed



            LSTPLN    Integer     4     Number of last pplane accessed









                         ### - Data format dependent