*IF DEF,SCMA                                                               S_DPDIAG.2      
C *****************************COPYRIGHT******************************     S_DPDIAG.3      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    S_DPDIAG.4      
C                                                                          S_DPDIAG.5      
C Use, duplication or disclosure of this code is subject to the            S_DPDIAG.6      
C restrictions as set forth in the contract.                               S_DPDIAG.7      
C                                                                          S_DPDIAG.8      
C                Meteorological Office                                     S_DPDIAG.9      
C                London Road                                               S_DPDIAG.10     
C                BRACKNELL                                                 S_DPDIAG.11     
C                Berkshire UK                                              S_DPDIAG.12     
C                RG12 2SZ                                                  S_DPDIAG.13     
C                                                                          S_DPDIAG.14     
C If no contract has been raised with this copy of the code, the use,      S_DPDIAG.15     
C duplication or disclosure of it is strictly prohibited.  Permission      S_DPDIAG.16     
C to do so must first be obtained in writing from the Head of Numerical    S_DPDIAG.17     
C Modelling at the above address.                                          S_DPDIAG.18     
C ******************************COPYRIGHT******************************    S_DPDIAG.19     
C                                                                          S_DPDIAG.20     
C Purpose:-           To calculate diagnostics for DUMP and OUTPUT         S_DPDIAG.21     
C                     table                                                S_DPDIAG.22     
C Programmer:-        J. LEAN                                              S_DPDIAG.23     
C                                                                          S_DPDIAG.24     
C Modification History:                                                    S_DPDIAG.25     
C Version  Date                                                            S_DPDIAG.26     
C  4.5     07/98     SCM integrated as a standard UM configuration         S_DPDIAG.27     
C                    JC Thil.                                              S_DPDIAG.28     
C = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =      S_DPDIAG.29     

      Subroutine DUMPDIAG(                                                  1S_DPDIAG.30     
C     ! IN leading dimensions of arrays                                    S_DPDIAG.31     
     &  points, nlevs, nwet                                                S_DPDIAG.32     
     &  ,nfor, nbl_levs, nsoilt_levs, nsoilm_levs, ntrop                   S_DPDIAG.33     
C     ! IN dump description.                                               S_DPDIAG.34     
     &  ,nvars, nprimvars, ndump, cloud_count, tcount, qcount              S_DPDIAG.35     
     &  ,t1p5m_maxcount ,t1p5m_mincount                                    S_DPDIAG.36     
C     !                                                                    S_DPDIAG.37     
     &  ,dump, m1, land_mask, u, v, t, theta, q, qcl, qcf                  S_DPDIAG.38     
     &  ,lca, dt, dq, cca, ccb, cct, conv_rain, conv_snow                  S_DPDIAG.39     
     &  ,ls_rain, ls_snow                                                  S_DPDIAG.40     
     &  ,taux, tauy, fqw, ftl, tdeep, pstar, tstar, smc, canopy            S_DPDIAG.41     
     &  ,snodep, zh, z0m, can_evap, soil_evap, surf_ht_flux, seai_htf      S_DPDIAG.42     
     &  ,sublim, lat_ht, sens_ht, u10m, v10m, t1p5m, rib, q1p5m            S_DPDIAG.43     
     &  ,fast_roff, sub_roff, snomlt_htf, snomlt, thro_fall                S_DPDIAG.44     
     &  ,sw, swsea, lw, lwsea, net_rad, os_toa, is_toa, olr_toa            S_DPDIAG.45     
     &  ,csolrd, csosdi, tca                                               S_DPDIAG.46     
     &  ,dump_step, akh, bkh, timestep, stepcount                          S_DPDIAG.47     
     &  ,delta_ak, delta_bk, rh, smcl, sice_mlt_htf                        S_DPDIAG.48     
     &  ,snomlt_surf_htf, snomlt_sub_htf                                   S_DPDIAG.49     
C     ! Extra diagnostics output for MOSES                                 S_DPDIAG.50     
     &  ,sthu, sthf, gs, lai, canht                                        S_DPDIAG.51     
     &  ,etran, gpp, npp, resp_p, down_surf_sw_b1                          S_DPDIAG.52     
     &  )                                                                  S_DPDIAG.53     
C                                                                          S_DPDIAG.54     
      Implicit none                                                        S_DPDIAG.55     
