initialization of cpl_scalars
I've been debugging an issue in UFS where adding a new configuration setting (write_restart_at_endofrun) caused an intel debug test on only derecho to fail in med.F90, during the creation of the component dimemsions
https://github.com/ESCOMP/CMEPS/blob/47fb4e633a76ec6d60969b1af751f90790387246/mediator/med.F90#L2117-L2119
The fact that the failure was triggered by adding an unrelated config variable led me to believe the cause was access of some different (garbage) memory location. I traced the failure to the initialization of the cpl_scalar fields in the MOM6 cap.
All the caps I am aware of which utilize CMEPS use the same SetScalarField routine, including CMEPS
https://github.com/ESCOMP/CMEPS/blob/47fb4e633a76ec6d60969b1af751f90790387246/mediator/esmFlds.F90#L563
In MOM6, I was able to resolve the issue with
! num of scalar values
field = ESMF_FieldCreate(name=trim(scalar_field_name), grid=grid, typekind=ESMF_TYPEKIND_R8, &
ungriddedLBound=(/1/), ungriddedUBound=(/scalar_field_count/), gridToFieldMap=(/2/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! initialize fldptr to zero
call ESMF_FieldGet(field, farrayPtr=fldptr2d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
fldptr2d(:,:) = 0.0
Should this change also be made in CMEPS (as well as all other caps utilizing cpl_scalars)? I don't think that ESMF automatically initializes a field when it is created (?).