Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem when running fortran file

  1. May 15, 2012 #1
    I write a test.f to generate a range of random numbers. I use gasdev.f and RAN2.F functions.

    program main
    implicit none
    integer*4 :: idum,i
    real*8 :: gasdev,random(100)
    idum=2000
    do i=1,100
    random(i)=gasdev(idum)
    write(*,*) i,random(i)
    end do
    end program main

    gfortran test.f -o test.x gasdev.f RAN2.F

    The file can be compiled successfully, but when I try to run it, nothing happens. The cursor jumps to a new line and nothing shows up. I am not sure what the problem is.

    gasdev.f

    FUNCTION gasdev(idum)
    C-----------------------------------------------------
    C DOUBLE PRECISION VERSION OF NUMREC ROUTINE
    C FRANK GROSSMANN, 12.9.1994
    C-----------------------------------------------------
    INTEGER idum
    REAL*8 gasdev
    CU USES ran2
    INTEGER iset
    REAL*8 fac,gset,rsq,v1,v2,ran2
    SAVE iset,gset
    DATA iset/0/
    if (iset.eq.0) then
    1 v1=2.*ran2(idum)-1.
    v2=2.*ran2(idum)-1.
    rsq=v1**2+v2**2
    if(rsq.ge.1..or.rsq.eq.0.)goto 1
    fac=sqrt(-2.*log(rsq)/rsq)
    gset=v1*fac
    gasdev=v2*fac
    iset=1
    else
    gasdev=gset
    iset=0
    endif
    return
    END

    RAN2.F

    FUNCTION ran2(idum)
    INTEGER idum,IM1,IM2,IMM1,IA1,IA2,IQ1,IQ2,IR1,IR2,NTAB,NDIV
    REAL ran2,AM,EPS,RNMX
    PARAMETER (IM1=2147483563,IM2=2147483399,AM=1./IM1,IMM1=IM1-1,
    *IA1=40014,IA2=40692,IQ1=53668,IQ2=52774,IR1=12211,IR2=3791,
    *NTAB=32,NDIV=1+IMM1/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
    INTEGER idum2,j,k,iv(NTAB),iy
    SAVE iv,iy,idum2
    DATA idum2/123456789/, iv/NTAB*0/, iy/0/
    if (idum.le.0) then
    idum=max(-idum,1)
    idum2=idum
    do 11 j=NTAB+8,1,-1
    k=idum/IQ1
    idum=IA1*(idum-k*IQ1)-k*IR1
    if (idum.lt.0) idum=idum+IM1
    if (j.le.NTAB) iv(j)=idum
    11 continue
    iy=iv(1)
    endif
    k=idum/IQ1
    idum=IA1*(idum-k*IQ1)-k*IR1
    if (idum.lt.0) idum=idum+IM1
    k=idum2/IQ2
    idum2=IA2*(idum2-k*IQ2)-k*IR2
    if (idum2.lt.0) idum2=idum2+IM2
    j=1+iy/NDIV
    iy=iv(j)-idum2
    iv(j)=idum
    if(iy.lt.1)iy=iy+IMM1
    ran2=min(AM*iy,RNMX)
    return
    END
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Problem when running fortran file
Loading...