From e17c53fddea7f762dba8d87d5a9f1e3e4d646c45 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 30 Jan 2024 14:39:17 -0700 Subject: [PATCH 01/23] Define an abstract type for the bmi_geo extension --- bmi_geo/bmi_geo.f90 | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bmi_geo/bmi_geo.f90 diff --git a/bmi_geo/bmi_geo.f90 b/bmi_geo/bmi_geo.f90 new file mode 100644 index 0000000..4f8727e --- /dev/null +++ b/bmi_geo/bmi_geo.f90 @@ -0,0 +1,60 @@ +! BMI extension for geospatial data + +module bmi_geo + + implicit none + + type, abstract :: bmi_geo + contains + + procedure(bmi_geo_initialize), deferred :: geo_initialize + procedure(bmi_geo_get_grid_coordinate_names), deferred :: get_grid_coordinate_names + procedure(bmi_geo_get_grid_coordinate_units), deferred :: get_grid_coordinate_units + procedure(bmi_geo_get_grid_coordinate), deferred :: get_grid_coordinate + procedure(bmi_geo_get_grid_crs), deferred :: get_grid_crs + + end type bmi_geo + + abstract interface + + function bmi_geo_initialize(this, config_file) result(bmi_status) + import :: bmi_geo + class(bmi_geo), intent(out) :: this + character(len=*), intent(in) :: config_file + integer :: bmi_status + end function bmi_geo_initialize + + function bmi_geo_get_grid_coordinate_names(this, names) result(bmi_status) + import :: bmi_geo + class(bmi_geo), intent(in) :: this + character(len=*), pointer, intent(out) :: names(:) + integer :: bmi_status + end function bmi_geo_get_grid_coordinate_names + + function bmi_geo_get_grid_coordinate_units(this, units) result(bmi_status) + import :: bmi_geo + class(bmi_geo), intent(in) :: this + character(len=*), pointer, intent(out) :: units(:) + integer :: bmi_status + end function bmi_geo_get_grid_coordinate_units + + function bmi_geo_get_grid_coordinate(this, grid, coordinate, values) result(bmi_status) + import :: bmi_geo + class(bmi_geo), intent(in) :: this + integer, intent(in) :: grid + character(len=*), intent(in) :: coordinate + double precision, dimension(:), intent(out) :: values + integer :: bmi_status + end function bmi_geo_get_grid_coordinate + + function bmi_geo_get_grid_crs(this, grid, crs) result(bmi_status) + import :: bmi_geo + class(bmi_geo), intent(in) :: this + integer, intent(in) :: grid + character(len=*), intent(out) :: crs + integer :: bmi_status + end function bmi_geo_get_grid_crs + + end interface + +end module bmi_geo From 216d9079982906a0d0f9b920e8886e7ec880edc4 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 30 Jan 2024 15:36:34 -0700 Subject: [PATCH 02/23] Implement get_extensions function; add extension string --- bmi_heat/bmi_heat.f90 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bmi_heat/bmi_heat.f90 b/bmi_heat/bmi_heat.f90 index 1e22091..379b9ca 100644 --- a/bmi_heat/bmi_heat.f90 +++ b/bmi_heat/bmi_heat.f90 @@ -9,6 +9,7 @@ module bmiheatf private type (heat_model) :: model contains + procedure :: get_extensions procedure :: get_component_name => heat_component_name procedure :: get_input_item_count => heat_input_item_count procedure :: get_output_item_count => heat_output_item_count @@ -98,8 +99,23 @@ module bmiheatf dimension(output_item_count) :: & output_items = (/'plate_surface__temperature'/) + ! Extensions + integer, parameter :: extension_count = 1 + character (len=BMI_MAX_VAR_NAME), target, & + dimension(extension_count) :: & + extension_strings = (/'bmi_geospatial@bmiheatfgeo:bmi_heat_geo'/) + contains + function get_extensions(this, extensions) result (bmi_status) + class (bmi_heat), intent(in) :: this + character (*), pointer, intent(out) :: extensions(:) + integer :: bmi_status + + extensions => extension_strings + bmi_status = BMI_SUCCESS + end function get_extensions + ! Get the name of the model. function heat_component_name(this, name) result (bmi_status) class (bmi_heat), intent(in) :: this From 153273c87ebc8dcb692e12729036cdf6662fcd38 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 31 Jan 2024 15:19:35 -0700 Subject: [PATCH 03/23] Stub the bmi_geo CMake build file --- bmi_geo/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 bmi_geo/CMakeLists.txt diff --git a/bmi_geo/CMakeLists.txt b/bmi_geo/CMakeLists.txt new file mode 100644 index 0000000..3d2c44f --- /dev/null +++ b/bmi_geo/CMakeLists.txt @@ -0,0 +1 @@ +# bmi_geo From 8d19012ead430db92951afdc55ec7f16110f700d Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 31 Jan 2024 15:20:35 -0700 Subject: [PATCH 04/23] Change module name to match bmif --- bmi_geo/bmi_geo.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bmi_geo/bmi_geo.f90 b/bmi_geo/bmi_geo.f90 index 4f8727e..fb21dcb 100644 --- a/bmi_geo/bmi_geo.f90 +++ b/bmi_geo/bmi_geo.f90 @@ -1,6 +1,6 @@ ! BMI extension for geospatial data -module bmi_geo +module bmigeof implicit none @@ -57,4 +57,4 @@ end function bmi_geo_get_grid_crs end interface -end module bmi_geo +end module bmigeof From 2417582b4f68a3759e4fcee67de97ae89faf11f0 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 31 Jan 2024 15:21:48 -0700 Subject: [PATCH 05/23] Follow the naming convention used for bmiheatf library --- bmi_heat/bmi_heat.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi_heat/bmi_heat.f90 b/bmi_heat/bmi_heat.f90 index 379b9ca..7be646a 100644 --- a/bmi_heat/bmi_heat.f90 +++ b/bmi_heat/bmi_heat.f90 @@ -103,7 +103,7 @@ module bmiheatf integer, parameter :: extension_count = 1 character (len=BMI_MAX_VAR_NAME), target, & dimension(extension_count) :: & - extension_strings = (/'bmi_geospatial@bmiheatfgeo:bmi_heat_geo'/) + extension_strings = (/'bmi_geospatial@bmiheatgeof:bmi_heat_geo'/) contains From 41177829b51156131068d9ef9d32d3ce661d70bf Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 31 Jan 2024 15:24:15 -0700 Subject: [PATCH 06/23] Stub the bmi_geospatial extension example --- example/bmi_geospatial_ex.f90 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 example/bmi_geospatial_ex.f90 diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 new file mode 100644 index 0000000..5e66fab --- /dev/null +++ b/example/bmi_geospatial_ex.f90 @@ -0,0 +1,6 @@ +! An example of using a BMI extension +program bmi_geospatial_ex + + implicit none + +end program bmi_geospatial_ex From 473173b7e248d8bcb77739619c42de3985983366 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 31 Jan 2024 21:28:54 -0700 Subject: [PATCH 07/23] Add concrete type for bmi_geo --- bmi_heat/bmi_heat_geo.f90 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bmi_heat/bmi_heat_geo.f90 diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 new file mode 100644 index 0000000..00448e3 --- /dev/null +++ b/bmi_heat/bmi_heat_geo.f90 @@ -0,0 +1,22 @@ +! Implement the bmi_geo type and use the bmi_heat type in a new type, bmi_heat_geo + +module bmiheatgeof + + use bmigeof + use bmiheatf + implicit none + + type, extends (bmi_geo) :: bmi_heat_geo + private + type (bmi_heat) :: bmi_base + contains + procedure :: geo_initialize => heat_geo_initialize + procedure :: get_grid_coordinate_names => heat_grid_coordinate_names + procedure :: get_grid_coordinate_units => heat_grid_coordinate_units + procedure :: get_grid_coordinate => heat_grid_coordinate + procedure :: get_grid_crs => heat_grid_crs + end type bmi_heat_geo + +contains + +end module bmiheatgeof From b97489f8b2eb4994a7031c3628cc7e0dfa3e3878 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 10:57:24 -0700 Subject: [PATCH 08/23] Use initialize, not geo_initialize --- bmi_geo/bmi_geo.f90 | 2 +- bmi_heat/bmi_heat_geo.f90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bmi_geo/bmi_geo.f90 b/bmi_geo/bmi_geo.f90 index fb21dcb..0a7723a 100644 --- a/bmi_geo/bmi_geo.f90 +++ b/bmi_geo/bmi_geo.f90 @@ -7,7 +7,7 @@ module bmigeof type, abstract :: bmi_geo contains - procedure(bmi_geo_initialize), deferred :: geo_initialize + procedure(bmi_geo_initialize), deferred :: initialize procedure(bmi_geo_get_grid_coordinate_names), deferred :: get_grid_coordinate_names procedure(bmi_geo_get_grid_coordinate_units), deferred :: get_grid_coordinate_units procedure(bmi_geo_get_grid_coordinate), deferred :: get_grid_coordinate diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index 00448e3..56db886 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -10,7 +10,7 @@ module bmiheatgeof private type (bmi_heat) :: bmi_base contains - procedure :: geo_initialize => heat_geo_initialize + procedure :: initialize => heat_initialize procedure :: get_grid_coordinate_names => heat_grid_coordinate_names procedure :: get_grid_coordinate_units => heat_grid_coordinate_units procedure :: get_grid_coordinate => heat_grid_coordinate From 03ced034e79d7b19df08a9782d2bd28887e6dd45 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 11:19:01 -0700 Subject: [PATCH 09/23] Include the grid parameter in get_grid_coordinate_names and get_grid_coordinate_units --- bmi_geo/bmi_geo.f90 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bmi_geo/bmi_geo.f90 b/bmi_geo/bmi_geo.f90 index 0a7723a..be69308 100644 --- a/bmi_geo/bmi_geo.f90 +++ b/bmi_geo/bmi_geo.f90 @@ -24,16 +24,18 @@ function bmi_geo_initialize(this, config_file) result(bmi_status) integer :: bmi_status end function bmi_geo_initialize - function bmi_geo_get_grid_coordinate_names(this, names) result(bmi_status) + function bmi_geo_get_grid_coordinate_names(this, grid, names) result(bmi_status) import :: bmi_geo class(bmi_geo), intent(in) :: this + integer, intent(in) :: grid character(len=*), pointer, intent(out) :: names(:) integer :: bmi_status end function bmi_geo_get_grid_coordinate_names - function bmi_geo_get_grid_coordinate_units(this, units) result(bmi_status) + function bmi_geo_get_grid_coordinate_units(this, grid, units) result(bmi_status) import :: bmi_geo class(bmi_geo), intent(in) :: this + integer, intent(in) :: grid character(len=*), pointer, intent(out) :: units(:) integer :: bmi_status end function bmi_geo_get_grid_coordinate_units From 31ee2ae6178b9df744b8d757b6ccc050eca064bf Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 11:29:57 -0700 Subject: [PATCH 10/23] Stub out concrete type bmi_heat_geo --- bmi_heat/bmi_heat_geo.f90 | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index 56db886..0bdc77b 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -18,5 +18,50 @@ module bmiheatgeof end type bmi_heat_geo contains - + + function heat_initialize(this, config_file) result (bmi_status) + class (bmi_heat_geo), intent(out) :: this + character (len=*), intent(in) :: config_file + integer :: bmi_status + + bmi_status = BMI_SUCCESS + end function heat_initialize + + function heat_grid_coordinate_names(this, grid, names) result (bmi_status) + class (bmi_heat_geo), intent(in) :: this + integer, intent(in) :: grid + character (*), pointer, intent(out) :: names(:) + integer :: bmi_status + + bmi_status = BMI_SUCCESS + end function heat_grid_coordinate_names + + function heat_grid_coordinate_units(this, grid, units) result (bmi_status) + class (bmi_heat_geo), intent(in) :: this + integer, intent(in) :: grid + character (*), pointer, intent(out) :: units(:) + integer :: bmi_status + + bmi_status = BMI_SUCCESS + end function heat_grid_coordinate_units + + function heat_grid_coordinate(this, grid, coordinate, values) result (bmi_status) + class (bmi_heat_geo), intent(in) :: this + integer, intent(in) :: grid + character(len=*), intent(in) :: coordinate + double precision, dimension(:), intent(out) :: values + integer :: bmi_status + + bmi_status = BMI_SUCCESS + end function heat_grid_x + + function heat_grid_crs(this, grid, crs) result (bmi_status) + class (bmi_heat_geo), intent(in) :: this + integer, intent(in) :: grid + character (len=*), intent(out) :: crs + integer :: bmi_status + + bmi_status = BMI_SUCCESS + end function heat_grid_crs + end module bmiheatgeof From 3c983186c7ce855bb1cdca3a7a46db675dec8afd Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 14:31:17 -0700 Subject: [PATCH 11/23] Move bmi_geo type definition to a separate repository --- bmi_geo/CMakeLists.txt | 1 - bmi_geo/bmi_geo.f90 | 62 ------------------------------------------ 2 files changed, 63 deletions(-) delete mode 100644 bmi_geo/CMakeLists.txt delete mode 100644 bmi_geo/bmi_geo.f90 diff --git a/bmi_geo/CMakeLists.txt b/bmi_geo/CMakeLists.txt deleted file mode 100644 index 3d2c44f..0000000 --- a/bmi_geo/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -# bmi_geo diff --git a/bmi_geo/bmi_geo.f90 b/bmi_geo/bmi_geo.f90 deleted file mode 100644 index be69308..0000000 --- a/bmi_geo/bmi_geo.f90 +++ /dev/null @@ -1,62 +0,0 @@ -! BMI extension for geospatial data - -module bmigeof - - implicit none - - type, abstract :: bmi_geo - contains - - procedure(bmi_geo_initialize), deferred :: initialize - procedure(bmi_geo_get_grid_coordinate_names), deferred :: get_grid_coordinate_names - procedure(bmi_geo_get_grid_coordinate_units), deferred :: get_grid_coordinate_units - procedure(bmi_geo_get_grid_coordinate), deferred :: get_grid_coordinate - procedure(bmi_geo_get_grid_crs), deferred :: get_grid_crs - - end type bmi_geo - - abstract interface - - function bmi_geo_initialize(this, config_file) result(bmi_status) - import :: bmi_geo - class(bmi_geo), intent(out) :: this - character(len=*), intent(in) :: config_file - integer :: bmi_status - end function bmi_geo_initialize - - function bmi_geo_get_grid_coordinate_names(this, grid, names) result(bmi_status) - import :: bmi_geo - class(bmi_geo), intent(in) :: this - integer, intent(in) :: grid - character(len=*), pointer, intent(out) :: names(:) - integer :: bmi_status - end function bmi_geo_get_grid_coordinate_names - - function bmi_geo_get_grid_coordinate_units(this, grid, units) result(bmi_status) - import :: bmi_geo - class(bmi_geo), intent(in) :: this - integer, intent(in) :: grid - character(len=*), pointer, intent(out) :: units(:) - integer :: bmi_status - end function bmi_geo_get_grid_coordinate_units - - function bmi_geo_get_grid_coordinate(this, grid, coordinate, values) result(bmi_status) - import :: bmi_geo - class(bmi_geo), intent(in) :: this - integer, intent(in) :: grid - character(len=*), intent(in) :: coordinate - double precision, dimension(:), intent(out) :: values - integer :: bmi_status - end function bmi_geo_get_grid_coordinate - - function bmi_geo_get_grid_crs(this, grid, crs) result(bmi_status) - import :: bmi_geo - class(bmi_geo), intent(in) :: this - integer, intent(in) :: grid - character(len=*), intent(out) :: crs - integer :: bmi_status - end function bmi_geo_get_grid_crs - - end interface - -end module bmigeof From 3aeadf46969b0ffc2de11a21d7ac96fa10dd1e45 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 16:06:31 -0700 Subject: [PATCH 12/23] Fix error in end function statement --- bmi_heat/bmi_heat_geo.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index 0bdc77b..ed49627 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -53,7 +53,7 @@ function heat_grid_coordinate(this, grid, coordinate, values) result (bmi_status integer :: bmi_status bmi_status = BMI_SUCCESS - end function heat_grid_x + end function heat_grid_coordinate function heat_grid_crs(this, grid, crs) result (bmi_status) class (bmi_heat_geo), intent(in) :: this From 9775ad63d10daeb57f9b437cfe3f00d316ae2b06 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 16:07:19 -0700 Subject: [PATCH 13/23] Build extension implementation --- bmi_heat/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 8f86d3b..0e92921 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -1,12 +1,17 @@ # bmi-heat +set(extension_name bmiheatgeof) + # Create shared library, except on Windows. if(WIN32) add_library(${bmi_name} bmi_heat.f90) + add_library(${extension_name} bmi_heat_geo.f90) else() add_library(${bmi_name} SHARED bmi_heat.f90) + add_library(${extension_name} SHARED bmi_heat_geo.f90) endif() target_link_libraries(${bmi_name} ${model_name} ${bmif_lib}) +target_link_libraries(${extension_name} ${bmi_name}) add_executable(run_${bmi_name} bmi_main.f90) target_link_libraries(run_${bmi_name} ${bmi_name}) @@ -16,12 +21,14 @@ install( RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install( - TARGETS ${bmi_name} + TARGETS ${bmi_name} ${extension_name} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install( - FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/${bmi_name}.mod + FILES + ${CMAKE_Fortran_MODULE_DIRECTORY}/${bmi_name}.mod + ${CMAKE_Fortran_MODULE_DIRECTORY}/${extension_name}.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) From 349d160f2769c8e38e590af9b1fbbdd39b8f9522 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 20:39:47 -0700 Subject: [PATCH 14/23] Locate libbmigeof --- CMakeLists.txt | 4 +++- bmi_heat/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cffe4c..e6045fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,12 +25,14 @@ message("-- BMIF module version - ${bmif_module_version}") set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod) # Locate the installed Fortran BMI bindings (bmif library and module file) -# through CMAKE_PREFIX_PATH. +# as well as bmi_geospatial extension through CMAKE_PREFIX_PATH. find_library(bmif_lib bmif) +find_library(bmigeof_lib bmigeof) find_path(bmif_inc bmif_${bmif_module_version}.mod) include_directories(${bmif_inc}) message("-- bmif_lib - ${bmif_lib}") message("-- bmif_inc - ${bmif_inc}") +message("-- bmigeof_lib - ${bmigeof_lib}") add_subdirectory(heat) add_subdirectory(bmi_heat) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 0e92921..701ea90 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -11,7 +11,7 @@ else() add_library(${extension_name} SHARED bmi_heat_geo.f90) endif() target_link_libraries(${bmi_name} ${model_name} ${bmif_lib}) -target_link_libraries(${extension_name} ${bmi_name}) +target_link_libraries(${extension_name} ${bmi_name} ${bmigeof_lib}) add_executable(run_${bmi_name} bmi_main.f90) target_link_libraries(run_${bmi_name} ${bmi_name}) From 7d177567777c58e08029e332f51e17db7c191c64 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 1 Feb 2024 20:40:38 -0700 Subject: [PATCH 15/23] Get parameters from bmif module --- bmi_heat/bmi_heat_geo.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index ed49627..93055b9 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -4,6 +4,7 @@ module bmiheatgeof use bmigeof use bmiheatf + use bmif_2_0 implicit none type, extends (bmi_geo) :: bmi_heat_geo From 914a405b6f7453d27f4cc8aec47ad44f4270a9ce Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Fri, 2 Feb 2024 11:51:18 -0700 Subject: [PATCH 16/23] Start writing example main program --- example/CMakeLists.txt | 1 + example/bmi_geospatial_ex.f90 | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index c9fabb6..0bfc64a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -15,3 +15,4 @@ make_example(get_value_ex) make_example(set_value_ex) make_example(conflicting_instances_ex) make_example(change_diffusivity_ex) +make_example(bmi_geospatial_ex) diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 index 5e66fab..f91d0a2 100644 --- a/example/bmi_geospatial_ex.f90 +++ b/example/bmi_geospatial_ex.f90 @@ -1,6 +1,16 @@ ! An example of using a BMI extension program bmi_geospatial_ex + use bmif_2_0 + use bmiheatf + use bmiheatgeof implicit none - + + type(bmi_heat) :: h + integer :: status + character (len=BMI_MAX_COMPONENT_NAME), pointer :: name + + status = h%get_component_name(name) + write (*,"(a, a30)") "Component name: ", name + end program bmi_geospatial_ex From 2de047111205db46614393d5aa03285d526b3a14 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 5 Feb 2024 10:44:03 -0700 Subject: [PATCH 17/23] Set up build for extension example --- CMakeLists.txt | 1 + bmi_heat/CMakeLists.txt | 2 -- example/CMakeLists.txt | 7 ++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6045fe..5c47a72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ include(GNUInstallDirs) set(model_name heatf) set(bmi_name bmi${model_name}) +set(extension_name bmiheatgeof) # Determine the Fortran BMI version. if(DEFINED ENV{BMIF_VERSION}) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 701ea90..88b1ab9 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -1,7 +1,5 @@ # bmi-heat -set(extension_name bmiheatgeof) - # Create shared library, except on Windows. if(WIN32) add_library(${bmi_name} bmi_heat.f90) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 0bfc64a..ba78e7a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -15,4 +15,9 @@ make_example(get_value_ex) make_example(set_value_ex) make_example(conflicting_instances_ex) make_example(change_diffusivity_ex) -make_example(bmi_geospatial_ex) + +# Extension example +set(extension_example bmi_geospatial_ex) +add_test(NAME ${extension_example} COMMAND ${extension_example} ${CMAKE_CURRENT_SOURCE_DIR}) +add_executable(${extension_example} ${extension_example}.f90 testing_helpers.f90) +target_link_libraries(${extension_example} ${extension_name}) From 58193c0ed65df6b91ae074ebeb3775b152511060 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 6 Feb 2024 12:17:59 -0700 Subject: [PATCH 18/23] Implement coordinate name, coordinate units, and crs functions --- bmi_heat/bmi_heat_geo.f90 | 10 ++++++++- example/bmi_geospatial_ex.f90 | 40 +++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index 93055b9..5ec4916 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -8,7 +8,6 @@ module bmiheatgeof implicit none type, extends (bmi_geo) :: bmi_heat_geo - private type (bmi_heat) :: bmi_base contains procedure :: initialize => heat_initialize @@ -18,6 +17,8 @@ module bmiheatgeof procedure :: get_grid_crs => heat_grid_crs end type bmi_heat_geo + public bmi_heat_geo + contains function heat_initialize(this, config_file) result (bmi_status) @@ -34,6 +35,9 @@ function heat_grid_coordinate_names(this, grid, names) result (bmi_status) character (*), pointer, intent(out) :: names(:) integer :: bmi_status + names(1) = "y" + names(2) = "x" + bmi_status = BMI_SUCCESS end function heat_grid_coordinate_names @@ -43,6 +47,9 @@ function heat_grid_coordinate_units(this, grid, units) result (bmi_status) character (*), pointer, intent(out) :: units(:) integer :: bmi_status + units(1) = "m" + units(2) = "m" + bmi_status = BMI_SUCCESS end function heat_grid_coordinate_units @@ -62,6 +69,7 @@ function heat_grid_crs(this, grid, crs) result (bmi_status) character (len=*), intent(out) :: crs integer :: bmi_status + crs = "none" bmi_status = BMI_SUCCESS end function heat_grid_crs diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 index f91d0a2..55e7e03 100644 --- a/example/bmi_geospatial_ex.f90 +++ b/example/bmi_geospatial_ex.f90 @@ -7,10 +7,42 @@ program bmi_geospatial_ex implicit none type(bmi_heat) :: h - integer :: status - character (len=BMI_MAX_COMPONENT_NAME), pointer :: name + type(bmi_heat_geo) :: g + integer :: status, grid_id, grid_rank, i + character (len=BMI_MAX_COMPONENT_NAME), pointer :: component_name + character (len=BMI_MAX_VAR_NAME), pointer :: names(:), units(:) + character (len=BMI_MAX_VAR_NAME) :: crs - status = h%get_component_name(name) - write (*,"(a, a30)") "Component name: ", name + status = h%get_component_name(component_name) + write (*,"(a, a30)") "Component name: ", component_name + + status = h%initialize("") + + status = h%get_var_grid("plate_surface__temperature", grid_id) + write (*,"(a, i3)") "Grid id:", grid_id + + status = h%get_grid_rank(grid_id, grid_rank) + write (*,"(a, i3)") "Grid rank:", grid_rank + + g = bmi_heat_geo(h) + + allocate(names(grid_rank)) + status = g%get_grid_coordinate_names(grid_id, names) + write (*,"(a)") "Coordinate names:" + do i = 1, size(names) + write (*,"(a)") "- " // trim(names(i)) + end do + + allocate(units(grid_rank)) + status = g%get_grid_coordinate_units(grid_id, units) + write (*,"(a)") "Coordinate units:" + do i = 1, size(units) + write (*,"(a)") "- " // trim(units(i)) + end do + + status = g%get_grid_crs(grid_id, crs) + write (*,"(a, a30)") "CRS: ", crs + + status = h%finalize() end program bmi_geospatial_ex From 62d161fda026c66eec956ffb8ec3ef0215d31234 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 6 Feb 2024 15:44:07 -0700 Subject: [PATCH 19/23] Implement get_grid_coordinate function --- bmi_heat/bmi_heat_geo.f90 | 22 +++++++++++++++++++++- example/bmi_geospatial_ex.f90 | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_heat_geo.f90 index 5ec4916..c585f9c 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_heat_geo.f90 @@ -58,7 +58,27 @@ function heat_grid_coordinate(this, grid, coordinate, values) result (bmi_status integer, intent(in) :: grid character(len=*), intent(in) :: coordinate double precision, dimension(:), intent(out) :: values - integer :: bmi_status + double precision, allocatable :: origin(:), spacing(:) + integer :: bmi_status, rank, dim, i + + bmi_status = this%bmi_base%get_grid_rank(grid, rank) + + allocate(origin(rank), spacing(rank)) + bmi_status = this%bmi_base%get_grid_origin(grid, origin) + bmi_status = this%bmi_base%get_grid_spacing(grid, spacing) + + select case(coordinate) + case("y") + dim = 1 + case("x") + dim = 2 + end select + + do i = 1, size(values) + values(i) = dble(i - 1) * spacing(dim) + origin(dim) + end do + + deallocate(origin, spacing) bmi_status = BMI_SUCCESS end function heat_grid_coordinate diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 index 55e7e03..fd01117 100644 --- a/example/bmi_geospatial_ex.f90 +++ b/example/bmi_geospatial_ex.f90 @@ -10,7 +10,9 @@ program bmi_geospatial_ex type(bmi_heat_geo) :: g integer :: status, grid_id, grid_rank, i character (len=BMI_MAX_COMPONENT_NAME), pointer :: component_name + integer, allocatable :: grid_shape(:) character (len=BMI_MAX_VAR_NAME), pointer :: names(:), units(:) + double precision, allocatable :: xcoordinate(:), ycoordinate(:) character (len=BMI_MAX_VAR_NAME) :: crs status = h%get_component_name(component_name) @@ -24,6 +26,13 @@ program bmi_geospatial_ex status = h%get_grid_rank(grid_id, grid_rank) write (*,"(a, i3)") "Grid rank:", grid_rank + allocate(grid_shape(grid_rank)) + status = h%get_grid_shape(grid_id, grid_shape) + write (*,"(a)") "Grid shape:" + do i = 1, size(grid_shape) + write (*,"(a, i3)") "-", grid_shape(i) + end do + g = bmi_heat_geo(h) allocate(names(grid_rank)) @@ -40,9 +49,21 @@ program bmi_geospatial_ex write (*,"(a)") "- " // trim(units(i)) end do + allocate(ycoordinate(grid_shape(1))) + status = g%get_grid_coordinate(grid_id, names(1), ycoordinate) + write (*,"(a)") "Y-coordinate:" + write (*,"(*(x, f4.1))") ycoordinate + + allocate(xcoordinate(grid_shape(2))) + status = g%get_grid_coordinate(grid_id, names(2), xcoordinate) + write (*,"(a)") "X-coordinate:" + write (*,"(*(x, f4.1))") xcoordinate + status = g%get_grid_crs(grid_id, crs) write (*,"(a, a30)") "CRS: ", crs + deallocate(grid_shape, names, units, ycoordinate, xcoordinate) + status = h%finalize() end program bmi_geospatial_ex From d3a85cd4a63975f2a4d9624f30fb9e7115b7b0b5 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 6 Feb 2024 15:52:49 -0700 Subject: [PATCH 20/23] Simplify formatting for printing arrays --- example/bmi_geospatial_ex.f90 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 index fd01117..a5993b0 100644 --- a/example/bmi_geospatial_ex.f90 +++ b/example/bmi_geospatial_ex.f90 @@ -28,10 +28,7 @@ program bmi_geospatial_ex allocate(grid_shape(grid_rank)) status = h%get_grid_shape(grid_id, grid_shape) - write (*,"(a)") "Grid shape:" - do i = 1, size(grid_shape) - write (*,"(a, i3)") "-", grid_shape(i) - end do + write (*,"(a, *(x, i3))") "Grid shape:", grid_shape g = bmi_heat_geo(h) @@ -51,13 +48,11 @@ program bmi_geospatial_ex allocate(ycoordinate(grid_shape(1))) status = g%get_grid_coordinate(grid_id, names(1), ycoordinate) - write (*,"(a)") "Y-coordinate:" - write (*,"(*(x, f4.1))") ycoordinate + write (*,"(a, *(x, f4.1))") "Y-coordinate:", ycoordinate allocate(xcoordinate(grid_shape(2))) status = g%get_grid_coordinate(grid_id, names(2), xcoordinate) - write (*,"(a)") "X-coordinate:" - write (*,"(*(x, f4.1))") xcoordinate + write (*,"(a, *(x, f4.1))") "X-coordinate:", xcoordinate status = g%get_grid_crs(grid_id, crs) write (*,"(a, a30)") "CRS: ", crs From 77407c889da85531295e96149695ef41c96a60c0 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 6 Feb 2024 16:12:36 -0700 Subject: [PATCH 21/23] Rename extension implementation from bmiheatgeof to bmigeoheatf --- CMakeLists.txt | 2 +- bmi_heat/CMakeLists.txt | 2 +- .../{bmi_heat_geo.f90 => bmi_geo_heat.f90} | 22 +++++++++---------- example/bmi_geospatial_ex.f90 | 6 ++--- 4 files changed, 16 insertions(+), 16 deletions(-) rename bmi_heat/{bmi_heat_geo.f90 => bmi_geo_heat.f90} (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c47a72..8b7f43d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ include(GNUInstallDirs) set(model_name heatf) set(bmi_name bmi${model_name}) -set(extension_name bmiheatgeof) +set(extension_name bmigeo${model_name}) # Determine the Fortran BMI version. if(DEFINED ENV{BMIF_VERSION}) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 88b1ab9..74bd518 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -6,7 +6,7 @@ if(WIN32) add_library(${extension_name} bmi_heat_geo.f90) else() add_library(${bmi_name} SHARED bmi_heat.f90) - add_library(${extension_name} SHARED bmi_heat_geo.f90) + add_library(${extension_name} SHARED bmi_geo_heat.f90) endif() target_link_libraries(${bmi_name} ${model_name} ${bmif_lib}) target_link_libraries(${extension_name} ${bmi_name} ${bmigeof_lib}) diff --git a/bmi_heat/bmi_heat_geo.f90 b/bmi_heat/bmi_geo_heat.f90 similarity index 86% rename from bmi_heat/bmi_heat_geo.f90 rename to bmi_heat/bmi_geo_heat.f90 index c585f9c..8686ba3 100644 --- a/bmi_heat/bmi_heat_geo.f90 +++ b/bmi_heat/bmi_geo_heat.f90 @@ -1,13 +1,13 @@ -! Implement the bmi_geo type and use the bmi_heat type in a new type, bmi_heat_geo +! Implement the bmi_geo type and use the bmi_heat type in a new type, bmi_geo_heat -module bmiheatgeof +module bmigeoheatf use bmigeof use bmiheatf use bmif_2_0 implicit none - type, extends (bmi_geo) :: bmi_heat_geo + type, extends (bmi_geo) :: bmi_geo_heat type (bmi_heat) :: bmi_base contains procedure :: initialize => heat_initialize @@ -15,14 +15,14 @@ module bmiheatgeof procedure :: get_grid_coordinate_units => heat_grid_coordinate_units procedure :: get_grid_coordinate => heat_grid_coordinate procedure :: get_grid_crs => heat_grid_crs - end type bmi_heat_geo + end type bmi_geo_heat - public bmi_heat_geo + public bmi_geo_heat contains function heat_initialize(this, config_file) result (bmi_status) - class (bmi_heat_geo), intent(out) :: this + class (bmi_geo_heat), intent(out) :: this character (len=*), intent(in) :: config_file integer :: bmi_status @@ -30,7 +30,7 @@ function heat_initialize(this, config_file) result (bmi_status) end function heat_initialize function heat_grid_coordinate_names(this, grid, names) result (bmi_status) - class (bmi_heat_geo), intent(in) :: this + class (bmi_geo_heat), intent(in) :: this integer, intent(in) :: grid character (*), pointer, intent(out) :: names(:) integer :: bmi_status @@ -42,7 +42,7 @@ function heat_grid_coordinate_names(this, grid, names) result (bmi_status) end function heat_grid_coordinate_names function heat_grid_coordinate_units(this, grid, units) result (bmi_status) - class (bmi_heat_geo), intent(in) :: this + class (bmi_geo_heat), intent(in) :: this integer, intent(in) :: grid character (*), pointer, intent(out) :: units(:) integer :: bmi_status @@ -54,7 +54,7 @@ function heat_grid_coordinate_units(this, grid, units) result (bmi_status) end function heat_grid_coordinate_units function heat_grid_coordinate(this, grid, coordinate, values) result (bmi_status) - class (bmi_heat_geo), intent(in) :: this + class (bmi_geo_heat), intent(in) :: this integer, intent(in) :: grid character(len=*), intent(in) :: coordinate double precision, dimension(:), intent(out) :: values @@ -84,7 +84,7 @@ function heat_grid_coordinate(this, grid, coordinate, values) result (bmi_status end function heat_grid_coordinate function heat_grid_crs(this, grid, crs) result (bmi_status) - class (bmi_heat_geo), intent(in) :: this + class (bmi_geo_heat), intent(in) :: this integer, intent(in) :: grid character (len=*), intent(out) :: crs integer :: bmi_status @@ -93,4 +93,4 @@ function heat_grid_crs(this, grid, crs) result (bmi_status) bmi_status = BMI_SUCCESS end function heat_grid_crs -end module bmiheatgeof +end module bmigeoheatf diff --git a/example/bmi_geospatial_ex.f90 b/example/bmi_geospatial_ex.f90 index a5993b0..3b08bc0 100644 --- a/example/bmi_geospatial_ex.f90 +++ b/example/bmi_geospatial_ex.f90 @@ -3,11 +3,11 @@ program bmi_geospatial_ex use bmif_2_0 use bmiheatf - use bmiheatgeof + use bmigeoheatf implicit none type(bmi_heat) :: h - type(bmi_heat_geo) :: g + type(bmi_geo_heat) :: g integer :: status, grid_id, grid_rank, i character (len=BMI_MAX_COMPONENT_NAME), pointer :: component_name integer, allocatable :: grid_shape(:) @@ -30,7 +30,7 @@ program bmi_geospatial_ex status = h%get_grid_shape(grid_id, grid_shape) write (*,"(a, *(x, i3))") "Grid shape:", grid_shape - g = bmi_heat_geo(h) + g = bmi_geo_heat(h) allocate(names(grid_rank)) status = g%get_grid_coordinate_names(grid_id, names) From c252d057ab83af58c22ab719cdf985165933d06c Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Tue, 6 Feb 2024 16:22:56 -0700 Subject: [PATCH 22/23] Also change name of source on Windows --- bmi_heat/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 74bd518..93c2864 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -3,7 +3,7 @@ # Create shared library, except on Windows. if(WIN32) add_library(${bmi_name} bmi_heat.f90) - add_library(${extension_name} bmi_heat_geo.f90) + add_library(${extension_name} bmi_geo_heat.f90) else() add_library(${bmi_name} SHARED bmi_heat.f90) add_library(${extension_name} SHARED bmi_geo_heat.f90) From d4eb7e7c04355290c4bbc408a7dd721325322c7f Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 7 Feb 2024 15:17:47 -0700 Subject: [PATCH 23/23] Rename library and entry point in extension string This matchesthe change in 77407c889da85531295e96149695ef41c96a60c0. [ci skip] --- bmi_heat/bmi_heat.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi_heat/bmi_heat.f90 b/bmi_heat/bmi_heat.f90 index 7be646a..462f2ad 100644 --- a/bmi_heat/bmi_heat.f90 +++ b/bmi_heat/bmi_heat.f90 @@ -103,7 +103,7 @@ module bmiheatf integer, parameter :: extension_count = 1 character (len=BMI_MAX_VAR_NAME), target, & dimension(extension_count) :: & - extension_strings = (/'bmi_geospatial@bmiheatgeof:bmi_heat_geo'/) + extension_strings = (/'bmi_geospatial@bmigeoheatf:bmi_geo_heat'/) contains