3 Examples of Using the NBS Routines

 3.1 Defining the Noticeboard Contents
 3.2 Creating the Noticeboard
 3.3 Finding the Noticeboard
 3.4 Putting Values into the Noticeboard
 3.5 Getting values from the Noticeboard
 3.6 Finding out about Items
 3.7 Saving and Restoring of Values
 3.8 Losing Noticeboards

This section takes the form of a tutorial. Starting with a listing of a noticeboard contents, we present the calls necessary to define that noticeboard, to put the required values into it and for another process to access those values.

Suppose that we wish to create and access a simple noticeboard. We will use as an example a subset of the noticeboard that is maintained by the AUTOFIB control software. The notation used is the same as that used by the NBTRACE (Trace Noticeboard) program (see Section C.1) — each structure entry is of the form:

  type name (children)

and each primitive entry is of the form:

  type name[(maxd) dim1,dim2...] (actb/maxb/mod) val1,val2,...

with appropriately indented entries. The shape information is shown only if the maximum number of dimensions (maxd) is greater than zero. The three slash-separated numbers are actual number of bytes, maximum number of bytes and modified count.

The result of running NBTRACE on this noticeboard might be:

  Software version   = 5 (5)
  Size of section    = 13284 (33e4)
  Size of definition = 8952 (22f8)
  Noticeboard owner  = 405 (195)
  Modified count     = 2 (2)
  
  NOTICEBOARD AUTOFIB (3)
     _CHAR            CURRENT_CONFIG         (18/132/2) "current.fib"
     CURRENT_STATUS   CURRENT_STATUS[(1) 72] (0/4608/0)
     FIBRE_PARAMETERS FIBRE_PARAMETERS (1)
         _INTEGER     TRANS_MATRIX[(2) 2,2]  (16/16/2)  1,0,0,1

3.1 Defining the Noticeboard Contents

The following Fortran-like calls will define the contents of the above noticeboard and save the definition in a disc file.

  INCLUDE   ‘NBS_ERR’       ! Error code definitions
  INCLUDE   ‘SAE_PAR’       ! Error code definitions
  
  INTEGER   STATUS          ! Modified STATUS variable
  INTEGER   TOPSID          ! Top-level static ID
  INTEGER   SID             ! General purpose static ID
  INTEGER   FIBSID          ! FIBRE_PARAMETERS static ID
  INTEGER   DIMS(2)         ! TRANS_MATRIX dimensions
  
  STATUS = SAI__OK          ! Initially set status to be OK

Begin the noticeboard definition.

  NBS_BEGIN_DEFINITION (TOPSID,STATUS)      ! Top-level static ID

Define the primitive item CURRENT_CONFIG. This is a character string of maximum length 132 bytes. We choose to regard it as a scalar.

  NBS_DEFINE_PRIMITIVE (TOPSID,             ! Parent static ID
                        ‘CURRENT_CONFIG’,   ! Name of item
                        ‘_CHAR’,            ! Type of item
                        0,132,              ! Max # dims and bytes
                        SID,STATUS)         ! Returned static ID

Define the primitive item CURRENT_STATUS. This is a 1D array of 72 64 byte records.

  NBS_DEFINE_PRIMITIVE (TOPSID,             ! Parent static ID
                        ‘CURRENT_STATUS’,   ! Name of item
                        ‘CURRENT_STATUS’,   ! Type of item
                        1,72*64,            ! Max # dims and bytes
                        SID,STATUS)         ! Returned static ID
  
  NBS_DEFINE_SHAPE     (SID,                ! Static ID
                        1,72,STATUS)        ! Actual # dims and dims

Define the structured item FIBRE_PARAMETERS. Structured items cannot have shapes or values.

  NBS_DEFINE_STRUCTURE (TOPSID,             ! Parent static ID
                        ‘FIBRE_PARAMETERS’, ! Name of item
                        ‘FIBRE_PARAMETERS’, ! Type of item
                        FIBSID,STATUS)      ! Returned static ID

