ESMF_AttributeUpdateContainerStressUTest Program

Variables

Type Attributes Name Initial
character(len=*), parameter :: version = '$Id$'
character(len=ESMF_MAXSTR) :: attname
character(len=ESMF_MAXSTR), dimension(2) :: attrList
character(len=ESMF_MAXSTR) :: convESMF
character(len=ESMF_MAXSTR) :: failMsg
character(len=ESMF_MAXSTR) :: name
character(len=ESMF_MAXSTR) :: name1
character(len=ESMF_MAXSTR) :: outVal
character(len=ESMF_MAXSTR) :: purpGen
character(len=ESMF_MAXSTR) :: value1
character(len=ESMF_MAXSTR), dimension(2) :: valueList
integer :: localPet
integer :: petCount
integer :: rc = ESMF_SUCCESS
integer :: result = 0
logical :: isPresent1
logical :: isPresent2
type(ESMF_AttPack) :: attpack
type(ESMF_AttPack) :: attpack_parent
type(ESMF_CplComp) :: cplcomp
type(ESMF_Field) :: field10
type(ESMF_Field) :: field2
type(ESMF_Field) :: field3
type(ESMF_Field) :: field6
type(ESMF_Field) :: field7
type(ESMF_Field) :: field8
type(ESMF_Field) :: field9
type(ESMF_FieldBundle) :: fieldbundle2
type(ESMF_Grid) :: grid
type(ESMF_GridComp) :: gridcomp1
type(ESMF_GridComp) :: gridcomp2
type(ESMF_State) :: c1exp
type(ESMF_State) :: c2imp
type(ESMF_VM) :: vm

Source Code

program ESMF_AttributeUpdateContainerStressUTest

#include "ESMF.h"

!==============================================================================
!BOP
! !PROGRAM: ESMF_AttributeUpdateUTest - Attribute Update Unit Tests
!
! !DESCRIPTION:
!
! The code in this file drives F90 Attribute Update unit tests.
!
!-----------------------------------------------------------------------------
! !USES:
  use ESMF
  use ESMF_TestMod
  use AttributeUpdateContainerStressUTestMod, only : &
    userm1_setvm, userm1_register, &
    userm2_setvm, userm2_register, &
    usercpl_setvm, usercpl_register


  implicit none

!------------------------------------------------------------------------------
! The following line turns the CVS identifier string into a printable variable.
    character(*), parameter :: version = &
    '$Id$'
!------------------------------------------------------------------------------


    ! individual test failure message
    character(ESMF_MAXSTR) :: failMsg
    character(ESMF_MAXSTR) :: name

    ! cumulative result: count failures; no failures equals "all pass"
    integer :: result = 0

    ! individual test result code
    integer :: rc = ESMF_SUCCESS

    ! local variables
    integer                 :: petCount, localPet
    type(ESMF_VM)           :: vm
    type(ESMF_State)        :: c1exp, c2imp
    type(ESMF_GridComp)     :: gridcomp1
    type(ESMF_GridComp)     :: gridcomp2
    type(ESMF_CplComp)      :: cplcomp
    character(ESMF_MAXSTR)  :: convESMF,purpGen

        type(ESMF_AttPack)      :: attpack, attpack_parent
    type(ESMF_Field)        :: field2, field3, field6, field7, field8, field9, field10
    type(ESMF_FieldBundle)  :: fieldbundle2
    type(ESMF_Grid)         :: grid

    character(ESMF_MAXSTR)  :: name1, value1, outVal, attname
    character(ESMF_MAXSTR),dimension(2) :: attrList, valueList
    logical                 :: isPresent1, isPresent2

!-------------------------------------------------------------------------------
!  The unit tests are divided into Sanity and Exhaustive. The Sanity tests are
!  always run. When the environment variable, EXHAUSTIVE, is set to ON then
!  the EXHAUSTIVE and sanity tests both run. If the EXHAUSTIVE variable is set
!  to OFF, then only the sanity unit tests.
!  Special strings (Non-exhaustive and exhaustive) have been
!  added to allow a script to count the number and types of unit tests.
!-------------------------------------------------------------------------------

    !-----------------------------------------------------------------------------
    call ESMF_TestStart(ESMF_SRCLINE, rc=rc)
    if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    !-----------------------------------------------------------------------------

