C $Header: /u/gcmpack/MITgcm/pkg/cal/cal_getdate.F,v 1.3 2003/10/09 04:19:19 edhill Exp $
C $Name:  $

#include "CAL_OPTIONS.h"

      subroutine CAL_GETDATE(
     I                        myiter,
     I                        mytime,
     O                        mydate,
     I                        mythid
     &                      )

c     ==================================================================
c     SUBROUTINE cal_GetDate
c     ==================================================================
c
c     o Determine the current date given the iteration number and/or the
c       current time of integration.
c              
c     started: Christian Eckert eckert@mit.edu  30-Jun-1999
c
c     changed: Christian Eckert eckert@mit.edu  29-Dec-1999
c
c              - restructured the original version in order to have a
c                better interface to the MITgcmUV.
c
c              Christian Eckert eckert@mit.edu  03-Feb-2000
c
c              - Introduced new routine and function names, cal_,
c                for verion 0.1.3.
c
c     ==================================================================
c     SUBROUTINE cal_GetDate
c     ==================================================================

      implicit none

c     == global variables ==

#include "cal.h"

c     == routine arguments ==

      integer myiter
      _RL     mytime
      integer mydate(4)
      integer mythid

c     == local variables ==

      _RL     secs
      integer workdate(4)

c     == end of interface ==

      if (mytime .lt. 0) then
        if (myiter .ge. 0) then
          secs = float(myiter - modeliter0)*modelstep
        else
          print*,' cal_GetDate: Not a valid input!'
        endif
      else
        secs = mytime - modelstart
      endif

      call CAL_TIMEINTERVAL( secs, 'secs', workdate, mythid )
      call CAL_ADDTIME( modelstartdate, workdate, mydate, mythid )

      return
      end