- #1
Dgrosser
- 3
- 0
Hello fellows,
I am writing a computer program in Fortran, to find the perimeter of multiple squares. These squares move as "time" goes along, and if they come in contact with each other, they stick together, forming clusters. The reason why I'm doing this in Fortran is because the original program that randomly places the cubes and moves them is also in Fortran.
To help, I know the program has the position of each square (Which looks like this):
*L is the dimensions of the field)
do i = 1, N
10 x(i) = int(L*ranr()) + 1
y(i) = int(L*ranr()) + 1
if (occ(x(i),y(i)).eq.1) goto 10
occ(x(i),y(i)) = 1
id(x(i),y(i)) = i
write(11,*) x(i), y(i) !Write into pos.dat
enddo
This gives the definition of the squares, which it then transfers to a file (pos.dat).
There is also code to define the clusters, so that each cluster has its own area:
iclust = 0 ! iclust: the temporary number of clusters
csize = 0.0
do i = 1, N
xc = x(i) ! current position in x
yc = y(i) ! current position in y
x1 = xc
y1 = yc
if (fill(x(i),y(i)).eq.1) then
iclust = iclust + 1
tab = 0
clustN(iclust) = tab
clustI(iclust,:) = ids(:)
csize = csize + tab
Finally, all the clusters are figured out by a flood-fill algorithm, which I think may be relavent:
*Note old = 1*
one = 1
if (fill(x1,y1).eq.old) then
fill(x1,y1) = new
tab = tab + 1
ids(tab) = id(x1,y1)
if (x1.eq.L) then
call floodPBC(xc,yc,one,y1,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1+1,y1,new,old,fill,tab,ids,id)
endif
if (y1.eq.L) then
call floodPBC(xc,yc,x1,one,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1,y1+1,new,old,fill,tab,ids,id)
endif
if (x1.eq.1) then
call floodPBC(xc,yc,L,y1,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1-1,y1,new,old,fill,tab,ids,id)
endif
if (y1.eq.1) then
call floodPBC(xc,yc,x1,L,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1,y1-1,new,old,fill,tab,ids,id)
endif
endif
return
Where yc and xc are original positions, and x1 and y1 are the new updated positions.
Any advice will help. I am not a programer, but I am beginning to learn it. Thank you.
I am writing a computer program in Fortran, to find the perimeter of multiple squares. These squares move as "time" goes along, and if they come in contact with each other, they stick together, forming clusters. The reason why I'm doing this in Fortran is because the original program that randomly places the cubes and moves them is also in Fortran.
To help, I know the program has the position of each square (Which looks like this):
*L is the dimensions of the field)
do i = 1, N
10 x(i) = int(L*ranr()) + 1
y(i) = int(L*ranr()) + 1
if (occ(x(i),y(i)).eq.1) goto 10
occ(x(i),y(i)) = 1
id(x(i),y(i)) = i
write(11,*) x(i), y(i) !Write into pos.dat
enddo
This gives the definition of the squares, which it then transfers to a file (pos.dat).
There is also code to define the clusters, so that each cluster has its own area:
iclust = 0 ! iclust: the temporary number of clusters
csize = 0.0
do i = 1, N
xc = x(i) ! current position in x
yc = y(i) ! current position in y
x1 = xc
y1 = yc
if (fill(x(i),y(i)).eq.1) then
iclust = iclust + 1
tab = 0
clustN(iclust) = tab
clustI(iclust,:) = ids(:)
csize = csize + tab
Finally, all the clusters are figured out by a flood-fill algorithm, which I think may be relavent:
*Note old = 1*
one = 1
if (fill(x1,y1).eq.old) then
fill(x1,y1) = new
tab = tab + 1
ids(tab) = id(x1,y1)
if (x1.eq.L) then
call floodPBC(xc,yc,one,y1,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1+1,y1,new,old,fill,tab,ids,id)
endif
if (y1.eq.L) then
call floodPBC(xc,yc,x1,one,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1,y1+1,new,old,fill,tab,ids,id)
endif
if (x1.eq.1) then
call floodPBC(xc,yc,L,y1,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1-1,y1,new,old,fill,tab,ids,id)
endif
if (y1.eq.1) then
call floodPBC(xc,yc,x1,L,new,old,fill,tab,ids,id)
else
call floodPBC(xc,yc,x1,y1-1,new,old,fill,tab,ids,id)
endif
endif
return
Where yc and xc are original positions, and x1 and y1 are the new updated positions.
Any advice will help. I am not a programer, but I am beginning to learn it. Thank you.