Reputation: 13
I'm trying to compile this program for monte carlo importance sampling, but i'm running into a couple issues:
1 - Error: Syntax error in data declaration at (1), referring to the following line, where the (1) is placed right after and beneath the word "function".
real function f(x)
2 - Error: Two main PROGRAMS at (1) and (2), referring to these two lines
program importance1
and
t=0.0
.
The sample code follows. There are more lines of code in the program, but I don't think there are any problems so I've just posted this first segment.
program importance1
implicit none
real mean_value,t,ta,rr
real x,xtrials,s_square_old,s_square_new,std_dev,std_error,frac_stand_dev
integer k
real :: alpha=0.90
integer :: trials=50
xtrials=trials
real function f(x)
f=exp(x)
return
end
real function g(x)
g=(alpha/(exp(alpha)-1.))*exp(alpha*x)
return
end
t=0.0
s_square_old=0.0
Upvotes: 1
Views: 772
Reputation: 3264
Not sure where you got the idea to do that, but it looks like you are defining functions in the middle of your code, which is the wrong place. In Fortran, the functions go in a separate MODULE
or at the end of the program under a CONTAINS
block:
program importance1
implicit none
real :: mean_value,t,ta,rr
real :: x,xtrials,s_square_old,s_square_new,std_dev,std_error,frac_stand_dev
integer :: k
real :: alpha=0.90
integer :: trials=50
xtrials=trials
t=0.0
s_square_old=0.0
contains
real function f(x)
real :: x
f=exp(x)
end function
real function g(x)
real :: x
g=(alpha/(exp(alpha)-1.))*exp(alpha*x)
end function
end program
Upvotes: 1