Professional Documents
Culture Documents
program main
print*,'Enter the dimensions separated by space:' read*,x,y,z call coordgen(x,y,z,latarray) print*,'Enter the charge at the origin:' read*,first call assignlat(latarray,first) call printlat(latarray) end program
module lattice contains subroutine coordgen(sizex,sizey,sizez,latarray) implicit none integer,intent(in) :: sizez,sizey,sizex integer :: ok
integer,dimension(:,:,:),allocatable :: latarray
subroutine assignlat(lattice,first) implicit none integer,intent(inout),dimension(:,:,:) :: lattice integer,intent(in) :: first integer,allocatable,dimension(:) :: row integer,allocatable,dimension(:,:) :: plane,plntemp integer :: ok,index,charge,length,width
print*,'Enter the assignlat' allocate(row(size(lattice, dim=1)),STAT=ok) if (ok/=0) stop "***Cannot allocate memory***" allocate(plane(1:size(lattice, dim=1),1:size(lattice, dim=2)),STAT=ok) if (ok/=0) stop "***Cannot allocate memory***"
charge=first
plane(:,:)=lattice(:,:,1) length=size(lattice, dim=1) width=size(lattice, dim=2) do index=2,size(lattice,dim=3) plane(:,:)=-1*plane(:,:) lattice(:,:,index)=plane(:,:) end do print*,'Exit the assignlat' end subroutine
integer :: index1,index2,index3,count=0
open(1,FILE='E:\fortran\course\lab3\question2\output.txt',ACCESS='APPEND',STATUS='NEW')
write(1,*) 'X
charge'
do index1=1,size(lattice,dim=1) do index2=1,size(lattice,dim=2) do index3=1,size(lattice,dim=3) write(1,*) index1,index2,index3,lattice(index1,index2,index3) count=count+1 end do end do end do Write(1,*) 'The total number of points:',count close(1) end subroutine end module