*ID SOLVAR
*/
*/  4.4 modset to include long-term variations of the solar "constant" in 
*/    HadCM3 runs, and minor accompanying changes in spectral file stuff 
*/    but no variation in ozone amounts, which is probably more important. 
*/  The solar variability is taken from Hoyt & Schatten (1993) to cover 
*/    the period 1700-1992 & Willson & al (1997) to extend it 4 more years
*/    - it does check the year is in this range.
*/  There is some discussion on http://www_hc/~hadeb/fcgmenu.html & I wrote
*/    a short report on natural forcings of climate 12/97.              WJI
*/
*DECLARE RAD_CTL1
*/
*I GHM5F405.19
*/

CL  Tweak SCS and SW spectral file to allow for solar variability -
CL    the total output & its spectral distribution:

      CALL SOLVAR (PREVIOUS_TIME(1), SCS, NPD_BAND_SW,
     &     SOLAR_FLUX_BAND_SW,  RAYLEIGH_COEFFICIENT_SW,
     &     W_ESFT_SW(1+2*NPD_ESFT_TERM_SW*NPD_BAND_SW,1,1),
C     !  2* to skip two species & get to ozone, the third - can't put
C     !  W_ESFT_SW(1,1,3) as here it is dimensioned by NPD_ESFT_TERM
C     !  & NPD_BAND, but its contents are arranged as if dimensioned 
C     !  by NPD_ESFT_TERM_SW & NPD_BAND_SW.
     &     CMESSAGE, ICODE)

      IF ( ICODE .GT. 0 ) RETURN

*/
*DECLARE CLDCTL1
*/
*I CLDCTL1.102 
     &       DUMMY,
*I CLDCTL1.327

CL  Tweak SCS to allow for variation in total solar output:

      CALL SOLVAR (PREVIOUS_TIME(1), SCS, DUMMY, DUMMY, DUMMY, DUMMY,
     &     CMESSAGE, ICODE)

*/
*/
*DECK SOLVAR1A

!+   Represent variation of solar output - its total & distribution.
! Subroutine Interface:
      SUBROUTINE SOLVAR (YEAR, SCS, NBANDS, FB, RA, OZWB1,
     &     ErrorMessage, ErrorStatus)
      IMPLICIT NONE
