[問題] 不同的編輯軟體出來結果不同?
我想請問為什麼我的程式碼在舊版的Compaq Visual Fortran可以順利執行(作業環境是在
Win7的XP_Mode裡執行),但是我把同樣的程式碼放在微軟的Microsoft Visual Studio 的
Fortran編輯器裡卻出現兩個錯(作業系統直接在Win7),請問有人可以幫我偵錯嗎?
以下是我的程式碼
program homework01
implicit none
integer::num,i,j
real::U(20)
real::Matrix_Bij(20,20)
real::T(20)
real::Y(20)
real::b,a,G,E,pr,n,L,f,xi,xj,bij,bij1,bij2,bij3,bij4,uyi,PI,a1,a2,a3,a4,Tyy
real::ux,uy,d,zxx,zyy,zxy,r1,r2,th1,th2
real::sumux,sumuy,sumzxx,sumzxy,sumzyy
real::MATRIX_C(20)
real::MATRIX_x(20)
real::MATRIX_y(20)
real::MATRIX_xx(20)
real::MATRIX_yy(20)
real::MATRIX_xy(20)
! bij1: bij的第一部分
! bij2: bij的第二部分
! bij3: bij的第三部分
! bij4: bij的第四部分
PI=3.14159
num=20
E=10000
pr=0.3
G=0.5*(E/(1+pr))
uyi=-0.03
open(10,file='output.txt')
! L的修正
write(*,*)"L=b*f,請輸入此次的f值"
read(*,*)f
write(*,*)"請輸入此次的b值"
read(*,*)b
L=b*f
write(*,*)"請輸入此次的num值,不超過20"
read(*,*)num
write(10,*)"元素數目:",num
write(10,*)"楊氏模數:",E,"MPa"
write(10,*)"柏松比:",pr
write(10,*)"剪力模數:",G
write(10,*)"一半的基礎寬:",b,"m"
write(10,*)"元素長度 :",2*a,"m"
write(10,*)"L =",f,"*基礎寬 :",L
write(10,*)"沉陷量 :",uyi,"m"
call slove_Bij
(num,i,j,xi,xj,a,bij,bij1,bij2,bij3,bij4,pr,G,Matrix_Bij,U,uyi,L,b,a1,a2,a3,a4)
call solve (U,Matrix_Bij,T,num,uyi)
!
call compare (num,g,uyi,b,pr,Y,Tyy,xi,a,i)
!
call sum (ux,uy,zxx,zxy,zyy,uyi,r1,r2,th1,th2,y,a,d,f,b,pr,num,&
PI,G,L,T,Matrix_x,Matrix_y,Matrix_xx,Matrix_xy,Matrix_yy,sumzxx,sumzxy,sumzyy)
!
stop
end program homework01
! 解Bij subroutine1 Matrix_Bij
subroutine slove_Bij
(num,i,j,xi,xj,a,bij,bij1,bij2,bij3,bij4,pr,G,Matrix_Bij,U,uyi,L,b,a1,a2,a3,a4)
implicit none
integer::num,i,j
real::U(20)
real::Matrix_Bij(20,20)
real::T(20)
real::a,b,G,xi,xj,pr,n,L,bij,bij1,bij2,bij3,bij4,uyi,PI,E,a1,a2,a3,a4
PI=3.14159
E=10000
pr=0.3
G=0.5*(E/(1+pr))
uyi=-0.03
! 定義元素
a=b/num
write(10,*)"L :"
write(10,*)L
write(10,*)"a:"
write(10,*)a
write(10,*)"Bij :"
do I=1,num
xi=-b+(2*i-1)*a
do j=1,num
xj=-b+(2*j-1)*a
a1=abs(xi-xj+a)
a2=abs(xi-xj-a)
a3=(L-xj-a)
a4=(L-xj+a)
write(10,*)"i"
write(10,*)i
write(10,*)"j:"
write(10,*)j
write(10,*)"xi:"
write(10,*)xi
write(10,*)"xj:"
write(10,*)xj
bij1=(xi-xj+a)*log(a1)
bij2=(xi-xj-a)*log(a2)
bij3=(L-xj-a)*log(a3)
bij4=(L-xj+a)*log(a4)
bij=-((1-pr)/(PI*G))*(bij1-bij2+bij3-bij4)
Matrix_Bij(i,j)=bij
write(10,*)"Bij :"
write(10,*)bij
write(*,*)"Bij :"
write(*,*)bij
Matrix_Bij(i,j)=bij
end do
end do
! uyi
do i=1,num
U(i)=uyi
write(10,*)"uyi :"
write(10,*)U(i)
end do
return
end subroutine
! 比較理論解與數值分析 subroutine3 compare
subroutine compare (num,G,uyi,b,pr,Y,Tyy,xi,a,i)
implicit none
integer::num,i
real::Y(20)
real::Tyy
real::G,uyi,b,pr,xi,a
write(10,*)"解析解為 :"
write(*,*)"解析解為 :"
do i=1,num
a=b/num
xi=(-1)*b+(2*i-1)*a
Tyy=(((-1)*G*uyi)/((1-pr)*0.69314718))*(1/((b**2-xi**2)**0.5))
write(10,*)Tyy
write(*,*)Tyy
end do
write(*,*)"---------------"
return
end subroutine
! 第二題 subroutine4 summary
subroutine sum (ux,uy,zxx,zxy,zyy,uyi,r1,r2,th1,th2,y,a,d,f,b,pr,num,&
PI,G,L,Matrix_C,Matrix_x,Matrix_y,Matrix_xx,Matrix_xy,Matrix_yy,sumzxx,sumzxy,sumzyy)
integer::num,i
real::ux,uy,zxx,zxy,zyy,r1,r2,th1,th2,uyi,a,b,f,PI,G,pr,L,o
real::sumux,sumuy,sumzxx,sumzxy,sumzyy
real::MATRIX_C(20)
real::MATRIX_x(20)
real::MATRIX_y(20)
real::MATRIX_xx(20)
real::MATRIX_yy(20)
real::MATRIX_xy(20)
L=b*f
y=-1
r1=(x-a)**2+y**2
r2=(x+a)**2+y**2
do i=1,num
sumux=0
sumuy=0
sumuzxx=0
sumuzxy=0
sumuzyy=0
xi=-b+(2*i-1)*a
do j=1,num
xj=-b+(2*i-1)*a
x=xi-xj
th1=Atan(y/(x-a))
th2=Atan(y/(x+a))
if((x-a) .le.0 .and. y .ge.0) then
th1=th1+PI
th2=th2+PI
end if
if((x+a) .le.0 .and. y .le.0) then
th1=th1-PI
th2=th2-PI
end if
ux=(-1*Matrix_C(i)/(2*PI*G))*((1-2*pr)*((x-a)*th1-(x+a)*th2-PI*a)+(1-pr)*y*(log(r1/r2)))
uy=(1*Matrix_C(i)/(2*PI*G))*(-(1-2*pr)*y*(th1-th2)&
+(1-pr)*((x-a)*LOG(r1)-(x+a)*LOG(r2)+(L+a)*(LOG(L+a)**2)-(L-a)*(LOG(L-a)**2)))
zxx=(-1*Matrix_C(i)/PI)*(th1-th2+y*(x-a)/r1-y*(x+a)/r2)
zyy=(-1*Matrix_C(i)/PI)*(th1-th2-y*(x-a)/r1+y*(x+a)/r2)
zxy=(-1*Matrix_C(i)/PI)*y**2*(1/(r1)-1/(r2))
Sumux=Sumux+ux
Sumuy=Sumuy+uy
Sumuzxx=Sumuzxx+zxx
Sumuzxy=Sumuzxy+zxy
Sumuzyy=Sumuzyy+zyy
write(10,*)ux,uy,zxx,zxy,zyy,Matrix_C(i)
end do
write(10,*)
write(*,*)
write(10,*)sumux,"sumux"
write(10,*)sumuy,"sumuy"
write(10,*)sumuzxx,"sumuzxx"
write(10,*)sumuzxy,"sumuzxy"
write(10,*)sumuzyy,"sumuzyy"
write(*,*)sumux,"sumux"
write(*,*)sumuy,"sumuy"
write(*,*)sumuzxx,"sumuzxx"
write(*,*)sumuzxy,"sumuzxy"
write(*,*)sumuzyy,"sumuzyy"
end do
write(*,*)"---------------"
return
end subroutine
SUBROUTINE SOLVE(b,a,x,N,uyi)
implicit none
integer::i,j,m,k,nb,n,l,jj
real::b(20)
real::a(20,20)
real::x(20)
real::E,sum,uyi,xm
NB=N-1
DO 20 J=1,NB
L=J+1
DO 20 JJ=L,N
XM=A(JJ,J)/A(J,J)
DO 10 I=J,N
10 A(JJ,I)=A(JJ,I)-A(J,I)*XM
20 B(JJ)=B(JJ)-B(J)*XM
X(N)=B(N)/A(N,N)
DO 40 J=1,NB
JJ=N-J
L=JJ+1
SUM=0.
DO 30 I=L,N
30 SUM=SUM+A(JJ,I)*X(I)
40 X(JJ)=(B(JJ)-SUM)/A(JJ,JJ)
write(*,*)"Ty:"
write(10,*)"Ty:"
do 60 j=1,n
write(*,*)x(j)
write(10,*)x(j)
60 continue
RETURN
END
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.28.104
→
12/10 16:58, , 1F
12/10 16:58, 1F
我也不清楚在哪,但是怎麼跑就是會有>test1 - 2 error(s), 0 warning(s)出現
→
12/10 18:11, , 2F
12/10 18:11, 2F
→
12/10 18:12, , 3F
12/10 18:12, 3F
→
12/10 18:12, , 4F
12/10 18:12, 4F
回M大,謝謝你概略的幫我看過,我剛剛把你說的地方移回去過了,一樣還是兩個錯
→
12/10 19:39, , 5F
12/10 19:39, 5F
→
12/10 19:40, , 6F
12/10 19:40, 6F
→
12/10 19:41, , 7F
12/10 19:41, 7F
回M大,請問IVF設定問題是什麼意思呢?如果要我貼圖片是貼"顯示輸出視窗"嗎?
不是DOS視窗那個,是會顯示檔案是否建置成功那個!
→
12/11 09:44, , 8F
12/11 09:44, 8F
→
12/11 09:45, , 9F
12/11 09:45, 9F
謝謝M大的熱心回應,沒有助教可以問說,目前在新版fortran執行算是還在嘗試階段,
我有考慮過如果新版無法執行,那就直接用舊版的編輯器呈現就好了,畢竟m大也幫我
看過,程式碼沒問題我就放心了!
※ 編輯: Kira76 來自: 140.120.28.104 (12/11 12:07)
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章