主题:子程序为什么不返回主程序
program main
implicit none
real,parameter :: width=120.0,heighth=120.0 !模型大小
double precision r !种子数
real :: totarea=0.0 !多边形的总面积
real :: area=0.0 !单个多边形的面积
real,parameter :: e=0.6 !块石含量
integer :: number=1 !记录多边形的编号
real x(9),y(9)
integer n,i
real x0,y0
open(unit=10,file='point.txt')
write(*,*) "Please input the number of seed!"
read(*,*) r
do while(totarea<e*heighth*width)
call point(r,width,heighth,x,y,n,x0,y0)
call checkin(x,y,n,width,heighth,r)
totarea=totarea+area+60.0
write(10,*) "Number=",number
do i=1,n+1
write(10,*) i,x(i),y(i)
end do
write(10,*)
number=number+1
end do
close(10)
stop
end program
!产生多边形的顶点
subroutine point(r,width,heighth,x,y,n,x0,y0)
implicit none
double precision r
real width,heighth
real,external :: NRND1 !产生随机数的子程序
real theta,beta !定义N边形的角度和随机旋转的角度
real,parameter :: pi=3.1415926
integer :: i=0 !循环用
integer n !多边形边的数目
real,parameter :: Nmax=8.0,Nmin=3.0 !岩石块的最大,最小边数
real,parameter :: Bmax=20.0,Bmin=2.0 !岩石块的最大,最小半径
real x0,y0 !岩石块的圆心坐标
real num !存放生成的随机数
real angle !顶点的角度
real lenth !多边形半径的长
real x(9),y(9)
num=NRND1(r)
n=nint(num*(Nmax-Nmin)+Nmin) !生成多边形的边的数目
theta=2*pi/n
num=NRND1(r)
x0=num*width !多边形圆心的x坐标值
num=NRND1(r)
y0=num*heighth !多边形圆心的y坐标值
beta=NRND1(r) !多边形第一条边偏转的角度
do i=1,n
angle=beta+theta*(i-1)
num=NRND1(r)
lenth=num*(Bmax-Bmin)+Bmin !多边形的半径
x(i)=x0+lenth*cos(angle)
y(i)=y0+lenth*sin(angle)
end do
x(n+1)=x(1)
y(n+1)=y(1)
i=0
return
end subroutine
!产生随机数的子程序
real function NRND1(R)
double precision S,U,V,R
S=65536.0
U=2053.0
V=13849.0
M=R/S
R=R-M*S
R=U*R+V
M=R/S
R=R-M*S
NRND1=R/S
return
end function
!判断多边形顶点是否在样本内
subroutine checkin(x,y,n,width,heighth,r)
implicit none
integer n
real x(9),y(9)
real width,heighth
double precision r
real x0,y0
integer :: i=0
do i=1,n
if(x(i)<=0 .or. x(i)>=width)then
call point(r,width,heighth,x,y,n,x0,y0)
end if
if(y(i)<=0 .or. y(i)>=heighth)then
call point(r,width,heighth,x,y,n,x0,y0)
end if
end do
return
end subroutine
这个程序在运行的时候,point这个子程序执行之后,应该是返回主程序,但是只执行了一次,第二次时,当运行完point之后,就直接跳到了checkin这个子程序,而且还不是跳到checkin子程序的开头。
希望哪位大侠能帮小弟看看,小弟在此谢过了!
implicit none
real,parameter :: width=120.0,heighth=120.0 !模型大小
double precision r !种子数
real :: totarea=0.0 !多边形的总面积
real :: area=0.0 !单个多边形的面积
real,parameter :: e=0.6 !块石含量
integer :: number=1 !记录多边形的编号
real x(9),y(9)
integer n,i
real x0,y0
open(unit=10,file='point.txt')
write(*,*) "Please input the number of seed!"
read(*,*) r
do while(totarea<e*heighth*width)
call point(r,width,heighth,x,y,n,x0,y0)
call checkin(x,y,n,width,heighth,r)
totarea=totarea+area+60.0
write(10,*) "Number=",number
do i=1,n+1
write(10,*) i,x(i),y(i)
end do
write(10,*)
number=number+1
end do
close(10)
stop
end program
!产生多边形的顶点
subroutine point(r,width,heighth,x,y,n,x0,y0)
implicit none
double precision r
real width,heighth
real,external :: NRND1 !产生随机数的子程序
real theta,beta !定义N边形的角度和随机旋转的角度
real,parameter :: pi=3.1415926
integer :: i=0 !循环用
integer n !多边形边的数目
real,parameter :: Nmax=8.0,Nmin=3.0 !岩石块的最大,最小边数
real,parameter :: Bmax=20.0,Bmin=2.0 !岩石块的最大,最小半径
real x0,y0 !岩石块的圆心坐标
real num !存放生成的随机数
real angle !顶点的角度
real lenth !多边形半径的长
real x(9),y(9)
num=NRND1(r)
n=nint(num*(Nmax-Nmin)+Nmin) !生成多边形的边的数目
theta=2*pi/n
num=NRND1(r)
x0=num*width !多边形圆心的x坐标值
num=NRND1(r)
y0=num*heighth !多边形圆心的y坐标值
beta=NRND1(r) !多边形第一条边偏转的角度
do i=1,n
angle=beta+theta*(i-1)
num=NRND1(r)
lenth=num*(Bmax-Bmin)+Bmin !多边形的半径
x(i)=x0+lenth*cos(angle)
y(i)=y0+lenth*sin(angle)
end do
x(n+1)=x(1)
y(n+1)=y(1)
i=0
return
end subroutine
!产生随机数的子程序
real function NRND1(R)
double precision S,U,V,R
S=65536.0
U=2053.0
V=13849.0
M=R/S
R=R-M*S
R=U*R+V
M=R/S
R=R-M*S
NRND1=R/S
return
end function
!判断多边形顶点是否在样本内
subroutine checkin(x,y,n,width,heighth,r)
implicit none
integer n
real x(9),y(9)
real width,heighth
double precision r
real x0,y0
integer :: i=0
do i=1,n
if(x(i)<=0 .or. x(i)>=width)then
call point(r,width,heighth,x,y,n,x0,y0)
end if
if(y(i)<=0 .or. y(i)>=heighth)then
call point(r,width,heighth,x,y,n,x0,y0)
end if
end do
return
end subroutine
这个程序在运行的时候,point这个子程序执行之后,应该是返回主程序,但是只执行了一次,第二次时,当运行完point之后,就直接跳到了checkin这个子程序,而且还不是跳到checkin子程序的开头。
希望哪位大侠能帮小弟看看,小弟在此谢过了!