C                                                                          S_DPDIAG.56     
C---------------------------------------------------------------------     S_DPDIAG.57     
C     Arguments                                                            S_DPDIAG.58     
C---------------------------------------------------------------------     S_DPDIAG.59     
C                                                                          S_DPDIAG.60     
      Integer                                                              S_DPDIAG.61     
     &  points                  ! IN leading dimension of SCM arrays.      S_DPDIAG.62     
     &  ,nlevs                  ! IN no of levels.                         S_DPDIAG.63     
     &  ,nwet                   ! IN no of model levels in which Q         S_DPDIAG.64     
                                !   is set.                                S_DPDIAG.65     
     &  ,nfor                   ! IN Number terms for observational        S_DPDIAG.66     
                                !   forcing                                S_DPDIAG.67     
     &  ,nbl_levs               ! IN Number of Boundary layer levels       S_DPDIAG.68     
     &  ,nsoilt_levs            ! IN Number of soil temperature            S_DPDIAG.69     
                                !   levels                                 S_DPDIAG.70     
     &  ,nsoilm_levs            ! IN Number of soil moisture levels        S_DPDIAG.71     
     &  ,ntrop                  ! IN Max number of levels in the           S_DPDIAG.72     
                                !   troposphere                            S_DPDIAG.73     
     &  ,nvars                  ! IN no. variables in dump,                S_DPDIAG.74     
                                !  equal to NPRIMVARS + X                  S_DPDIAG.75     
                                !  where X is any no. of variables         S_DPDIAG.76     
                                !  (default 71)                            S_DPDIAG.77     
     &  ,nprimvars              ! IN nprimvars is the minimum no. of       S_DPDIAG.78     
                                !  variables required to restart           S_DPDIAG.79     
                                !  from a dump and is equal to             S_DPDIAG.80     
     &  ,ndump                  ! IN ndump is the number of dumps per      S_DPDIAG.81     
     &  ,cloud_count            !  day counter which points to             S_DPDIAG.82     
                                !  position of mean cloud base             S_DPDIAG.83     
                                !  in DUMP                                 S_DPDIAG.84     
     &  ,qcount                 ! IN points to position of q               S_DPDIAG.85     
                                !  averaged throughout atmos.              S_DPDIAG.86     
     &  ,tcount                 ! IN points to position of T               S_DPDIAG.87     
                                !  averaged throughout atmos.              S_DPDIAG.88     
                                !  column in DUMP                          S_DPDIAG.89     
     &  ,T1p5m_maxcount         ! IN Pointer to T1p5m_max in dump          S_DPDIAG.90     
     &  ,T1p5m_mincount         ! Pointer to T1P5M_MIN in dump             S_DPDIAG.91     
     &  ,dump_step              ! IN No. of timesteps between dumps        S_DPDIAG.92     
     &  ,i, icount, j, l        ! Counters                                 S_DPDIAG.93     
      Logical                                                              S_DPDIAG.94     
     &  land_mask(points)       ! IN true if land point.                   S_DPDIAG.95     
      Integer                                                              S_DPDIAG.96     
     &  m1                      ! IN no. of dumps                          S_DPDIAG.97     
     &  ,stepcount              ! IN counts through timesteps              S_DPDIAG.98     
      Real                                                                 S_DPDIAG.99     
     &  rh(points,nwet,2)       ! RH in moist physics                      S_DPDIAG.100    
