*IF DEF,RECON                                                              CUHGT1A.2      
C *****************************COPYRIGHT******************************     CUHGT1A.3      
C (c) CROWN COPYRIGHT 1996, METEOROLOGICAL OFFICE, All Rights Reserved.    CUHGT1A.4      
C                                                                          CUHGT1A.5      
C Use, duplication or disclosure of this code is subject to the            CUHGT1A.6      
C restrictions as set forth in the contract.                               CUHGT1A.7      
C                                                                          CUHGT1A.8      
C                Meteorological Office                                     CUHGT1A.9      
C                London Road                                               CUHGT1A.10     
C                BRACKNELL                                                 CUHGT1A.11     
C                Berkshire UK                                              CUHGT1A.12     
C                RG12 2SZ                                                  CUHGT1A.13     
C                                                                          CUHGT1A.14     
C If no contract has been raised with this copy of the code, the use,      CUHGT1A.15     
C duplication or disclosure of it is strictly prohibited.  Permission      CUHGT1A.16     
C to do so must first be obtained in writing from the Head of Numerical    CUHGT1A.17     
C Modelling at the above address.                                          CUHGT1A.18     
C ******************************COPYRIGHT******************************    CUHGT1A.19     
! Returns the height of each u point on the Charney-Phillips grid given    CUHGT1A.20     
!                                                                          CUHGT1A.21     
! Subroutine interface:                                                    CUHGT1A.22     

      SUBROUTINE CU_HGT(z_in,z_out,                                         3CUHGT1A.23     
     &                  points,levels,j,row_length,                        CUHGT1A.24     
     &                  lam)                                               CUHGT1A.25     
                                                                           CUHGT1A.26     
      IMPLICIT NONE                                                        CUHGT1A.27     
!                                                                          CUHGT1A.28     
! Description: Calculates the height at each u point on the Charney        CUHGT1A.29     
!              Phillips grid using an average of the two adjacent height   CUHGT1A.30     
!              of the pressure points along each row.                      CUHGT1A.31     
!                                                                          CUHGT1A.32     
!                                                                          CUHGT1A.33     
! Current Code Owner: I Edmond                                             CUHGT1A.34     
!                                                                          CUHGT1A.35     
! History:                                                                 CUHGT1A.36     
! Version   Date     Comment                                               CUHGT1A.37     
! -------   ----     -------                                               CUHGT1A.38     
! 4.1       15/6/96   Original code. Ian Edmond                            CUHGT1A.39     
!                                                                          CUHGT1A.40     
! Code Description:                                                        CUHGT1A.41     
!   Language: FORTRAN 77 + common extensions.                              CUHGT1A.42     
!   This code is written to UMDP3 v6 programming standards.                CUHGT1A.43     
!                                                                          CUHGT1A.44     
! System component covered: <appropriate code>                             CUHGT1A.45     
! System Task:              <appropriate code>                             CUHGT1A.46     
!                                                                          CUHGT1A.47     
! Declarations:                                                            CUHGT1A.48     
!   These are of the form:-                                                CUHGT1A.49     
!     INTEGER      ExampleVariable      !Description of variable           CUHGT1A.50     
!                                                                          CUHGT1A.51     
! Subroutine arguments                                                     CUHGT1A.52     
!   Scalar arguments with intent(in):                                      CUHGT1A.53     
       INTEGER                                                             CUHGT1A.54     
     & points      ! Number of points to be processed.                     CUHGT1A.55     
     &,levels      ! Number of levels in source data.                      CUHGT1A.56     
     &,row_length  ! Number of columns per level.                          CUHGT1A.57     
                                                                           CUHGT1A.58     
!   Array  arguments with intent(in):                                      CUHGT1A.59     
       REAL                                                                CUHGT1A.60     
     & z_in(points,levels) ! Full level heights. i.e press level heights   CUHGT1A.61     
                                                                           CUHGT1A.62     
!   Array  arguments with intent(out):                                     CUHGT1A.63     
      REAL                                                                 CUHGT1A.64     
     & z_out(points) ! 3-D field of heights at which PF u is stored.       CUHGT1A.65     
                                                                           CUHGT1A.66     
! Local scalars:                                                           CUHGT1A.67     
       INTEGER                                                             CUHGT1A.68     
     & i,j                                                                 CUHGT1A.69     
                                                                           CUHGT1A.70     
       LOGICAL                                                             CUHGT1A.71     
     & lam      ! Determines whether input grid is LAM or global.          CUHGT1A.72     
                                                                           CUHGT1A.73     
!- End of header                                                           CUHGT1A.74     
                                                                           CUHGT1A.75     
        Do i = 1, points                                                   CUHGT1A.76     
                                                                           CUHGT1A.77     
          If (MOD(i,row_length).ne.0) then                                 CUHGT1A.78     
                                                                           CUHGT1A.79     
           ! Columns 1 -> row_length-1, height of U on the C grid          CUHGT1A.80     
           ! found from averaging adjacent heights of UM press points.     CUHGT1A.81     
            z_out(i) = (z_in(i,j) + z_in(i+1,j)) / 2.0                     CUHGT1A.82     
                                                                           CUHGT1A.83     
          else                                                             CUHGT1A.84     
           ! Last column of grid.                                          CUHGT1A.85     
            if (lam) then                                                  CUHGT1A.86     
                                                                           CUHGT1A.87     
             ! if lam grid, set V on last column of the C grid to          CUHGT1A.88     
             ! those on last column of the UM grid.                        CUHGT1A.89     
             z_out(i) = z_in(i,j)                                          CUHGT1A.90     
                                                                           CUHGT1A.91     
            else                                                           CUHGT1A.92     
             ! if global model i.e wrap around grid, calculate V on        CUHGT1A.93     
             ! column 1 of the C grid by averaging V on the 1st and        CUHGT1A.94     
             ! last columns of the UM grid.                                CUHGT1A.95     
             z_out(i) = (z_in(i,j) + z_in(i-row_length+1,j)) / 2.0         CUHGT1A.96     
                                                                           CUHGT1A.97     
            End if                                                         CUHGT1A.98     
                                                                           CUHGT1A.99     
          End if                                                           CUHGT1A.100    
                                                                           CUHGT1A.101    
        End do ! i                                                         CUHGT1A.102    
                                                                           CUHGT1A.103    
                                                                           CUHGT1A.104    
      RETURN                                                               CUHGT1A.105    
      END                                                                  CUHGT1A.106    
*ENDIF                                                                     CUHGT1A.107