|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Dič
Joined: 21 Sep 2008 Posts: 3 Location: french
|
Posted: Sat Jan 03, 2009 3:58 pm Post subject: Integrale,winio+ and fortran95 |
|
|
good morning
Thanks to LitusSaxonicum and PaulLaidler about your help
now my program is running and give very good results
WINAPP
INCLUDE<windows.ins>
DOUBLE PRECISION A,B,somme
CHARACTER*50 s
COMMON A,B,somme,N
INTEGER i,w,N
EXTERNAL TRAP
A=0.0E0
B=0.0E0
somme=0.0E0
N=0
i=winio@('%ca[Calcule une integrale]&')
s='{integral A;B} (X+1)dx=somme'
w=winio@('%ob%eq@%cb&',s,0,0)
w=winio@('&')
i=winio@('%5tl&',1,2,3,4,5)
i=winio@('%ffA=%ta&')
i=winio@('%rf&',A)
i=winio@('%ffB=%ta&')
i=winio@('%rf&',B)
i=winio@('%ffsomme=%ta&')
i=winio@('%rf&',somme)
i=winio@('%ffN=%ta&')
i=winio@('%rd&',N)
i=winio@('%ta%`^12bt[INTEGRATION]',TRAP)
END
FUNCTION F(T)
REAL(SELECTED_REAL_KIND(15,307))T
F=T+1
RETURN
END
REAL FUNCTION TRAP()
INTEGER I,N
COMMON A,B,somme,N
REAL (SELECTED_REAL_KIND(15,307))X,B,A,somme
DX=(B-A)/N
TRAPE=(F(A)+F(B))/2
X=A
DO 10 I=1,N-1
X=X+DX
TRAPE=TRAPE+F(X)
10 CONTINUE
TRAP=TRAPE*DX
somme=TRAP
CALL window_update@(somme)
RETURN
END
your very truly[/img] |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat Jan 03, 2009 4:41 pm Post subject: |
|
|
I'm a great believer in adding white space. I put in some code to catch the obvious error cases - there may be more. The TRAP function should be an INTEGER FUNCTION. You don't need to use the variable "TRAP" in calculating "somme".
Code: | WINAPP
OPTIONS (INTL)
PROGRAM INTEGRATOR
INCLUDE<windows.ins>
DOUBLE PRECISION A, B, somme
CHARACTER*50 s
COMMON A, B, somme, N
INTEGER i, w, N
EXTERNAL TRAP
A = 0.0D0
B = 0.0D0
somme = 0.0D0
N = 0
i=winio@('%ca[Calcule une integrale]&')
s='{integral A;B} (X+1)dx=somme'
w=winio@('%ob%eq@%cb&',s,0,0)
w=winio@('&')
i=winio@('%5tl&',1,2,3,4,5)
i=winio@('%ffA=%ta&')
i=winio@('%rf&',A)
i=winio@('%ffB=%ta&')
i=winio@('%rf&',B)
i=winio@('%ffsomme=%ta&')
i=winio@('%rf&',somme)
i=winio@('%ffN=%ta&')
i=winio@('%rd&',N)
i=winio@('%ta%`^12bt[INTEGRATION]',TRAP)
END
FUNCTION F(T)
REAL(SELECTED_REAL_KIND(15,307))T
F=T+1.0D0
RETURN
END
INTEGER FUNCTION TRAP()
INTEGER I, N
COMMON A, B, somme, N
REAL (SELECTED_REAL_KIND(15,307)) X, B, A, somme
INCLUDE <WINDOWS.INS>
IF (A .EQ. B .OR. N .EQ. 0) THEN
IA=WINIO@('%ca[Error!]%cn%si!%ff%nl%cnCannot integrate this&')
IA=WINIO@('%2nl%cn%bt[OK]')
TRAP = 1
RETURN
ENDIF
DX = (B-A)/N
TRAPE = (F(A)+F(B))/2.0D0
X = A
DO 10 I=1,N-1
X = X + DX
TRAPE = TRAPE+F(X)
10 CONTINUE
somme=TRAPE*DX
CALL window_update@(somme)
TRAP = 1
RETURN
END |
Happy New Year
Eddie |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|