print, ‘no grp name’ write(6,) ‘ncid, short_name, varid’, ncid, trim(short_name), varid
Type | Intent | Optional | 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 |
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