Fortran severe (40) Error... Help?!

Posted by Taka on Stack Overflow See other posts from Stack Overflow or by Taka
Published on 2010-06-09T12:20:35Z Indexed on 2010/06/09 12:22 UTC
Read the original article Hit count: 189

Filed under:

I can compile but when I run I get this error "forrtl: severe (40): recursive I/O operation, unit -1, file unknown" if I set n = 29 or more... Can anyone help with where I might have gone wrong? Thanks.

 PROGRAM  SOLUTION
IMPLICIT NONE

! Variable Declaration

INTEGER  :: i
REAL  :: dt
DOUBLE PRECISION  :: st(0:9)
DOUBLE PRECISION  :: stmean(0:9)
DOUBLE PRECISION  :: first_argument
DOUBLE PRECISION  :: second_argument
DOUBLE PRECISION  :: lci, uci, mean
REAL  :: exp1, n
REAL  :: r, segma

! Get inputs

WRITE(*,*) 'Please enter number of trials: '
READ(*,*) n

WRITE(*,*)
dt=1.0
segma=0.2
r=0.1

! For n Trials

st(0)=35.0
stmean(0)=35.0
mean = stmean(0)

PRINT *, 'For ', n ,' Trials'
PRINT *,'          1     ',st(0)

! Calculate results

DO i=0, n-2
    first_argument = r-(1/2*(segma*segma))*dt
    exp1 = -(1/2)*(i*i)
    second_argument = segma*sqrt(dt)*((1/sqrt(2*3.1416))*exp(exp1))
    st(i+1) = st(i) * exp(first_argument+second_argument)

    IF(st(i+1)<=20) THEN
       stmean(i+1) = 0.0
       st(i+1) = st(i)
       else
       stmean(i+1) = st(i+1)
    ENDIF

    PRINT *,i+2,'     ',stmean(i+1)
    mean = mean+stmean(i+1)
END DO

! Output results

uci = mean+(1.96*(segma/sqrt(n)))
lci = mean-(1.96*(segma/sqrt(n)))
PRINT *,'95% Confidence Interval for ', n, ' trials is between ', lci, ' and ', uci
PRINT *,''

END PROGRAM SOLUTION

© Stack Overflow or respective owner

Related posts about fortran