Skip to content

Commit

Permalink
add -options- argument in functionspace%create_field; adapt unit test…
Browse files Browse the repository at this point in the history
… fctest_functionspace
  • Loading branch information
sbrdar committed Apr 29, 2024
1 parent 2f8f0d9 commit 3003ce6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
50 changes: 29 additions & 21 deletions src/atlas_f/functionspace/atlas_FunctionSpace_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/tests/functionspace/fctest_functionspace.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) )
Expand Down

0 comments on commit 3003ce6

Please sign in to comment.