Skip to content

Commit

Permalink
Implement get_grid_coordinate function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Feb 6, 2024
1 parent 58193c0 commit 62d161f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bmi_heat/bmi_heat_geo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions example/bmi_geospatial_ex.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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

0 comments on commit 62d161f

Please sign in to comment.