From 3003ce6e6a7d2d8a5806b200595e55756f1cfd7c Mon Sep 17 00:00:00 2001 From: Slavko Brdar Date: Mon, 29 Apr 2024 12:47:40 +0000 Subject: [PATCH] add -options- argument in functionspace%create_field; adapt unit test fctest_functionspace --- .../atlas_FunctionSpace_module.F90 | 50 +++++++++++-------- .../functionspace/fctest_functionspace.F90 | 5 +- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/atlas_f/functionspace/atlas_FunctionSpace_module.F90 b/src/atlas_f/functionspace/atlas_FunctionSpace_module.F90 index c99896c6b..39177bf7c 100644 --- a/src/atlas_f/functionspace/atlas_FunctionSpace_module.F90 +++ b/src/atlas_f/functionspace/atlas_FunctionSpace_module.F90 @@ -105,7 +105,7 @@ function atlas_FunctionSpace__name(this) result(name) -function create_field_args(this,kind,name,levels,variables,type,alignment,global,owner) result(field) +function create_field_args(this,kind,name,levels,variables,type,alignment,global,owner,options) result(field) use atlas_functionspace_c_binding use, intrinsic :: iso_c_binding, only : c_int type(atlas_Field) :: field @@ -118,28 +118,32 @@ function create_field_args(this,kind,name,levels,variables,type,alignment,global integer(c_int), intent(in), optional :: alignment logical, intent(in), optional :: global integer(c_int), intent(in), optional :: owner + type(atlas_Config), intent(inout), optional :: options - type(atlas_Config) :: options - options = atlas_Config() + type(atlas_Config) :: options_ + options_ = atlas_Config() - call options%set("datatype",kind) - if( present(name) ) call options%set("name",name) - if( present(owner) ) call options%set("owner",owner) - if( present(global) ) call options%set("global",global) - if( present(levels) ) call options%set("levels",levels) - if( present(variables) ) call options%set("variables",variables) - if( present(type) ) call options%set("type",type) - if( present(alignment) ) call options%set("alignment",alignment) + if (present(options)) then + call options_%set(options) + endif + call options_%set("datatype",kind) + if( present(name) ) call options_%set("name",name) + if( present(owner) ) call options_%set("owner",owner) + if( present(global) ) call options_%set("global",global) + if( present(levels) ) call options_%set("levels",levels) + if( present(variables) ) call options_%set("variables",variables) + if( present(type) ) call options_%set("type",type) + if( present(alignment) ) call options_%set("alignment",alignment) - field = atlas_Field( atlas__FunctionSpace__create_field( this%CPTR_PGIBUG_A, options%CPTR_PGIBUG_B ) ) + field = atlas_Field( atlas__FunctionSpace__create_field( this%CPTR_PGIBUG_A, options_%CPTR_PGIBUG_B ) ) call field%return() - call options%final() + call options_%final() end function !------------------------------------------------------------------------------ -function create_field_template(this,template,name,global,owner) result(field) +function create_field_template(this,template,name,global,owner,options) result(field) use atlas_functionspace_c_binding use, intrinsic :: iso_c_binding, only : c_int type(atlas_Field) :: field @@ -149,18 +153,22 @@ function create_field_template(this,template,name,global,owner) result(field) character(len=*), intent(in), optional :: name logical, intent(in), optional :: global integer(c_int), intent(in), optional :: owner + type(atlas_Config), intent(inout), optional :: options - type(atlas_Config) :: options - options = atlas_Config() + type(atlas_Config) :: options_ + options_ = atlas_Config() + if (present(options)) then + call options_%set(options) + endif - if( present(name) ) call options%set("name",name) - if( present(owner) ) call options%set("owner",owner) - if( present(global) ) call options%set("global",global) + if( present(name) ) call options_%set("name",name) + if( present(owner) ) call options_%set("owner",owner) + if( present(global) ) call options_%set("global",global) field = atlas_Field( atlas__FunctionSpace__create_field_template( & - & this%CPTR_PGIBUG_A, template%CPTR_PGIBUG_A,options%CPTR_PGIBUG_B) ) + & this%CPTR_PGIBUG_A, template%CPTR_PGIBUG_A,options_%CPTR_PGIBUG_B) ) - call options%final() + call options_%final() call field%return() end function diff --git a/src/tests/functionspace/fctest_functionspace.F90 b/src/tests/functionspace/fctest_functionspace.F90 index ee63cc600..ef6c4dd07 100644 --- a/src/tests/functionspace/fctest_functionspace.F90 +++ b/src/tests/functionspace/fctest_functionspace.F90 @@ -49,6 +49,7 @@ module fcta_FunctionSpace_fxt type(atlas_Field) :: field, template type(atlas_mesh_Nodes) :: nodes integer :: halo_size, nb_nodes +type(atlas_Config) :: config halo_size = 1 grid = atlas_StructuredGrid("N24") @@ -66,7 +67,9 @@ module fcta_FunctionSpace_fxt FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) ) call field%final() -field = fs%create_field(name="field",kind=atlas_real(c_float)) +config = atlas_Config() +field = fs%create_field(name="field",kind=atlas_real(c_float),options=config) +call config%final() FCTEST_CHECK_EQUAL( field%rank() , 1 ) FCTEST_CHECK_EQUAL( field%name() , "field" ) FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )