*IF DEF,A15_1A                                                             DTHDP1A.2      
C ******************************COPYRIGHT******************************    GTS2F400.2305   
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.2306   
C                                                                          GTS2F400.2307   
C Use, duplication or disclosure of this code is subject to the            GTS2F400.2308   
C restrictions as set forth in the contract.                               GTS2F400.2309   
C                                                                          GTS2F400.2310   
C                Meteorological Office                                     GTS2F400.2311   
C                London Road                                               GTS2F400.2312   
C                BRACKNELL                                                 GTS2F400.2313   
C                Berkshire UK                                              GTS2F400.2314   
C                RG12 2SZ                                                  GTS2F400.2315   
C                                                                          GTS2F400.2316   
C If no contract has been raised with this copy of the code, the use,      GTS2F400.2317   
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.2318   
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.2319   
C Modelling at the above address.                                          GTS2F400.2320   
C ******************************COPYRIGHT******************************    GTS2F400.2321   
C                                                                          GTS2F400.2322   
CLL Subroutine dthe_dp -----------------------------------------------     DTHDP1A.3      
CLL                                                                        DTHDP1A.4      
CLL Purpose: To compute dtheta_dp on model half-levels                     DTHDP1A.5      
CLL          for use in potential vorticity calculation.                   DTHDP1A.6      
CLL          These are the natural definition of static stability          DTHDP1A.7      
CLL          given that theta is held on model levels.                     DTHDP1A.8      
CLL          The subroutine calculates both dtheta/dp and the              DTHDP1A.9      
CLL          half-levels (called e_levels) between the top and             DTHDP1A.10     
CLL          bottom full levels. Therefore there are p_levels-1            DTHDP1A.11     
CLL          e_levels and dtheta/dp's.                                     DTHDP1A.12     
CLL                                                                        DTHDP1A.13     
CLL Not suitable for single column use.                                    DTHDP1A.14     
CLL                                                                        DTHDP1A.15     
CLL  13/9/93 Written by Terry Davies                                       DTHDP1A.16     
CLL                                                                        DTHDP1A.17     
CLL  Model            Modification history:                                DTHDP1A.18     
CLL version  Date                                                          DTHDP1A.19     
CLL   3.3   14/12/93  Original version                                     DTHDP1A.20     
CLL                                                                        DTHDP1A.21     
CLL Programming Standard: UM DOC Paper3, Version 4 (05/02/92)              DTHDP1A.22     
CLL                                                                        DTHDP1A.23     
CLL Logical Component Covered: D415                                        DTHDP1A.24     
CLL                                                                        DTHDP1A.25     
CLL System Task: D4                                                        DTHDP1A.26     
CLL                                                                        DTHDP1A.27     
CLL Documentation: U.M.D.P No 13. Derivation and Calculation of            DTHDP1A.28     
CLL                Unified Model Potential Vorticity.                      DTHDP1A.29     
CLL                by Simon Anderson and Ian Roulstone.                    DTHDP1A.30     
CLL                                                                        DTHDP1A.31     
CLLEND                                                                     DTHDP1A.32     
                                                                           DTHDP1A.33     
C*L ARGUMENTS: ---------------------------------------------------------   DTHDP1A.34     

      subroutine dthe_dp                                                    1DTHDP1A.35     
     1                  (pstar,theta,p_field,p_levels,                     DTHDP1A.36     
     2                   ak,bk,akh,bkh,n_levels,                           DTHDP1A.37     
     3                   e_levels,dthe_dph)                                DTHDP1A.38     
                                                                           DTHDP1A.39     
      implicit none                                                        DTHDP1A.40     
                                                                           DTHDP1A.41     
C Input variables ------------------------------------------------------   DTHDP1A.42     
                                                                           DTHDP1A.43     
      integer                                                              DTHDP1A.44     
     & p_field                 !IN    Size of field on pressure points.    DTHDP1A.45     
     &,p_levels                !IN    Number of pressure levels.           DTHDP1A.46     
     &,n_levels                !IN    Number of half-levels (p_levels-1)   DTHDP1A.47     
C                                     for dtheta/dp and e_levels.          DTHDP1A.48     
                                                                           DTHDP1A.49     
      real                                                                 DTHDP1A.50     
     & pstar(p_field)          !IN    Surface pressure field.              DTHDP1A.51     
     &,theta(p_field,p_levels) !IN    Theta field on p_levels              DTHDP1A.52     
                                                                           DTHDP1A.53     
      real                                                                 DTHDP1A.54     
     & ak(p_levels)            !IN    A coefficient of hybrid              DTHDP1A.55     
     &                         !      coordinates at full levels.          DTHDP1A.56     
     &,bk(p_levels)            !IN    B coefficient of hybrid              DTHDP1A.57     
     &                         !      coordinates at full levels.          DTHDP1A.58     
     &,akh(p_levels+1)          !IN    A coefficient of hybrid             DTHDP1A.59     
     &                         !      coordinates at half levels.          DTHDP1A.60     
     &,bkh(p_levels+1)         !IN    B coefficient of hybrid              DTHDP1A.61     
     &                         !      coordinates at half levels.          DTHDP1A.62     
                                                                           DTHDP1A.63     
