I have the following problem. I have a file that I must:
- divide in cells to create an
NxN
grid;
- counts the particles in each cell;
- write the resulting numbers in a particular way.
The problem is the third point: I must write an NxN array each numbers represent the total numbers of particles in each cell, but I don't know how to write the file in an NxN
array.
program eccen
implicit none
integer, parameter:: grid=200
integer::i,j,k,n,m
real*8,allocatable::f(:,:)
real*8::xx(grid),yy(grid),mval,Mxval
real*8,allocatable::x(:),y(:)
open(10,file='coordXY.txt')
n=0
DO
READ(10,*,END=100)
n=n+1
END DO
100 continue
rewind(10)
allocate(x(n),y(n))
do i=1, n
read(10,*) x(i),y(i)
end do
! create a grid
mval=-15.
Mxval=15.
do i=1, grid
xx(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
yy(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
end do
open(20,file='fluxXY.dat')
! counts the paticles in each cell of the grid
allocate(f(grid,grid))
f=0
do i=1,grid
do j=1,grid
m=0.
do k=1, n
if (x(k) > xx(i) .and. x(k) < xx(i+1) .and. &
& y(k) > yy(j) .and. y(k) < yy(j+1)) then
m=m+1 ! CONTA IL NUMERO DI PARTICELLE
end if
end do
f(i,j)=float(m+1)
! THIS IS HOW I WRITE THE FILE BUT THIS SHOULD BE CHANGED
write(20,*) f(i,:)
end do
write(20,*)
print *,i
end do
end program eccen
Thanks a lot for Your help!