I have this code:
PROGRAM xfit
! driver for routine fit
USE nrtype; USE nrutil
USE nr
USE ran_state, ONLY : ran_seed
IMPLICIT NONE
INTEGER(I4B), PARAMETER :: NPT=100
REAL(SP), PARAMETER :: SPREAD=0.5_sp
INTEGER(I4B) :: mwt
REAL(SP) :: a,b,chi2,q,siga,sigb
REAL(SP), DIMENSION(NPT) :: harvest,sig,x,y
call ran_seed(sequence=731)
x(:)=arth(0.1_sp,0.1_sp,NPT)
call gasdev(harvest)
y(:)=-2.0_sp*x(:)+1.0_sp+SPREAD*harvest
sig(:)=SPREAD
do mwt=0,1
if (mwt == 0) then
write(*,'(//1x,a)') 'Ignoring standard deviation'
call fit(x,y,a,b,siga,sigb,chi2,q)
else
write(*,'(//1x,a)') 'Including standard deviation'
call fit(x,y,a,b,siga,sigb,chi2,q,sig)
end if
write(*,'(1x,t5,a,f9.6,t24,a,f9.6)') 'A = ',a,'Uncertainty: ',&
siga
write(*,'(1x,t5,a,f9.6,t24,a,f9.6)') 'B = ',b,'Uncertainty: ',&
sigb
write(*,'(1x,t5,a,4x,f10.6)') 'Chi-squared: ',chi2
write(*,'(1x,t5,a,f10.6)') 'Goodness-of-fit: ',q
end do
END PROGRAM xfit
But when I compile it I get the following error
USE ran_state, ONLY : ran_seed
1
Fatal Error: Can't open module file 'ran_state.mod' for reading at (1):
No such file or directory
Could you please tell me how I can solve it?
A rather late answer.
Get your sub modules and compile:
gfortran -c nrtype.f90 nrutil.f90 nr.f90 ran_state.f90
Now link the generated o
files with your main program: xfit.f90
and create the executable, which I've called main
:
gfortran -o main xfit.f90 nrtype.o nrutil.o nr.o ran_state.o
Run the executable:
./main