C
C Program GRDRAN to compute the pseudorandom numbers distributed
C uniformly between -0.5 and 0.5 on the input grid.
C
C Version: 5.40
C Date: 2002, May 20
C
C Coded by Petr Bulant
C     Department of Geophysics, Charles University Prague,
C     Ke Karlovu 3, 121 16 Praha 2, Czech Republic,
C     E-mail: bulant@seis.karlov.mff.cuni.cz
C
C.......................................................................
C                                                    
C Description of data files:
C
C Input data read from the standard input device (*):
C     The data are read by the list directed input (free format) and
C     consist of a single string 'SEP':
C     'SEP'...String in apostrophes containing the name of the input
C             SEP parameter or history file with the input data.
C     No default, 'SEP' must be specified and cannot be blank.
C
C                                                     
C Input data file 'SEP':
C     File 'SEP' has the form of the SEP
C     parameter file.  The parameters, which do not differ from their
C     defaults, need not be specified in file 'SEP'.
C Data specifying the parameters of the grid:
C     N1=positive integer... Number of gridpoints along the X1 axis.
C             Default: N1=1
C     N2=positive integer... Number of gridpoints along the X2 axis.
C             Default: N2=1
C     N3=positive integer... Number of gridpoints along the X3 axis.
C             Default: N3=1
C Selection of a particular pseudorandom representation:
C     ISEED=integer ... Nonzero integer seed for the generation of
C             pseudorandom numbers.  Its sign is ignored.
C     Default: ISEED=-1.
C Name of output formatted file with the computed values:
C     RANOUT='string'
C             Default: RANOUT='grdran.out'
C     For general description of the files with gridded data refer to
C     file forms.htm.
C Optional parameters specifying the form of the real quantities
C written in the output formatted files:
C     MINDIG,MAXDIG=positive integers ... See the description in file
C             forms.for.
C
C-----------------------------------------------------------------------
C Subroutines and external functions required:
      EXTERNAL ERROR,RSEP1,RSEP3T,RSEP3I,WARRAY,RAN3
      REAL RAN3
C     ERROR ... File error.for.
C     RSEP1,RSEP3T,RSEP3I ...
C             File sep.for.
C     WARRAY ... File forms.for.
C     RAN3 ... File ran3.for.
C
C
C Common block /RAMC/:
      INCLUDE 'ram.inc'
C     ram.inc
C
      CHARACTER*80 FILSEP,FILOUT
      INTEGER LU1
      PARAMETER (LU1=1)
      INTEGER N1,N2,N3,ISEED,I1,N1N2N3
C-----------------------------------------------------------------------
C
C     Reading a name of the file with the input data:
      WRITE(*,'(A)') '+GRDRAN: Enter input filename: '
      FILSEP=' '
      READ(*,*) FILSEP
C
C     Reading all the data from the SEP file into the memory:
      IF (FILSEP.NE.' ') THEN
        CALL RSEP1(LU1,FILSEP)
      ELSE
C       GRDRAN-01
        CALL ERROR('GRDRAN-01: SEP file not given')
      ENDIF
C
      WRITE(*,'(A)') '+GRDRAN: Working ...           '
C
C     Filename of the output file:
      CALL RSEP3T('RANOUT',FILOUT,'grdran.out')
C     The values describing the grid:
      CALL RSEP3I('N1',N1,1)
      CALL RSEP3I('N2',N2,1)
      CALL RSEP3I('N3',N3,1)
      N1N2N3=N1*N2*N3
      IF (N1N2N3.GT.MRAM) THEN
C       GRDRAN-02
        CALL ERROR('GRDRAN-02: Small array RAM.')
      ENDIF
C     Reading numerical constant ISEED:
      CALL RSEP3I('ISEED',ISEED,-1)
C
C
C     Random numbers:
      DO 10, I1=1,N1N2N3
        RAM(I1)=RAN3(ISEED)-0.5
  10  CONTINUE
C
      IF (FILOUT.NE.' ') THEN
        CALL WARRAY(LU1,FILOUT,'FORMATTED',.FALSE.,0.,.FALSE.,0.,
     *              N1N2N3,RAM)
      ENDIF
      WRITE(*,'(A)') '+GRDRAN: Done.                 '
      STOP
      END
C
C=======================================================================
C
      INCLUDE 'error.for'
C     error.for
      INCLUDE 'sep.for'
C     sep.for
      INCLUDE 'forms.for'
C     forms.for
      INCLUDE 'length.for'
C     length.for
      INCLUDE 'ran3.for'
C     ran3.for of Numerical Recipes
C
C=======================================================================
C