      PROGRAM DYNAMIC
C
C     This program demonstrates the use of
C        dynamic arrays in FORTRAN.
C
C     Find out how much memory to get
10    TYPE *,'How many bytes do you want ?'
      ACCEPT *,NBYTES
C     If <= 0 then quit
      IF(NBYTES.LE.0)STOP 'I QUIT'
C     Get the memory & check for errors
      CALL IFERR(LIB$GET_VM(NBYTES,IBASE))
C     Now pass the memory to a subprogram.
C     Since the value of IBASE is the
C     address of the memory we just allocated,
C     pass it by value.
      CALL USE_IT(%VAL(IBASE),NBYTES)
C     Don't forget to give memory back when done!
      CALL IFERR(LIB$FREE_VM(NBYTES,IBASE))
      GOTO 10
      END
      
      SUBROUTINE USE_IT(BUFFER,N)
C
C     This subroutine does nothing useful!
C     It thinks it gets called with a BYTE
C     array and the length of the array.
C
      BYTE BUFFER(N)
C     Demonstrate that we can write into array
      DO 10 I = 1 , N
10    BUFFER(I) = 14
C     Demonstrate that we can read array
      DO 20 I = 1 , N
20    TYPE *,BUFFER(I)
C     Nothing else to demonstrate !
      RETURN
      END
