subroutine MAPL_StateEval(state,expression,field,rc)
type(ESMF_State), intent(in ) :: state
character(len=*), intent(in ) :: expression
type(ESMF_Field), intent(inout) :: field
integer, optional, intent(out ) :: rc
character(len=ESMF_MAXSTR), allocatable :: fieldNames(:)
integer :: varCount
type(ESMF_Field) :: state_field
integer :: i
type(tComp) :: pcode
logical, allocatable :: needed(:)
logical :: isConformal
integer :: status
call ESMF_StateGet(state,ITEMCOUNT=varCount,_RC)
allocate(fieldnames(varCount),needed(varCount))
call ESMF_StateGet(state,itemnamelist=fieldNames,_RC)
! confirm that each needed field is conformal
call CheckSyntax(expression,fieldNames,needed,_RC)
do i=1,varCount
if (needed(i)) then
call ESMF_StateGet(state,fieldNames(i),field=state_field,_RC)
isConformal = FieldsAreBroadcastConformable(state_field,field,_RC)
if (.not.isConformal) then
_FAIL('needs informative message')
end if
end if
end do
call parsef (pcode, expression, fieldNames, field, _RC)
call evalf(pcode,state,fieldNames,field,_RC)
call bytecode_dealloc(pcode,_RC)
deallocate(fieldNames,needed)
end subroutine MAPL_StateEval