MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
bmi.f90
Go to the documentation of this file.
1module bmif
2
3 implicit none
4
5 integer, parameter :: bmi_max_component_name = 2048
6 integer, parameter :: bmi_max_var_name = 2048
7 integer, parameter :: bmi_max_type_name = 2048
8 integer, parameter :: bmi_max_units_name = 2048
9
10 integer, parameter :: bmi_failure = 1
11 integer, parameter :: bmi_success = 0
12
13 type, abstract :: bmi
14 contains
15 procedure(bmif_get_component_name), deferred :: get_component_name
16 procedure(bmif_get_input_var_names), deferred :: get_input_var_names
17 procedure(bmif_get_output_var_names), deferred :: get_output_var_names
18 procedure(bmif_initialize), deferred :: initialize
19 procedure(bmif_finalize), deferred :: finalize
20 procedure(bmif_get_start_time), deferred :: get_start_time
21 procedure(bmif_get_end_time), deferred :: get_end_time
22 procedure(bmif_get_current_time), deferred :: get_current_time
23 procedure(bmif_get_time_step), deferred :: get_time_step
24 procedure(bmif_get_time_units), deferred :: get_time_units
25 procedure(bmif_update), deferred :: update
26 procedure(bmif_update_frac), deferred :: update_frac
27 procedure(bmif_update_until), deferred :: update_until
28 procedure(bmif_get_var_grid), deferred :: get_var_grid
29 procedure(bmif_get_grid_type), deferred :: get_grid_type
30 procedure(bmif_get_grid_rank), deferred :: get_grid_rank
31 procedure(bmif_get_grid_shape), deferred :: get_grid_shape
32 procedure(bmif_get_grid_size), deferred :: get_grid_size
33 procedure(bmif_get_grid_spacing), deferred :: get_grid_spacing
34 procedure(bmif_get_grid_origin), deferred :: get_grid_origin
35 procedure(bmif_get_grid_x), deferred :: get_grid_x
36 procedure(bmif_get_grid_y), deferred :: get_grid_y
37 procedure(bmif_get_grid_z), deferred :: get_grid_z
38 procedure(bmif_get_grid_connectivity), deferred :: get_grid_connectivity
39 procedure(bmif_get_grid_offset), deferred :: get_grid_offset
40 procedure(bmif_get_var_type), deferred :: get_var_type
41 procedure(bmif_get_var_units), deferred :: get_var_units
42 procedure(bmif_get_var_itemsize), deferred :: get_var_itemsize
43 procedure(bmif_get_var_nbytes), deferred :: get_var_nbytes
44 procedure(bmif_get_value_int), deferred :: get_value_int
45 procedure(bmif_get_value_float), deferred :: get_value_float
46 procedure(bmif_get_value_double), deferred :: get_value_double
47 procedure(bmif_get_value_ptr_int), deferred :: get_value_ptr_int
48 procedure(bmif_get_value_ptr_float), deferred :: get_value_ptr_float
49 procedure(bmif_get_value_ptr_double), deferred :: get_value_ptr_double
50 procedure(bmif_get_value_at_indices_int), deferred :: &
51 get_value_at_indices_int
52 procedure(bmif_get_value_at_indices_float), deferred :: &
53 get_value_at_indices_float
54 procedure(bmif_get_value_at_indices_double), deferred :: &
55 get_value_at_indices_double
56 procedure(bmif_set_value_int), deferred :: set_value_int
57 procedure(bmif_set_value_float), deferred :: set_value_float
58 procedure(bmif_set_value_double), deferred :: set_value_double
59 procedure(bmif_set_value_at_indices_int), deferred :: &
60 set_value_at_indices_int
61 procedure(bmif_set_value_at_indices_float), deferred :: &
62 set_value_at_indices_float
63 procedure(bmif_set_value_at_indices_double), deferred :: &
64 set_value_at_indices_double
65 end type bmi
66
67 abstract interface
68
69 ! Get the name of the model.
70 function bmif_get_component_name(this, name) result(bmi_status)
71 import :: bmi
72 class(bmi), intent(in) :: this
73 character(len=*), pointer, intent(out) :: name
74 integer :: bmi_status
75 end function bmif_get_component_name
76
77 ! List a model's input variables.
78 function bmif_get_input_var_names(this, names) result(bmi_status)
79 import :: bmi
80 class(bmi), intent(in) :: this
81 character(len=*), pointer, intent(out) :: names(:)
82 integer :: bmi_status
83 end function bmif_get_input_var_names
84
85 ! List a model's output variables.
86 function bmif_get_output_var_names(this, names) result(bmi_status)
87 import :: bmi
88 class(bmi), intent(in) :: this
89 character(len=*), pointer, intent(out) :: names(:)
90 integer :: bmi_status
91 end function bmif_get_output_var_names
92
93 ! Perform startup tasks for the model.
94 function bmif_initialize(this, config_file) result(bmi_status)
95 import :: bmi
96 class(bmi), intent(out) :: this
97 character(len=*), intent(in) :: config_file
98 integer :: bmi_status
99 end function bmif_initialize
100
101 ! Perform teardown tasks for the model.
102 function bmif_finalize(this) result(bmi_status)
103 import :: bmi
104 class(bmi), intent(inout) :: this
105 integer :: bmi_status
106 end function bmif_finalize
107
108 ! Start time of the model.
109 function bmif_get_start_time(this, time) result(bmi_status)
110 import :: bmi
111 class(bmi), intent(in) :: this
112 double precision, intent(out) :: time
113 integer :: bmi_status
114 end function bmif_get_start_time
115
116 ! End time of the model.
117 function bmif_get_end_time(this, time) result(bmi_status)
118 import :: bmi
119 class(bmi), intent(in) :: this
120 double precision, intent(out) :: time
121 integer :: bmi_status
122 end function bmif_get_end_time
123
124 ! Current time of the model.
125 function bmif_get_current_time(this, time) result(bmi_status)
126 import :: bmi
127 class(bmi), intent(in) :: this
128 double precision, intent(out) :: time
129 integer :: bmi_status
130 end function bmif_get_current_time
131
132 ! Time step of the model.
133 function bmif_get_time_step(this, time_step) result(bmi_status)
134 import :: bmi
135 class(bmi), intent(in) :: this
136 double precision, intent(out) :: time_step
137 integer :: bmi_status
138 end function bmif_get_time_step
139
140 ! Time units of the model.
141 function bmif_get_time_units(this, time_units) result(bmi_status)
142 import :: bmi
143 class(bmi), intent(in) :: this
144 character(len=*), intent(out) :: time_units
145 integer :: bmi_status
146 end function bmif_get_time_units
147
148 ! Advance the model one time step.
149 function bmif_update(this) result(bmi_status)
150 import :: bmi
151 class(bmi), intent(inout) :: this
152 integer :: bmi_status
153 end function bmif_update
154
155 ! Advance the model by a fraction of a time step.
156 function bmif_update_frac(this, time_frac) result(bmi_status)
157 import :: bmi
158 class(bmi), intent(inout) :: this
159 double precision, intent(in) :: time_frac
160 integer :: bmi_status
161 end function bmif_update_frac
162
163 ! Advance the model until the given time.
164 function bmif_update_until(this, time) result(bmi_status)
165 import :: bmi
166 class(bmi), intent(inout) :: this
167 double precision, intent(in) :: time
168 integer :: bmi_status
169 end function bmif_update_until
170
171 ! Get the grid identifier for the given variable.
172 function bmif_get_var_grid(this, var_name, grid_id) result(bmi_status)
173 import :: bmi
174 class(bmi), intent(in) :: this
175 character(len=*), intent(in) :: var_name
176 integer, intent(out) :: grid_id
177 integer :: bmi_status
178 end function bmif_get_var_grid
179
180 ! Get the grid type as a string.
181 function bmif_get_grid_type(this, grid_id, grid_type) result(bmi_status)
182 import :: bmi
183 class(bmi), intent(in) :: this
184 integer, intent(in) :: grid_id
185 character(len=*), intent(out) :: grid_type
186 integer :: bmi_status
187 end function bmif_get_grid_type
188
189 ! Get number of dimensions of the computational grid.
190 function bmif_get_grid_rank(this, grid_id, grid_rank) result(bmi_status)
191 import :: bmi
192 class(bmi), intent(in) :: this
193 integer, intent(in) :: grid_id
194 integer, intent(out) :: grid_rank
195 integer :: bmi_status
196 end function bmif_get_grid_rank
197
198 ! Get the dimensions of the computational grid.
199 function bmif_get_grid_shape(this, grid_id, grid_shape) result(bmi_status)
200 import :: bmi
201 class(bmi), intent(in) :: this
202 integer, intent(in) :: grid_id
203 integer, dimension(:), intent(out) :: grid_shape
204 integer :: bmi_status
205 end function bmif_get_grid_shape
206
207 ! Get the total number of elements in the computational grid.
208 function bmif_get_grid_size(this, grid_id, grid_size) result(bmi_status)
209 import :: bmi
210 class(bmi), intent(in) :: this
211 integer, intent(in) :: grid_id
212 integer, intent(out) :: grid_size
213 integer :: bmi_status
214 end function bmif_get_grid_size
215
216 ! Get distance between nodes of the computational grid.
217 function bmif_get_grid_spacing(this, grid_id, grid_spacing) result(bmi_status)
218 import :: bmi
219 class(bmi), intent(in) :: this
220 integer, intent(in) :: grid_id
221 double precision, dimension(:), intent(out) :: grid_spacing
222 integer :: bmi_status
223 end function bmif_get_grid_spacing
224
225 ! Get coordinates of the origin of the computational grid.
226 function bmif_get_grid_origin(this, grid_id, grid_origin) result(bmi_status)
227 import :: bmi
228 class(bmi), intent(in) :: this
229 integer, intent(in) :: grid_id
230 double precision, dimension(:), intent(out) :: grid_origin
231 integer :: bmi_status
232 end function bmif_get_grid_origin
233
234 ! Get the x-coordinates of the nodes of a computational grid.
235 function bmif_get_grid_x(this, grid_id, grid_x) result(bmi_status)
236 import :: bmi
237 class(bmi), intent(in) :: this
238 integer, intent(in) :: grid_id
239 double precision, dimension(:), intent(out) :: grid_x
240 integer :: bmi_status
241 end function bmif_get_grid_x
242
243 ! Get the y-coordinates of the nodes of a computational grid.
244 function bmif_get_grid_y(this, grid_id, grid_y) result(bmi_status)
245 import :: bmi
246 class(bmi), intent(in) :: this
247 integer, intent(in) :: grid_id
248 double precision, dimension(:), intent(out) :: grid_y
249 integer :: bmi_status
250 end function bmif_get_grid_y
251
252 ! Get the z-coordinates of the nodes of a computational grid.
253 function bmif_get_grid_z(this, grid_id, grid_z) result(bmi_status)
254 import :: bmi
255 class(bmi), intent(in) :: this
256 integer, intent(in) :: grid_id
257 double precision, dimension(:), intent(out) :: grid_z
258 integer :: bmi_status
259 end function bmif_get_grid_z
260
261 ! Get the connectivity array of the nodes of an unstructured grid.
262 function bmif_get_grid_connectivity(this, grid_id, grid_conn) &
263 result(bmi_status)
264 import :: bmi
265 class(bmi), intent(in) :: this
266 integer, intent(in) :: grid_id
267 integer, dimension(:), intent(out) :: grid_conn
268 integer :: bmi_status
269 end function bmif_get_grid_connectivity
270
271 ! Get the offsets of the nodes of an unstructured grid.
272 function bmif_get_grid_offset(this, grid_id, grid_offset) &
273 result(bmi_status)
274 import :: bmi
275 class(bmi), intent(in) :: this
276 integer, intent(in) :: grid_id
277 integer, dimension(:), intent(out) :: grid_offset
278 integer :: bmi_status
279 end function bmif_get_grid_offset
280
281 ! Get the data type of the given variable as a string.
282 function bmif_get_var_type(this, var_name, var_type) result(bmi_status)
283 import :: bmi
284 class(bmi), intent(in) :: this
285 character(len=*), intent(in) :: var_name
286 character(len=*), intent(out) :: var_type
287 integer :: bmi_status
288 end function bmif_get_var_type
289
290 ! Get the units of the given variable.
291 function bmif_get_var_units(this, var_name, var_units) result(bmi_status)
292 import :: bmi
293 class(bmi), intent(in) :: this
294 character(len=*), intent(in) :: var_name
295 character(len=*), intent(out) :: var_units
296 integer :: bmi_status
297 end function bmif_get_var_units
298
299 ! Get memory use per array element, in bytes.
300 function bmif_get_var_itemsize(this, var_name, var_size) result(bmi_status)
301 import :: bmi
302 class(bmi), intent(in) :: this
303 character(len=*), intent(in) :: var_name
304 integer, intent(out) :: var_size
305 integer :: bmi_status
306 end function bmif_get_var_itemsize
307
308 ! Get size of the given variable, in bytes.
309 function bmif_get_var_nbytes(this, var_name, var_nbytes) result(bmi_status)
310 import :: bmi
311 class(bmi), intent(in) :: this
312 character(len=*), intent(in) :: var_name
313 integer, intent(out) :: var_nbytes
314 integer :: bmi_status
315 end function bmif_get_var_nbytes
316
317 ! Get a copy of values (flattened!) of the given integer variable.
318 function bmif_get_value_int(this, var_name, dest) result(bmi_status)
319 import :: bmi
320 class(bmi), intent(in) :: this
321 character(len=*), intent(in) :: var_name
322 integer, intent(inout) :: dest(:)
323 integer :: bmi_status
324 end function bmif_get_value_int
325
326 ! Get a copy of values (flattened!) of the given real variable.
327 function bmif_get_value_float(this, var_name, dest) result(bmi_status)
328 import :: bmi
329 class(bmi), intent(in) :: this
330 character(len=*), intent(in) :: var_name
331 real, intent(inout) :: dest(:)
332 integer :: bmi_status
333 end function bmif_get_value_float
334
335 ! Get a copy of values (flattened!) of the given double variable.
336 function bmif_get_value_double(this, var_name, dest) result(bmi_status)
337 import :: bmi
338 class(bmi), intent(in) :: this
339 character(len=*), intent(in) :: var_name
340 double precision, intent(inout) :: dest(:)
341 integer :: bmi_status
342 end function bmif_get_value_double
343
344 ! Get a reference to the given integer variable.
345 function bmif_get_value_ptr_int(this, var_name, dest) &
346 result(bmi_status)
347 import :: bmi
348 class(bmi), intent(in) :: this
349 character(len=*), intent(in) :: var_name
350 integer, pointer, intent(inout) :: dest(:)
351 integer :: bmi_status
352 end function bmif_get_value_ptr_int
353
354 ! Get a reference to the given real variable.
355 function bmif_get_value_ptr_float(this, var_name, dest) &
356 result(bmi_status)
357 import :: bmi
358 class(bmi), intent(in) :: this
359 character(len=*), intent(in) :: var_name
360 real, pointer, intent(inout) :: dest(:)
361 integer :: bmi_status
362 end function bmif_get_value_ptr_float
363
364 ! Get a reference to the given double variable.
365 function bmif_get_value_ptr_double(this, var_name, dest) &
366 result(bmi_status)
367 import :: bmi
368 class(bmi), intent(in) :: this
369 character(len=*), intent(in) :: var_name
370 double precision, pointer, intent(inout) :: dest(:)
371 integer :: bmi_status
372 end function bmif_get_value_ptr_double
373
374 ! Get integer values at particular (one-dimensional) indices.
375 function bmif_get_value_at_indices_int(this, var_name, dest, indices) &
376 result(bmi_status)
377 import :: bmi
378 class(bmi), intent(in) :: this
379 character(len=*), intent(in) :: var_name
380 integer, intent(inout) :: dest(:)
381 integer, intent(in) :: indices(:)
382 integer :: bmi_status
384
385 ! Get real values at particular (one-dimensional) indices.
386 function bmif_get_value_at_indices_float(this, var_name, dest, indices) &
387 result(bmi_status)
388 import :: bmi
389 class(bmi), intent(in) :: this
390 character(len=*), intent(in) :: var_name
391 real, intent(inout) :: dest(:)
392 integer, intent(in) :: indices(:)
393 integer :: bmi_status
395
396 ! Get double values at particular (one-dimensional) indices.
397 function bmif_get_value_at_indices_double(this, var_name, dest, indices) &
398 result(bmi_status)
399 import :: bmi
400 class(bmi), intent(in) :: this
401 character(len=*), intent(in) :: var_name
402 double precision, intent(inout) :: dest(:)
403 integer, intent(in) :: indices(:)
404 integer :: bmi_status
406
407 ! Set new values for an integer model variable.
408 function bmif_set_value_int(this, var_name, src) result(bmi_status)
409 import :: bmi
410 class(bmi), intent(inout) :: this
411 character(len=*), intent(in) :: var_name
412 integer, intent(in) :: src(:)
413 integer :: bmi_status
414 end function bmif_set_value_int
415
416 ! Set new values for a real model variable.
417 function bmif_set_value_float(this, var_name, src) result(bmi_status)
418 import :: bmi
419 class(bmi), intent(inout) :: this
420 character(len=*), intent(in) :: var_name
421 real, intent(in) :: src(:)
422 integer :: bmi_status
423 end function bmif_set_value_float
424
425 ! Set new values for a double model variable.
426 function bmif_set_value_double(this, var_name, src) result(bmi_status)
427 import :: bmi
428 class(bmi), intent(inout) :: this
429 character(len=*), intent(in) :: var_name
430 double precision, intent(in) :: src(:)
431 integer :: bmi_status
432 end function bmif_set_value_double
433
434 ! Set integer values at particular (one-dimensional) indices.
435 function bmif_set_value_at_indices_int(this, var_name, indices, src) &
436 result(bmi_status)
437 import :: bmi
438 class(bmi), intent(inout) :: this
439 character(len=*), intent(in) :: var_name
440 integer, intent(in) :: indices(:)
441 integer, intent(in) :: src(:)
442 integer :: bmi_status
444
445 ! Set real values at particular (one-dimensional) indices.
446 function bmif_set_value_at_indices_float(this, var_name, indices, src) &
447 result(bmi_status)
448 import :: bmi
449 class(bmi), intent(inout) :: this
450 character(len=*), intent(in) :: var_name
451 integer, intent(in) :: indices(:)
452 real, intent(in) :: src(:)
453 integer :: bmi_status
455
456 ! Set double values at particular (one-dimensional) indices.
457 function bmif_set_value_at_indices_double(this, var_name, indices, src) &
458 result(bmi_status)
459 import :: bmi
460 class(bmi), intent(inout) :: this
461 character(len=*), intent(in) :: var_name
462 integer, intent(in) :: indices(:)
463 double precision, intent(in) :: src(:)
464 integer :: bmi_status
466
467 end interface
468
469end module bmif
Definition bmi.f90:1
integer, parameter bmi_max_type_name
Definition bmi.f90:7
integer, parameter bmi_success
Definition bmi.f90:11
integer, parameter bmi_max_units_name
Definition bmi.f90:8
integer, parameter bmi_max_component_name
Definition bmi.f90:5
integer, parameter bmi_failure
Definition bmi.f90:10
integer, parameter bmi_max_var_name
Definition bmi.f90:6