Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My error: REAL cannot be declared inside labelled DO block (perhaps missing CONTAINS or END statemen 1

Status
Not open for further replies.

hoanghiep

Technical User
Nov 7, 2015
3
RU
When I make a compile. the output shows me the following error:
-REAL cannot be declared inside labelled DO block (perhaps missing CONTAINS or END statement?)
Can any one help me with this problem?
Thank you!

Below is my code:

program researchwork
implicit none

integer, parameter :: ikind=selected_real_kind(p=15)
REAL (kind=ikind) :: nI,f10,f20,f30,f1,previousf1,f2,f3,phi1,previousphi1,phi2,phi10,phi20,n,H,smallnumber,error1,error2,Pr
REAL (kind=ikind) :: df1(1:4),df2(1:4),df3(1:4),dphi1(1:4),dphi2(1:4)


f10=0
f20=0
f30=2.0
phi10=1.0
phi20=1.0
nI=0
Pr=10.0


H=0.1

f1=f10
previousf1=0.0
f2=f20
f3=f30
phi1=phi10
previousphi1=0.0
phi2=phi20
smallnumber = 10.0_ikind**(-15.0)

do 10 n=nI,100,H
WRITE (2,*) n,f1,f2,f3,phi1,phi2,M1(f1,f2,f3,phi1,n),M2(f1,phi2,n)


df1(1)=H*f2
df2(1)=H*f3
df3(1)=H*M1(f1,f2,f3,phi1,n)
dphi1(1)=H*phi2
dphi2(1)=H*M2(f1,phi2,n)


df1(2)=H*(f2+df2(1)/2)
df2(2)=H*(f3+df3(1)/2)
df3(2)=H*M1(n + H/2,f1+df1(1)/2,f2+df2(1)/2,f3+df3(1)/2,phi1+dphi1(1)/2)
dphi1(2)=H*(phi2+dphi2(1)/2)
dphi2(2)=H*M2(n+H/2,f1+df1(1)/2,phi2+dphi2(1)/2)


df1(3)=H*(f2+df2(2)/2)
df2(3)=H*(f3+df3(2)/2)
df3(3)=H*M1(n + H/2,f1+df1(2)/2,f2+df2(2)/2,f3+df3(2)/2,phi1+dphi1(2)/2)
dphi1(3)=H*(phi2+dphi2(2)/2)
dphi2(3)=H*M2(n+H/2,f1+df1(2)/2,phi2+dphi2(2)/2)


df1(4)=H*(f2+df2(3))
df2(4)=H*(f3+df3(3))
df3(4)=H*M1(n + H,f1+df1(3),f2+df2(3),f3+df3(3),phi1+dphi1(3))
dphi1(4)=H*(phi2+dphi2(3))
dphi2(4)=H*M2(n+H,f1+df1(3),phi2+dphi2(3))

f1=f1+(df1(1)+2.0*df1(2)+2.0*df1(3)+df1(4))/6.0
f2=f2+(df2(1)+2.0*df2(2)+2.0*df2(3)+df2(4))/6.0
f3=f3+(df3(1)+2.0*df3(2)+2.0*df3(3)+df3(4))/6.0
phi1=phi1+(dphi1(1)+2.0*dphi1(2)+2.0*dphi1(3)+dphi1(4))/6.0
phi2=phi2+(dphi2(1)+2.0*dphi2(2)+2.0*dphi2(3)+dphi2(4))/6.0
error1=abs(f1-previousf1)
error2=abs(phi1-previousphi1)
if (error1<smallnumber .and. error2<smallnumber) then
print*,'f1 ',f1,'phi1 ',phi1
exit
end if
previousf1=f1
previousphi1=phi1


CONTINUE

REAL FUNCTION M1(n,f1,f2,f3,phi1)
REAL n,f1,f2,f3,phi1
M1=-3*f1*f3+2*f2*f2-phi1
end

REAL FUNCTION M2(n,f1,phi2)
REAL n,f1,phi2
M2=-3*Pr*f1*phi2
end

end program researchwork
 
What it is telling you is that the two function declarations cannot be inside the main program and that the end of your do block is missing.
Code:
...
do n = nI, 100, H  ! was do 10 nI, 100, H
...
end do ! was continue
end program researchwork

real function M1 ...
...
 
Thank Mr xwb for showing me my error. I have changed "do 10 nI, 100, H" into "do n = nI, 100, H" and put the two function declarartions out of do block. But when I look at the output, It seems that I have one more error.
Here is what Output says about the error:

M2 must appear in a type declaration because IMPLICIT NONE has been used
M1 must appear in a type declaration because IMPLICIT NONE has been used

Could you please tell me how can I fix this error?
Thank you!
 
Where your declarations are add
Code:
REAL M1, M2
 

I try to fix the program again. But then It does not run when I press 'start run'. Nothing happens even the black window
what's wrong with it?
Thank you!

Below is my code which has been edited.



program researchwork
implicit none

integer, parameter :: ikind=selected_real_kind(p=15)
real (kind=ikind :: nI,f10,f20,f30,f1,f2,previousf2,f3,phi1,previousphi1,phi2,phi10,phi20,n,H,smallnumber,error1,error2,Pr,df1(1:4),df2(1:4),df3(1:4),dphi1(1:4),dphi2(1:4),M1,M2

f10=0.0
f20=0.0
f30=2.0
phi10=1.0
phi20=1.0
nI=0.0
Pr=10.0


H=0.1

f1=f10
f2=f20
previousf2=0.0
f3=f30
phi1=phi10
previousphi1=0.0
phi2=phi20
smallnumber = 10.0_ikind**(-15.0)

do n=nI,100.0,H


df1(1)=H*f2
df2(1)=H*f3
df3(1)=H*M1(f1,f2,f3,phi1)
dphi1(1)=H*phi2
dphi2(1)=H*M2(f1,phi2)


df1(2)=H*(f2+df2(1)/2)
df2(2)=H*(f3+df3(1)/2)
df3(2)=H*M1(f1+df1(1)/2,f2+df2(1)/2,f3+df3(1)/2,phi1+dphi1(1)/2)
dphi1(2)=H*(phi2+dphi2(1)/2)
dphi2(2)=H*M2(f1+df1(1)/2,phi2+dphi2(1)/2)


df1(3)=H*(f2+df2(2)/2)
df2(3)=H*(f3+df3(2)/2)
df3(3)=H*M1(f1+df1(2)/2,f2+df2(2)/2,f3+df3(2)/2,phi1+dphi1(2)/2)
dphi1(3)=H*(phi2+dphi2(2)/2)
dphi2(3)=H*M2(f1+df1(2)/2,phi2+dphi2(2)/2)

df1(4)=H*(f2+df2(3))
df2(4)=H*(f3+df3(3))
df3(4)=H*M1(f1+df1(3),f2+df2(3),f3+df3(3),phi1+dphi1(3))
dphi1(4)=H*(phi2+dphi2(3))
dphi2(4)=H*M2(f1+df1(3),phi2+dphi2(3))

f1=f1+(df1(1)+2.0*df1(2)+2.0*df1(3)+df1(4))/6.0
f2=f2+(df2(1)+2.0*df2(2)+2.0*df2(3)+df2(4))/6.0
f3=f3+(df3(1)+2.0*df3(2)+2.0*df3(3)+df3(4))/6.0
phi1=phi1+(dphi1(1)+2.0*dphi1(2)+2.0*dphi1(3)+dphi1(4))/6.0
phi2=phi2+(dphi2(1)+2.0*dphi2(2)+2.0*dphi2(3)+dphi2(4))/6.0
error1=abs(f2-previousf2)
error2=abs(phi1-previousphi1)
if (error1<smallnumber .and. error2<smallnumber) then
write(*,10) 'f1 is ',f1
format(a,2f10.3)
exit
end if
previousf2=f2
previousphi1=phi1


end do
end program researchwork

real function M1(f1,f2,f3,phi1)
implicit none
integer, parameter :: ikind=selected_real_kind(p=15)
real (kind=ikind) :: f1,f2,f3,phi1
M1=-3.0*f1*f3+2*f2*f2-phi1
end function M1

real function M2(f1,phi2)
implicit none
integer, parameter :: ikind=selected_real_kind(p=15)
real (kind=ikind) :: f1,phi2
M2=-3.0*10.0*f1*phi2
end function M2

 
I suspect that your "smallnumber" is far too small so your program writes nothing.



François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top