! Find all phase space files ! Combine all phase_space_files from dated directories with suffix energy on-command line. program combine_phase_space use sim_utils implicit none character*300 string, new_string, phase_space_file(20), word character*300 dir_file character*300 dir(300) character*20 dir_min, dir_max character*20 file_prefix character*200 cwd logical first/.true./, itexists integer reason, n integer lun, lun2 integer number_files integer min_date,max_date, min_time, max_time, date, time integer nargs nargs = command_argument_count() if (nargs == 1)then call cesr_getarg(1, file_prefix) ! file_prefix = END140 for example endif !get the list of dated directories string='ls > out.dat' call execute_command_line(string) lun=lunget() open(unit=lun,file='out.dat', status='old') n=0 do while(.true.) read(lun, '(a)', IOSTAT = reason)new_string if(reason < 0)exit if( (index(new_string,'2025')==0) .and. (index(new_string,'2019')==0) .and. (index(new_string,'2021')==0) .and. (index(new_string,'2022')== 0).and. (index(new_string,'2023')== 0).and. (index(new_string,'2024')== 0) )cycle n=n+1 dir(n)=trim(new_string) print '(i10,1x,a19)',n, dir(n) number_files = n end do close(lun) !_______________________________________________________________________ lun2=lunget() open (unit=lun2,file = 'all_'//trim(file_prefix)//'_phase_space.dat') do n=1, number_files lun=lunget() dir_file = trim(dir(n))//'/'//trim(file_prefix)//'_phase_space.dat' inquire (file = dir_file, exist = itexists) if(.not. itexists)then print *, dir_file, 'does not exist' cycle endif open(unit=lun,file=dir_file) do while(.true.) read(lun, '(a)', IOSTAT = reason)new_string if(reason < 0)exit if(.not. first .and. index(new_string,'!')/=0)cycle write(lun2,'(a)')new_string end do first = .false. close(unit=lun) end do close(unit=lun2) print '(a)', 'write all_'//trim(file_prefix)//'_phase_space.dat' end program