diff --git a/src/atlas/grid/detail/grid/Grid.cc b/src/atlas/grid/detail/grid/Grid.cc index e9750b3d7..e2ec13d69 100644 --- a/src/atlas/grid/detail/grid/Grid.cc +++ b/src/atlas/grid/detail/grid/Grid.cc @@ -163,7 +163,7 @@ Grid::Spec* atlas__grid__Grid__spec(Grid* This) { } void atlas__grid__Grid__uid(const Grid* This, char*& uid, int& size) { - ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Projection"); + ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Grid"); eckit::MD5 md5; This->hash(md5); std::string s = This->uid(); @@ -172,6 +172,14 @@ void atlas__grid__Grid__uid(const Grid* This, char*& uid, int& size) { std::strncpy(uid, s.c_str(), size + 1); } +void atlas__grid__Grid__name(const Grid* This, char*& name, int& size) { + ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_Grid"); + std::string s = This->name(); + size = static_cast(s.size()); + name = new char[size + 1]; + std::strncpy(name, s.c_str(), size + 1); +} + Grid::Domain::Implementation* atlas__grid__Grid__lonlat_bounding_box(const Grid* This) { Grid::Domain::Implementation* lonlatboundingbox; { diff --git a/src/atlas/grid/detail/grid/Grid.h b/src/atlas/grid/detail/grid/Grid.h index 35fe9eeed..db652cf82 100644 --- a/src/atlas/grid/detail/grid/Grid.h +++ b/src/atlas/grid/detail/grid/Grid.h @@ -183,6 +183,7 @@ class GridObserver { //---------------------------------------------------------------------------------------------------------------------- extern "C" { +void atlas__grid__Grid__name(const Grid* This, char*& uid, int& size); idx_t atlas__grid__Grid__size(Grid* This); Grid::Spec* atlas__grid__Grid__spec(Grid* This); void atlas__grid__Grid__uid(const Grid* This, char*& uid, int& size); diff --git a/src/atlas_f/grid/atlas_Grid_module.F90 b/src/atlas_f/grid/atlas_Grid_module.F90 index 42dd9e458..a2682a550 100644 --- a/src/atlas_f/grid/atlas_Grid_module.F90 +++ b/src/atlas_f/grid/atlas_Grid_module.F90 @@ -54,6 +54,7 @@ module atlas_Grid_module !------------------------------------------------------------------------------ contains + procedure :: name => atlas_Grid__name procedure :: size => atlas_Grid__size procedure :: spec => atlas_Grid__spec procedure :: uid @@ -751,6 +752,19 @@ function atlas_grid_ShiftedLat__ctor_int64(nlon,nlat) result(this) ! ----------------------------------------------------------------------------- ! Structured members +function atlas_Grid__name(this) result(name) + use atlas_grid_Grid_c_binding + use fckit_c_interop_module, only : c_ptr_to_string, c_ptr_free + use, intrinsic :: iso_c_binding, only : c_ptr + class(atlas_Grid), intent(in) :: this + character(len=:), allocatable :: name + type(c_ptr) :: name_c_str + integer :: size + call atlas__grid__Grid__name(this%CPTR_PGIBUG_A, name_c_str, size ) + name = c_ptr_to_string(name_c_str) + call c_ptr_free(name_c_str) +end function + function atlas_Grid__size(this) result(npts) use, intrinsic :: iso_c_binding, only: c_int use atlas_grid_Grid_c_binding