So much for theory, here are some examples of the use of PSX routines. Each POSIX routine tends to stand on its own, so the examples are fairly simple.
The requirement is to create a file that will be used to hold the output of several programs, but this file must be in a directory that is used by several people. Clearly the file name must be related to the username. Also it is necessary to take into account the difference in the syntax of directory names on VMS and Unix systems.
Although the PSX routines are designed to be used with other Starlink routines in the ADAM environment and use the concept of inherited status, they can just as easily be used in a stand alone program like the one above provided that the status is set correctly before calling the first routine. This is important since the PSX routine will exit immediately if STATUS is not set to the value of the symbolic constant SAI__OK.
One of the annoying features of FORTRAN 77 is that all storage space must be allocated at compile time, i.e. there are no dynamic arrays. Here is an example of using PSX routines to dynamically allocate an array.
In this case the main program merely sets the value of STATUS and calls the subroutine GETVM to do the work. Although this is more typing, it does have the advantage that this could be made into an ADAM task simply by deleting the main program. GETVM tests that the value of STATUS returned from PSX_CALLOC is OK, but does not print any error message. This is not necessary, as the PSX routines all report their own errors via the EMS routines. The reporting of error messages may be deferred if required, as described in SUN/104 and SSN/4.
If the code is required to work where pointers may be longer than INTEGERs, The construct
%VAL(CNF_PVAL(PNTR))
, rather than simply %VAL(PNTR)
, should be used in passing the pointer to FILL
and PRNT. Function CNF_PVAL is defined in the CNF_PAR include file and described in SUN/209
(section ‘Pointers’).