current date & time from Fortran

current date & time from Fortran

Post by Jim Jennin » Wed, 29 Apr 1992 05:37:26



Is there an easy way to get the current system time & date in
Fortran on an RS/6000 running AIX 3.1.5?  The closest thing I can
find in the Fortran manuals is MCLOCK which returns cpu time.
The FAQ list doesn't seem to have anything about it.

It would also be nice to get the current time in ticks or
milliseconds (or something like it) for the purpose of setting the
seed of a random number generator.

I will write the C interfaces if I have too, I was just wondering
if there was an easier way that I have missed.

....................................................................
Jim Jennings   Voice: (214) 754-6922   ARCO Exploration and    Plano

Disclamer:  Don't blame my employer for any dumb things I might say.

 
 
 

current date & time from Fortran

Post by Lawrence R. Do » Fri, 08 May 1992 10:25:15


  Jim> Article-I.D.: Arco.1992Apr27.203726.22775

  Jim> Is there an easy way to get the current system time & date in
  Jim> Fortran on an RS/6000 running AIX 3.1.5?  The closest thing I can
  Jim> find in the Fortran manuals is MCLOCK which returns cpu time.
  Jim> The FAQ list doesn't seem to have anything about it.

Jim,

Here is my version of FDATE() for the RS6000.  I wrote it to emulate
the FDATE routine of Sun f77. You can use IEpoch for the current
number of seconds since "the epoch."

                   Share and Enjoy,
                            Larry

................... Cut Along Dotted Line ...................
      Program Main

      External FDATE

        Character FDATE*24

      Write(*,'(A24)') FDATE()

      End

C---------------------------------------------------------------------C
C     FDATE() hack for RS6000                                         C
C     Returns character string of length 24 containing date           C
C     Usage: FDATE()                                                  C
C     LRD - Tue Mar 10 14:25:08 PST 1992                              C
C---------------------------------------------------------------------C

      Function FDATE()

      Implicit None

C     < VALUE

        Character*24 FDATE

C     < LOCAL

        Integer*4 SinceEpoch, IEpoch, IAddress, ith

        Character String(26)*1

        External TIME, CTIME

          Integer*4 TIME, CTIME

C     < The TIME subroutine returns the value of time in seconds since
C     < Epoch, (i.e., 00:00:00 GMT, January 1, 1970).  It is assigned
C     < to the integer variable SinceEpoch.  The variable IEpoch also
C     < contains the value of the number of seconds since Epoch.

      IEpoch = TIME(SinceEpoch)

C     < The ctime subroutine converts a time value pointed to by the
C     < Clock parameter, which represents the time in seconds since
C     < 00:00:00 Greenwich Mean Time (GMT), January 1, 1970, into a
C     < 26-character string in the following form:
C     <
C     <     Sun Sep 16 01:03:52 1973\n\0
C     <
C     < where \n is a newline and \0 is the ubiquitous null character
C     < that C requires to terminate all strings.  The variable
C     < IAddress contains the address of the character string created
C     < by ctime.

      IAddress = CTIME(SinceEpoch)

C     < Convert this address to a character string.  Note:
C     < %VAL(foobar) will return the contents of address foobar.
C     < String is a 26 element array with each element a character of
C     < length one.

      Call ADDRESS_TO_STRING( %VAL(IAddress), String, 26 )

C     < Extract the date from string String.  We do not want the
C     < end-of-line or the null characters. We do this with a do-loop
C     < because string is an array and FDATE is a plain character
C     < string.  These are different in FORTRAN (but identical in C).

      do ith = 1, 24
        FDATE(ith:ith) = String(ith)
      end do

      Return
      End

C---------------------------------------------------------------------C
C     The routine ADDRESS_TO_STRING is utterly stupid and should
C     perhaps be called 'COPY.'  The trick is that FDATE calls it by
C     value, passing the address, and picks the result by reference,
C     allowing access of the array.  Maybe there is a smarter way of
C     doing this, without the need of generating a new copy of the
C     data?
C---------------------------------------------------------------------C

      Subroutine ADDRESS_TO_STRING( Address, Array, N )

      Implicit None

C     < PASSED

        Integer*4 N

        Character*1 ADDRESS(N), ARRAY(N)

C     < LOCAL

        Integer ith

      Do ith= 1, N
        Array(ith) = Address(ith)
      End Do

      Return
      End
................... Cut Along Dotted Line ...................
--
                            Larry


 
 
 

1. date/time of a file compare with current date/time

Hi,

I hope i can drop my question about Linux shell programming here?

I'm writing a script in bash to find files. I'm using the slocate
programm, which is being runned every hour using a cron job, to create
it's database.

Now i want to know how long it is ago that the database has been
recreated. Zo i need to check the date and time from that file and
compare it with the current date and time. I know there must be easy to
do but i can't find the trick to do it.

Maikel van Gorkom

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Having 1.1.* kernel problems

3. Calling date and time in Fortran on RS/6000

4. procmail postprocessing question

5. run time date and syslog date/time conflict

6. No hostname or bogus ip?

7. how to get date/time using fortran (xlf) on IBM RS/6000

8. LinuX Journal

9. question obtain the current date and time on a UNIX system.

10. Getting current date and time.

11. WANTED: C routine to return current date/time

12. How to Compare File Date to Current Date

13. Get current time & schedule work in Kernel process