!
#include "tm5.inc"
!
MODULE PHOTOLYSIS_DATA

  use dims, only: nregions

  implicit none

  ! types used in photolysis...

  TYPE PHOT_DATA
     !
     ! o3klim_top
     ! vo3_surf    : vertical column ozone at the surface (#/cm2)
     ! cloudfrac   : maximum overlap cloud fraction (-)
     ! albedo      : surface albedo (UV spectral region)
     ! vo3         : overhead ozone (#/cm2)
     ! ags_av      : statistics: contains average albedo
     ! vo3s_av     : statistics: contains average ozone column (#/cm2)
     ! cfr_av      : statistics: average cloud fraction
     ! jo3_av      : statistics: contains average jo3 (1/s)
     ! jno2_av     : statistics: contains average jno2 (1/s)
     ! additional fields added to assess the upgrade to the photolysis
     ! jh2o2_av    : statistics: contains average jh2o2(1/s)
     ! jhno3_av    : statistics: contains average jhno3(1/s)
     ! jhno4_av    : statistics: contains average jhno4(1/s)
     ! jn2o5_av    : statistics: contains average jn2o5(1/s)
     ! jch2o_a_av  : statistics: contains average jach2o(1/s)
     ! jch2o_b_av  : statistics: contains average jbch2o(1/s)
     ! jmepe_av    : statistics: contains average jch3ooh(1/s)
     ! jpan_av     : statistics: contains average jpan(1/s)
     ! jorgn_av    : statistics: contains average jorgn(1/s)
     ! jno3a_av     : statistics: contains average jno3a(1/s)
     ! jno3b_av    : statistics: contains average jno3b(1/s) 
     ! nj_av, nvo3s_av, ncloud_av, nalb_av     : couters for statistics
     !
     real,    dimension(:),         pointer :: o3klim_top
     real,    dimension(:,:),       pointer :: albedo
!     real,    dimension(:,:,:),     pointer :: vo3
     real,    dimension(:,:,:),     pointer :: cloud_reff
     real,    dimension(:,:,:),     pointer :: sad_cld
     real,    dimension(:,:,:),     pointer :: sad_ice
     real,    dimension(:,:,:),     pointer :: sad_aer
     real,    dimension(:,:,:),     pointer :: sad_cld_av
     real,    dimension(:,:,:),     pointer :: sad_ice_av
     real,    dimension(:,:,:),     pointer :: sad_aer_av
     real,    dimension(:,:,:),     pointer :: cfr_av      
     real,    dimension(:,:,:),     pointer :: lwp_av
     real,    dimension(:,:,:),     pointer :: reff_av
     real,    dimension(:,:),       pointer :: ags_av
     real,    dimension(:,:),       pointer :: sza_av      
     integer, dimension(:,:),       pointer :: aero_surface_clim

     ! J-values and their averages                               
     real,    dimension(:,:,:),     pointer :: jo3,  jo3_av
     real,    dimension(:,:,:),     pointer :: jno2, jno2_av

     ! averaged optical 
     real,    dimension(:,:,:),     pointer :: pmcld_av   
     real,    dimension(:,:,:),     pointer :: taus_cld_av
     real,    dimension(:,:,:),     pointer :: taua_cld_av
     real,    dimension(:,:,:,:,:), pointer :: pmaer_av    
     real,    dimension(:,:,:,:,:), pointer :: taus_aer_av 
     real,    dimension(:,:,:,:,:), pointer :: taua_aer_av

     ! counters for averages     
     real                                   :: nj_av, nvo3s_av, nalb_av, ncloud_av, naer_av, nsad_av

     ! ONLINE PARAMETERS
     ! ------------------     
     ! optical depth aerosol
     real,    dimension(:,:,:,:,:), pointer :: taus_aer, taua_aer
     ! optical depth clouds and aerosols
     real,    dimension(:,:,:),     pointer :: taua_cld, taus_cld    
     ! scattering aerosol
     real,    dimension(:,:,:,:,:), pointer :: pmaer   
     ! scattering cloud
     real,    dimension(:,:,:),     pointer :: pmcld                                                               
     ! column densities
     real,    dimension(:,:,:),     pointer :: v2, v3
     ! scaling ratio limits
     real,    dimension(:,:),       pointer :: v3_surf
     ! band limits for low direct fluxes
     real,    dimension(:,:),       pointer :: band1_limit, band3_limit
     ! temp dependent cross-sections ; the o2 has been replaced by a 1-D array
     ! each individual look up array has been tuned to reduce the overhead (JEW, AUG 2008)
     ! the valuesa are now ascribed in the main loop calculating the photolysis rates
     real,    dimension(:,:,:,:),   pointer :: qy_ch3cocho

  END TYPE PHOT_DATA

  type(phot_data),dimension(nregions),target :: phot_dat

  integer,parameter :: nj = 17

  integer,parameter :: jo3d  =  1
  integer,parameter :: jno2  =  2
  integer,parameter :: jh2o2 =  3
  integer,parameter :: jhno3 =  4
  integer,parameter :: jhno4 =  5
  integer,parameter :: jn2o5 =  6
  integer,parameter :: jach2o=  7
  integer,parameter :: jbch2o=  8
  integer,parameter :: jmepe =  9
  integer,parameter :: jano3 = 10
  integer,parameter :: jbno3 = 11
  integer,parameter :: jpan  = 12
  integer,parameter :: jorgn = 13
  integer,parameter :: j45   = 14
  integer,parameter :: j74   = 15
  integer,parameter :: jrooh = 16
  integer,parameter :: jo2   = 17

  character(len=8), dimension(nj), parameter ::  jnam = (/  &
       'jo3d    ','jno2    ','jh2o2   ','jhno3   ','jhno4   ', &
       'jn2o5   ','jach2o  ','jbch2o  ','jmepe   ','jano3   ', &
       'jbno3   ','jpan    ','jorgn   ','j45     ','j74     ', &
       'jrooh   ','jo2     '/)

  integer, parameter  :: maxwav = 122  ! maximal number of wave length intervals
  integer, parameter  :: maxw = 120    ! maximal number of wave length intervals for calculations

  ! purely o2 and o3 absorbing atmosphere
  integer, parameter  :: nmom = 16        ! number of moments of phase functions
  integer, parameter  :: nbands_trop = 7  ! number of wave length intervals (bands)
  integer, parameter  :: ngrid = 2        ! number of spectral grid types: normal and high angle
  integer             :: nwdep            ! number of wave length intervals (bands)

  ! o2 cross section in band 1
  real,dimension(17)  :: cross_o2

  data cross_o2 /7.448E-24, 7.322E-24, 7.002E-24, 6.608E-24, 6.118E-24, 5.736E-24, 5.302E-24,&
       4.741E-24, 4.261E-24, 3.788E-24, 3.213E-24, 2.69E-24, 2.218E-24, 1.793E-24,&
       1.384E-24, 1.054E-24, 6.318E-25/     

  ! rayleigh scattering cross section [cm^2/part.]
  real,dimension(maxwav)     :: cs_ray
  !cross sections [cm^2/part.]
  real,dimension(maxwav,nj)  :: cs

  real,dimension(maxwav,8,4)  :: sca,abs_eff,g,ext
  !  effective scattering cross section [cm^2/p]
  !  effective absorption cross section [cm^2/p]
  !  effective asymmetry factor,extinction coefficient [1/km]

  !     different aerosol types:                                          
  !        1 = rural aerosol                                              
  !        2 = maritime aerosol                                           
  !        3 = urban aerosol                                              
  !        4 = free troposphere aerosol                                   

  real,dimension(4) :: pn_ref = (/ 15000., 4000., 20000., 5000./) 


  ! The wavelengths < 204 nm are not yet considered for the tropospheric version
  ! ------------------------------------------------------------------------
  ! O2 absorption features:
  ! ------------------------------------------------------------------------
  ! ( 121.4 - 121.9 nm Lyman-Alpha line         : removed in trop version)
  ! (  100 - 175   nm  Schumann-Runge continuum : removed in trop version)
  ! (  175 - 204   nm  Schumann-Runge bands     : removed in trop version)
  !    204 - 241   nm  Herzberg continuum       : include scattering effects
  !
  ! ------------------------------------------------------------------------
  ! O3 absorption features:
  ! ------------------------------------------------------------------------
  !    204 - 240   nm  (no name)                : include scattering effects
  !    240 - 310   nm  Hartley band             : include scattering effects
  !    310 - 400   nm  Huggins band             : include scattering effects 
  !    400 - 850   nm  Chappuis bands           : include scattering effects
  !
  ! ------------------------------------------------------------------------
  ! Scattering bands: The selection of the bands and their effective
  !                   wavelengths are inspired on Landgraf and Crutzen
  ! ------------------------------------------------------------------------
  !     band     spectral range      eff. wavelength    index spectral grid
  ! ------------------------------------------------------------------------
  !     1        204.082 - 240.964 nm    205.128             1
  !     2        240.964 - 289.855 nm    287.770            29
  !     3        289.855 - 305.500 nm    303.000            33
  !     4        305.500 - 313.500 nm    309.000            39
  !     5        313.500 - 337.500 nm    320.000            46
  !     6        337.500 - 422.500 nm    370.000            56
  !     7        422.500 - 735.000 nm    580.000            98
  !
  ! JEW : band 7 has been optimized and truncated down to end of NO3 spectra
  ! JEW : Removal of bins < 204nm and >640nm reduces the main spectral array by ~25%
  ! JEW : Band limits for band 7 have subsequently changed
  
  real, dimension(:), allocatable  :: photo_wavelengths

  integer, dimension(nbands_trop) :: wav_grid , wav_gridA

  integer,dimension(nbands_trop)    :: &          
       lini  = (/1,  18,  31,  40,  48,  61,  78 /),        &
       lfin  = (/17, 30,  39,  47,  60,  77,  122/),        &
       lmid  = (/2,  30,  36,  43,  54,  67,  109/)

  integer,dimension(nbands_trop)    :: &          
       lini_gridA  = (/1,  18,  31,  40,  48,  63,  90/),   &
       lfin_gridA  = (/17, 30,  39,  47,  62,  89,  122/),  &
       lmid_gridA  = (/4,  30,  36,  45,  58,  70,  115/)

  ! maximum zenith angle for photolysis calculations
  real, parameter           :: sza_limit =  85. !calculations are shut off at sza=85

  real,dimension(maxwav)    :: wave      ! wavelength in the middle of the interval
  real,dimension(maxwav+54) :: wave_full ! full 8 band grid 
  real,dimension(maxwav)    :: dwave     ! width of the wavelength intervals [cm]
  real,dimension(maxwav+54) :: dwave_full 

  ! extra-terrestrial flux per wave length bin
  real,dimension(maxwav)    :: flux

end module photolysis_data
