!-------------------------------------- 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 --------------------------------------

      REAL FUNCTION JULIAND( DEET,NPAS,IDATIM ) 12
*
#include "impnone.cdk"
*
      INTEGER IDATIM(14),NPAS
      REAL DEET
*
*Author
*            B. Bilodeau - may 1993
*
*Revision
* 001        B. Bilodeau - June 1998 - Newdate
* 002        B. Dugas    - June 2000 - Calculate NDAYS in REAL*8
*
*Object
*            This function calculates the number of days
*            since the beginning of the current year,
*            using the analysis date, the number of time
*            steps since that date and the length of
*            the time step.
*
*Arguments
*
*            - Input -
* DEET       Length of the time step in seconds
* NPAS       Number of time steps since the beginning of the
*            time integration.
* IDATIM     Valid CMC date time group
*
*Notes
*            This function will be replaced eventually by
*            the function JJULIEN from RMNLIB, written
*            by B. Dugas. Note that the last argument
*            of the function will be replaced by the date
*            time stamp.
*
**
*
*
      INTEGER DAY,MONTH,YEAR
      INTEGER JDBEGIN,JDNOW,JD1JAN,NDAYS
      integer is1,is2
*
      EXTERNAL DATEC, JDATEC, NEWDATE
*
*     JULIAN DAY AT THE BEGINNING OF THE TIME INTEGRATION
*
      call newdate(idatim(14),is1,is2,-3)
*
      year  = is1/10000
*
      CALL JDATEC(JDBEGIN,YEAR,IDATIM(2),IDATIM(3))
*
*     NUMBER OF DAYS SPENT SINCE JDBEGIN
      NDAYS = NINT( (DEET*DBLE( NPAS ))/(24*3600) )
*
*     ACTUAL JULIAN DAY
      JDNOW = JDBEGIN + NDAYS
*
*     ACTUAL YEAR, MONTH AND DAY
      CALL DATEC(JDNOW,YEAR,MONTH,DAY)
*
*     JULIAN DAY OF THE FIRST OF JANUARY OF THE SAME YEAR
      CALL JDATEC(JD1JAN,YEAR,1,1)
*
*     ACTUAL DAY OF THE YEAR
      JULIAND = JDNOW - JD1JAN + 1
*
      RETURN
      END