I have made a linear interpolation code, but when i try to get out this value in a main program or in another subroutine it displays the value of 0.0000, but when i run the program in the subroutine it gets the correct value.
write(,) ' Interpolverdi=', interpolverdi gets the correct value but when i run write(,)'main interpolverdi',interpolverdi i get the value of 0.0000
My input file is working perfect.
What am i doing wrong? How do you get a specific value from a subroutine and then use this value in another subroutine?
Thanks for all the help i can get :)
!main.f90
program mainn
use inputt
use interpoll
!use mongo
implicit none
integer :: n, itmax,k,bc
real(8) :: epsilon, Re, tmax,dt,h,fux,interpolverdi
real(8), dimension (:), allocatable :: oo,u,v,p
integer, dimension (:), allocatable :: nn
!real(8), dimension(:,:), allocatable :: Uvel, Vvel, pres, psi
call lesinput(n,itmax,k,epsilon,Re,tmax,dt,oo,nn,bc)
call interpol(nn,oo,n)
write(*,*)'main interpolverdi',interpolverdi
end program mainn
!interpoll.f90
module interpoll
implicit none
contains
subroutine interpol(nn,oo,n)
integer :: nn(:), n,s,i
real(8) :: oo(:),interpolverdi
s = size(nn)
do i=1,s-1
if (n==nn(i)) then
interpolverdi= oo(i)
exit
else if ((n>nn(i)) .and. (n<nn(i+1))) then
interpolverdi= oo(i)+((oo(i+1)-oo(i))*(n-nn(i)))/(nn(i+1)-nn(i))
exit
else
interpolverdi=nn(s)
end if
end do
write(*,*) ' Interpolverdi=', interpolverdi
write(*,*)'n=',n
end subroutine interpol
end module interpoll