Skip to content

Commit

Permalink
Fortran API: atlas_Grid%name()
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Jan 9, 2024
1 parent e734e7a commit eb58f83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/atlas/grid/detail/grid/Grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<int>(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;
{
Expand Down
1 change: 1 addition & 0 deletions src/atlas/grid/detail/grid/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/atlas_f/grid/atlas_Grid_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb58f83

Please sign in to comment.