|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
bplevenson
Joined: 02 Nov 2006 Posts: 21
|
Posted: Thu Nov 09, 2006 6:37 am Post subject: Why is it telling me I have two main programs? |
|
|
I'm writing a very simple climate model program which calls a logical function, DoneYet, to signal the program when the simulation is done. Here's the code:
-------------------------------------------------------------------------------------------------
!=====
! RadA is a time-marching radiative equilibrium model of Earth's
! atmosphere.
!=====
Module RadAstuff
! Run parameters:
integer, parameter :: N = 20 ! Number of atmosphere layers.
integer, parameter :: ground = N + 1
integer, parameter :: Nlayers = ground
! Type definitions:
Type layer
real(kind=2) :: aIR ! IR absorptivity.
real(kind=2) :: rIR ! Reflectance.
real(kind=2) :: tIR ! Transmittance.
real(kind=2) :: aVis ! Visual absorptivity.
real(kind=2) :: rVis ! Reflectance.
real(kind=2) :: tVis ! Transmittance.
real(kind=2) :: cp ! Specific heat, J/kg/K.
real(kind=2) :: g ! Lapse rate, K/km.
real(kind=2) :: ht ! Layer height, m.
real(kind=2) :: m ! Mass, kg.
real(kind=2) :: T ! Temperature, K.
real(kind=2) :: z ! Mean altitude, m.
End Type layer
! Global variables:
Type(layer) :: L(Nlayers) ! The layers.
End Module RadAstuff
!=====
! main routine starts here.
!=====
Program Demo
use RadAstuff
implicit none
integer :: i ! Loop counter.
logical :: small ! True when we're done.
!-----
! Main processing loop:
do
small = DoneYet ! Are we done yet?
if (small) exit ! If so, leave the loop.
do i = 1, ground
write(*, *) i, L(i)%T, L(i)%ht, L(i)%z, L(i)%g
end do
end do
! Clean up and quit:
write (*, *) 'Run ends'
End Program Demo
!=====
! DoneYet checks if temperature change since the last cycle is small
! enough to quit.
!=====
Logical Function DoneYet
use RadAstuff
DoneYet = .true.
End Function DoneYet
-------------------------------------------------------------------------------------------------
And here are the error messages:
-------------------------------------------------------------------------------------------------
Compiling file: Demo.f95
C:FortranDemo.F95(16) : comment 981 - Specifying the kind of the type REAL with the constant '2' is non-portable - 'SELECTED_REAL_KIND(15,307)' would be better
C:FortranDemo.F95(50) : warning 298 - Variable DONEYET has been used without being given an initial value
C:FortranDemo.F95(50) : error 250 - You cannot assign an expression of type REAL(KIND=1) to a variable of type LOGICAL(KIND=3)
C:FortranDemo.F95(50) : error 283 - DONEYET must appear in a type declaration because IMPLICIT NONE has been used
C:FortranDemo.F95(67) : error 775 - More than one main program encountered
C:FortranDemo.F95(67) : error 820 - 'D' found after FUNCTION where a comma was expected
C:FortranDemo.F95(6 : error 299 - Statement ordering error - USE cannot appear after type definition statements
C:FortranDemo.F95(71) : error 778 - END FUNCTION found where END PROGRAM was expected
Compilation failed
-------------------------------------------------------------------------------------------------
For some reason it's not recognizing DoneYet as a function. What am I doing wrong? I've looked all through the documentation and can't find anything under functions, arguments, calling conventions, etc. that explains what's going on here. Is the function improperly declared? How does one declare a function with no arguments?
-BPL |
|
Back to top |
|
|
bplevenson
Joined: 02 Nov 2006 Posts: 21
|
Posted: Thu Nov 09, 2006 6:41 am Post subject: Why is it telling me I have two main programs? |
|
|
Sorry, I forgot to hit "pre" on that one for the code. I'll try again:
---------------------------------------------------------------------------------------------------
[pre]!=====
! RadA is a time-marching radiative equilibrium model of Earth's
! atmosphere.
!=====
Module RadAstuff
! Run parameters:
integer, parameter :: N = 20 ! Number of atmosphere layers.
integer, parameter :: ground = N + 1
integer, parameter :: Nlayers = ground
! Type definitions:
Type layer
real(kind=2) :: aIR ! IR absorptivity.
real(kind=2) :: rIR ! Reflectance.
real(kind=2) :: tIR ! Transmittance.
real(kind=2) :: aVis ! Visual absorptivity.
real(kind=2) :: rVis ! Reflectance.
real(kind=2) :: tVis ! Transmittance.
real(kind=2) :: cp ! Specific heat, J/kg/K.
real(kind=2) :: g ! Lapse rate, K/km.
real(kind=2) :: ht ! Layer height, m.
real(kind=2) :: m ! Mass, kg.
real(kind=2) :: T ! Temperature, K.
real(kind=2) :: z ! Mean altitude, m.
End Type layer
! Global variables:
Type(layer) :: L(Nlayers) ! The layers.
End Module RadAstuff
!=====
! main routine starts here.
!=====
Program Demo
use RadAstuff
implicit none
integer :: i ! Loop counter.
logical :: small ! True when we're done.
!-----
! Main processing loop:
do
small = DoneYet ! Are we done yet?
if (small) exit ! If so, leave the loop.
do i = 1, ground
write(*, *) i, L(i)%T, L(i)%ht, L(i)%z, L(i)%g
end do
end do
! Clean up and quit:
write (*, *) 'Run ends'
End Program Demo
!=====
! DoneYet checks if temperature change since the last cycle is small
! enough to quit.
!=====
Logical Function DoneYet
use RadAstuff
DoneYet = .true.
End Function DoneYet[/pre]---------------------------------------------------------------------------------------------------
Well, that's not much better, but it's better than last time. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Thu Nov 09, 2006 6:50 am Post subject: Why is it telling me I have two main programs? |
|
|
Barton
DoneYet is external so you must declare it as LOGICAL
logical::small, DoneYet
Also you must use brackets in the call and in the definition.
small = DoneYet()
.......
logical function DoneYet()
|
|
Back to top |
|
|
bplevenson
Joined: 02 Nov 2006 Posts: 21
|
Posted: Thu Nov 09, 2006 8:48 am Post subject: Why is it telling me I have two main programs? |
|
|
[small]Paul Laidler wrote:[/small]
DoneYet is external so you must declare it as LOGICAL
logical::small, DoneYet
Also you must use brackets in the call and in the definition.
small = DoneYet()
It works! Thanks!
-BPL |
|
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
|