MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
memorysethandlermodule Module Reference

Data Types

type  eventhandlerdatatype
 
interface  set_handler_iface
 

Functions/Subroutines

subroutine, public mem_register_handler (var_name, mem_path, handler, ctx)
 Register the event handler and context for this variable. More...
 
subroutine, public on_memory_set (var_name, mem_path, status)
 Triggers the calling of the side effect handler for this variable. More...
 

Variables

type(listtypehandler_list
 

Function/Subroutine Documentation

◆ mem_register_handler()

subroutine, public memorysethandlermodule::mem_register_handler ( character(len=*), intent(in)  var_name,
character(len=*), intent(in)  mem_path,
procedure(set_handler_iface), pointer  handler,
class(*), pointer  ctx 
)

The event handler and its ctx are called whenever the trigger is given by calling on_set_memory(). This allows to handle side effects, e.g. when a variable is from outside a class (the context) such as happens with the BMI.

Parameters
[in]var_namethe variable name
[in]mem_paththe memory path
handlercalled after memory is set
ctxthe context with which the handler should be called

Definition at line 39 of file MemorySetHandler.f90.

40  character(len=*), intent(in) :: var_name !< the variable name
41  character(len=*), intent(in) :: mem_path !< the memory path
42  procedure(set_handler_iface), pointer :: handler !< called after memory is set
43  class(*), pointer :: ctx !< the context with which the handler should be called
44  ! local
45  integer(I4B) :: handler_idx
46  class(EventHandlerDataType), pointer :: handler_data => null()
47  class(*), pointer :: handler_data_genptr
48  type(MemoryType), pointer :: mt
49  logical(LGP) :: found
50 
51  ! first store the handler data
52  allocate (handler_data)
53  handler_data%handler => handler
54  handler_data%handlerContext => ctx
55 
56  handler_data_genptr => handler_data
57  call handler_list%Add(handler_data_genptr)
58 
59  ! this is the index for the current handler
60  handler_idx = handler_list%Count()
61 
62  ! now set it to the memory item
63  mt => null()
64  found = .false.
65  call get_from_memorylist(var_name, mem_path, mt, found)
66  mt%set_handler_idx = handler_idx
67 
Here is the call graph for this function:

◆ on_memory_set()

subroutine, public memorysethandlermodule::on_memory_set ( character(len=*), intent(in)  var_name,
character(len=*), intent(in)  mem_path,
integer(i4b), intent(out)  status 
)

The handler can be set by calling mem_register_handler(). When the status contains an error code, the program should be stopped because the data in memory is no longer consistent...

Parameters
[in]var_namethe variable name
[in]mem_paththe memory path
[out]statusstatus: 0 for success, -1 when failed

Definition at line 76 of file MemorySetHandler.f90.

77  character(len=*), intent(in) :: var_name !< the variable name
78  character(len=*), intent(in) :: mem_path !< the memory path
79  integer(I4B), intent(out) :: status !< status: 0 for success, -1 when failed
80  ! local
81  type(MemoryType), pointer :: mt
82  logical(LGP) :: found
83  class(*), pointer :: handler_data_genptr => null()
84  class(EventHandlerDataType), pointer :: evt_handler_data => null()
85 
86  ! get the handler data and cast
87  mt => null()
88  found = .false.
89  call get_from_memorylist(var_name, mem_path, mt, found)
90  if (mt%set_handler_idx == 0) then
91  ! nothing to be done
92  status = 0
93  return
94  end if
95 
96  handler_data_genptr => handler_list%GetItem(mt%set_handler_idx)
97  select type (handler_data_genptr)
98  class is (eventhandlerdatatype)
99  evt_handler_data => handler_data_genptr
100  end select
101 
102  ! call the function
103  call evt_handler_data%handler(evt_handler_data%handlerContext, status)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ handler_list

type(listtype) memorysethandlermodule::handler_list
private

Definition at line 20 of file MemorySetHandler.f90.

20  type(ListType) :: handler_list