      SUBROUTINE RMASET(IUO,IUD,ISEED1,ISEED2,cfile) 
C Bernd Berg Sep 28 2000.
C INITIALIZING ROUTINE FOR RANMAR OR RAVMAR, MUST BE CALLED 
C BEFORE GENERATING PSEUDORANDOM NUMBERS WITH RANMAR (RAVMAR).
C RANGES: 0 <= IJ <= 31328  AND  0 <= KL <= 30081.
C FOR IUO<=5 THE INFORMATIVE MESSAGES ARE OFF.
      include '../../Libs/Fortran/implicit.sta'
      include '../../Libs/Fortran/constants.par'
      CHARACTER*(*) cfile
      COMMON/RASET1/U(97),C,CD,CM,I,J
C
      inquire(file=cfile,exist=lexist)
      IF(.not.lexist) THEN
        IF(ISEED1.LT.0.OR.ISEED1.GT.31328) GOTO 1
        IF(ISEED2.LT.0.OR.ISEED1.GT.30081) GOTO 1
        IJ=ISEED1+1801
        KL=9373+ISEED2 
        I=MOD(IJ/177, 177)+2 ! I=0 for IJ=0 and IJ=31329.
        J=MOD(IJ,     177)+2
        K=MOD(KL/169, 178)+1 ! K=0 for KL=0 and KL=30082.
        M=MOD(KL,     169)
        IF(IUO.GT.5) WRITE(IUO,*) 'RANMAR INITIALIZED.'
        DO II=1,97
          S=ZERO
          T=HALF
          DO JJ=1,24
            N=MOD(MOD(I*J,179)*K, 179)
            I=J
            J=K
            K=N
            M=MOD(53*M+1, 169)
            IF(MOD(M*N,64).GE.32) S=S+T
            T=HALF*T
          END DO
          U(II)=S
        END DO
        C =  (362436*ONE)/(16777216*ONE) ! 2**24=16777216
        CD= (7654321*ONE)/(16777216*ONE)
        CM=(16777213*ONE)/(16777216*ONE)
        I=97
        J=33
      ELSE
        IF(IUO.GT.5) WRITE(IUO,*) "MARSAGLIA CONTINUATION."
        IF(IUD.LT.8) STOP "RMASET: Error in continuation IUD."
        OPEN(IUD,FILE=cfile,STATUS='OLD',FORM='UNFORMATTED')
        REWIND IUD
        READ(IUD) U,C,CD,CM,I,J
        CLOSE(IUD)
      END IF
C
      RETURN
C
1     PRINT*,"RMASET: Seeds not allowed!"
      PRINT*,"ISEED1,ISEED2 =",ISEED1,ISEED2
      STOP "RMASET: Seeds not allowed!"
      END
