Subroutine that creates a vector containing the folders of a file path
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | file_path | |||
character(len=512), | intent(out), | dimension(:), allocatable | :: | vec_path |
subroutine path2vec(file_path, vec_path) !! Subroutine that creates a vector containing the folders of a file path implicit none character(len = *), intent(in ) :: file_path character(len = 512), intent(out), dimension(:), allocatable :: vec_path character(len = 512) :: dir character(len = 1) :: sep integer(kind = I4) :: is1, is2, k sep = dir_separator() k = 0 is2 = len_trim( file_path ) do is2 = index( file_path(1:is2 - 1), sep, back = .true. ) if ( is2 > 0 ) then k = k + 1 else exit endif enddo allocate( vec_path(1:k - 1) ) is2 = index( file_path, sep, back = .true. ) dir = file_path(1:is2 - 1) k = 0 do is1 = index( file_path(1:is2 - 1), sep, back = .true. ) if ( is1 > 0 ) then k = k + 1 vec_path(k) = file_path( is1 + 1:is2 - 1 ) is2 = is1 else exit endif enddo vec_path = vec_path( size(vec_path):1:-1 ) return endsubroutine path2vec