#ifdef ESMF_TESTEXHAUSTIVE
    call ESMF_VMGetCurrent(vm, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_VMGet(vm, petCount=petCount, localPet=localPet, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    gridcomp1 = ESMF_GridCompCreate(name="gridcomp1", &
      petList=(/0,1/), rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    gridcomp2 = ESMF_GridCompCreate(name="gridcomp2", &
      petList=(/2,3/), rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    cplcomp = ESMF_CplCompCreate(name="cplcomp", &
      petList=(/0,1,2,3/), rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    c1exp = ESMF_StateCreate(name="Comp1 exportState", &
                             stateintent=ESMF_STATEINTENT_EXPORT, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    c2imp = ESMF_StateCreate(name="Comp2 importState", &
                             stateintent=ESMF_STATEINTENT_IMPORT, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_GridCompSetVM(gridcomp1, userm1_setvm, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompSetVM(gridcomp2, userm2_setvm, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompSetVM(cplcomp, usercpl_setvm, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_GridCompSetServices(gridcomp1, userRoutine=userm1_register, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompSetServices(gridcomp2, userRoutine=userm2_register, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompSetServices(cplcomp, userRoutine=usercpl_register, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_GridCompInitialize(gridcomp1, exportState=c1exp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompInitialize(gridcomp2, importState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompInitialize(cplcomp, importState=c1exp, &
      exportState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    ! now we test to see if the values are what we would expect
    call ESMF_StateGet(c1exp, "fieldbundle2", fieldbundle2, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_StateGet(c1exp, "field10", field10, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, grid=grid, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field2", field=field2, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field3", field=field3, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field6", field=field6, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field7", field=field7, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field8", field=field8, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_FieldBundleGet(fieldbundle2, fieldname="field9", field=field9, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)


    ! Now continue with the run phase, and AttributeUpdate
    call ESMF_GridCompRun(gridcomp1, exportState=c1exp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompRun(cplcomp, importState=c1exp, &
      exportState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompRun(gridcomp2, importState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)


    ! at this point we have fieldbundle2 and field10 on the state and fieldbundle2
    ! should include field2, 3, 6, 7, 8, 9.

    ! Now we can start doing some testing
    convESMF = 'ESMF'
    purpGen = 'General'
    name1 = 'ShortName'
    value1 = 'fieldAttribute'

    ! field2: add an attribute to the package and then set it
    !EX_UTest_Multi_Proc_Only
    attname = "att1"
    outVal = ""
    call ESMF_AttributeGetAttPack(field2, convESMF, purpGen, attpack=attpack, &
                                  rc=rc)
    call ESMF_AttributeGet(field2, attname, value=outVal, attpack=attpack, rc=rc)
    write(failMsg, *) "Did not return ESMF_SUCCESS or wrong value"
    write(name, *) "Testing for correct value on field2"
    call ESMF_Test((rc==ESMF_SUCCESS .and. outVal=="val1"), &
                    name, failMsg, result, ESMF_SRCLINE)

    ! field3: add an attribute to a package and set it, then delete it, readd it and set it to a different value
    !EX_UTest_Multi_Proc_Only
    call ESMF_AttributeGetAttPack(field3, convESMF, purpGen, attpack=attpack, &
                                  rc=rc)
    attname = "att1"
    outVal = ""
    call ESMF_AttributeGet(field3, attname, value=outVal, attpack=attpack, rc=rc)
    write(failMsg, *) "Did not return ESMF_SUCCESS or wrong value"
    write(name, *) "Testing for correct value on field3"
    call ESMF_Test((rc==ESMF_SUCCESS .and. outVal == "val2"), &
                    name, failMsg, result, ESMF_SRCLINE)

    ! field6: add a nested attribute package and set a value
    !EX_UTest_Multi_Proc_Only
    call ESMF_AttributeGetAttPack(field6, "newConvention", "newPurpose", &
                                  attpack=attpack, rc=rc)
    attname = "att1"
    outVal = ""
    call ESMF_AttributeGet(field6, attname, value=outVal, attpack=attpack, rc=rc)
    write(failMsg, *) "Did not return ESMF_SUCCESS or wrong value"
    write(name, *) "Testing for correct value on field6"
    call ESMF_Test((rc==ESMF_SUCCESS .and. outVal == "val1"), &
                    name, failMsg, result, ESMF_SRCLINE)

    ! field7: add a nested attribute package, set a value, remove the nested package,
    ! then readd the nested package and reset the value
    !EX_UTest_Multi_Proc_Only
    call ESMF_AttributeGetAttPack(field7, "newConvention", "newPurpose", &
                                  attpack=attpack_parent, rc=rc)
    call ESMF_AttributeGetAttPack(field7, convESMF, purpGen, &
                                  attpack=attpack, rc=rc)
    attname = "att1"
    outVal = ""
    call ESMF_AttributeGet(field7, attname, value=outVal, attpack=attpack_parent, rc=rc)
    write(failMsg, *) "Did not return ESMF_SUCCESS or wrong value"
    write(name, *) "Testing for correct value on field7"
    call ESMF_Test((rc==ESMF_SUCCESS .and. outVal == "val2"), &
                    name, failMsg, result, ESMF_SRCLINE)

    ! field8: add a nested package, then remove all attributes from parent package and the nested package,
    ! then add it all back, remove all attributes from nested package, add one back and then modify the value
    !EX_UTest_Multi_Proc_Only
    call ESMF_AttributeGetAttPack(field8, "newConvention", "newPurpose", &
                                  attpack=attpack, rc=rc)
    attname = "att1"
    outVal = ""
    call ESMF_AttributeGet(field8, attname, value=outVal, attpack=attpack, rc=rc)
    write(failMsg, *) "Did not return ESMF_SUCCESS or wrong value"
    write(name, *) "Testing for correct value on field8"
    call ESMF_Test((rc==ESMF_SUCCESS .and. outVal == "val1.2"), &
                    name, failMsg, result, ESMF_SRCLINE)

    ! field9: open for a new test

    ! field10: open for a new test

    ! Now back to finalizing the model run
    call ESMF_GridCompFinalize(gridcomp1, exportState=c1exp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompFinalize(gridcomp2, importState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompFinalize(cplcomp, importState=c1exp, &
      exportState=c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_GridCompDestroy(gridcomp1, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_GridCompDestroy(gridcomp2, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_CplCompDestroy(cplcomp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

    call ESMF_StateDestroy(c1exp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
    call ESMF_StateDestroy(c2imp, rc=rc)
    if (rc .ne. ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)

#endif
    !-----------------------------------------------------------------------------
    call ESMF_TestEnd(ESMF_SRCLINE)
    !-----------------------------------------------------------------------------

end program ESMF_AttributeUpdateContainerStressUTest