! Description:
!  SOLVAR allows for solar variability: its effects on the total solar 
!   output, and on its distribution with wavelength - or at least some 
!   of those things that depend on the latter, namely spectrally 
!   averaged items in the shortwave spectral file.  It assumes that the 
!   empirical (but theoretically plausible) correlations between total 
!   solar output & its spectral distribution over recent solar cycles 
!   due to Lean et al apply across the board, even down to Maunder 
!   minimum, but the time variation is the "plausible" solar "constant" 
!   variations from 1700 to 1992 of Hoyt & Schatten (J. Geophys. Res.,
!   98., 18895-18906, 1993).  It is written to work with the HadCM3 SW
!   spectral file (or slight variations) only.  Only the division of 
!   the total energy between the bands, ozone absorption in band 1 & 
!   Rayleigh scattering are worth bothering with (& the last only
!   because it's so easy).  The ozone absorption can be done just by 
!   tweaking the weights, thanks to Stephen C.
!
! Method:
!  First time in, save the "standard" values of the quantities 
!   concerned in the spectral file.  
!  Every time the year changes, the quantities to be altered in the 
!   spectral file are varied as functions of the solar "constant".
!  Every call re-set SCS, which is set fresh every timestep by SOLPOS.
!
! Current Code Owner: William Ingram
!                    
! History:
! Version  Date     Comment
! =======  ====     =======
! 4.4-mods 27/2/98  4.3 mods changed for new arrangement of radiation 
!                   stuff & error checking added.  (William Ingram)
!    
! Code description:
!   FORTRAN 77 + common extensions also in fortran 90.
!   This code is written to UM programming standards version 6
! 
! System component covered:  not applicable
! System task:               not applicable
!
! Declarations: these are of the form:-
!     INTEGER      ExampleVariable  !Description of variable

! 
! Global variables (*CALLed common blocks etc.)

*CALL SWSC

! Subroutine arguments
!   Scalar arguments with intent(in):
      INTEGER YEAR,                !  Current year
     &        NBANDS               !  Number of bands in spectral file
      CHARACTER*80 ErrorMessage    !
!   Scalar arguments with intent(InOut):
      REAL SCS                     
!     Solar constant scaling factor, taking into consideration the
!     changes in solar irradiance & the earth-sun distance.
!   Array  arguments with intent(InOut):
      REAL FB(6),                  ! Fraction of insolation in each band
     &     RA(6),                  ! Rayleigh coefficients for each band
     &     OZWB1(5)                ! Ozone esft weights in band 1
!   ErrorStatus:
      INTEGER      ErrorStatus     !+ve = fatal error    

! Local parameters:
      REAL FC2B1D,                 ! Used to convert FCSC to BAND1D
     &     FBSEN1,                 ! Sensitivity of FB(1) to BAND1D
     &     FBSEN2,                 ! Sensitivity of FB(2) to FCSC
     &     RASEN1,                 ! Sensitivity of RA(1) to BAND1D
     &     RASEN2                  ! Sensitivity of RA(2) to FCSC 
      PARAMETER ( FC2B1D = 213. )
      PARAMETER ( FBSEN1 = 5.212, FBSEN2 = 0.1458 )
      PARAMETER ( RASEN1 = 4.360, RASEN2 = 0.2185 )
! Local scalars:
      REAL SOV                     ! Solar "constant" for the year
      REAL MNFB(6), MNRA(2), MNOZ(5)
      ! Reference values for FB, RA and OZWB1.
      REAL FCSC,                   ! Fractional change in solar constant
     &     BAND1D                  
!     Factor representing the band-1 quantities's quadratic dependence
!     on solar constant (in band 2 they vary linearly).

      REAL HSPSIV (297)
      ! Year-to-year variation of the solar "constant".
      ! Following list is `head -n 336 ~hadjm/in/solarforcingtc | tail \
      !-n 293 | awk '{print $2-1365. ","}' | paste -s -d'          \n' \
      !- | awk '{print "     & " $0}'` & then . the 5736 that awk left
      ! looking integral & the last removed & replaced by 5 Willson #s.
      DATA HSPSIV /
     & 2.52, 2.65, 2.9, 3.23, 3.45, 3.7, 3.59, 3.61, 3.63, 3.71, 3.57,
     & 3.77, 3.99, 4.14, 4.32, 4.43, 4.6, 4.82, 5.05, 5.18, 5.2, 5.29,
     & 5.27, 5.09, 5.02, 5.16, 5.4, 5.66, 5.54, 5.32, 5.08, 5.13, 4.86,
     & 4.71, 4.69, 4.75, 4.95, 5., 5.32, 5.1, 5.45, 5.28, 4.96, 4.79,
     & 4.69, 4.72, 4.83, 5.02, 5.22, 5.43, 5.44, 5.22, 5.29, 5.28, 5.28,
     & 5.44, 5.56, 5.8, 5.93, 5.94, 6.04, 6.3, 6.33, 6.55, 6.61, 6.55,
     & 6.56, 6.66, 6.81, 7., 6.95, 6.87, 6.92, 6.59, 6.38, 6.14, 6.03,
     & 6.36, 6.68, 6.42, 6.17, 5.94, 5.42, 4.88, 4.29, 4.08, 4.29, 4.36,
     & 4.25, 4.05, 3.82, 3.59, 3.54, 3.41, 3.36, 3.26, 3.16, 3.05, 3.,
     & 2.97, 2.91, 3.03, 3.06, 3.08, 3.17, 3.28, 3.24, 3.1, 3.22, 3.32,
     & 3.42, 3.55, 3.64, 3.75, 3.83, 4.13, 4.25, 4.38, 4.54, 4.61, 4.77,
     & 5.01, 5.2, 5.34, 5.46, 5.55, 5.61, 5.77, 5.95, 5.95, 5.99, 5.87,
     & 5.61, 5.39, 5.35, 5.54, 5.9, 6.1, 5.93, 5.83, 5.67, 5.29, 5.05,
     & 4.69, 4.5, 4.58, 4.67, 4.92, 4.99, 4.74, 4.53, 4.51, 4.36, 4.28,
     & 4.23, 4.19, 4.2, 4.38, 4.59, 4.84, 4.89, 4.79, 4.76, 4.78, 4.75,
     & 4.57, 4.3, 4.08, 4.19, 4.38, 4.87, 4.73, 4.76, 4.55, 4.53, 4.39,
     & 4.43, 4.49, 4.5, 4.39, 4.59, 4.71, 4.76, 4.34, 4.3, 4.15, 3.86,
     & 3.69, 3.61, 3.58, 3.53, 3.7, 3.99, 4.11, 4.07, 4.03, 3.99, 3.99,
     & 4.19, 4.28, 4.4, 4.44, 4.54, 4.72, 4.9, 5.06, 5.06, 5.15, 5.1,
     & 5.15, 5.03, 5.02, 5.08, 5.14, 5.26, 5.58, 5.71, 6.15, 6.04, 5.98,
     & 5.86, 5.85, 5.84, 5.87, 6., 6.27, 6.44, 6.48, 6.5, 6.48, 6.32,
     & 6.28, 6.2, 6.12, 6.15, 6.34, 6.62, 6.86, 6.85, 6.73, 6.62, 6.56,
     & 6.53, 6.49, 6.49, 6.63, 6.99, 7.42, 7.21, 7.13, 6.71, 6.52, 6.05,
     & 5.7, 5.47, 5.51, 6.03, 6.26, 6.1, 5.84, 5.55, 5.16, 5.02, 4.96,
     & 4.88, 4.97, 5.26, 5.69, 5.82, 5.87, 5.91, 5.7, 5.73, 5.5, 5.7,
     & 5.59, 5.57, 5.65, 6.21, 6.74, 6.83, 6.86, 6.84, 6.48, 6.37, 6.2,
     & 6.49, 6.6, 7.09, 7.5, 7.38, 7.41, 7.41, 7.16, 6.97, 6.83, 6.64 /
      REAL OZSEN(5)                ! Sensitivities of OZWB1 to BAND1D
      DATA OZSEN / -3.65009, -3.84821, -2.57906, 2.44108, 12.7060 /

      LOGICAL FIRST                ! First time in ?
      DATA FIRST  / .TRUE. /
      INTEGER LASTYR               ! Year last time through
      DATA LASTYR / -99999 /

      SAVE FIRST, LASTYR, MNRA, MNFB, MNOZ, FCSC
!- End of header  

      IF ( FIRST ) THEN

C  Check only on the number of bands & that there seem to be 5 esft 
C   terms for the first gas in the first band - any more complex test on, 
C   say, the total size of the file, or band limits could be vitiated by
C   adding more aerosols or re-labelling the (pseudo-)band limits.

        IF ( SUM(OZWB1) .GT. 1.0001 .OR. SUM(OZWB1) .LE. 0.9999 
     &                               .OR. NBANDS .NE. 6 ) THEN
          ErrorMessage = ' SOLVAR: Inappropriate spectral file'
          WRITE (6, *) NBANDS, OZWB1
          WRITE (6, *) ErrorMessage
          ErrorStatus = 8
          RETURN
        ENDIF

C       Store reference values.
        MNFB = FB
        MNRA = RA(1:2)
        MNOZ = OZWB1
        FIRST = .FALSE.

      ENDIF

      IF ( YEAR .LT. 1700 .OR. YEAR .GT. 1996 ) THEN
        ErrorMessage = ' SOLVAR: Only years 1700-1996 covered'
        WRITE (6, *) YEAR
        WRITE (6, *) ErrorMessage
        ErrorStatus = 9
        RETURN
      ENDIF

      IF ( YEAR .NE. LASTYR ) THEN

!       Calculate this year's solar constant & thence FCSC and BAND1D
        SOV = HSPSIV(YEAR-1699) + 1359.8658
!       1359.8658 = SC - mean(HSPSIV)
        FCSC = SOV / SC - 1.
        BAND1D = FCSC * ( 1. + FC2B1D * FCSC )

!       Set FB(1,2) using BAND1D & FCSC and the rest by normalization.
        FB(1) = ( 1. + FBSEN1 * BAND1D ) * MNFB (1)
        FB(2) = ( 1. + FBSEN2 * FCSC )   * MNFB (2)
        FB(3:6) = MNFB(3:6)   *  ( 1. - FB(1) - FB(2) ) / SUM(MNFB(3:6))

!       Set RA(1,2) using BAND1D & FCSC: the rest are insignificant.
        RA(1) = ( 1. + RASEN1 * BAND1D ) * MNRA (1)
        RA(2) = ( 1. + RASEN2 * FCSC )   * MNRA (2)

!       Set OZWB1 using BAND1D but must then re-normalize.
        OZWB1 = ( 1. + OZSEN * BAND1D ) * MNOZ
        OZWB1 = OZWB1 / SUM(OZWB1)

        LASTYR = YEAR

      ENDIF

      SCS = SCS * ( 1. + FCSC )

      RETURN
      END
