Need help writing second() function 
Author Message
 Need help writing second() function

I need to write a fortran function that returns the number of seconds
from an arbitrary time.  In C this would look something like:

#include <sys/time.h>

/* the needed seconds function to return the time in seconds */
float second()
{
   return (float) time(NULL);

Quote:
}

Can someone give me the fortran code?  Thanks.

        Mark
--




Sat, 01 Feb 1997 02:21:24 GMT  
 Need help writing second() function

Quote:
>I need to write a Fortran function that returns the number of seconds
>from an arbitrary time.  In C this would look something like:
>#include <sys/time.h>
>/* the needed seconds function to return the time in seconds */
>float second()
>{
>   return (float) time(NULL);
>}
>Can someone give me the fortran code?  Thanks.
>    Mark
>--


  First, you should be aware that seconds() is NOT an ANSI C standard
function.  Apparently, it is a standard Unix library function, but
remember that not every operating system is a version of Unix.

  Fortran 90 does not provide a seconds function directly but it is
very easy to construct one.  Fortran 90 provides two intrinsic
subroutines which deal with dates and times:

  DATE_AND_TIME - returns the current date and time in both character
and numerical format.

  SYSTEM_CLOCK - returns the elapsed time since midnight in processor
dependent units (which are usually clock ticks but MAY be anything
else).

  I usually find it easier to work with DATE_AND_TIME since its units
are precisely defined and you can use it to construct a function that
works properly if midnight occurs while your program is running or your
program runs over several days.

  Note that all of this concerns ELAPSED time, NOT CPU time.  I hope
that this helps.

Sincerely,
--

Elmbrook Computer Services      Voice Phone: (414) 783-5869
17130 W. Burleigh Place        
Brookfield, WI   53005          Disclaimer:  These opinions are mine alone.
USA                             They do NOT represent any organization.

"Those who would give up essential Liberty, to purchase a little temporary
    Safety, deserve neither Liberty nor Safety."    -- Benjamin Franklin



Sat, 01 Feb 1997 21:14:25 GMT  
 Need help writing second() function

Quote:
>I need to write a Fortran function that returns the number of seconds
>from an arbitrary time.  In C this would look something like:

>#include <sys/time.h>

>/* the needed seconds function to return the time in seconds */
>float second()
>{
>   return (float) time(NULL);
>}

>Can someone give me the fortran code?  Thanks.

The answer depends on what you mean by Fortran.

There is no F77 solution for your problem.
In F90 you can use the SYSTEM_CLOCK subroutine.
On a Unix box, you can use the TIME function. "man 3f time" for details.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Sun, 02 Feb 1997 01:13:41 GMT  
 Need help writing second() function

Quote:

>>I need to write a Fortran function that returns the number of seconds
>>from an arbitrary time.  In C this would look something like:

>>#include <sys/time.h>

>>/* the needed seconds function to return the time in seconds */
>>float second()
>>{
>>   return (float) time(NULL);
>>}

>  First, you should be aware that seconds() is NOT an ANSI C standard
>function.  Apparently, it is a standard Unix library function, but
>remember that not every operating system is a version of Unix.

Of course it's not an ANSI C standard function, that's precisely why
he had to implement it himself. But the implementation is standard ANSI
(apart from the fact that he included <sys/time.h> instead of <time.h>)
because time() is a standard C library function.

What is not guaranteed by the standard is the fact that time() returns
a number of seconds elapsed since some origin.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Tue, 04 Feb 1997 01:36:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help in writing F77 subroutine and function!!!

2. FUNCTION second() NEEDED

3. Please help with function Date and seconds.

4. List box position - Second Posting - Need Help

5. Need Help with Date and Seconds.

6. second try - need help with iwidgets extfileselectionbox

7. help trying to write a function

8. Help writing lisp function

9. how to write function that returns function

10. how to write function that returns function

11. need some help writing a awk command

12. Need help with writing a factorial method

 

 
Powered by phpBB® Forum Software