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
type(ESMF_Info) :: infoh
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_InfoGetFromHost(field,infoh,_RC)
call ESMF_InfoSet(infoh,key='LONG_NAME',value=trim(long_name),_RC)
call ESMF_InfoSet(infoh,key='UNITS',value=trim(units),_RC)
if (lm == 0) then
call ESMF_InfoSet(infoh,key='DIMS',value=MAPL_DimsHorzOnly,_RC)
call ESMF_InfoSet(infoh,key='VLOCATION',value=MAPL_VLocationNone,_RC)
else if (lm > 0) then
call ESMF_InfoSet(infoh,key='DIMS',value=MAPL_DimsHorzVert,_RC)
call ESMF_InfoSet(infoh,key='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