      subroutine rangset(iuo,iud,iseed1,iseed2,cfile) 
c generic call. bernd berg apr 14 2007.
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*,"rmargset: seeds not allowed!"
      print*,"iseed1,iseed2 =",iseed1,iseed2
      stop "rmargset: seeds not allowed!"
      end
