Hello all,
My goal is to make a program that reads a data file with 5 columns of data, reads each column and counts how many data points fit within different ranges (these counts are placed into different bins, which represent different ranges.) So, for column b I want 20 bins with the complete bin range going from (-3 to 3). For example, bin1 for column b will count how many numbers in that column are in the range (-3 to -2.7), bin2 would count for the range (-2.7, -2.4), etc… I want the bin width and each bin range to be the same for each column so that each column is counted for the same ranges. Originally, I had a horribly inefficient program (which worked) but in the end I had 80 if statements (20 for each column.) I wanted to see if I could use arrays and the count function to reduce it to just 4 lines. I have seen suggestions to have an array that looks like:
binb(i)=binb(i)+count(b>=lower(i) .and. b<upper(i))
binc(i)=binc(i)+count(c>=lower(i) .and. c<upper(i))
bind(i)=bind(i)+count(d>=lower(i) .and. d<upper(i))
bine(i)=bine(i)+count(e>=lower(i) .and. e<upper(I))
but lower and upper must be arrays instead of scalars… Here is my program thus far:
program mean_analysis
implicit none
integer i, j, k, N, l
double precision a, b, c, d, e
integer binb(1:20),binc(1:20),bind(1:20),bine(1:20)
real lower(1:20),upper(1:20)
character(100) event
upper(1)=-2.7
lower(1)=-3
open(unit = 7, file="zpc_initial_momenta.dat")
do l=2,20
lower(l)=lower(l-1)+.3
upper(l)=upper(l-1)+.3
end do
do k=1, 10
read(7,'(A)') event
do j=1,4000
read(7,*) a, b, c, d, e
do i=1,20
binb(i)=binb(i)+count(b>=lower(i:) .and. b<upper(:i))
binc(i)=binc(i)+count(c>=lower(i:) .and. c<upper(:i))
bind(i)=bind(i)+count(d>=lower(i:) .and. d<upper(:i))
bine(i)=bine(i)+count(e>=lower(i:) .and. e<upper(:i))
end do
end do
end do
close(7)
open(unit = 8, file="outputanalysis.dat")
Write(8,*) 'The bins in each column are as follows:'
Write(8,*) 'FIRST COLUMN (MOMENTUM IN X DIRECTION)'
write(8,*) binb
close(8)
end program
I have tried to remedy the lower - upper scalar issue by implementing an idea someone had on another post of mine, to make lower-> lower(I:) and upper → upper(:I) , but it does not use the correct i-th values for the upper and lower arrays that I defined earlier with a do loop. Any suggestions or help is greatly appreciated. Thank you!