Define the lower-level primitive item TRANS_MATRIX. This is a 2D array of 2 x 2 integers.

  NBS_DEFINE_PRIMITIVE (FIBSID,             ! Parent static ID
                        ‘TRANS_MATRIX’,     ! Name of item
                        ‘_INTEGER’,         ! Type of item
                        2,4*4,              ! Max # dims and bytes
                        SID,STATUS)         ! Returned static ID
  DIMS(1) = 2
  DIMS(2) = 2
  NBS_DEFINE_SHAPE     (SID,                ! Static ID
                        2,DIMS,STATUS)      ! Actual # dims and dims

End the definition, writing to file AUTOFIB.NBD.

  NBS_END_DEFINITION   (‘AUTOFIB’,          ! Name of noticeboard file
                        ‘DEFINITION_SAVE’,  ! Write definition to disc
                        STATUS)

3.2 Creating the Noticeboard

Having defined the noticeboard contents, the actual noticeboard must be created. There are three ways of doing this, depending on whether the definition is being read from a file, the definition plus data is being read from a file (this is illustrated in Section 3.7), or the noticeboard is being created in memory.

Restore the noticeboard definition from a file and create the noticeboard …

  NBS_RESTORE_DEFINITION (‘AUTOFIB’,            ! Noticeboard name
                          ‘AUTOFIB’,            ! Name of noticeboard file
                          STATUS)

…or, instead of issuing the above NBS_END_DEFINITION call, issue this one.

  NBS_END_DEFINITION     (‘AUTOFIB’,            ! Noticeboard name
                          ‘CREATE_NOTICEBOARD’, ! Don’t write a file
                          STATUS)

3.3 Finding the Noticeboard

Any process that wants to use a noticeboard must map it. This is done in precisely the same way by both the noticeboard owner and any other processes wishing to use it.

  INTEGER   TOPID                           ! Top-level noticeboard ID

Map (find) the noticeboard.

  NBS_FIND_NOTICEBOARD (‘AUTOFIB’,          ! Noticeboard name
                        TOPID,STATUS)       ! Top-level ID

3.4 Putting Values into the Noticeboard

We can now put values into primitive items.

  INTEGER   CONID                   ! CURRENT_CONFIG ID
  INTEGER   STAID                   ! CURRENT_STATUS ID
  INTEGER   FIBID                   ! FIBRE_PARAMETERS ID
  INTEGER   MATID                   ! COORD_MATRIX ID
  
  CHARACTER STRING*(*)              ! String to write to CURRENT_CONFIG
  PARAMETER (STRING=‘CURRENT.FIB’)
  INTEGER   MATRIX(2,2)             ! Matrix to write to COORD_MATRIX
  DATA      MATRIX /1,0,0,1/

Get the IDs for all the items we want to write to.

  NBS_FIND_ITEM (TOPID,‘CURRENT_CONFIG  ’,CONID,STATUS)
  NBS_FIND_ITEM (TOPID,‘CURRENT_STATUS  ’,STAID,STATUS)
  NBS_FIND_ITEM (TOPID,‘FIBRE_PARAMETERS’,FIBID,STATUS)
  NBS_FIND_ITEM (FIBID,‘COORD_MATRIX    ’,MATID,STATUS)

Put values to some of them.

  NBS_PUT_CVALUE (CONID,0,STRING,STATUS)
  NBS_PUT_VALUE  (MATID,0,16,MATRIX,STATUS)
  NBS_PUT_VALUE  (CONID,0,LEN(STRING),%REF(STRING),STATUS)

3.5 Getting values from the Noticeboard

Values can be accessed either by copying to and from the user’s buffer or else directly to and from the noticeboard. Both methods are illustrated here.

  INTEGER   ACTBYTES                ! Actual number of bytes stored
  INTEGER   POINTER                 ! Pointer to MATRIX data
  CHARACTER*20  CONF                ! Configuration to be read

Get current value of MATRIX. We expect the actual number of bytes to be at least 16.

  NBS_GET_VALUE (MATID,0,16,MATRIX,ACTBYTES,STATUS)
  IF (ACTBYTES .LT. 16) THEN
    panic
  ENDIF

