Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
clock.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 #pragma ident "@(#) libfi/element/clock.c       92.1    06/16/99 15:47:23"
00038 #include <fortran.h> 
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <time.h>
00042 #include <sys/types.h>
00043 
00044 /*
00045  *      CLOCK   Returns the current time in "HH:MM:SS" format.
00046  *              HH = Hour (0 - 23).
00047  *              MM = Minute (00 - 59).
00048  *              SS = Second (00 - 59).
00049  *
00050  *              May be called as either a function or a subroutine.
00051  *              If called as a subroutine, the parameter may be
00052  *              either CHARACTER or INTEGER type.
00053  */
00054 
00055 /*
00056  *      Duplicate names
00057  *
00058  *      _CLOCK_         - for f90 
00059  *      CLOCK           - for PVP & MPP systems if called as a subroutine
00060  *      $CLOCK          - for cf77
00061  *      _CLOCK          - for f90 3.0? and previous on PVP systems 
00062  */
00063 
00064 #if     !defined(__mips) && !defined(_LITTLE_ENDIAN)
00065 #pragma _CRI duplicate _CLOCK_ as CLOCK
00066 #pragma _CRI duplicate _CLOCK_ as $CLOCK
00067 #pragma _CRI duplicate _CLOCK_ as _CLOCK
00068 #endif
00069 
00070 #define CLOCK_CHRS      8
00071 
00072 #ifdef _UNICOS
00073 _f_int
00074 #else
00075 void
00076 #endif
00077 _CLOCK_(timeofday)
00078 _fcd    timeofday;
00079 {
00080 #ifdef  _UNICOS
00081         long            clock;
00082 #endif
00083         struct tm       *sp;
00084         time_t          now;
00085         char            str[CLOCK_CHRS + 1];
00086  
00087         now     = time((time_t *) NULL);
00088         sp      = localtime(&now);
00089 
00090         (void) sprintf(str, "%02d:%02d:%02d", sp->tm_hour, sp->tm_min,
00091                         sp->tm_sec);
00092 
00093 
00094 #ifdef  _UNICOS
00095         clock   = *(long *) str;
00096 
00097         if (_numargs() > 0) 
00098 #ifdef  _isfcd
00099                 if (! _isfcd(timeofday)) {      /* If Hollerith */
00100 #elif   defined(_UNICOS) && defined(_ADDR64)
00101                 if (_numargs() == 1) {          /* If Hollerith */
00102 #endif
00103                         **(long **) &timeofday  = clock;
00104                 }
00105                 else
00106 #endif  /* _UNICOS */
00107                 {                               /* Fortran character */
00108                         unsigned int    len;
00109                         char            *cp;
00110 
00111                         cp      = _fcdtocp(timeofday);
00112                         len     = _fcdlen (timeofday);
00113 
00114                         (void) strncpy(cp, str, len);
00115 
00116                         if (len > CLOCK_CHRS)
00117                                 (void) memset(cp + CLOCK_CHRS, (_f_int) ' ',
00118                                                 len - CLOCK_CHRS);
00119                 }
00120 
00121 #ifdef  _UNICOS
00122         return ( (_f_int) clock );
00123 #endif
00124 
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines