Silverfrost Forums

Welcome to our forums

Why is it telling me I have two main programs?

9 Nov 2006 5:37 #1241

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:\Fortran\Demo.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:\Fortran\Demo.F95(50) : warning 298 - Variable DONEYET has been used without being given an initial value C:\Fortran\Demo.F95(50) : error 250 - You cannot assign an expression of type REAL(KIND=1) to a variable of type LOGICAL(KIND=3) C:\Fortran\Demo.F95(50) : error 283 - DONEYET must appear in a type declaration because IMPLICIT NONE has been used C:\Fortran\Demo.F95(67) : error 775 - More than one main program encountered C:\Fortran\Demo.F95(67) : error 820 - 'D' found after FUNCTION where a comma was expected C:\Fortran\Demo.F95(68) : error 299 - Statement ordering error - USE cannot appear after type definition statements C:\Fortran\Demo.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

9 Nov 2006 5:41 #1242

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.

9 Nov 2006 5:50 #1243

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()

9 Nov 2006 7:48 #1244

[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

Please login to reply.