forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why is it telling me I have two main programs?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
bplevenson



Joined: 02 Nov 2006
Posts: 21

PostPosted: Thu Nov 09, 2006 6:37 am    Post subject: Why is it telling me I have two main programs? Reply with quote

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(6Cool : 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
View user's profile Send private message
bplevenson



Joined: 02 Nov 2006
Posts: 21

PostPosted: Thu Nov 09, 2006 6:41 am    Post subject: Why is it telling me I have two main programs? Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Nov 09, 2006 6:50 am    Post subject: Why is it telling me I have two main programs? Reply with quote

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
View user's profile Send private message AIM Address
bplevenson



Joined: 02 Nov 2006
Posts: 21

PostPosted: Thu Nov 09, 2006 8:48 am    Post subject: Why is it telling me I have two main programs? Reply with quote

[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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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