ESCOMP / CMEPS

NUOPC Community Mediator for Earth Prediction Systems
https://escomp.github.io/CMEPS/
24 stars 79 forks source link

med_methods_FB_init creates fields with mismatched ungridded dimensions #427

Open kieranricardo opened 10 months ago

kieranricardo commented 10 months ago

Hi there,

I'm currently using CMEPs to couple CICE6, MOM6, and the UM and I noticed some unexpected behaviour while using CMEPS.

When ungridded dimensions are present, behaviour of med_methods_FB_init seems to depend on the internal field ordering of the input state. med_methods_FB_init removes cpl_scalars from the field name list lfieldNameList, but then accesses the fields from the input state by index when determining the ungridded dimensions. Unless cpl_scalars is the last field in the input state, this causes the wrong fields to be used when determining the ungridded dimensions of the output fields.

The following small change fixed this for my use case. Changing

https://github.com/ESCOMP/CMEPS/blob/d2a08f0edc84b30b91891d96d3dd0040a595db5e/mediator/med_methods_mod.F90#L399-L403

to

elseif (present(STflds)) then
  call ESMF_StateGet(STflds, itemName=trim(lfieldnamelist(n)), field=lfield, rc=rc)
  if (chkerr(rc,__LINE__,u_FILE_u)) return

Happy to submit a PR from my fork https://github.com/kieranricardo/CMEPS/tree/bugfix-FB-init-dim-mismatch if appropriate :)