The simple forward model

From Interactive System for Ice sheet Simulation
Jump to: navigation, search

The driver program

program driver
 
implicit none
 
real(8), dimension(2) :: xvec
real(8) :: fc
real(8) :: alpha, beta
 
! initialize	
        fc = 0.
        xvec(1)    = 10.
	xvec(2)    = 30.
        alpha = 5.
        beta = 2.
 
! call model
	call simple(alpha,beta,xvec,fc)
 
! write output
	print *, 'alpha, beta = ', alpha, beta
	print *, 'x1, x2 = ', xvec(1), xvec(2)
	print *, 'fc = ', fc
 
	end

The subroutine(s) and function(s) containing the model

!----------------------
module simple_variables
!----------------------
 
real(8), dimension(2) :: yvec
 
end module simple_variables
 
!----------------------
module simple_functions
!----------------------
 
contains
 
function costfunction(yvec)
 
implicit none
 
! arguments
real(8) :: costfunction
real(8), dimension(2) :: yvec
 
 
! local
real(8), parameter :: var1=1, var2=1
real(8), parameter :: d1=55., d2=65.
 
! evaluate cost function J = J(y) = J(M(x))
costfunction  = 1.d0/var1*(yvec(1)-d1)**2 + &
                1.d0/var1*(yvec(2)-d2)**2
 
end function costfunction
 
end module simple_functions
 
!----------------------
subroutine simple( alpha, beta, xvec, fc )
!----------------------
 
use simple_variables
use simple_functions
 
implicit none
 
! argument
real(8), intent(out) :: fc
real(8), intent(in) :: alpha, beta
real(8), intent(in), dimension(2) :: xvec
 
! evaluate model y = M(x)
yvec(1) = alpha*xvec(1)
yvec(2) = -beta*xvec(2)
 
! evaluate cost function J = J(y) = J(M(x))
fc = costfunction( yvec )
 
      return
      end