diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/utilities.F90 | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90 index 961a349..ddc0c79 100644 --- a/common/utilities.F90 +++ b/common/utilities.F90 @@ -6,6 +6,8 @@ module utilities character, parameter::dir_sep = '/' #endif + integer, parameter::DIR_LIST_STRING_LENGTH = 128 + interface replace_field module procedure replace_field_text module procedure replace_field_int @@ -276,7 +278,7 @@ contains implicit none character(*), intent(in)::directory - character(1024), dimension(:), pointer::res + character(DIR_LIST_STRING_LENGTH), dimension(:), pointer::res character(80)::line character(len=:), pointer::tempfile integer::dcount, unum, ierr, i @@ -288,6 +290,10 @@ contains wait=.true.) open(newunit=unum, file=tempfile, action='read') + + ! First line is "total ###" + read(unum, '(A)', iostat=ierr) line + dcount = 0 read(unum, '(A)', iostat=ierr) line do while(ierr == 0) @@ -303,14 +309,14 @@ contains allocate(res(dcount)) ! Now call ls, but group directories first - call execute_command_line("ls -g "//trim(directory)//" > "//trim(tempfile), & + call execute_command_line("ls --group-directories-first "//trim(directory)//" > "//trim(tempfile), & wait=.true.) open(newunit=unum, file=tempfile, action='read') i = 0 read(unum, '(A)', iostat=ierr) line do while(ierr == 0 .and. i < dcount) i = i + 1 - call combine_paths(trim(directory), trim(line), res(i)) + res(i) = trim(line) read(unum, '(A)', iostat=ierr) line end do @@ -325,7 +331,7 @@ contains implicit none character(*), intent(in)::directory - character(1024), dimension(:), pointer::res + character(DIR_LIST_STRING_LENGTH), dimension(:), pointer::res character(80)::line character(len=:), pointer::tempfile integer::dcount, total_count, unum, ierr, i @@ -337,6 +343,10 @@ contains wait=.true.) open(newunit=unum, file=tempfile, action='read') + + ! First line is "total ###" + read(unum, '(A)', iostat=ierr) line + dcount = 0 total_count = 0 read(unum, '(A)', iostat=ierr) line @@ -354,16 +364,18 @@ contains allocate(res(total_count - dcount)) ! Now call ls, but group directories first - call execute_command_line("ls -g "//trim(directory)//" > "//trim(tempfile), & + call execute_command_line("ls --group-directories-first "//trim(directory)//" > "//trim(tempfile), & wait=.true.) open(newunit=unum, file=tempfile, action='read') + i = 0 read(unum, '(A)', iostat=ierr) line - do while(ierr == 0 .and. i < dcount) + do while(ierr == 0 .and. i <= total_count) i = i + 1 if(i > dcount) then - call combine_paths(trim(directory), trim(line), res(i-dcount)) + res(i-dcount) = trim(line) end if + read(unum, '(A)', iostat=ierr) line end do |