get_var_from_name_w_group Subroutine

public subroutine get_var_from_name_w_group(var_name, var2d, filename, rc)

print, ‘no grp name’ write(6,) ‘ncid, short_name, varid’, ncid, trim(short_name), varid

Arguments

Type IntentOptional Attributes Name
character(len=ESMF_MAXSTR), intent(in) :: var_name
real(kind=ESMF_KIND_R8), intent(inout) :: var2d(:,:)
character(len=ESMF_MAXSTR), intent(in) :: filename
integer, intent(out), optional :: rc

Calls

proc~~get_var_from_name_w_group~~CallsGraph proc~get_var_from_name_w_group get_var_from_name_w_group nf90_close nf90_close proc~get_var_from_name_w_group->nf90_close nf90_get_var nf90_get_var proc~get_var_from_name_w_group->nf90_get_var nf90_inq_ncid nf90_inq_ncid proc~get_var_from_name_w_group->nf90_inq_ncid nf90_inq_varid nf90_inq_varid proc~get_var_from_name_w_group->nf90_inq_varid nf90_open nf90_open proc~get_var_from_name_w_group->nf90_open proc~check_nc_status check_nc_status proc~get_var_from_name_w_group->proc~check_nc_status proc~mapl_return MAPL_Return proc~get_var_from_name_w_group->proc~mapl_return proc~mapl_verify MAPL_Verify proc~get_var_from_name_w_group->proc~mapl_verify proc~check_nc_status->proc~mapl_return interface~mapl_assert MAPL_Assert proc~check_nc_status->interface~mapl_assert nf90_strerror nf90_strerror proc~check_nc_status->nf90_strerror at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Called by

proc~~get_var_from_name_w_group~~CalledByGraph proc~get_var_from_name_w_group get_var_from_name_w_group proc~read_m_files_4_swath read_M_files_4_swath proc~read_m_files_4_swath->proc~get_var_from_name_w_group

Source Code

  subroutine get_var_from_name_w_group (var_name, var2d, filename, rc)
    character(len=ESMF_MAXSTR), intent(in) :: var_name, filename
    real(ESMF_KIND_R8), intent(inout) :: var2d(:,:)
    integer, optional, intent(out) :: rc

    integer :: i, j
    character(len=ESMF_MAXSTR) :: grp1, grp2
    character(len=ESMF_MAXSTR) :: short_name
    integer :: ncid, ncid1, ncid2, ncid_final, varid
    logical :: found_group
    integer :: status


    i=index(var_name, '/')
    if (i>0) then
       found_group = .true.
       grp1 = var_name(1:i-1)
       j=index(var_name(i+1:), '/')
       if (j>0) then
          grp2=var_name(i+1:i+j-1)
          short_name=var_name(i+j+1:)
       else
          grp2=''
          short_name=var_name(i+1:)
       endif
       i=i+j
    else
       found_group = .false.
       grp1 = ''
       grp2=''
       short_name=var_name
    endif


    ! ncid
    ! ncid1:  grp1
    ! ncid2:  grp2
    !
    call check_nc_status(nf90_open(filename, NF90_NOWRITE, ncid), _RC)
    ncid_final = ncid
    if ( found_group ) then
       call check_nc_status(nf90_inq_ncid(ncid, grp1, ncid1), _RC)
       ncid_final = ncid1
       if (j>0) then
          call check_nc_status(nf90_inq_ncid(ncid1, grp2, ncid2), _RC)
          ncid_final = ncid2
       endif
    else
!!       print*, 'no grp name'
    endif

    call check_nc_status(nf90_inq_varid(ncid_final, short_name, varid), _RC)
!!    write(6,*) 'ncid, short_name, varid', ncid, trim(short_name), varid
    call check_nc_status(nf90_get_var(ncid_final, varid, var2d), _RC)

    call check_nc_status(nf90_close(ncid), _RC)

    _RETURN(_SUCCESS)

  end subroutine get_var_from_name_w_group