-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。 –