Again, reading character strings is slightly different,

  NBS_GET_CVALUE (MATID,0,CONF,     ! Use the portable routine
                ACTBYTES,STATUS)
  NBS_GET_VALUE (MATID,0,LEN(CONF), ! or the VMS specific call
      %REF(CONFIG),ACTBYTES,STATUS) ! using %REF

Alternatively get a pointer to the actual data in the noticeboard.

  NBS_GET_POINTER (MATID,POINTER,STATUS)
  MATRIX_OP       (%VAL(POINTER),STATUS)

3.6 Finding out about Items

There is a complete set of enquiry routines that allow programs that know nothing about a noticeboard to navigate through it. NBTRACE is just such a program. A few of these routines are illustrated here.

  INCLUDE   ‘NBS_PAR’               ! Parameter definitions
  
  CHARACTER NAME*(NBS_K_MAXNAME)    ! Item name
  CHARACTER TYPE*(NBS_K_MAXTYPE)    ! Item type
  INTEGER   MAXBYTES                ! Maximum number of bytes
  INTEGER   ACTBYTES                ! Actual number of bytes
  INTEGER   MAXDIMS                 ! Maximum number of dimensions
  INTEGER   DIMS(7)                 ! Actual dimensions
  INTEGER   ACTDIMS                 ! Actual number of dimensions
  
  NBS_GET_NAME  (MATID,NAME,STATUS)
  NBS_GET_TYPE  (MATID,TYPE,STATUS)
  NBS_GET_SIZE  (MATID,MAXBYTES,ACTBYTES,STATUS)
  MAXDIMS = 7                       ! MAXDIMS is a MODIFIED parameter
  NBS_GET_SHAPE (MATID,MAXDIMS,DIMS,ACTDIMS,STATUS)

3.7 Saving and Restoring of Values

It is possible to save and restore the noticeboard data as well as just the definition by using a different option when ending the noticeboard definition.

End the definition, writing it and the noticeboard data to file AUTOFIB.NBD.

  NBS_END_DEFINITION   (‘AUTOFIB’,          ! Name of noticeboard file
                        ‘NOTICEBOARD_SAVE’, ! Write noticeboard to disc
                        STATUS)

Restore the noticeboard definition plus data from a file and create the noticeboard.

  NBS_RESTORE_NOTICEBOARD (‘AUTOFIB’,       ! Noticeboard name
                           ‘AUTOFIB’,       ! Name of noticeboard file
                           STATUS)

Map (find) the noticeboard.

  NBS_FIND_NOTICEBOARD (‘AUTOFIB’,          ! Noticeboard name
                        TOPID,STATUS)       ! Top-level ID

Get the ID for an item we want to write to and put its value.

  NBS_FIND_ITEM (TOPID,‘CURRENT_CONFIG’,CONID,STATUS)
  NBS_PUT_CVALUE (CONID,0,STRING,STATUS)

Save the noticeboard to disc.

  NBS_SAVE_NOTICEBOARD (TOPID,              ! ID of any item on noticeboard
                        STATUS)

3.8 Losing Noticeboards

Noticeboards can be explicitly lost (unmapped). Often you will not need to worry about this and will be happy to allow them to be unmapped on image exit. Sometimes, however, you may require explicit control. Note though that a noticeboard is not actually deleted until the last process unmaps it.

Find a noticeboard and an item within it.

  NBS_FIND_NOTICEBOARD (‘AUTOFIB’,          ! Noticeboard name
                        TOPID,STATUS)       ! Top-level ID
  NBS_FIND_ITEM (TOPID,‘CURRENT_CONFIG’,CONID,STATUS)

Lose the item and the noticeboard.

  NBS_LOSE_ITEM (CONID,‘CHECK’,STATUS)
  NBS_LOSE_NOTICEBOARD (TOPID,‘CHECK’,STATUS)

Alternatively, if you like living dangerously, try this.

  NBS_LOSE_NOTICEBOARD (TOPID,‘FORCE’,STATUS)