I'm trying to solve a maximum likelihood problem in Fortran using the NAG optimization library, but I'm running into problems accessing the variables in the main program from the external subroutines funct and hess (see pseudo-code below). What is the best way to pass variables (e.g. b) from the main program to such routines, given that I cannot pass them directly as arguments (a restriction of the NAG library). I have tried to implement COMMON blocks, but without much succes.
MODULE user_parameters
! Define the user parameters
INTEGER, PARAMETER :: a = 100
... other parameters
END MODULE user_parameters
MODULE process_data
USE user_parameters
! Define some other variables
INTEGER :: b
... other variables
CONTAINS
SUBROUTINE read_data
... read the data (e.g. alter value of b)
END SUBROUTINE read_data
SUBROUTINE clean_data
... clean the data (e.g. alter value of b)
END SUBROUTINE clean_data
END MODULE process_data
MODULE maximum_likelihood
USE user_parameters
USE process_data
CONTAINS
SUBROUTINE funct
... returns the LL's function value and gradient
END SUBROUTINE funct
SUBROUTINE hess
... returns the LL's hessian
END SUBROUTINE hess
END MODULE maximum_likelihood
PROGRAM estimation
USE user_parameters
USE process_data
USE maximum_likelihood
EXTERNAL funct, hess
CALL read_data
CALL clean_data
! Call minimization routine
CALL E04LBF(funct, hess)
END PROGRAM estimation
maximum_likelihoodneitherfunctnorhessshould be (re-)declared asexternal. I don't think this answers your question, but you should probably fix it. Furthermore, I don't recognise your call toe04lbfas a proper call to that NAG routine. Perhaps what you've shown is rather toopseudo...CALL E04LBF(n, funct, hess, monit, iprint, maxcal, eta, xtol, stepmx, ibound, bl, bu, x, hesl, hesd, istate, f, g, iw, liw, w, lw, ifail).