C Output variables -----------------------------------------------------   DTHDP1A.64     
                                                                           DTHDP1A.65     
      real                                                                 DTHDP1A.66     
     & e_levels(n_levels)    !OUT   Model half-levels over range.          DTHDP1A.67     
     &,dthe_dph(p_field,n_levels)   !OUT dtheta/dp on half levels          DTHDP1A.68     
                                                                           DTHDP1A.69     
                                                                           DTHDP1A.70     
C*----------------------------------------------------------------------   DTHDP1A.71     
C*L Workspace Usage: 2  arrays are required.                               DTHDP1A.72     
      real                                                                 DTHDP1A.73     
     & pressure(p_field,2)   ! Pressure on model levels                    DTHDP1A.74     
     &,thetae(p_field,2)    ! thetate on model levels                      DTHDP1A.75     
C                            ! 2 levels used, IL, IU used to switch        DTHDP1A.76     
                                                                           DTHDP1A.77     
C*----------------------------------------------------------------------   DTHDP1A.78     
C*L External subroutine calls:                                             DTHDP1A.79     
                                                                           DTHDP1A.80     
C*----------------------------------------------------------------------   DTHDP1A.81     
C*L Call comdecks to get required variables:                               DTHDP1A.82     
                                                                           DTHDP1A.83     
C*----------------------------------------------------------------------   DTHDP1A.84     
C*L Define local variables.                                                DTHDP1A.85     
      integer i,j,ii       ! Loop variables.                               DTHDP1A.86     
     & ,il,iu,is           ! Pointers for pressure arrays                  DTHDP1A.87     
                                                                           DTHDP1A.88     
C ----------------------------------------------------------------------   DTHDP1A.89     
CL Section 1 Compute model half-levels over required range                 DTHDP1A.90     
CL ~~~~~~~~~                                                               DTHDP1A.91     
C ----------------------------------------------------------------------   DTHDP1A.92     
                                                                           DTHDP1A.93     
CL Section 1.1                                                             DTHDP1A.94     
CL ~~~~~~~~~~~ Half-levels in e_levels                                     DTHDP1A.95     
                                                                           DTHDP1A.96     
      do i=1,p_levels-1                                                    DTHDP1A.97     
      ii=i+1                                                               DTHDP1A.98     
      e_levels(i)=0.00001*akh(ii)+bkh(ii)                                  DTHDP1A.99     
      end do                                                               DTHDP1A.100    
                                                                           DTHDP1A.101    
CL Section 1.2 Calculate pressure at bottom of range                       DTHDP1A.102    
CL             Store in pressure(p_field,1)                                DTHDP1A.103    
                                                                           DTHDP1A.104    
      do j=1,p_field                                                       DTHDP1A.105    
      pressure(j,1)=ak(1)+bk(1)*pstar(j)                                   DTHDP1A.106    
      end do                                                               DTHDP1A.107    
                                                                           DTHDP1A.108    
C ----------------------------------------------------------------------   DTHDP1A.109    
CL Section 2 Calculate dtheta/dp on model half-levels                      DTHDP1A.110    
CL ~~~~~~~~~                                                               DTHDP1A.111    
C ----------------------------------------------------------------------   DTHDP1A.112    
                                                                           DTHDP1A.113    
      is=1                                                                 DTHDP1A.114    
      il=2                                                                 DTHDP1A.115    
      do i=1,p_levels-1                                                    DTHDP1A.116    
      iu=il                                                                DTHDP1A.117    
      il=is                                                                DTHDP1A.118    
      ii=i+1                                                               DTHDP1A.119    
       do j=1,p_field                                                      DTHDP1A.120    
       pressure(j,iu)=ak(ii)+bk(ii)*pstar(j)                               DTHDP1A.121    
       dthe_dph(j,i)=(theta(j,ii-1)-theta(j,ii))/                          DTHDP1A.122    
     2           (pressure(j,il)-pressure(j,iu))                           DTHDP1A.123    
       end do                                                              DTHDP1A.124    
      is=iu                                                                DTHDP1A.125    
      end do                                                               DTHDP1A.126    
                                                                           DTHDP1A.127    
      return                                                               DTHDP1A.128    
      end                                                                  DTHDP1A.129    
                                                                           DTHDP1A.130    
*ENDIF                                                                     DTHDP1A.131