add_variable Subroutine

public subroutine add_variable(metadata, field, rc)

Arguments

Type IntentOptional Attributes Name
type(FileMetadata), intent(inout) :: metadata
type(ESMF_Field), intent(in) :: field
integer, intent(out), optional :: rc

Calls

proc~~add_variable~2~~CallsGraph proc~add_variable~2 add_variable ESMF_InfoGetCharAlloc ESMF_InfoGetCharAlloc proc~add_variable~2->ESMF_InfoGetCharAlloc ESMF_InfoGetFromHost ESMF_InfoGetFromHost proc~add_variable~2->ESMF_InfoGetFromHost esmf_fieldget esmf_fieldget proc~add_variable~2->esmf_fieldget get_gridded_dims get_gridded_dims proc~add_variable~2->get_gridded_dims none~add_attribute~3 Variable%add_attribute proc~add_variable~2->none~add_attribute~3 none~add_variable~2 FileMetadata%add_variable proc~add_variable~2->none~add_variable~2 proc~esmf_to_pfio_type esmf_to_pfio_type proc~add_variable~2->proc~esmf_to_pfio_type proc~get_mapl_geom get_mapl_geom proc~add_variable~2->proc~get_mapl_geom proc~get_vertical_dimension_name_from_field get_vertical_dimension_name_from_field proc~add_variable~2->proc~get_vertical_dimension_name_from_field proc~mapl_return MAPL_Return proc~add_variable~2->proc~mapl_return proc~mapl_verify MAPL_Verify proc~add_variable~2->proc~mapl_verify proc~string_vec_to_comma_sep string_vec_to_comma_sep proc~add_variable~2->proc~string_vec_to_comma_sep proc~ungridded_dim_names ungridded_dim_names proc~add_variable~2->proc~ungridded_dim_names

Called by

proc~~add_variable~2~~CalledByGraph proc~add_variable~2 add_variable proc~add_variables add_variables proc~add_variables->proc~add_variable~2 proc~bundle_to_metadata bundle_to_metadata proc~bundle_to_metadata->proc~add_variables

Source Code

   subroutine add_variable(metadata, field,  rc)
      type(ESMF_Field), intent(in) :: field
      type(FileMetaData), intent(inout) :: metadata
      integer, intent(out), optional :: rc

      type(Variable) :: v
      integer :: status
      character(len=:), allocatable :: dims
      type(ESMF_TYPEKIND_FLAG) :: typekind
      integer :: pfio_type
      type(ESMF_Info) :: info
      character(len=:), allocatable :: char
      character(len=ESMF_MAXSTR) :: fname
      type(MAPLGeom), pointer :: mapl_geom
      type(StringVector) :: grid_variables
      type(ESMF_Geom) :: esmfgeom
      character(len=:), allocatable :: vert_dim_name, ungridded_names

      call ESMF_FieldGet(field, geom=esmfgeom, _RC)
      mapl_geom => get_mapl_geom(esmfgeom, _RC)
      grid_variables = mapl_geom%get_gridded_dims()
      dims = string_vec_to_comma_sep(grid_variables)
      call ESMF_FieldGet(field, name=fname, typekind = typekind, _RC)
      ! add vertical dimension
      vert_dim_name = get_vertical_dimension_name_from_field(field, _RC)
      if(vert_dim_name /= EMPTY) dims = dims//","//vert_dim_name
      ! add any ungridded dimensions
      ungridded_names = ungridded_dim_names(field, _RC)
      if(ungridded_names /= EMPTY) dims = dims // ungridded_names
      ! add time dimension
      dims = dims//",time"
      pfio_type = esmf_to_pfio_type(typekind ,_RC)
      v = Variable(type=pfio_type, dimensions=dims)
      call ESMF_InfoGetFromHost(field, info, _RC)
      call ESMF_InfoGetCharAlloc(info, 'MAPL/units', char, _RC)
      call v%add_attribute('units',char)
      call ESMF_InfoGetCharAlloc(info, 'MAPL/standard_name', char, _RC)
      call v%add_attribute('long_name',char)
      call metadata%add_variable(trim(fname), v, _RC)
      _RETURN(_SUCCESS)

   end subroutine add_variable