-1
我正在编写一个代码,将一个圆圈离散化,然后在用户指定的时间间隔内返回哪些点。使用变量x,y和theta,它将y和theta的值按照它们应该写入文件info.dat的方式写入,但写入x不管我做什么都是零。写到points.dat也没有问题。顺便说一下所有变量进行了适当从一开始就为两种分配,目标,指针定义等需要帮助调试写入Fortran中的文件
open(unit=2, file="points.DAT")
print*, 'Please enter the reference angle of the arc in degrees, number of points on the arc, and radius of the arc.'
read(*,*) a, n, r
a = a * pi/180
allocate(x(1:n),y(1:n),theta(1:n))
do i = 1,n
theta(i:i) = a*(i-1)/n
x(i:i) = r * cos(theta(i:i))
y(i:i) = r * sin(theta(i:i))
xcoord(i:i) => x(i:i)
ycoord(i:i) => y(i:i)
angle(i:i) => theta(i:i)
write(2,*) 'x',i,'=',x(i:i),'y',i,'=',y(i:i), 'theta', i,'=', theta(i:i)
end do
deallocate(x,y,theta)
close(2)
open(unit=3, file="info.DAT")
print*, 'Please specify the interval of interest between 0 and 360 degrees'
read(*,*) b, c
b = b * pi/180
c = c * pi/180
do i = 1, n
if (any(b <= angle(i:i) .and. angle(i:i) <= c)) then
write(3,*) 'x', i, '=', xcoord(i:i), 'y', i, '=', ycoord(i:i), 'theta', i, '=', angle(i:i)
end if
end do
close(3)
它可能会帮助任何人试图帮助你在你的代码中显示变量的声明,实际上是发布一个MCVE - http://stackoverflow.com/help/mcve –
@高级别1 dim( 1)数组与(标量)元素 用于计算(至少这里是简单用法)和I/O,但不用于指针关联(显然使用不是F95的边界重新映射),也不传递参数(这里不使用),因为在这些情况下,排名必须匹配(以及类型和种类)。 –
始终使用标签[tag:fortran],只有在必要时添加版本才能区分您的问题是否具体。例如,您不能使用Fortran 2008,而只能使用Fortran 90。 –