!copyright (C) 2001  MSC-RPN COMM  %%%RPNPHY%%%
***S/P SUNCOS
*
#include "phy_macros_f.h"

      SUBROUTINE SUNCOS(SCOS,LMX,XLAT,XLON,HZ,DATE,IDATIM) 6
#include "impnone.cdk"
          INTEGER IDATIM(14),I,LMX
          REAL XLAT(LMX),XLON(LMX),SCOS(LMX),HZ,DATE
          REAL DH,SDEC,CDEC,RDEC,AJOUR
          REAL A,EOT
*
*Author
*          L.Garand (1989)
*
*Revision
* 001      G.Pellerin(Mar90)Standard documentation
* 002      N. Brunet  (May91)
*                New version of thermodynamic functions
*                and file of constants
* 003      L. Garand (Fev95) Add equation of time
* 004      J.P. Toviessi (June 2003) - IBM conversion
*               - calls to vscos, vssin routine (from massvp4 library)
*               - unnecessary calculations removed
*
*Object
*          to calculate the cosines of the solar angle for LMX
*          points
*
*Arguments
*
*          - Output -
* SCOS     cosines of the solar angle
*
*          - Input -
* LMX      number of points
* XLAT     latitude in radians
* XLON     longitude in radians
* HZ       Greenwich hour (0 to 24)
* DATE     julian day (0 to 366) (real number)
* IDATIM   time coded in standard RPN format
*
**
*
*
#include "consphy.cdk"
C
*
      AUTOMATIC ( tmcos   , REAL  , (LMX) )
      AUTOMATIC ( tmsin   , REAL  , (LMX) )
*
       IF(DATE.NE.0.) AJOUR=DATE
       IF(DATE.EQ.0.) AJOUR=30.4*(IDATIM(2)-1)+IDATIM(3)
      RDEC=0.412*COS((AJOUR+10.)*2.*PI/365.25 -PI)
      SDEC=SIN(RDEC)
      CDEC=COS(RDEC)
c correction for "equation of time"
      A = DATE/365.*2.*PI
c in minutes
      EOT = .002733 -7.343*sin(a)+ .5519*cos(a) -9.47*sin(2.*a)
     x  -3.02*cos(2.*a) -.3289*sin(3.*a) -.07581*cos(3.*a)
     x -.1935*sin(4.*a) -.1245*cos(4.*a)
c express in a fraction of hour
      EOT=EOT/60.
c express in radians
      EOT=EOT*15.*PI/180.
c
      call VSCOS(tmcos,XLAT(1),LMX)
      call VSSIN(tmsin,XLAT(1),LMX)
*
      DO 1 I=1,LMX
      DH=HZ*PI/12. +XLON(I) -PI + EOT
      SCOS(I)=AMAX1(tmsin(I)*SDEC + tmcos(I)*CDEC*
     X   COS(DH) , 0.00001)
C
  1     CONTINUE
      RETURN
      END