I have several input data files with the name angleFile1.dat, angleFile2.dat, angleFile3.dat and so on. (I have more than 100 files)
Each file contain 45000 data of angles. I want to group these angles to get a distribution within 0 to 360 degrees.
I have written a Fortran code to do the job for one file at a time.
This code will read in the input file "angleFile1.dat" and write the distribution (in bins) in the "angleOut.dat" file.
program binangle
implicit none
integer :: i, j, k
integer,parameter :: arr=45000
real,dimension(1:arr) :: aangle
integer,dimension(0:360) :: binaangle
do i = 0,360
binaangle(i) = 0.0
end do
!OPEN OUTPUT FILE
open(unit=49,status="unknown",file="angleOut.dat")
!OPEN INPUT FILE
open(unit=50,status="unknown",file="angleFile1.dat")
read(50,'(F8.3)') (aangle(i), i = 1,arr)
! DO THE BINNING
do j = 1, arr
binaangle(int(aangle(j))) = binaangle(int(aangle(j))) + 1
end do
! WRITE INTO OUTPUT FILE
do k = 0,360
write(49,*) k, " ", binaangle(k)
end do
How to make this code to recursively take in the input files (angleFile1.dat, angleFile2.dat, angleFile3.dat and say until angleFile100.dat) and write the distribution in the same output file?
Help is much appreciated.