!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
***s/r gemtim - Print out date and cpu statistics
*
#include "model_macros_f.h"
*

      subroutine gemtim (unf) 1
*
      implicit none
*
      integer unf
*
*author
*     B. Dugas
*
*revision
* v2_30 - Dugas B.       - initial version
* v3_11 - Dugas B.       - Adapt to AIX envvironment
* v3_22 - Lee V.         - add max residual memory 
*
*object
*     
**
      logical, save :: timini_L
      data timini_L / .false. /
*
#if defined (NEC)
      character*24 temp_S,fdate
      real totals,users,systs,ra(2),dtime
      equivalence (ra(1),users),(ra(2),systs)
*----------------------------------------------------------------
*
      totals = dtime( ra )
      temp_S = fdate( )
*
      if (timini_L) write(unf,1000) temp_S, users, systs
#endif
#if defined (AIX)
      integer get_max_rss
      external get_max_rss
      character date_S*8 ,time_S*10
      character jour_S*11,heure_S*10
      real          users,systs
      real, save :: user0,syst0
      data          user0,syst0 / 0.0, 0.0 /
*----------------------------------------------------------------
*
      call date_and_time( date_S,time_S )
      jour_S  = date_S(1:4)//'/'//date_S(5:6)//'/'//date_S(7:8)//' '
      heure_S = time_S(1:2)//'h'//time_S(3:4)//'m'//time_S(5:6)//'s,'
*
      call setrteopts('cpu_time_type=total_usertime')
      call cpu_time( users )
*
      call setrteopts('cpu_time_type=total_systime')
      call cpu_time( systs )
*
      if (timini_L)  write(unf,1000)
     +    ' At '//jour_S//heure_S, users-user0, systs-syst0,get_max_rss()
*
      user0 = users
      syst0 = systs
#endif
      timini_L = .true.
*
*----------------------------------------------------------------
 1000    format(/A,' User Time (sec) : ',f10.6,
     +             ' Sys  Time (sec) : ',f10.6,
     +            ', Mem (Kbytes/PE) : ',i10)
*
      return
      end