** Count the number of points in 0-2, 2-4, ... 8-10 range * The input data file is data.dat ** The output is in data.out * * Steve Gao, 10/22/2018 parameter(max=100000) real a(max) open(2,file='data.out') *Read the data into array a(max): open(1,file='data.dat') do i=1,max read(1,*,end=111) a(i) enddo 111 close(1) npts=i-1 * Do the counting: do k=1,5 s1=(k-1)*2.0 s2=s1+2.0 n=0 do i=1,npts if(a(i).ge.s1.and.a(i).lt.s2) n=n+1 enddo write(6,1) s1, s2, n write(2,1) s1, s2, n 1 format(f5.2, 1x, f5.2, 1x, i4) enddo !! k loop ends here close(2) print*,'The output file is data.out' stop end