Topic: A simple clock timer

The following works well in Fortran 95:
!Timer variables
real(4)                 :: time1, time2
!Start timer
time1=secnds(0.0)
(do stuff)
! Stop timer and write
time2=secnds(time1)
WRITE (*,'(A,F8.2)')     "Time (sec):", time2

But in Fortran 77 I get these error messages:
     time1=secnds(0.0)                                                 
       1
Error: Syntax error in DATA statement at (1)

      time2=secnds(time1)                                               
                   1
Error: 'x' argument of 'secnds' intrinsic at (1) must be of kind 4

Any ideas?

Re: A simple clock timer

I'm not sure I understand the problem you're experiencing.  The code you posted is obviously Fortran 90+ code.  When you say you're receiving the error in Fortran 77, are you using code modified to be in fixed-format?

I should also point out that the SECNDS intrinsic is a GNU extension who's use is discouraged.  I would suggest looking instead at using the CPU_TIME intrinsic procedure, which is part of the Fortran 95 standard.  That way you'll ensure code portability.

Jeff Armstrong
Approximatrix, LLC

Re: A simple clock timer

Yes, so it works in F90+ programs but when I plug it into an F77 program it doesn't.
If I compile the F77 program without the compiler flag -std=legacy it compiles OK, but I'm worried this may lead to other problems.
So I guess the question is:
What is the equivalent F77 code? Or where can I find another simple clock (not CPU) timer in F77?

Re: A simple clock timer

The problem you're encountering is that the timer intrinsic procedures are only available in Fortran 90 and higher.  If you set the compiler to enforce the legacy standard, Fortran 77, the compiler specifically disallows these intrinsics.  The Fortran 77 standard doesn't provide or specify any way to do what you're asking except, perhaps, via a custom, 3rd party, system-dependent library.

I would suggest using the CPU_TIME intrinsic with your fixed-format (Fortran-77-style) source code.  While it isn't part of the Fortran 77 standard, it is at least part of later standards.  If you need to port your code to other compilers, the CPU_TIME intrinsic will be supported by other compilers if they allow you to use Fortran 90+ intrinsics with fixed-format source code (almost every one will).  The use of SECNDS is discouraged simply because it is a GNU Fortran extension, and it may not be supported by other compilers.

Jeff Armstrong
Approximatrix, LLC