C                                                                          S_DPDIAG.101    
C     Primary model variables + T (essential to run)                       S_DPDIAG.102    
C                                                                          S_DPDIAG.103    
      Integer                                                              S_DPDIAG.104    
     &  ccb(points)             ! IN Convective cloud base                 S_DPDIAG.105    
     &  ,cct(points)            ! IN Convective cloud top                  S_DPDIAG.106    
      Real                                                                 S_DPDIAG.107    
     &  akh(nlevs + 1)          ! IN Coefficients defining                 S_DPDIAG.108    
     &  ,bkh(nlevs + 1)         !  hybrid vert. coords at lower            S_DPDIAG.109    
                                !  level interfaces                        S_DPDIAG.110    
     &  ,can_evap(points)       ! IN Evaporation from canopy               S_DPDIAG.111    
                                !  (kg m^-2 s^-1)                          S_DPDIAG.112    
     &  ,canopy(points)         ! IN Surface canopy water (kg m^-2)        S_DPDIAG.113    
     &  ,cca(points)            ! IN Convective cloud amount               S_DPDIAG.114    
     &  ,conv_rain(points)      ! IN Convective rainfall                   S_DPDIAG.115    
                                !  IN (kg m^-2)                            S_DPDIAG.116    
     &  ,conv_snow(points)      ! IN Convective snowfall rate              S_DPDIAG.117    
                                !  (kg m^-2)                               S_DPDIAG.118    
     &  ,csolrd(points)         ! IN Clear-sky outgoing LW                 S_DPDIAG.119    
                                !  radiation (W m^-2)                      S_DPDIAG.120    
     &  ,csosdi(points)         ! IN Clear-sky outgoing solar              S_DPDIAG.121    
                                !  radiation (W m^-2)                      S_DPDIAG.122    
     &  ,delta_ak(nlevs)        ! IN Difference of hybrid 'A'              S_DPDIAG.123    
                                !  across layers (K-1/2 to K + 1/2).       S_DPDIAG.124    
                                !  NB: Upper minus lower.                  S_DPDIAG.125    
     &  ,delta_bk(nlevs)        ! IN Difference of hybrid 'B'              S_DPDIAG.126    
                                !  across layers (K-1/2 to K + 1/2).       S_DPDIAG.127    
                                ! NB: Upper minus lower.                   S_DPDIAG.128    
     &  ,dq(points,nwet)        ! Increments to mixing ratio               S_DPDIAG.129    
                                !  due to convection                       S_DPDIAG.130    
                                !  (kg kg^-1 s^-1)                         S_DPDIAG.131    
     &  ,dt(points,nwet)        ! Increments to potential                  S_DPDIAG.132    
                                !  temperature due to convection           S_DPDIAG.133    
                                !  (K s^-1)                                S_DPDIAG.134    
     &  ,fast_roff(points)      ! IN Surface runoff (kg m^-2 s^-1)         S_DPDIAG.135    
     &  ,fqw(points,nbl_levs)   ! IN Moisture flux between layers          S_DPDIAG.136    
                                !  (kg m^-2 s^-1)                          S_DPDIAG.137    
                                !  FQW(,1) is total water flux             S_DPDIAG.138    
                                !  from surface, 'E'.                      S_DPDIAG.139    
     &  ,ftl(points,nbl_levs)   ! IN FTL(,K) contain net turbulent         S_DPDIAG.140    
                                !  sensible heat flux into layer           S_DPDIAG.141    
                                !  K from below; so FTL(,1) is the         S_DPDIAG.142    
                                !  surface sensible heat, H.(W m^-2)       S_DPDIAG.143    
     &  ,is_toa(points)         ! IN Incoming solar radiation              S_DPDIAG.144    
                                !  at TOA (W m^-2)                         S_DPDIAG.145    
     &  ,lat_ht(points)         ! IN Surface latent heat flux              S_DPDIAG.146    
                                !  (W m^-2 s^-1)  + ve upwards             S_DPDIAG.147    
     &  ,lca(points,nwet)       ! IN Layer cloud amount (decimal f         S_DPDIAG.148    
     &  ,ls_rain(points)        ! IN Large scale rainfall rate             S_DPDIAG.149    
                                !  (kg m^-2)                               S_DPDIAG.150    
     &  ,ls_snow(points)        ! IN Large scale snowfall rate             S_DPDIAG.151    
                                !  (kg m^-2)                               S_DPDIAG.152    
     &  ,lw(points,nlevs + 1)   ! IN LW atmos.heating                      S_DPDIAG.153    
                                ! rates in levels 2,NLEVS + 1              S_DPDIAG.154    
                                ! (K s^-1). NET LW flux                    S_DPDIAG.155    
                                !  in level 1 over solid portion           S_DPDIAG.156    
                                ! of box (ie land or contribution          S_DPDIAG.157    
                                ! to flux from sea-ice fraction            S_DPDIAG.158    
                                ! of the box at sea-ice points)            S_DPDIAG.159    
                                ! The rest of the total flux is            S_DPDIAG.160    
                                ! put in LWSEA.                            S_DPDIAG.161    
     &  ,lwsea(points)          ! IN Net LW flux at surface                S_DPDIAG.162    
                                !  over sea (W m^-2)                       S_DPDIAG.163    
     &  ,net_rad(points)        ! IN Net radiation at surface              S_DPDIAG.164    
     &  ,olr_toa(points)        ! IN Outgoing longwave radiation           S_DPDIAG.165    
                                !  at TOA (W m^2)                          S_DPDIAG.166    
     &  ,os_toa(points)         ! IN Outgoing solar radiation              S_DPDIAG.167    
                                !  at TOA (W m^2)                          S_DPDIAG.168    
     &  ,Pstar(points)          ! IN Pressure at earth's surface           S_DPDIAG.169    
                                !  (Pa not HPa)                            S_DPDIAG.170    
     &  ,q(points,nwet)         ! IN Specific humidity (kg kg^-1)          S_DPDIAG.171    
     &  ,Q1p5m(points)          ! IN Q at 1.5m (kg kg^-1)                  S_DPDIAG.172    
     &  ,qcf(points,nwet)       ! IN Cloud ice content (kg kg^-1)          S_DPDIAG.173    
     &  ,qcl(points,nwet)       ! IN Cloud water content (kg kg^-1)        S_DPDIAG.174    
     &  ,rib(points)            ! IN Bulk Richardson number                S_DPDIAG.175    
     &  ,seai_htf(points)       ! IN Heat flux through sea-ice             S_DPDIAG.176    
                                !  (W m^-2)  + ve down                     S_DPDIAG.177    
     &  ,sens_ht(points)        ! IN Sensible heat (W m^-2)                S_DPDIAG.178    
                                !   = FTL(1)                               S_DPDIAG.179    
     &  ,sice_mlt_htf(points)   ! Sea ice top melt latent heat             S_DPDIAG.180    
                                !  flux (W m^-2)                           S_DPDIAG.181    
     &  ,smc(points)            ! IN Soil moisture content                 S_DPDIAG.182    
                                !  (kg m^-2)                               S_DPDIAG.183    
     &  ,smcl(points,nsoilm_levs) ! IN Soil moisture content in            S_DPDIAG.184    
                                !  the layers (kg m^-2)                    S_DPDIAG.185    
     &  ,snodep(points)         ! IN Snow depth (kg m^-2)                  S_DPDIAG.186    
     &  ,snomlt_htf(points)     ! IN Snowmelt heat flux (W m^-2) non       S_DPDIAG.187    
                                !  PM                                      S_DPDIAG.188    
     &  ,snomlt(points)         ! IN snow melt (kg m^-2)                   S_DPDIAG.189    
     &  ,snomlt_surf_htf(points) ! IN surface snowmelt heat flux -PM       S_DPDIAG.190    
                                !  (W m^-2)                                S_DPDIAG.191    
     &  ,snomlt_sub_htf(points) ! IN subsurface snowmelt heat flux         S_DPDIAG.192    
                                !  -PM (W m^-2)                            S_DPDIAG.193    
     &  ,soil_evap(points)      ! IN Evaporation from soil                 S_DPDIAG.194    
                                !  (kg m^-2 s^-1)                          S_DPDIAG.195    
     &  ,sublim(points)         ! IN Sublimation from lying snow           S_DPDIAG.196    
                                !  or sea-ice (kg m^-2 s^-1)               S_DPDIAG.197    
     &  ,sub_roff(points)       ! IN Subsurface runoff                     S_DPDIAG.198    
                                !  (kg m^-2 s^-1)                          S_DPDIAG.199    
     &  ,sw(points,nlevs + 1)   ! IN Shortwave atmospheric heating         S_DPDIAG.200    
                                !  rates in levels 2,NLEVS + 1             S_DPDIAG.201    
                                !  (K s^-1). NET SW flux                   S_DPDIAG.202    
                                !  in level 1 over solid portion           S_DPDIAG.203    
                                !  of box (ie land or contribution         S_DPDIAG.204    
                                !  to flux from sea-ice fraction           S_DPDIAG.205    
                                !  of the box at sea-ice points)           S_DPDIAG.206    
                                !  The rest of the total flux is           S_DPDIAG.207    
                                !  put in SWSEA.                           S_DPDIAG.208    
     &  ,swsea(points)          ! IN Net SW flux at surface over           S_DPDIAG.209    
                                !  sea (W m^-2)                            S_DPDIAG.210    
     &  ,t(points,nlevs)        ! IN Temperature at each level (K)         S_DPDIAG.211    
     &  ,taux(points,nlevs)     ! IN W'ly component of surface             S_DPDIAG.212    
                                !  stress (N m^-2)                         S_DPDIAG.213    
     &  ,tauy(points,nlevs)     ! IN S'ly component of surface             S_DPDIAG.214    
                                !  stress (N m^-2)                         S_DPDIAG.215    
     &  ,T1p5m(points)          ! IN T at 1.5m (K)                         S_DPDIAG.216    
     &  ,tca(points)            ! IN Total cloud amount                    S_DPDIAG.217    
     &  ,Tdeep(points,nsoilt_levs) ! IN Deep soil temperatures (K)         S_DPDIAG.218    
     &  ,theta(points,nlevs)    ! IN Potential temperature (K)             S_DPDIAG.219    
     &  ,thro_fall(points)      ! IN Throughfall (kg m^-2 s^-1)            S_DPDIAG.220    
     &  ,timestep               ! IN Timestep (s)                          S_DPDIAG.221    
     &  ,Tstar(points)          ! IN Surface temperature (K)               S_DPDIAG.222    
     &  ,u(points,nlevs)        ! IN Zonal wind at each level              S_DPDIAG.223    
                                !  (m s^-2)                                S_DPDIAG.224    
     &  ,u10m(points)           ! IN U at 10m (m s^-1)                     S_DPDIAG.225    
     &  ,v(points,nlevs)        ! IN Meridional wind at each level         S_DPDIAG.226    
                                !  (m s^-2)                                S_DPDIAG.227    
     &  ,v10m(points)           ! IN V at 10m (m s^-1)                     S_DPDIAG.228    
     &  ,zh(points)             ! IN Height above surface of top o         S_DPDIAG.229    
                                !  boundary layer (m)                      S_DPDIAG.230    
     &  ,z0m(points)            ! IN roughness length                      S_DPDIAG.231    
C                                                                          S_DPDIAG.232    
C---------------------------------------------------------------------     S_DPDIAG.233    
C     Extra diagnostics for MOSES boundary layer code                      S_DPDIAG.234    
C---------------------------------------------------------------------     S_DPDIAG.235    
      Real                                                                 S_DPDIAG.236    
     &  down_surf_sw_b1(points) ! Downward shortwave radiationin           S_DPDIAG.237    
                                !  in band 1. Required for hydrology       S_DPDIAG.238    
                                !  calculations in MOSES                   S_DPDIAG.239    
     &  ,canht(points)          ! Canopy height (m)                        S_DPDIAG.240    
     &  ,etran(points)          ! Transpiration (kg m^-2 s^-1)             S_DPDIAG.241    
     &  ,gs(points)             ! Stomatal conductance                     S_DPDIAG.242    
     &  ,gpp(points)            ! Gross primary productivity               S_DPDIAG.243    
     &  ,lai(points)            ! Leaf area index                          S_DPDIAG.244    
     &  ,npp(points)            ! Net primary productivity                 S_DPDIAG.245    
     &  ,resp_p(points)         ! Plant respiration (kg C m^-2 s^-1)       S_DPDIAG.246    
     &  ,sthf(points,nsoilm_levs) ! Frozen soil moisture content           S_DPDIAG.247    
                                !  of each layer as a fraction of          S_DPDIAG.248    
                                !  saturation.                             S_DPDIAG.249    
     &  ,sthu(points,nsoilm_levs) ! IUnfrozen soil moisture content        S_DPDIAG.250    
                                !  of each layer as a fraction of          S_DPDIAG.251    
                                !  saturation.                             S_DPDIAG.252    
     &  ,surf_ht_flux(points)   ! Net downward heat flux at surface        S_DPDIAG.253    
                                !  over land or sea-ice fraction of        S_DPDIAG.254    
                                !  gridbox (W m^-2)                        S_DPDIAG.255    
      Real                                                                 S_DPDIAG.256    
     &  dump(points,nvars, ndump) ! OUT Array to store dump                S_DPDIAG.257    
C                                                                          S_DPDIAG.258    
      Do l = 1, points                                                     S_DPDIAG.259    
        Do i = 1, nlevs                                                    S_DPDIAG.260    
          dump(l,i,m1) = dump(l,i,m1) + u(l,i)                             S_DPDIAG.261    
        enddo                                                              S_DPDIAG.262    
        icount = i                                                         S_DPDIAG.263    
        Do i = icount,icount + nlevs-1                                     S_DPDIAG.264    
          dump(l,i,m1) = dump(l,i,m1) + v(l,i-icount + 1)                  S_DPDIAG.265    
        enddo                                                              S_DPDIAG.266    
        icount = i                                                         S_DPDIAG.267    
        Do i = icount,icount + nlevs-1                                     S_DPDIAG.268    
          dump(l,i,m1) = dump(l,i,m1) + t(l,i-icount + 1)                  S_DPDIAG.269    
        enddo                                                              S_DPDIAG.270    
        icount = i                                                         S_DPDIAG.271    
        Do i = icount,icount + nlevs-1                                     S_DPDIAG.272    
          dump(l,i,m1) = dump(l,i,m1) + theta(l,i-icount + 1)              S_DPDIAG.273    
        enddo                                                              S_DPDIAG.274    
        icount = i                                                         S_DPDIAG.275    
C                                                                          S_DPDIAG.276    
C       Calculate deltapk and T*deltapk throughout atmospheric column      S_DPDIAG.277    
C       for later calculations of TATMOS (see documentation)               S_DPDIAG.278    
C                                                                          S_DPDIAG.279    
        Do j = 1, nlevs                                                    S_DPDIAG.280    
          dump(l,icount,m1) = dump(l,icount,m1) +                          S_DPDIAG.281    
     &      (delta_ak(j) + pstar(l) * delta_bk(j))                         S_DPDIAG.282    
        enddo                                                              S_DPDIAG.283    
        icount = icount + 1                                                S_DPDIAG.284    
        Do j = 1, nlevs                                                    S_DPDIAG.285    
          dump(l,icount,m1) = dump(l,icount,m1) +                          S_DPDIAG.286    
     &      ((delta_ak(j) + pstar(l) * delta_bk(j)) * t(l,j))              S_DPDIAG.287    
        enddo                                                              S_DPDIAG.288    
                                                                           S_DPDIAG.289    
C                                                                          S_DPDIAG.290    
C       Leave 1 space in DUMP for later calculation of TATMOS              S_DPDIAG.291    
C                                                                          S_DPDIAG.292    
        icount = icount + 2                                                S_DPDIAG.293    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.294    
          dump(l,i,m1) = dump(l,i,m1) + q(l,i-icount + 1)                  S_DPDIAG.295    
        enddo                                                              S_DPDIAG.296    
        icount = i                                                         S_DPDIAG.297    
C       RH relative humidity                                               S_DPDIAG.298    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.299    
          dump(l,i,m1) = dump(l,i,m1) + rh(l,i-icount + 1, 1)              S_DPDIAG.300    
        enddo                                                              S_DPDIAG.301    
        icount = i                                                         S_DPDIAG.302    
C       RH relative humidity over liquid water                             S_DPDIAG.303    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.304    
          dump(l,i,m1) = dump(l,i,m1) + rh(l,i-icount + 1, 2)              S_DPDIAG.305    
        enddo                                                              S_DPDIAG.306    
        icount = i                                                         S_DPDIAG.307    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.308    
          dump(l,i,m1) = dump(l,i,m1) + qcl(l,i-icount + 1)                S_DPDIAG.309    
        enddo                                                              S_DPDIAG.310    
        icount = i                                                         S_DPDIAG.311    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.312    
          dump(l,i,m1) = dump(l,i,m1) + qcf(l,i-icount + 1)                S_DPDIAG.313    
        enddo                                                              S_DPDIAG.314    
        icount = i                                                         S_DPDIAG.315    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.316    
          dump(l,i,m1) = dump(l,i,m1) + lca(l,i-icount + 1)                S_DPDIAG.317    
        enddo                                                              S_DPDIAG.318    
        icount = i                                                         S_DPDIAG.319    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.320    
          dump(l,i,m1) = dump(l,i,m1) + dt(l,i-icount + 1)*86400.          S_DPDIAG.321    
        enddo                                                              S_DPDIAG.322    
        icount = i                                                         S_DPDIAG.323    
        Do i = icount,icount + nwet-1                                      S_DPDIAG.324    
          dump(l,i,m1) = dump(l,i,m1) + dq(l,i-icount + 1)*86400.          S_DPDIAG.325    
        enddo                                                              S_DPDIAG.326    
        icount = i                                                         S_DPDIAG.327    
C                                                                          S_DPDIAG.328    
C       Calculate Q*deltapk throughout atmospheric column                  S_DPDIAG.329    
C       for later calculations of QATMOS (see documentation)               S_DPDIAG.330    
C                                                                          S_DPDIAG.331    
        Do j = 1, nwet                                                     S_DPDIAG.332    
          dump(l,icount,m1) = dump(l,icount,m1) + ((delta_ak(j)            S_DPDIAG.333    
     &      + pstar(l) * delta_bk(j))*q(l,j))                              S_DPDIAG.334    
        enddo                                                              S_DPDIAG.335    
C                                                                          S_DPDIAG.336    
C       Leave 1 space in DUMP for later calculation of QATMOS              S_DPDIAG.337    
C                                                                          S_DPDIAG.338    
        icount = icount + 2                                                S_DPDIAG.339    
        dump(l,icount,m1) = dump(l,icount,m1) + cca(l)                     S_DPDIAG.340    
        icount = icount + 1                                                S_DPDIAG.341    
C                                                                          S_DPDIAG.342    
C       Calculate convective cloud base and top in Pa                      S_DPDIAG.343    
C                                                                          S_DPDIAG.344    
        If (ccb(l) .ne. 0)                                                 S_DPDIAG.345    
     &    dump(l,icount,m1) = (dump(l,icount,m1) + akh(ccb(l)) +           S_DPDIAG.346    
     &    pstar(l) * bkh(ccb(l))) * cca(l)                                 S_DPDIAG.347    
        icount = icount + 1                                                S_DPDIAG.348    
        If (cct(l) .ne. 0)                                                 S_DPDIAG.349    
     &    dump(l,icount,m1) = (dump(l,icount,m1) + akh(cct(l)) +           S_DPDIAG.350    
     &    pstar(l) * bkh(cct(l))) * cca(l)                                 S_DPDIAG.351    
C                                                                          S_DPDIAG.352    
C       Save next 2 spaces in dump for mean of convective cloud            S_DPDIAG.353    
C       top and base                                                       S_DPDIAG.354    
C                                                                          S_DPDIAG.355    
        icount = icount + 3                                                S_DPDIAG.356    
        dump(l,icount,m1) = dump(l,icount,m1) + conv_rain(l) * 86400.      S_DPDIAG.357    
        icount = icount + 1                                                S_DPDIAG.358    
        dump(l,icount,m1) = dump(l,icount,m1) + conv_snow(l) * 86400.      S_DPDIAG.359    
        icount = icount + 1                                                S_DPDIAG.360    
        dump(l,icount,m1) = dump(l,icount,m1) + ls_rain(l) * 86400.        S_DPDIAG.361    
        icount = icount + 1                                                S_DPDIAG.362    
        dump(l,icount,m1) = dump(l,icount,m1) + ls_snow(l) * 86400.        S_DPDIAG.363    
        icount = icount + 1                                                S_DPDIAG.364    
        Do i = icount,icount + nbl_levs-1                                  S_DPDIAG.365    
          dump(l,i,m1) = dump(l,i,m1) + taux(l,i-icount + 1)               S_DPDIAG.366    
        enddo                                                              S_DPDIAG.367    
        icount = i                                                         S_DPDIAG.368    
        Do  i = icount,icount + nbl_levs-1                                 S_DPDIAG.369    
          dump(l,i,m1) = dump(l,i,m1) + tauy(l,i-icount + 1)               S_DPDIAG.370    
        enddo                                                              S_DPDIAG.371    
        icount = i                                                         S_DPDIAG.372    
        Do i = icount,icount + nbl_levs-1                                  S_DPDIAG.373    
          dump(l,i,m1) = dump(l,i,m1) + fqw(l,i-icount + 1)                S_DPDIAG.374    
        enddo                                                              S_DPDIAG.375    
        icount = i                                                         S_DPDIAG.376    
        Do i = icount,icount + nbl_levs-1                                  S_DPDIAG.377    
          dump(l,i,m1) = dump(l,i,m1) + ftl(l,i-icount + 1)                S_DPDIAG.378    
        enddo                                                              S_DPDIAG.379    
        icount = i                                                         S_DPDIAG.380    
        Do i = icount,icount + nsoilt_levs-1                               S_DPDIAG.381    
          dump(l,i,m1) = dump(l,i,m1) + tdeep(l,i-icount + 1)              S_DPDIAG.382    
        enddo                                                              S_DPDIAG.383    
        icount = i                                                         S_DPDIAG.384    
        dump(l,icount,m1) = dump(l,icount,m1) + pstar(l)                   S_DPDIAG.385    
        icount = icount + 1                                                S_DPDIAG.386    
        dump(l,icount,m1) = dump(l,icount,m1) + tstar(l)                   S_DPDIAG.387    
        icount = icount + 1                                                S_DPDIAG.388    
        dump(l,icount,m1) = dump(l,icount,m1) + smc(l)                     S_DPDIAG.389    
        icount = icount + 1                                                S_DPDIAG.390    
        dump(l,icount,m1) = dump(l,icount,m1) + canopy(l)                  S_DPDIAG.391    
        icount = icount + 1                                                S_DPDIAG.392    
        dump(l,icount,m1) = dump(l,icount,m1) + snodep(l)                  S_DPDIAG.393    
        icount = icount + 1                                                S_DPDIAG.394    
        dump(l,icount,m1) = dump(l,icount,m1) + zh(l)                      S_DPDIAG.395    
        icount = icount + 1                                                S_DPDIAG.396    
        dump(l,icount,m1) = dump(l,icount,m1) + z0m(l)                     S_DPDIAG.397    
        icount = icount + 1                                                S_DPDIAG.398    
        dump(l,icount,m1) = dump(l,icount,m1) + surf_ht_flux(l)            S_DPDIAG.399    
        icount = icount + 1                                                S_DPDIAG.400    
        dump(l,icount,m1) = dump(l,icount,m1) + can_evap(l)*86400.         S_DPDIAG.401    
        icount = icount + 1                                                S_DPDIAG.402    
        dump(l,icount,m1) = dump(l,icount,m1) + soil_evap(l)*86400.        S_DPDIAG.403    
        icount = icount + 1                                                S_DPDIAG.404    
        dump(l,icount,m1) = dump(l,icount,m1) + seai_htf(l)                S_DPDIAG.405    
        icount = icount + 1                                                S_DPDIAG.406    
        dump(l,icount,m1) = dump(l,icount,m1) + sice_mlt_htf(l)            S_DPDIAG.407    
        icount = icount + 1                                                S_DPDIAG.408    
        dump(l,icount,m1) = dump(l,icount,m1) + sublim(l)*86400.           S_DPDIAG.409    
        icount = icount + 1                                                S_DPDIAG.410    
        dump(l,icount,m1) = dump(l,icount,m1) + lat_ht(l)                  S_DPDIAG.411    
        icount = icount + 1                                                S_DPDIAG.412    
        dump(l,icount,m1) = dump(l,icount,m1) + sens_ht(l)                 S_DPDIAG.413    
        icount = icount + 1                                                S_DPDIAG.414    
        dump(l,icount,m1) = dump(l,icount,m1) + u10m(l)                    S_DPDIAG.415    
        icount = icount + 1                                                S_DPDIAG.416    
        dump(l,icount,m1) = dump(l,icount,m1) + v10m(l)                    S_DPDIAG.417    
        icount = icount + 1                                                S_DPDIAG.418    
        dump(l,icount,m1) = dump(l,icount,m1) + t1p5m(l)                   S_DPDIAG.419    
        icount = icount + 1                                                S_DPDIAG.420    
C       Set up T1p5m_max in dump. If dumps are requested every             S_DPDIAG.421    
C       physics timestep or if it is the 1st timestep in the dump          S_DPDIAG.422    
C       period or the current value of T1p5m is greater set it to          S_DPDIAG.423    
C       T1p5m.                                                             S_DPDIAG.424    
C                                                                          S_DPDIAG.425    
        If ((dump_step .eq. 1) .or.                                        S_DPDIAG.426    
     &    (mod(stepcount,dump_step) .eq. 1) .or.                           S_DPDIAG.427    
     &    (t1p5m(l) .gt. dump(l,icount,m1)))                               S_DPDIAG.428    
     &    then                                                             S_DPDIAG.429    
          dump(l,icount,m1) = t1p5m(l)                                     S_DPDIAG.430    
        endif                                                              S_DPDIAG.431    
        icount = icount + 1                                                S_DPDIAG.432    
C       Similarly set up T1p5m_min                                         S_DPDIAG.433    
C                                                                          S_DPDIAG.434    
        if ((dump_step .eq. 1)                                             S_DPDIAG.435    
     &    .or. (mod(stepcount,dump_step) .eq. 1)                           S_DPDIAG.436    
     &    .or. (t1p5m(l) .lt. dump(l,icount,m1))) then                     S_DPDIAG.437    
          dump(l,icount,m1) = t1p5m(l)                                     S_DPDIAG.438    
        endif                                                              S_DPDIAG.439    
        icount = icount + 1                                                S_DPDIAG.440    
        dump(l,icount,m1) = dump(l,icount,m1) + rib(l)                     S_DPDIAG.441    
        icount = icount + 1                                                S_DPDIAG.442    
        dump(l,icount,m1) = dump(l,icount,m1) + q1p5m(l)                   S_DPDIAG.443    
        icount = icount + 1                                                S_DPDIAG.444    
        dump(l,icount,m1) = dump(l,icount,m1) + fast_roff(l)*86400.        S_DPDIAG.445    
        icount = icount + 1                                                S_DPDIAG.446    
        dump(l,icount,m1) = dump(l,icount,m1) + sub_roff(l)*86400.         S_DPDIAG.447    
        icount = icount + 1                                                S_DPDIAG.448    
        dump(l,icount,m1) = dump(l,icount,m1) + snomlt_htf(l)              S_DPDIAG.449    
        icount = icount + 1                                                S_DPDIAG.450    
        dump(l,icount,m1) = dump(l,icount,m1) + snomlt_surf_htf(l)         S_DPDIAG.451    
        icount = icount + 1                                                S_DPDIAG.452    
        dump(l,icount,m1) = dump(l,icount,m1) + snomlt_sub_htf(l)          S_DPDIAG.453    
        icount = icount + 1                                                S_DPDIAG.454    
        dump(l,icount,m1) = dump(l,icount,m1) + snomlt(l)*86400.           S_DPDIAG.455    
        icount = icount + 1                                                S_DPDIAG.456    
        dump(l,icount,m1) = dump(l,icount,m1) + thro_fall(l)*86400.        S_DPDIAG.457    
        icount = icount + 1                                                S_DPDIAG.458    
        Do i = icount,icount + nsoilm_levs-1                               S_DPDIAG.459    
          dump(l,i,m1) = dump(l,i,m1) + smcl(l,i-icount + 1)               S_DPDIAG.460    
        enddo                                                              S_DPDIAG.461    
        icount = i                                                         S_DPDIAG.462    
        Do i = icount,icount + nsoilm_levs-1                               S_DPDIAG.463    
          dump(l,i,m1) = dump(l,i,m1) + sthu(l,i-icount + 1)               S_DPDIAG.464    
        enddo                                                              S_DPDIAG.465    
        icount = i                                                         S_DPDIAG.466    
        Do i = icount,icount + nsoilm_levs-1                               S_DPDIAG.467    
          dump(l,i,m1) = dump(l,i,m1) + sthf(l,i-icount + 1)               S_DPDIAG.468    
        enddo                                                              S_DPDIAG.469    
        icount = i                                                         S_DPDIAG.470    
        dump(l,icount,m1) = dump(l,icount,m1) + lai(l)                     S_DPDIAG.471    
        icount = icount + 1                                                S_DPDIAG.472    
        dump(l,icount,m1) = dump(l,icount,m1) + canht(l)                   S_DPDIAG.473    
        icount = icount + 1                                                S_DPDIAG.474    
        dump(l,icount,m1) = dump(l,icount,m1) + gs(l)                      S_DPDIAG.475    
        icount = icount + 1                                                S_DPDIAG.476    
        dump(l,icount,m1) = dump(l,icount,m1) + etran(l)*1000.0*86400.     S_DPDIAG.477    
        icount = icount + 1                                                S_DPDIAG.478    
        dump(l,icount,m1) = dump(l,icount,m1) + gpp(l)*1000.0*86400.       S_DPDIAG.479    
        icount = icount + 1                                                S_DPDIAG.480    
        dump(l,icount,m1) = dump(l,icount,m1) + npp(l)*1000.0*86400.       S_DPDIAG.481    
        icount = icount + 1                                                S_DPDIAG.482    
        dump(l,icount,m1) = dump(l,icount,m1) + resp_p(l)*1000.*86400.     S_DPDIAG.483    
        icount = icount + 1                                                S_DPDIAG.484    
        Do i = icount,icount + nlevs-1                                     S_DPDIAG.485    
          dump(l,i,m1) = dump(l,i,m1)                                      S_DPDIAG.486    
     &      + (sw(l,i-icount + 2)/timestep)*86400.                         S_DPDIAG.487    
        enddo                                                              S_DPDIAG.488    
        icount = i                                                         S_DPDIAG.489    
        Do i = icount,icount + nlevs-1                                     S_DPDIAG.490    
          dump(l,i,m1) = dump(l,i,m1)                                      S_DPDIAG.491    
     &      + (lw(l,i-icount + 2)/timestep)*86400.                         S_DPDIAG.492    
        enddo                                                              S_DPDIAG.493    
        icount = i                                                         S_DPDIAG.494    
        dump(l,icount,m1) = dump(l,icount,m1) + net_rad(l)                 S_DPDIAG.495    
        icount = icount + 1                                                S_DPDIAG.496    
        If (land_mask(l)) then                                             S_DPDIAG.497    
          dump(l,icount,m1) = dump(l,icount,m1) + sw(l,1)                  S_DPDIAG.498    
        else                                                               S_DPDIAG.499    
          dump(l,icount,m1) = dump(l,icount,m1) + swsea(l)                 S_DPDIAG.500    
        endif                                                              S_DPDIAG.501    
        icount = icount + 1                                                S_DPDIAG.502    
        dump(l,icount,m1) = dump(l,icount,m1) + down_surf_sw_b1(l)         S_DPDIAG.503    
        icount = icount + 1                                                S_DPDIAG.504    
        If (land_mask(l)) then                                             S_DPDIAG.505    
          dump(l,icount,m1) = dump(l,icount,m1) + lw(l,1)                  S_DPDIAG.506    
        else                                                               S_DPDIAG.507    
          dump(l,icount,m1) = dump(l,icount,m1) + lwsea(l)                 S_DPDIAG.508    
        endif                                                              S_DPDIAG.509    
        icount = icount + 1                                                S_DPDIAG.510    
        dump(l,icount,m1) = dump(l,icount,m1) + os_toa(l)                  S_DPDIAG.511    
        icount = icount + 1                                                S_DPDIAG.512    
        dump(l,icount,m1) = dump(l,icount,m1) + is_toa(l)                  S_DPDIAG.513    
        icount = icount + 1                                                S_DPDIAG.514    
        dump(l,icount,m1) = dump(l,icount,m1) + olr_toa(l)                 S_DPDIAG.515    
        icount = icount + 1                                                S_DPDIAG.516    
        dump(l,icount,m1) = dump(l,icount,m1) + csolrd(l)                  S_DPDIAG.517    
        icount = icount + 1                                                S_DPDIAG.518    
        dump(l,icount,m1) = dump(l,icount,m1) + csosdi(l)                  S_DPDIAG.519    
        icount = icount + 1                                                S_DPDIAG.520    
        dump(l,icount,m1) = dump(l,icount,m1) + tca(l)                     S_DPDIAG.521    
C                                                                          S_DPDIAG.522    
C       check that icount is now equal to the no. of variables             S_DPDIAG.523    
C                                                                          S_DPDIAG.524    
        If (nvars .gt. icount) then                                        S_DPDIAG.525    
          Write (6,41)                                                     S_DPDIAG.526    
          Write (6,43) icount, nvars                                       S_DPDIAG.527    
          Stop                                                             S_DPDIAG.528    
        elseif (nvars .lt. icount) then                                    S_DPDIAG.529    
          Write (6,42)                                                     S_DPDIAG.530    
          Write (6,43) icount, nvars                                       S_DPDIAG.531    
          Stop                                                             S_DPDIAG.532    
        endif                                                              S_DPDIAG.533    
      enddo                     ! l                                        S_DPDIAG.534    
 41   Format(' WARNING! no. of variables in dump does not match')          S_DPDIAG.535    
 42   Format(' WARNING! dump not big enough - nvars wrongly set')          S_DPDIAG.536    
 43   Format(' WARNING! icount = ',i4,' nvars =  ',i4)                     S_DPDIAG.537    
C                                                                          S_DPDIAG.538    
C     Form mean over basic time unit                                       S_DPDIAG.539    
C                                                                          S_DPDIAG.540    
      If (mod(stepcount,dump_step) .eq. 0) then                            S_DPDIAG.541    
        Do l = 1, points                                                   S_DPDIAG.542    
          Do i = 1, nvars                                                  S_DPDIAG.543    
            If (i .ne. t1p5m_maxcount                                      S_DPDIAG.544    
     &        .and. i .ne. t1p5m_mincount)  then                           S_DPDIAG.545    
              dump(l,i,m1) = dump(l,i,m1)/real(dump_step)                  S_DPDIAG.546    
            endif                                                          S_DPDIAG.547    
          enddo                                                            S_DPDIAG.548    
c                                                                          S_DPDIAG.549    
C         Calculate average T and q throughout atmospheric column          S_DPDIAG.550    
C                                                                          S_DPDIAG.551    
C                                                                          S_DPDIAG.552    
          Do i = 1, nvars                                                  S_DPDIAG.553    
            If (i .eq. tcount) then                                        S_DPDIAG.554    
              dump(l,i,m1) = dump(l,i-1,m1) / dump(l,i-2,m1)               S_DPDIAG.555    
            endif                                                          S_DPDIAG.556    
            If (i .eq. qcount) then                                        S_DPDIAG.557    
              dump(l,i,m1) = dump(l,i-1,m1) / dump(l,tcount-2,m1)          S_DPDIAG.558    
            endif                                                          S_DPDIAG.559    
C                                                                          S_DPDIAG.560    
C           Calculate mean of cloud base and top in Pa rather than         S_DPDIAG.561    
C           levels                                                         S_DPDIAG.562    
C                                                                          S_DPDIAG.563    
            If (i .eq. (cloud_count)) then                                 S_DPDIAG.564    
C                                                                          S_DPDIAG.565    
C             Check that sum of CCA is non-zero so that you don't          S_DPDIAG.566    
C             divide by zero                                               S_DPDIAG.567    
C                                                                          S_DPDIAG.568    
              If (dump(l,cloud_count-3,m1) .ne. 0.0)                       S_DPDIAG.569    
     &          dump(l,i,m1) = dump(l,i-2,m1)/                             S_DPDIAG.570    
     &          dump(l,i-3,m1)                                             S_DPDIAG.571    
                                                                           S_DPDIAG.572    
            elseif (i .eq. (cloud_count + 1)) then                         S_DPDIAG.573    
C                                                                          S_DPDIAG.574    
C             Check that sum of CCA is non-zero so that you don't          S_DPDIAG.575    
C             divide by zero                                               S_DPDIAG.576    
C                                                                          S_DPDIAG.577    
              If (dump(l,i-4,m1) .ne. 0.0)                                 S_DPDIAG.578    
     &          dump(l,i,m1) = dump(l,i-2,m1)/                             S_DPDIAG.579    
     &          dump(l,i-4,m1)                                             S_DPDIAG.580    
            endif                                                          S_DPDIAG.581    
          enddo                 ! nvars                                    S_DPDIAG.582    
        enddo                   ! l                                        S_DPDIAG.583    
        m1 = m1 + 1                                                        S_DPDIAG.584    
      endif                     ! mod(stepcount,dump_step) .eq. 0          S_DPDIAG.585    
      Return                                                               S_DPDIAG.586    
      End                       ! Subroutine DUMPDIAG                      S_DPDIAG.587    
                                                                           S_DPDIAG.588    
C                                                                          S_DPDIAG.589    
*ENDIF                                                                     S_DPDIAG.590