! ! -------------------------------------------------------------- ! Module of model control ! -------------------------------------------------------------- ! module util_model implicit none public :: init_model ! initialize model public :: run_model ! run model public :: check_model ! check constraint conditions contains !---------------------------------------------------------------------- ! Initialize model !---------------------------------------------------------------------- subroutine init_model(id, n, xmin, xmax, xinit, xname) use model_tank2 use model_sfunc implicit none integer, intent(in) :: id ! model ID integer, intent(out) :: n ! number of parameter real, intent(out) :: xinit(1:*), xmin(1:*), xmax(1:*) character(len=*), intent(out) :: xname(1:*) select case(id) case(1) call init_tank2(n, xmin, xmax, xinit, xname) case(2) call init_sfunc(n, xmin, xmax, xinit, xname) case default print *, 'init_model: invalid model ID', id stop end select end subroutine init_model !---------------------------------------------------------------------- ! Run model !---------------------------------------------------------------------- subroutine run_model(id, x, nd, p, e, q) use model_tank2 use model_sfunc implicit none integer, intent(in) :: id ! model ID real, intent(in) :: x(1:*) ! parameters integer, intent(in) :: nd ! number of data real, intent(in) :: p(1:nd) ! rainfall (mm/day) real, intent(in) :: e(1:nd) ! evapotranspiration (mm/day) real, intent(out) :: q(1:nd) ! simulated discharge (mm/day) select case(id) case(1) call run_tank2(x, nd, p, e, q) case(2) call run_sfunc(x, nd, p, e, q) case default print *, 'run_model: invalid model ID', id stop end select end subroutine run_model !---------------------------------------------------------------------- ! Check constraint conditions !---------------------------------------------------------------------- function check_model(id, x) result(r) use model_tank2 use model_sfunc implicit none integer, intent(in) :: id ! model ID real, intent(in) :: x(1:*) ! parameters integer :: r ! number of constrained condition select case(id) case(1) r = check_tank2(x) case(2) r = check_sfunc(x) case default print *, 'check_model: invalid model ID', id stop end select end function check_model end module util_model