C                                                            <HTML><PRE>
C Program GRDRAN to compute the pseudorandom numbers distributed
C uniformly between -0.5 and 0.5 on the input grid.
C
C Version: 8.00
C Date: 2022, April 24
C
C Coded by Petr Bulant
C     Department of Geophysics, Charles University Prague,
C     Ke Karlovu 3, 121 16 Praha 2, Czech Republic,
C     http://sw3d.cz/staff/bulant.htm
C
C.......................................................................
C                                                    <A NAME="data"></A>
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                                                     <A NAME="SEP"></A>
C Input data file 'SEP':
C     File 'SEP' has the form of the <A HREF="../forms/sep.htm">SEP</A>
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 Data specifying the distribution:
C     RANDIS='string'... Character specifying the distribution:
C             RANDIS='U' or RANDIS='u':  Uniform distribution between
C                                        -0.5 and 0.5.
C             RANDIS='G' or RANDIS='g':  Gaussian distribution.
C             Default: RANDIS='U'
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 <A HREF="../forms/forms.htm#GRD">forms.htm</A>.
C Optional parameters specifying the form of the quantities
C written in the output formatted files:
C     MINDIG,MAXDIG=positive integers ... See the description in file
C             <A HREF="forms.for#MAXDIG" TYPE="text/html">forms.for</A>.
C     NUMLIN=positive integer ... Number of reals or integers in one
C             line of the output file. See the description in file
C             <A HREF="forms.for#NUMLIN" TYPE="text/html">forms.for</A>.
C Form of the input/output files:
C     FORM='string'... Form of the input/output files: either
C             'FORMATTED' or 'UNFORMATTED' (case insensitive).
C             Default: FORM='FORMATTED'
C     FORMW='string'... Form of the output file. If both FORM and FORMW
C             are specified, FORMW is used for output files.
C             Default: FORMW=FORM
C Value of undefined quantities:
C     UNDEF=real... The value to be used for undefined real quantities.
C             Default: UNDEF=undefined value used in <A HREF="../forms/forms.for#UARRAY" TYPE="text/html">forms.for</A>
C
C-----------------------------------------------------------------------
C
C Subroutines and external functions required:
      EXTERNAL ERROR,RSEP1,RSEP3T,RSEP3I,WARRAY,RAN3
      REAL RAN3
C     ERROR...File <A HREF="error.for" TYPE="text/html">error.for</A>.
C     RSEP1,RSEP3T,RSEP3I...
C             File <A HREF="sep.for" TYPE="text/html">sep.for</A>.
C     WARRAY..File <A HREF="forms.for" TYPE="text/html">forms.for</A>.
C     RAN3... File
C     <A HREF="../general.htm#NR">ran3.for of Numerical Recipes</A>.
C
C Common block /RAMC/:
      INCLUDE 'ram.inc'
C     <A HREF="ram.inc" TYPE="text/html">ram.inc</A>
C
      CHARACTER*80 FILSEP,FILOUT
      CHARACTER*1 RANDIS
      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       <A NAME="error01"></A><FONT COLOR="RED">GRDRAN-01</FONT>
        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       <A NAME="error02"></A><FONT COLOR="RED">GRDRAN-02</FONT>
        CALL ERROR('GRDRAN-02: Small array RAM.')
      ENDIF
C     Reading distribution:
      CALL RSEP3T('RANDIS',RANDIS,'U')
C     Reading numerical constant ISEED:
      CALL RSEP3I('ISEED',ISEED,-1)
C
C     Random numbers:
C     Uniform distribution
      IF (RANDIS.EQ.'U'.OR.RANDIS.EQ.'u') THEN
        DO 10, I1=1,N1N2N3
          RAM(I1)=RAN3(ISEED)-0.5
   10   CONTINUE
      ELSE IF (RANDIS.EQ.'G'.OR.RANDIS.EQ.'g') THEN
C       Gaussian distribution
        DO 21, I1=1,N1N2N3,2
   20     CONTINUE
            V1=2.*RAN3(ISEED)-1.
            V2=2.*RAN3(ISEED)-1.
            VV=V1*V1+V2*V2
          IF(VV.GE.1.) GO TO 20
          VV=SQRT(-2.*ALOG(VV)/VV)
          RAM(I1)=V1*VV
          IF (I.LT.N1N2N3) THEN
            RAM(I1+1)=V2*VV
          END IF
   21   CONTINUE
      ELSE
C       <A NAME="error03"></A><FONT COLOR="RED">GRDRAN-03</FONT>
        CALL ERROR('GRDRAN-03: Unknown distribution.')
C       Check the value of parameter RANDIS.
      ENDIF
C
      IF (FILOUT.NE.' ') THEN
        CALL WARRAY(LU1,FILOUT,.FALSE.,0.,.FALSE.,0.,N1N2N3,RAM)
      ENDIF
      WRITE(*,'(A)') '+GRDRAN: Done.                 '
      STOP
      END
C
C=======================================================================
C
      INCLUDE 'error.for'
C     <A HREF="../forms/error.for" TYPE="text/html">error.for</A>
      INCLUDE 'sep.for'
C     <A HREF="../forms/sep.for" TYPE="text/html">sep.for</A>
      INCLUDE 'forms.for'
C     <A HREF="../forms/forms.for" TYPE="text/html">forms.for</A>
      INCLUDE 'length.for'
C     <A HREF="../forms/length.for" TYPE="text/html">length.for</A>
      INCLUDE 'ran3.for'
C     <A HREF="../general.htm#NR">ran3.for of Numerical Recipes</A>
C
C=======================================================================
C                                                                 </PRE>
