if variable name contains "/", these are interpreted as groups/subgroups. split the varname at first occurence of "/" to get the first group name on the file level. Then get the group id. repeat until no "/" is found anymore. output the final groupid and the variable name without the group names.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_ncfile), | intent(inout) | :: | sf |
self |
||
| character(len=*), | intent(in) | :: | varname_in |
name of the variable (can include "/" for groups) |
||
| integer, | intent(out) | :: | grpid |
id of the last group found |
||
| character(len=255), | intent(out) | :: | varname |
name of the variable without groups |
||
| logical, | intent(out) | :: | exists |
SUBROUTINE ncfile_enter_groups(sf,varname_in,grpid,varname,exists) ! MODULES IMPLICIT NONE !------------------------------------------------------------------------------------------------------------------------------- ! INPUT VARIABLES CHARACTER(LEN=*),INTENT(IN) :: varname_in !! name of the variable (can include "/" for groups) !------------------------------------------------------------------------------------------------------------------------------- ! OUTPUT VARIABLES CLASS(t_ncfile),INTENT(INOUT) :: sf !! self CHARACTER(LEN=255),INTENT(OUT) :: varname !! name of the variable without groups INTEGER,INTENT(OUT) :: grpid !! id of the last group found LOGICAL,INTENT(OUT) :: exists !------------------------------------------------------------------------------------------------------------------------------- ! LOCAL VARIABLES CHARACTER(LEN=255) :: grpname INTEGER :: grpid_old,id !=============================================================================================================================== CALL mpi_check_single_access() IF(.NOT.sf%isopen) CALL sf%openfile() grpid=sf%nc_id varname=varname_in exists=.TRUE. #if NETCDF id=INDEX(varname,"/") DO WHILE (id.NE.0) grpname=varname(1:id-1) varname=varname(id+1:) grpid_old=grpid sf%ioError = nf90_INQ_NCID(grpid_old, TRIM(grpname), grpid) exists=(sf%ioError .EQ. nf90_NOERR) IF(.NOT.exists) RETURN id=INDEX(varname,"/") END DO #endif /*NETCDF*/ END SUBROUTINE ncfile_enter_groups