subroutine add_new_field_to_bundle(bundle,grid,lm,field_name,long_name,units,rc)
type(ESMF_FieldBundle), intent(inout) :: bundle
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: lm
character(len=*), intent(in) :: field_name
character(len=*), intent(in) :: long_name
character(len=*), intent(in) :: units
integer, intent(out), optional :: rc
integer :: status
type(ESMF_Field) :: field
if (lm == 0) then
field = ESMF_FieldCreate(grid,name=trim(field_name),typekind=ESMF_TYPEKIND_R4,_RC)
else if (lm > 0) then
field = ESMF_FieldCreate(grid,name=trim(field_name),typekind=ESMF_TYPEKIND_R4, &
ungriddedLBound=[1],ungriddedUBound=[lm],_RC)
end if
call ESMF_AttributeSet(field,name='LONG_NAME',value=trim(long_name),_RC)
call ESMF_AttributeSet(field,name='UNITS',value=trim(units),_RC)
if (lm == 0) then
call ESMF_AttributeSet(field,name='DIMS',value=MAPL_DimsHorzOnly,_RC)
call ESMF_AttributeSet(field,name='VLOCATION',value=MAPL_VLocationNone,_RC)
else if (lm > 0) then
call ESMF_AttributeSet(field,name='DIMS',value=MAPL_DimsHorzVert,_RC)
call ESMF_AttributeSet(field,name='VLOCATION',value=MAPL_VLocationCenter,_RC)
end if
call MAPL_FieldBundleAdd(bundle,field,_RC)
if (present(rc)) then
RC=_SUCCESS
end if
end subroutine add_new_field_to_bundle