aboutsummaryrefslogtreecommitdiff
path: root/common/utilities.F90
diff options
context:
space:
mode:
Diffstat (limited to 'common/utilities.F90')
-rw-r--r--common/utilities.F9044
1 files changed, 33 insertions, 11 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90
index ddc0c79..981dee3 100644
--- a/common/utilities.F90
+++ b/common/utilities.F90
@@ -334,7 +334,7 @@ contains
character(DIR_LIST_STRING_LENGTH), dimension(:), pointer::res
character(80)::line
character(len=:), pointer::tempfile
- integer::dcount, total_count, unum, ierr, i
+ integer::dcount, total_count, unum, ierr, i, n
tempfile => generate_temporary_filename()
res => null()
@@ -344,24 +344,33 @@ contains
open(newunit=unum, file=tempfile, action='read')
- ! First line is "total ###"
- read(unum, '(A)', iostat=ierr) line
-
dcount = 0
total_count = 0
+
+ ! Count directories first
read(unum, '(A)', iostat=ierr) line
do while(ierr == 0)
+
if(line(1:1) == 'd') then
dcount = dcount + 1
end if
- total_count = total_count + 1
+
+ ! ls puts a nonsense entry first. harmless, but we don't want it
+ if(line(1:6) /= "total ") then
+ total_count = total_count + 1
+ end if
+
read(unum, '(A)', iostat=ierr) line
end do
close(unum)
- if((total_count - dcount) > 0) then
- allocate(res(total_count - dcount))
+ n = total_count - dcount
+ !print *, "Total: ", total_count, "Dirs:", dcount, "Files:", n
+
+ if(n > 0) then
+ allocate(res(n))
+ !print *, "Size: ", size(res)
! Now call ls, but group directories first
call execute_command_line("ls --group-directories-first "//trim(directory)//" > "//trim(tempfile), &
@@ -369,11 +378,24 @@ contains
open(newunit=unum, file=tempfile, action='read')
i = 0
+
+ ! First, skip directories
+ do while(i < dcount)
+ read(unum, '(A)', iostat=ierr) line
+ if(line(1:6) /= "total ") then
+ i = i + 1
+ end if
+ end do
+
+ ! Now we can read files
+ i = 0
read(unum, '(A)', iostat=ierr) line
- do while(ierr == 0 .and. i <= total_count)
- i = i + 1
- if(i > dcount) then
- res(i-dcount) = trim(line)
+ do while(ierr == 0 .and. i < n)
+ if(line(1:6) /= "total ") then
+ i = i + 1
+ res(i) = trim(line)
+
+ !print *, i, trim(res(i))//"|"
end if
read(unum, '(A)', iostat=ierr) line