!-------------------------------------- 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/P  CONRAY2
*

      SUBROUTINE CONRAY2(DECLSC,FRFLXS,SH,DSH,n,NK,DATE,IDATIM) 1
*
#include "impnone.cdk"
      INTEGER IDATIM(14), NK, n
      REAL DECLSC(2),  FRFLXS(n,NK),  SH(n,NK),DSH(n,NK)
      REAL DATE
*
*Author
*          Y.Delage(Jan 1979)
*
*Revision
* 001      C.Beaudoin(August 88)
*                 Add in the common physics library
* 002      N. Brunet  (May91)
*                 New version of thermodynamic functions
*                 and file of constants
* 003      R. Benoit (August 93) 2D version for use with Local Sigma
*
*Object
*          to calculate the sines and cosines of the solar
*          declination in the day function of the year.
*
*Arguments
*
*          - Output -
* DECLSC   sines and cosines centred on the sigma levels
* FRFLXS   weight shared from the warming by the ozone and the
*          cooling by the CO2 in the stratosphere.  It is assumed
*          that the warming(cooling) crosses linearly in Z from
*          sigma
*
*          - Input -
* SH       sigma levels
* DSH      depth of layers centred on the sigma levels
* n        horizontal dimension
* NK       number of sigma levels
* DATE     day of the year
* IDATIM   date array used for generating the date when DATE=0
*
**
*
      REAL AJOUR,RDECL,SFR
      INTEGER K,NS,NS1
*
#include "consphy.cdk"
#include "valcon.cdk"
      REAL SIGMAS
      SAVE SIGMAS
      integer j
      DATA SIGMAS / .25 /
*-----------------------------------------------------------------------

      IF(DATE.EQ.0.)  AJOUR = 30.4 * (IDATIM(2)-1) + IDATIM(3)
      IF(DATE.NE.0.)  AJOUR =  DATE
*
      RDECL = .412*COS((AJOUR+10.)*2.*PI/365.25-PI)
      DECLSC(1) = SIN(RDECL)
      DECLSC(2) = COS(RDECL)
*
      do 100 j=1,n
         NS = 0
         SFR = 0.
*
 10      NS = NS + 1
         FRFLXS(j,NS)=DSH(j,NS)*(-ALOG(MAX(SH(j,NS),.035))+ALOG(SIGMAS))
         SFR = SFR + FRFLXS(j,NS)
         IF(SH(j,NS+1).GE.SIGMAS) GO TO 20
         GO TO 10
*
 20      IF(ABS(SFR) .GT. 1.E-9) GO TO 30
*
         FRFLXS(j,1) = 1.
         GO TO 50
*
 30      DO 40 K=1,NS
            FRFLXS(j,K) = FRFLXS(j,K)/SFR
 40      CONTINUE

 50      NS1 = NS + 1
         DO 60 K=NS1,NK
 60         FRFLXS(j,K) = 0.

 100  continue
      RETURN
*
      END