C program to open file

advertisement
C program to open file
integer, parameter:: n=17
real, dimension(n)::to,tm,tempo,tempm
open(61,file='Temperature.txt')
open(51,file='tempimd.txt')
open(71,file='adding.txt')
do 1 i=1,n
read(61,*) tempo(i)
read(51,*) tempm(i)
1 continue
sumto=0
sumtm=0
do 2 i=1,n
sumto=tempo(i)+sumto
sumtm=sumtm+tempm(i)
2 continue
sumto=sumto/float(n)
sumtm=sumtm/float(n)
print*, sumto
C-------------------------------C--------RMS-------------------sumrmsetempm=0
do 3 i=1,n
sdtemp=(tempo(i)-tempm(i))**2
sumrmsetempm=sumrmsetempm+sdtemp
3 continue
sumrmsetempm=sumrmsetempm/float(n)
rmstempm=sqrt(sumrmsetempm)
print*, "RMS value is ", rmstempm
write(71,21)rmstempm
21 format(3x,'RMS is ', f10.3)
C--------------------------------C-------------FB-----------------FBtempm=(2*(sumto-sumtm))/(sumtm-sumto)
print*, "FBtemp is ", FBtempm
write(71,22)FBtempm
22 format(3x,'FBtemp is ', f10.3)
C----------------------------------C------------NMSE-----------------sumnmsetemp=0
do 4 i=1,n
tempmnodif=(tempo(i)-tempm(i))**2
sumnmsetempm=sumnmsetempm+tempmnodif
4 continue
sumnmsetempm=sumnmsetempm/float(n)
tempmnmse=sumnmsetempm/(sumto*sumtm)
write(71,23)tempmnmse
23 format(3x,'NMSE temperature is', f10.3)
print*, "NMSE temperature is ", tempmnmse
C-----------------------------------------------
C------------bias or me---------------------tempmne=sumto-sumtm
write(71,24)tempmne
24 format(3x,'Tempmne is ', f10.3)
print*, "Tempmne is ", tempmne
C-------------------------------------------------C-----------------Correlation Coefficient-----------stnum=0
sto=0
stm=0
do 5 i=1,n
tempodif=tempo(i)-sumto
tempmdif=tempm(i)-sumtm
stempodif=tempodif**2
stempmdif=tempmdif**2
tempmrnum=tempodif*tempmdif
stnum=stnum+tempmrnum
sto=sto+stempodif
stm=stm+stempmdif
5 continue
stnum=stnum/float(n)
sto=sto/float(n)
stm=stm/float(n)
sigmatempo=sqrt(sto)
sigmatempm=sqrt(stm)
tempmr=stnum/(sigmatempo*sigmatempm)
write(71,25)tempmr
25 format(3x,'CC is ', f10.3)
print*, "CC is ", tempmr
write(71,26)sumtm
write(71,27)sumto
26 format(3x,'sumtm is ', f10.3)
27 format(3x,'sumto is ', f10.3)
stop
end
----------------------------------------------------------------------------
C program to test RungeKutta method
c
IMPLICIT none
c
c
declarations
c nsteps:number of steps, tstep:length of steps, y: initial position
c
REAL*8 t,y1,y2,y3,tstep
INTEGER:: i,j,nsteps
nsteps=100
tstep=0.01
y1=1
y2=0
y3=0
c
c
open file
OPEN(6, FILE='rungef.dat')
WRITE (6,*) 0, y1, y2, y3
c
c
do loop nsteps of Runga-Kutta algorithm
DO 60 j = 1, nsteps
t=j*tstep
call rk4(t,y1,y2,y3,tstep)
WRITE (6,*) t,y1,y2,y3
60
CONTINUE
c
CLOSE(6)
STOP
END
c------------------------end of main program-----------------------c
c
fourth-order Runge-Kutta subroutine
SUBROUTINE rk4(t,y1,y2,y3,tstep)
IMPLICIT none
c
c
declarations
REAL*8 DERIV1,DERIV2,DERIV3, h, t, tstep,y1,y2,y3
REAL*8 k11,k12,k13,k14,k21,k22,k23,k24,k31
real*8 k32,k33,k34,k41,k42,k43,k44
INTEGER:: i, N
h=tstep/2.0
c
k11 = h * DERIV1(y1,y2,y3,t)
k21 = h * DERIV2(y1,y2,y3,t)
k31 = h * DERIV3(y1,y2,y3,t)
k12 = h * DERIV1(y1+k11/2,y2+k21/2,y3+k31/2,t+h/2)
k22 = h * DERIV2(y1+k11/2,y2+k21/2,y3+k31/2,t+h/2)
k32 = h * DERIV3(y1+k11/2,y2+k21/2,y3+k31/2,t+h/2)
k13 = h * DERIV1(y1+k12/2,y2+k22/2,y3+k32/2,t+h/2)
k23 = h * DERIV2(y1+k12/2,y2+k22/2,y3+k32/2,t+h/2)
k33 = h * DERIV3(y1+k12/2,y2+k22/2,y3+k32/2,t+h/2)
k14 = h * DERIV1(y1+k13,y2+k23,y3+k33,t+h)
k24 = h * DERIV2(y1+k13,y2+k23,y3+k33,t+h)
k34 = h * DERIV3(y1+k13,y2+k23,y3+k33,t+h)
c
y1 = y1 + (k11 + (2.*(k12 + k13)) + k14)/6.0
y2 = y2 + (k21 + (2.*(k22 + k23)) + k24)/6.0
y3 = y3 + (k31 + (2.*(k32 + k33)) + k34)/6.0
c
RETURN
END
c
c
function which returns the derivatives
FUNCTION DERIV1(y1,y2,y3,t)
IMPLICIT none
c
c
declarations
REAL*8 DERIV1,y1,y2,y3,t
INTEGER :: sigma
sigma=30
c
DERIV1=sigma*(y1-y2)
c
RETURN
END
FUNCTION DERIV2(y1,y2,y3,t)
IMPLICIT none
c
c
declarations
REAL*8 DERIV2,y1,y2,y3,t,r
r=25
c
DERIV2=-y1*y3+r*y1-y2
c
RETURN
END
FUNCTION DERIV3(y1,y2,y3,t)
IMPLICIT none
c
c
declarations
REAL*8 DERIV3,y1,y2,y3,t,b
b=8/3
c
DERIV3=y1*y2-b*y3
c
RETURN
END
--------------------------------------------------------------------------------
C program for Forced damped Pendulum
implicit none
real*8 t,y1,y2,tstep,pi
integer i,j,nstep
nstep=1000
tstep=0.094
y1=0
y2=2
pi=4.0*atan(1.0)
C open file
open(6,file='FDP.dat')
write(6,*)0, y1, y2
C do loop n steps of runga kutta algorithm
do 60 i=1, nstep
t=i*tstep
call rk4(t,y1,y2,tstep)
y1=y1-2*pi*nint(y1/(2*pi))
y2=y2-2*pi*nint(y2/(2*pi))
write(6,*)t,y1,y2
60 continue
close(6)
stop
end
C----------------end of main program-------------------------c-----------------------------------------------------------C-----------4th order runge kutta method-------------------
subroutine rk4(t,y1,y2,tstep)
implicit none
C--------Variable declaration--------------real*8 fun1,fun2,h,t,tstep,y1,y2
real*8 k11,k12,k21,k22,k31,k32,k41,k42
h=tstep/2
C--------------Computing----------------k11=h*fun1(t,y1,y2)
k21=h*fun2(t,y1,y2)
k12=h*fun1(t+h/2,y1+k11/2,y2+k21)
k22=h*fun2(t+h/2,y1+k11/2,y2+k21)
k31=h*fun1(t+h/2,y1+k12/2,y2+k22/2)
k41=h*fun2(t+h/2,y1+k12/2,y2+k22/2)
k32=h*fun1(t+h,y1+k31,y2+k41)
k42=h*fun2(t+h,y1+k31,y2+k41)
y1 = y1 + (k11 + (2.*(k12 + k31)) + k41)/6.0
y2 = y2 + (k21 + (2.*(k22 + k32)) + k42)/6.0
return
end
C----------------functions------------------------function fun1(t,y1,y2)
implicit none
real*8 fun1,t,y1,y2
fun1=y2
return
end
function fun2(t,y1,y2)
implicit none
real*8 fun2,t,y1,y2,q,b,w
q=0.5
b=1.2
w=2/3
fun2=-q*y2-sin(y1)+b*cos(w*t)
return
end
Download