23 use iso_c_binding,
only: c_int, c_char, c_double, c_null_char, c_loc, c_ptr, &
44 bind(C, name="get_component_name")
48 integer(kind=c_int) :: bmi_status
50 character(len=*),
parameter :: component_name =
'MODFLOW 6'
52 name(1:len(component_name) + 1) = &
71 integer(kind=c_int) :: bmi_status
97 function bmi_update()
result(bmi_status)
bind(C, name="update")
100 integer(kind=c_int) :: bmi_status
102 logical :: hasconverged
115 bind(C, name="update_until")
121 real(kind=c_double),
value,
intent(in) :: time
122 integer(kind=c_int) :: bmi_status
125 logical :: hasconverged
131 if (time <
totim - tol)
then
133 'which is before the current time'
139 'which is after the end time'
161 integer(kind=c_int) :: bmi_status
177 bind(C, name="get_start_time")
180 real(kind=c_double),
intent(out) :: start_time
181 integer(kind=c_int) :: bmi_status
193 function get_end_time(end_time)
result(bmi_status)
bind(C, name="get_end_time")
198 real(kind=c_double),
intent(out) :: end_time
199 integer(kind=c_int) :: bmi_status
212 bind(C, name="get_current_time")
217 real(kind=c_double),
intent(out) :: current_time
218 integer(kind=c_int) :: bmi_status
231 bind(C, name="get_time_step")
236 real(kind=c_double),
intent(out) :: time_step
237 integer(kind=c_int) :: bmi_status
250 bind(C, name="get_time_units")
255 character(kind=c_char),
intent(out) :: c_time_units(
bmi_lenunits)
256 integer(kind=c_int) :: bmi_status
258 character(len=LENUNITS) :: time_units
272 time_units =
'unknown'
274 c_time_units(1:len_trim(time_units) + 1) = &
285 bind(C, name="get_input_item_count")
288 integer(kind=c_int),
intent(out) :: count
289 integer(kind=c_int) :: bmi_status
302 bind(C, name="get_output_item_count")
305 integer(kind=c_int),
intent(out) :: count
306 integer(kind=c_int) :: bmi_status
329 bind(C, name="get_input_var_names")
332 character(kind=c_char, len=1),
intent(inout) :: c_names(*)
333 integer(kind=c_int) :: bmi_status
335 integer(I4B) :: start, i
338 character(len=LENMEMADDRESS) :: var_address
342 do while (itr%has_next())
346 do i = 1, len(trim(var_address))
347 c_names(start + i - 1) = var_address(i:i)
349 c_names(start + i) = c_null_char
364 bind(C, name="get_output_var_names")
367 character(kind=c_char, len=1),
intent(inout) :: c_names(*)
368 integer(kind=c_int) :: bmi_status
370 integer(I4B) :: start, i
373 character(len=LENMEMADDRESS) :: var_address
377 do while (itr%has_next())
381 do i = 1, len(trim(var_address))
382 c_names(start + i - 1) = var_address(i:i)
384 c_names(start + i) = c_null_char
395 bind(C, name="get_var_itemsize")
398 character(kind=c_char),
intent(in) :: c_var_address(*)
399 integer(kind=c_int),
intent(out) :: var_size
400 integer(kind=c_int) :: bmi_status
402 character(len=LENMEMPATH) :: mem_path
403 character(len=LENVARNAME) :: var_name
404 logical(LGP) :: valid
409 if (.not. valid)
then
422 bind(C, name="get_var_nbytes")
425 character(kind=c_char),
intent(in) :: c_var_address(*)
426 integer(kind=c_int),
intent(out) :: var_nbytes
427 integer(kind=c_int) :: bmi_status
429 integer(I4B) :: var_size, isize
430 character(len=LENMEMPATH) :: mem_path
431 character(len=LENVARNAME) :: var_name
432 logical(LGP) :: valid
437 if (.not. valid)
then
444 call get_isize(var_name, mem_path, isize)
447 var_nbytes = var_size * isize
459 bind(C, name="get_value_double")
464 character(kind=c_char),
intent(in) :: c_var_address(*)
465 type(c_ptr),
intent(in) :: c_arr_ptr
466 integer(kind=c_int) :: bmi_status
468 character(len=LENMEMPATH) :: mem_path
469 character(len=LENVARNAME) :: var_name
470 logical(LGP) :: valid
472 real(dp),
pointer :: src_ptr, tgt_ptr
473 real(dp),
dimension(:),
pointer,
contiguous :: src1d_ptr, tgt1d_ptr
474 real(dp),
dimension(:, :),
pointer,
contiguous :: src2d_ptr, tgt2d_ptr
475 real(dp),
dimension(:, :, :),
pointer,
contiguous :: src3d_ptr, tgt3d_ptr
476 integer(I4B) :: i, j, k
481 if (.not. valid)
then
493 call c_f_pointer(c_arr_ptr, tgt_ptr)
495 else if (rank == 1)
then
496 call mem_setptr(src1d_ptr, var_name, mem_path)
497 call c_f_pointer(c_arr_ptr, tgt1d_ptr, shape(src1d_ptr))
498 do i = 1,
size(tgt1d_ptr)
499 tgt1d_ptr(i) = src1d_ptr(i)
501 else if (rank == 2)
then
502 call mem_setptr(src2d_ptr, var_name, mem_path)
503 call c_f_pointer(c_arr_ptr, tgt2d_ptr, shape(src2d_ptr))
504 do j = 1,
size(tgt2d_ptr, 2)
505 do i = 1,
size(tgt2d_ptr, 1)
506 tgt2d_ptr(i, j) = src2d_ptr(i, j)
509 else if (rank == 3)
then
510 call mem_setptr(src3d_ptr, var_name, mem_path)
511 call c_f_pointer(c_arr_ptr, tgt3d_ptr, shape(src3d_ptr))
512 do k = 1,
size(tgt3d_ptr, 3)
513 do j = 1,
size(tgt3d_ptr, 2)
514 do i = 1,
size(tgt3d_ptr, 1)
515 tgt3d_ptr(i, j, k) = src3d_ptr(i, j, k)
536 bind(C, name="get_value_int")
541 character(kind=c_char),
intent(in) :: c_var_address(*)
542 type(c_ptr),
intent(in) :: c_arr_ptr
543 integer(kind=c_int) :: bmi_status
545 character(len=LENMEMPATH) :: mem_path
546 character(len=LENVARNAME) :: var_name
547 logical(LGP) :: valid
549 integer(I4B),
pointer :: src_ptr, tgt_ptr
550 integer(I4B),
dimension(:),
pointer,
contiguous :: src1d_ptr, tgt1d_ptr
551 integer(I4B),
dimension(:, :),
pointer,
contiguous :: src2d_ptr, tgt2d_ptr
552 integer(I4B),
dimension(:, :, :),
pointer,
contiguous :: src3d_ptr, tgt3d_ptr
553 integer(I4B) :: i, j, k
558 if (.not. valid)
then
570 call c_f_pointer(c_arr_ptr, tgt_ptr)
572 else if (rank == 1)
then
573 call mem_setptr(src1d_ptr, var_name, mem_path)
574 call c_f_pointer(c_arr_ptr, tgt1d_ptr, shape(src1d_ptr))
575 do i = 1,
size(tgt1d_ptr)
576 tgt1d_ptr(i) = src1d_ptr(i)
578 else if (rank == 2)
then
579 call mem_setptr(src2d_ptr, var_name, mem_path)
580 call c_f_pointer(c_arr_ptr, tgt2d_ptr, shape(src2d_ptr))
581 do j = 1,
size(tgt2d_ptr, 2)
582 do i = 1,
size(tgt2d_ptr, 1)
583 tgt2d_ptr(i, j) = src2d_ptr(i, j)
586 else if (rank == 3)
then
587 call mem_setptr(src3d_ptr, var_name, mem_path)
588 call c_f_pointer(c_arr_ptr, tgt3d_ptr, shape(src3d_ptr))
589 do k = 1,
size(tgt3d_ptr, 3)
590 do j = 1,
size(tgt3d_ptr, 2)
591 do i = 1,
size(tgt3d_ptr, 1)
592 tgt3d_ptr(i, j, k) = src3d_ptr(i, j, k)
611 bind(C, name="get_value_bool")
616 character(kind=c_char),
intent(in) :: c_var_address(*)
617 type(c_ptr),
intent(in) :: c_arr_ptr
618 integer(kind=c_int) :: bmi_status
620 character(len=LENMEMPATH) :: mem_path
621 character(len=LENVARNAME) :: var_name
622 logical(LGP) :: valid
624 logical(LGP),
pointer :: src_ptr, tgt_ptr
629 if (.not. valid)
then
640 call c_f_pointer(c_arr_ptr, tgt_ptr)
659 bind(C, name="get_value_string")
663 character(kind=c_char),
intent(in) :: c_var_address(*)
664 type(c_ptr),
intent(in) :: c_arr_ptr
665 integer(kind=c_int) :: bmi_status
667 character(len=LENMEMPATH) :: mem_path
668 character(len=LENVARNAME) :: var_name
669 logical(LGP) :: valid
671 character(len=:),
pointer :: srcstr
672 character(kind=c_char),
pointer :: tgtstr(:)
674 character(kind=c_char),
pointer :: tgtstr1d(:, :)
675 character(:),
allocatable :: tempstr
676 integer(I4B) :: i, ilen, isize
681 if (.not. valid)
then
694 call c_f_pointer(c_arr_ptr, tgtstr, shape=[ilen + 1])
698 else if (rank == 1)
then
700 call mem_setptr(srccharstr1d, var_name, mem_path)
701 if (.not.
associated(srccharstr1d))
then
709 call get_isize(var_name, mem_path, isize)
711 call c_f_pointer(c_arr_ptr, tgtstr1d, shape=[ilen + 1, isize])
715 allocate (
character(ilen) :: tempstr)
717 tempstr = srccharstr1d(i)
737 function get_value(c_var_address, c_arr_ptr)
result(bmi_status) &
738 bind(C, name="get_value")
743 character(kind=c_char),
intent(in) :: c_var_address(*)
744 type(c_ptr),
intent(inout) :: c_arr_ptr
745 integer(kind=c_int) :: bmi_status
747 character(len=LENMEMPATH) :: mem_path
748 character(len=LENMEMTYPE) :: mem_type
749 character(len=LENVARNAME) :: var_name
750 logical(LGP) :: valid
755 if (.not. valid)
then
762 if (index(mem_type,
"DOUBLE") /= 0)
then
764 else if (index(mem_type,
"INTEGER") /= 0)
then
766 else if (index(mem_type,
"LOGICAL") /= 0)
then
768 else if (index(mem_type,
"STRING") /= 0)
then
787 bind(C, name="get_value_ptr")
792 character(kind=c_char),
intent(in) :: c_var_address(*)
793 type(c_ptr),
intent(inout) :: c_arr_ptr
794 integer(kind=c_int) :: bmi_status
796 character(len=LENMEMPATH) :: mem_path
797 character(len=LENMEMTYPE) :: mem_type
798 character(len=LENVARNAME) :: var_name
799 logical(LGP) :: valid
804 if (.not. valid)
then
811 if (index(mem_type,
"DOUBLE") /= 0)
then
813 else if (index(mem_type,
"INTEGER") /= 0)
then
815 else if (index(mem_type,
"LOGICAL") /= 0)
then
834 bind(C, name="get_value_ptr_double")
837 character(kind=c_char),
intent(in) :: c_var_address(*)
838 type(c_ptr),
intent(inout) :: c_arr_ptr
839 integer(kind=c_int) :: bmi_status
841 character(len=LENMEMPATH) :: mem_path
842 character(len=LENVARNAME) :: var_name
843 logical(LGP) :: valid
844 real(dp),
pointer :: scalar_ptr
845 real(dp),
dimension(:),
pointer,
contiguous :: array_ptr
846 real(dp),
dimension(:, :),
pointer,
contiguous :: array2d_ptr
847 real(dp),
dimension(:, :, :),
pointer,
contiguous :: array3d_ptr
853 if (.not. valid)
then
861 call mem_setptr(scalar_ptr, var_name, mem_path)
862 c_arr_ptr = c_loc(scalar_ptr)
863 else if (rank == 1)
then
864 call mem_setptr(array_ptr, var_name, mem_path)
865 c_arr_ptr = c_loc(array_ptr)
866 else if (rank == 2)
then
867 call mem_setptr(array2d_ptr, var_name, mem_path)
868 c_arr_ptr = c_loc(array2d_ptr)
869 else if (rank == 3)
then
870 call mem_setptr(array3d_ptr, var_name, mem_path)
871 c_arr_ptr = c_loc(array3d_ptr)
888 bind(C, name="get_value_ptr_int")
891 character(kind=c_char),
intent(in) :: c_var_address(*)
892 type(c_ptr),
intent(inout) :: c_arr_ptr
893 integer(kind=c_int) :: bmi_status
895 character(len=LENMEMPATH) :: mem_path
896 character(len=LENVARNAME) :: var_name
897 logical(LGP) :: valid
899 integer(I4B),
pointer :: scalar_ptr
900 integer(I4B),
dimension(:),
pointer,
contiguous :: array_ptr
901 integer(I4B),
dimension(:, :),
pointer,
contiguous :: array2d_ptr
902 integer(I4B),
dimension(:, :, :),
pointer,
contiguous :: array3d_ptr
907 if (.not. valid)
then
916 call mem_setptr(scalar_ptr, var_name, mem_path)
917 c_arr_ptr = c_loc(scalar_ptr)
918 else if (rank == 1)
then
919 call mem_setptr(array_ptr, var_name, mem_path)
920 c_arr_ptr = c_loc(array_ptr)
921 else if (rank == 2)
then
922 call mem_setptr(array2d_ptr, var_name, mem_path)
923 c_arr_ptr = c_loc(array2d_ptr)
924 else if (rank == 3)
then
925 call mem_setptr(array3d_ptr, var_name, mem_path)
926 c_arr_ptr = c_loc(array3d_ptr)
941 bind(C, name="get_value_ptr_bool")
944 character(kind=c_char),
intent(in) :: c_var_address(*)
945 type(c_ptr),
intent(inout) :: c_arr_ptr
946 integer(kind=c_int) :: bmi_status
948 character(len=LENMEMPATH) :: mem_path
949 character(len=LENVARNAME) :: var_name
950 logical(LGP) :: valid
951 logical(LGP),
pointer :: scalar_ptr
957 if (.not. valid)
then
965 call mem_setptr(scalar_ptr, var_name, mem_path)
966 c_arr_ptr = c_loc(scalar_ptr)
982 function set_value(c_var_address, c_arr_ptr)
result(bmi_status) &
983 bind(C, name="set_value")
988 character(kind=c_char),
intent(in) :: c_var_address(*)
989 type(c_ptr),
intent(inout) :: c_arr_ptr
990 integer(kind=c_int) :: bmi_status
992 character(len=LENMEMPATH) :: mem_path
993 character(len=LENMEMTYPE) :: mem_type
994 character(len=LENVARNAME) :: var_name
995 logical(LGP) :: valid
1000 if (.not. valid)
then
1007 if (index(mem_type,
"DOUBLE") /= 0)
then
1009 else if (index(mem_type,
"INTEGER") /= 0)
then
1011 else if (index(mem_type,
"LOGICAL") /= 0)
then
1029 bind(C, name="set_value_double")
1034 character(kind=c_char),
intent(in) :: c_var_address(*)
1035 type(c_ptr),
intent(in) :: c_arr_ptr
1036 integer(kind=c_int) :: bmi_status
1038 character(len=LENMEMPATH) :: mem_path
1039 character(len=LENVARNAME) :: var_name
1040 logical(LGP) :: valid
1041 integer(I4B) :: rank
1042 real(dp),
pointer :: src_ptr, tgt_ptr
1043 real(dp),
dimension(:),
pointer,
contiguous :: src1d_ptr, tgt1d_ptr
1044 real(dp),
dimension(:, :),
pointer,
contiguous :: src2d_ptr, tgt2d_ptr
1045 integer(I4B) :: i, j
1046 integer(I4B) :: status
1050 call split_address(c_var_address, mem_path, var_name, valid)
1051 if (.not. valid)
then
1062 call c_f_pointer(c_arr_ptr, src_ptr)
1064 else if (rank == 1)
then
1065 call mem_setptr(tgt1d_ptr, var_name, mem_path)
1066 call c_f_pointer(c_arr_ptr, src1d_ptr, shape(tgt1d_ptr))
1067 do i = 1,
size(tgt1d_ptr)
1068 tgt1d_ptr(i) = src1d_ptr(i)
1070 else if (rank == 2)
then
1071 call mem_setptr(tgt2d_ptr, var_name, mem_path)
1072 call c_f_pointer(c_arr_ptr, src2d_ptr, shape(tgt2d_ptr))
1073 do j = 1,
size(tgt2d_ptr, 2)
1074 do i = 1,
size(tgt2d_ptr, 1)
1075 tgt2d_ptr(i, j) = src2d_ptr(i, j)
1087 if (status /= 0)
then
1102 bind(C, name="set_value_int")
1107 character(kind=c_char),
intent(in) :: c_var_address(*)
1108 type(c_ptr),
intent(in) :: c_arr_ptr
1109 integer(kind=c_int) :: bmi_status
1111 character(len=LENMEMPATH) :: mem_path
1112 character(len=LENVARNAME) :: var_name
1113 logical(LGP) :: valid
1114 integer(I4B) :: rank
1115 integer(I4B),
pointer :: src_ptr, tgt_ptr
1116 integer(I4B),
dimension(:),
pointer,
contiguous :: src1d_ptr, tgt1d_ptr
1117 integer(I4B),
dimension(:, :),
pointer,
contiguous :: src2d_ptr, tgt2d_ptr
1118 integer(I4B) :: i, j
1119 integer(I4B) :: status
1123 call split_address(c_var_address, mem_path, var_name, valid)
1124 if (.not. valid)
then
1135 call c_f_pointer(c_arr_ptr, src_ptr)
1137 else if (rank == 1)
then
1138 call mem_setptr(tgt1d_ptr, var_name, mem_path)
1139 call c_f_pointer(c_arr_ptr, src1d_ptr, shape(tgt1d_ptr))
1140 do i = 1,
size(tgt1d_ptr)
1141 tgt1d_ptr(i) = src1d_ptr(i)
1143 else if (rank == 2)
then
1144 call mem_setptr(tgt2d_ptr, var_name, mem_path)
1145 call c_f_pointer(c_arr_ptr, src2d_ptr, shape(tgt2d_ptr))
1146 do j = 1,
size(tgt2d_ptr, 2)
1147 do i = 1,
size(tgt2d_ptr, 1)
1148 tgt2d_ptr(i, j) = src2d_ptr(i, j)
1160 if (status /= 0)
then
1175 bind(C, name="set_value_bool")
1180 character(kind=c_char),
intent(in) :: c_var_address(*)
1181 type(c_ptr),
intent(in) :: c_arr_ptr
1182 integer(kind=c_int) :: bmi_status
1184 character(len=LENMEMPATH) :: mem_path
1185 character(len=LENVARNAME) :: var_name
1186 logical(LGP) :: valid
1187 integer(I4B) :: rank
1188 logical(LGP),
pointer :: src_ptr, tgt_ptr
1189 integer(I4B) :: status
1193 call split_address(c_var_address, mem_path, var_name, valid)
1194 if (.not. valid)
then
1205 call c_f_pointer(c_arr_ptr, src_ptr)
1216 if (status /= 0)
then
1234 result(bmi_status)
bind(C, name="get_value_at_indices")
1239 character(kind=c_char),
intent(in) :: c_var_address(*)
1240 type(c_ptr),
intent(in) :: c_arr_ptr
1241 integer(kind=c_int),
intent(in) :: c_inds(*)
1242 integer(kind=c_int),
intent(in) :: count
1243 integer(kind=c_int) :: bmi_status
1245 character(len=LENMEMPATH) :: mem_path
1246 character(len=LENMEMTYPE) :: mem_type
1247 character(len=LENVARNAME) :: var_name
1248 logical(LGP) :: valid
1249 integer(I4B) :: i, nvalues
1250 type(c_ptr) :: var_ptr
1251 real(dp),
dimension(:),
pointer,
contiguous :: src_dbl, tgt_dbl
1252 integer(I4B),
dimension(:),
pointer,
contiguous :: src_int, tgt_int
1256 call split_address(c_var_address, mem_path, var_name, valid)
1257 if (.not. valid)
return
1258 if (.not.
valid_indices(mem_path, var_name, c_inds, count, nvalues))
return
1262 if (index(mem_type,
"DOUBLE") /= 0)
then
1264 call c_f_pointer(var_ptr, src_dbl, [nvalues])
1265 call c_f_pointer(c_arr_ptr, tgt_dbl, [count])
1267 tgt_dbl(i) = src_dbl(c_inds(i) + 1)
1269 else if (index(mem_type,
"INTEGER") /= 0)
then
1271 call c_f_pointer(var_ptr, src_int, [nvalues])
1272 call c_f_pointer(c_arr_ptr, tgt_int, [count])
1274 tgt_int(i) = src_int(c_inds(i) + 1)
1295 result(bmi_status)
bind(C, name="set_value_at_indices")
1301 character(kind=c_char),
intent(in) :: c_var_address(*)
1302 integer(kind=c_int),
intent(in) :: c_inds(*)
1303 integer(kind=c_int),
intent(in) :: count
1304 type(c_ptr),
intent(in) :: c_arr_ptr
1305 integer(kind=c_int) :: bmi_status
1307 character(len=LENMEMPATH) :: mem_path
1308 character(len=LENMEMTYPE) :: mem_type
1309 character(len=LENVARNAME) :: var_name
1310 logical(LGP) :: valid
1311 integer(I4B) :: i, nvalues, status
1312 type(c_ptr) :: var_ptr
1313 real(dp),
dimension(:),
pointer,
contiguous :: src_dbl, tgt_dbl
1314 integer(I4B),
dimension(:),
pointer,
contiguous :: src_int, tgt_int
1318 call split_address(c_var_address, mem_path, var_name, valid)
1319 if (.not. valid)
return
1320 if (.not.
valid_indices(mem_path, var_name, c_inds, count, nvalues))
return
1324 if (index(mem_type,
"DOUBLE") /= 0)
then
1326 call c_f_pointer(var_ptr, tgt_dbl, [nvalues])
1327 call c_f_pointer(c_arr_ptr, src_dbl, [count])
1329 tgt_dbl(c_inds(i) + 1) = src_dbl(i)
1331 else if (index(mem_type,
"INTEGER") /= 0)
then
1333 call c_f_pointer(var_ptr, tgt_int, [nvalues])
1334 call c_f_pointer(c_arr_ptr, src_int, [count])
1336 tgt_int(c_inds(i) + 1) = src_int(i)
1346 if (status /= 0)
then
1361 character(len=*),
intent(in) :: mem_path
1362 character(len=*),
intent(in) :: var_name
1363 integer(kind=c_int),
intent(in) :: c_inds(*)
1364 integer(kind=c_int),
intent(in) :: count
1365 integer(I4B),
intent(out) :: nvalues
1366 logical(LGP) :: valid
1368 integer(I4B) :: i, rank
1373 if (rank < 0 .or. rank > 3)
then
1379 call get_isize(var_name, mem_path, nvalues)
1381 if (c_inds(i) < 0 .or. c_inds(i) >= nvalues)
then
1397 bind(C, name="get_var_type")
1402 character(kind=c_char),
intent(in) :: c_var_address(*)
1403 character(kind=c_char),
intent(out) :: c_var_type(
bmi_lenvartype)
1404 integer(kind=c_int) :: bmi_status
1406 character(len=LENMEMPATH) :: mem_path
1407 character(len=LENVARNAME) :: var_name
1408 character(len=LENMEMTYPE) :: mem_type
1409 logical(LGP) :: valid
1413 call split_address(c_var_address, mem_path, var_name, valid)
1414 if (.not. valid)
then
1420 c_var_type(1:len(trim(mem_type)) + 1) = &
1423 if (mem_type ==
'UNKNOWN')
then
1437 bind(C, name="get_var_units")
1440 character(kind=c_char),
intent(in) :: c_var_address(*)
1441 character(kind=c_char),
intent(out) :: c_var_units(
bmi_lenunits)
1442 integer(kind=c_int) :: bmi_status
1444 character(len=LENMEMPATH) :: mem_path
1445 character(len=LENVARNAME) :: var_name
1446 character(len=*),
parameter :: var_units =
'unknown'
1447 logical(LGP) :: valid
1451 call split_address(c_var_address, mem_path, var_name, valid)
1452 if (.not. valid)
return
1454 c_var_units(1:len(var_units) + 1) = &
1465 bind(C, name="get_var_location")
1468 character(kind=c_char),
intent(in) :: c_var_address(*)
1470 integer(kind=c_int) :: bmi_status
1472 character(len=LENMEMPATH) :: mem_path
1473 character(len=LENVARNAME) :: var_name
1474 character(len=*),
parameter :: var_location =
'node'
1475 logical(LGP) :: valid
1479 call split_address(c_var_address, mem_path, var_name, valid)
1480 if (.not. valid)
return
1482 c_var_location(1:len(var_location) + 1) = &
1494 bind(C, name="get_var_rank")
1497 character(kind=c_char),
intent(in) :: c_var_address(*)
1498 integer(kind=c_int),
intent(out) :: c_var_rank
1499 integer(kind=c_int) :: bmi_status
1501 character(len=LENMEMPATH) :: mem_path
1502 character(len=LENVARNAME) :: var_name
1503 logical(LGP) :: valid
1507 call split_address(c_var_address, mem_path, var_name, valid)
1508 if (.not. valid)
then
1514 if (c_var_rank == -1)
then
1532 bind(C, name="get_var_shape")
1537 character(kind=c_char),
intent(in) :: c_var_address(*)
1538 integer(c_int),
intent(inout) :: c_var_shape(*)
1539 integer(kind=c_int) :: bmi_status
1541 integer(I4B),
dimension(MAXMEMRANK) :: var_shape
1542 integer(I4B) :: var_rank
1543 character(len=LENMEMPATH) :: mem_path
1544 character(len=LENVARNAME) :: var_name
1545 logical(LGP) :: valid
1549 call split_address(c_var_address, mem_path, var_name, valid)
1550 if (.not. valid)
then
1559 if (var_shape(1) == -1 .or. var_rank == -1)
then
1568 c_var_shape(1:var_rank) = var_shape(var_rank:1:-1)
This module contains simulation constants.
integer(i4b), parameter lenvarname
maximum length of a variable name
integer(i4b), parameter, public maxmemrank
maximum memory manager length (up to 3-dimensional arrays)
integer(i4b), parameter, public lenmemtype
maximum length of a memory manager type
real(dp), parameter dprec
real constant machine precision
integer(i4b), parameter lenmempath
maximum length of the memory path
real(dp), parameter done
real constant 1
This module defines variable data types.
character(len=lenmemaddress) function create_mem_address(mem_path, var_name)
returns the address string of the memory object
subroutine, public get_mem_type(name, mem_path, var_type)
@ brief Get the variable memory type
subroutine, public get_mem_shape(name, mem_path, mem_shape)
@ brief Get the variable memory shape
type(memorystoretype), public memorystore
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
subroutine, public get_mem_rank(name, mem_path, rank)
@ brief Get the variable rank
subroutine, public get_mem_elem_size(name, mem_path, size)
@ brief Get the memory size of a single element of the stored variable
subroutine, public on_memory_set(var_name, mem_path, status)
Triggers the calling of the side effect handler for this variable.
This module contains the MODFLOW 6 BMI.
integer(kind=c_int) function get_end_time(end_time)
Get the end time of the simulation.
integer(kind=c_int) function get_input_var_names(c_names)
Returns all input variables in the simulation.
integer(kind=c_int) function get_input_item_count(count)
Get the number of input variables in the simulation.
logical(lgp) function valid_indices(mem_path, var_name, c_inds, count, nvalues)
Check that every index is within the variable, and count its values.
integer(kind=c_int) function get_value_ptr_double(c_var_address, c_arr_ptr)
Get a pointer to the array of double precision numbers.
integer(kind=c_int) function bmi_update_until(time)
Perform time steps until the current time reaches time.
integer(kind=c_int) function get_value_ptr_int(c_var_address, c_arr_ptr)
Get a pointer to the array of integer numbers.
integer(kind=c_int) function get_current_time(current_time)
Get the current time of the simulation.
integer(kind=c_int) function get_var_rank(c_var_address, c_var_rank)
Get the variable rank (non-BMI)
integer(kind=c_int) function get_output_item_count(count)
Get the number of output variables in the simulation.
integer(kind=c_int) function get_value_ptr_bool(c_var_address, c_arr_ptr)
Get a pointer to the logical scalar value.
integer(kind=c_int) function set_value(c_var_address, c_arr_ptr)
Set new values for a given variable.
integer(kind=c_int) function get_time_step(time_step)
Get the time step for the simulation.
integer(kind=c_int) function get_var_nbytes(c_var_address, var_nbytes)
Get size of the variable, in bytes.
integer(kind=c_int) function set_value_double(c_var_address, c_arr_ptr)
Set new values for a variable of type double.
integer(kind=c_int) function get_start_time(start_time)
Get the start time of the simulation.
integer(kind=c_int) function set_value_int(c_var_address, c_arr_ptr)
Set new values for a variable of type integer.
integer(kind=c_int) function get_var_itemsize(c_var_address, var_size)
Get the size (in bytes) of a single element of a variable.
integer(kind=c_int) function get_time_units(c_time_units)
Get the time units of the simulation.
integer(kind=c_int) function bmi_get_component_name(name)
integer(kind=c_int) function bmi_update()
Perform a computational time step.
integer(kind=c_int) function get_value_ptr(c_var_address, c_arr_ptr)
Get a pointer to an array.
integer(kind=c_int) function get_var_shape(c_var_address, c_var_shape)
Get the shape of the array for the variable (non-BMI)
integer(kind=c_int) function bmi_initialize()
Initialize the computational core.
integer(kind=c_int) function get_value_at_indices(c_var_address, c_arr_ptr, c_inds, count)
Copy the values of a variable at the given indices into the array.
integer(kind=c_int) function set_value_at_indices(c_var_address, c_inds, count, c_arr_ptr)
Set the values of a variable at the given indices.
integer(kind=c_int) function bmi_finalize()
Clean up the initialized simulation.
integer(kind=c_int) function get_value_int(c_var_address, c_arr_ptr)
Copy the integer values of a variable into the array.
integer(kind=c_int) function get_output_var_names(c_names)
Returns all output variables in the simulation.
integer(kind=c_int) function get_var_type(c_var_address, c_var_type)
Get the variable type as a string.
integer(kind=c_int) function get_var_units(c_var_address, c_var_units)
Get the units of a variable.
integer(kind=c_int) function get_value_double(c_var_address, c_arr_ptr)
Copy the double precision values of a variable into the array.
integer(kind=c_int) function set_value_bool(c_var_address, c_arr_ptr)
Set new value for a logical scalar variable.
integer(kind=c_int) function get_value(c_var_address, c_arr_ptr)
Copy the value of a variable into the array.
integer(kind=c_int) function get_var_location(c_var_address, c_var_location)
Get the grid location of a variable.
integer(kind=c_int) function get_value_string(c_var_address, c_arr_ptr)
Copy the string(s) of a variable into the array.
integer(kind=c_int) function get_value_bool(c_var_address, c_arr_ptr)
Copy the logical scalar value into the array.
integer(c_int), bind(C, name="ISTDOUTTOFILE") istdout_to_file
output control: =0 to screen, >0 to file
Detailed error information for the BMI.
character(len= *), parameter fmt_general_err
integer, parameter bmi_failure
BMI status code for failure (taken from bmi.f90, CSDMS)
character(len= *), parameter fmt_unsupported_type
character(len= *), parameter fmt_invalid_time
character(len=lenerrmessage) bmi_last_error
module variable containing the last error as a Fortran string
character(len= *), parameter fmt_invalid_index
subroutine report_bmi_error(err_msg)
Sets the last BMI error message and copies it to an exported C-string.
character(len= *), parameter fmt_invalid_mem_access
character(len= *), parameter fmt_unsupported_rank
integer, parameter bmi_success
BMI status code for success (taken from bmi.f90, CSDMS)
This module contains helper routines and parameters for the MODFLOW 6 BMI.
integer(c_int), bind(C, name="BMI_LENVARTYPE") bmi_lenvartype
max. length for variable type C-strings
integer(c_int), bind(C, name="BMI_LENCOMPONENTNAME") bmi_lencomponentname
component name length, i.e. 'MODFLOW 6'
subroutine split_address(c_var_address, mem_path, var_name, success)
Split the variable address string.
pure character(kind=c_char, len=1) function, dimension(length+1) string_to_char_array(string, length)
Convert Fortran string to C-style character string.
integer(c_int), bind(C, name="BMI_LENUNITS") bmi_lenunits
max. length for units C-strings
integer(c_int), bind(C, name="BMI_LENVARLOCATION") bmi_lenvarlocation
max. length for variable location C-strings
integer(c_int), bind(C, name="BMI_LENVARADDRESS") bmi_lenvaraddress
max. length for the variable's address C-string
logical(lgp) function mf6update()
Run a time step.
subroutine mf6initialize()
Initialize a simulation.
subroutine mf6finalize()
Finalize the simulation.
This module contains simulation variables.
integer(i4b) iforcestop
forced stop flag (1) forces a call to ustop(..) when the simulation has ended, (0) doesn't
character(len=linelength) simstdout
name of standard out file if screen output is piped to a file
integer(i4b) istdout
unit number for stdout
logical(lgp), pointer, public endofsimulation
flag indicating end of simulation
integer(i4b), pointer, public itmuni
flag indicating time units
real(dp), pointer, public totim
time relative to start of simulation
real(dp), pointer, public totalsimtime
time at end of simulation
integer(i4b), pointer, public kstp
current time step number
integer(i4b), pointer, public kper
current stress period number
real(dp), pointer, public delt
length of the current time step
This class is used to store a single deferred-length character string. It was designed to work in an ...
An iterator used to iterate through a MemoryContainer.