*IF DEF,A71_1A,OR,DEF,MAKEBC                                               DRINTFA1.2      
*IF DEF,ATMOS                                                              DRINTFA1.3      
C ******************************COPYRIGHT******************************    DRINTFA1.4      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    DRINTFA1.5      
C                                                                          DRINTFA1.6      
C Use, duplication or disclosure of this code is subject to the            DRINTFA1.7      
C restrictions as set forth in the contract.                               DRINTFA1.8      
C                                                                          DRINTFA1.9      
C                Meteorological Office                                     DRINTFA1.10     
C                London Road                                               DRINTFA1.11     
C                BRACKNELL                                                 DRINTFA1.12     
C                Berkshire UK                                              DRINTFA1.13     
C                RG12 2SZ                                                  DRINTFA1.14     
C                                                                          DRINTFA1.15     
C If no contract has been raised with this copy of the code, the use,      DRINTFA1.16     
C duplication or disclosure of it is strictly prohibited.  Permission      DRINTFA1.17     
C to do so must first be obtained in writing from the Head of Numerical    DRINTFA1.18     
C Modelling at the above address.                                          DRINTFA1.19     
C ******************************COPYRIGHT******************************    DRINTFA1.20     
!+ Subroutine DERV_INTF_A : Calculates Interface array dimensions.         DRINTFA1.21     
!                                                                          DRINTFA1.22     
! Subroutine Interface :                                                   DRINTFA1.23     
!                                                                          DRINTFA1.24     

      SUBROUTINE DERV_INTF_A (TOT_LEN_INTFA_P,TOT_LEN_INTFA_U,              2DRINTFA1.25     
     &           MAX_INTF_P_LEVELS,N_INTF_A,U_FIELD,U_FIELD_INTFA)         DRINTFA1.26     
                                                                           DRINTFA1.27     
      IMPLICIT NONE                                                        DRINTFA1.28     
!                                                                          DRINTFA1.29     
! Description : Calculate array dimensions for boundary data output.       DRINTFA1.30     
!                                                                          DRINTFA1.31     
! Method : Reads in INTFCNSTA namelist to get grid dimensions of           DRINTFA1.32     
!          interface area. Calculates array dimensions for boundary        DRINTFA1.33     
!          data. Also sets dimensions to 1 if no interface areas           DRINTFA1.34     
!          required to prevent zero dynamic allocation.                    DRINTFA1.35     
!                                                                          DRINTFA1.36     
! Current Code Owner : Dave Robinson, NWP                                  DRINTFA1.37     
!                                                                          DRINTFA1.38     
! History :                                                                DRINTFA1.39     
! Version    Date    Comment                                               DRINTFA1.40     
! -------    ----    -------                                               DRINTFA1.41     
!   4.5    03/08/98  Original Code                                         DRINTFA1.42     
!                                                                          DRINTFA1.43     
! Code Description :                                                       DRINTFA1.44     
! Language : FORTRAN 77 + common extensions                                DRINTFA1.45     
!                                                                          DRINTFA1.46     
! Declarations :                                                           DRINTFA1.47     
                                                                           DRINTFA1.48     
!     Arguments                                                            DRINTFA1.49     
      Integer TOT_LEN_INTFA_P   ! OUT  Total length of interface data      DRINTFA1.50     
                                !      on P grid                           DRINTFA1.51     
      Integer TOT_LEN_INTFA_U   ! OUT  Total length of interface data      DRINTFA1.52     
                                !      on U grid                           DRINTFA1.53     
      Integer MAX_INTF_P_LEVELS ! OUT  Max no of levels for all areas      DRINTFA1.54     
      Integer N_INTF_A          ! IN   No of interface areas               DRINTFA1.55     
      Integer U_FIELD           ! IN   Dimension of U_FIELD                DRINTFA1.56     
      Integer U_FIELD_INTFA     ! OUT  Dimension of U_FIELD for dynamic    DRINTFA1.57     
                                !      allocation.                         DRINTFA1.58     
                                                                           DRINTFA1.59     
*CALL CMAXSIZE                                                             DRINTFA1.60     
*CALL CINTFA                                                               DRINTFA1.61     
                                                                           DRINTFA1.62     
C  Namelist for atmos interface constants                                  DRINTFA1.63     
*CALL CNAMINFA                                                             DRINTFA1.64     
                                                                           DRINTFA1.65     
!     Local variables                                                      DRINTFA1.66     
      INTEGER JINTF  !  loop index                                         DRINTFA1.67     
                                                                           DRINTFA1.68     
!     Read in INTFCNSTA namelist to get output grids for                   DRINTFA1.69     
!     generating boundary data.                                            DRINTFA1.70     
                                                                           DRINTFA1.71     
      REWIND 5                                                             DRINTFA1.72     
      READ (5,INTFCNSTA)                                                   DRINTFA1.73     
      REWIND 5                                                             DRINTFA1.74     
                                                                           DRINTFA1.75     
      IF (N_INTF_A.GT.0) THEN                                              DRINTFA1.76     
                                                                           DRINTFA1.77     
!       Boundary data to be generated in this run.                         DRINTFA1.78     
                                                                           DRINTFA1.79     
        TOT_LEN_INTFA_P=0                                                  DRINTFA1.80     
        TOT_LEN_INTFA_U=0                                                  DRINTFA1.81     
        MAX_INTF_P_LEVELS=0                                                DRINTFA1.82     
                                                                           DRINTFA1.83     
        DO JINTF=1,N_INTF_A                                                DRINTFA1.84     
                                                                           DRINTFA1.85     
!         Calculate lengths for interface area JINTF                       DRINTFA1.86     
                                                                           DRINTFA1.87     
          LEN_INTFA_P(JINTF) = ( INTF_ROW_LENGTH(JINTF) +                  DRINTFA1.88     
     &    INTF_P_ROWS(JINTF) - 2*INTFWIDTHA(JINTF) )                       DRINTFA1.89     
     &    * 2 * INTFWIDTHA(JINTF)                                          DRINTFA1.90     
          LEN_INTFA_U(JINTF) = LEN_INTFA_P(JINTF) - 4*INTFWIDTHA(JINTF)    DRINTFA1.91     
                                                                           DRINTFA1.92     
!         Add on to total length                                           DRINTFA1.93     
                                                                           DRINTFA1.94     
          TOT_LEN_INTFA_P = TOT_LEN_INTFA_P + LEN_INTFA_P(JINTF)           DRINTFA1.95     
          TOT_LEN_INTFA_U = TOT_LEN_INTFA_U + LEN_INTFA_U(JINTF)           DRINTFA1.96     
          MAX_INTF_P_LEVELS =                                              DRINTFA1.97     
     &    MAX ( MAX_INTF_P_LEVELS , INTF_P_LEVELS(JINTF) )                 DRINTFA1.98     
                                                                           DRINTFA1.99     
        ENDDO                                                              DRINTFA1.100    
                                                                           DRINTFA1.101    
!       U_FIELD_INTFA Dimensions COEFF3 & COEFF4 in TYPINFA                DRINTFA1.102    
                                                                           DRINTFA1.103    
        U_FIELD_INTFA = U_FIELD                                            DRINTFA1.104    
                                                                           DRINTFA1.105    
        write (6,*) ' '                                                    DRINTFA1.106    
        write (6,*) ' Data lengths calculated in DERV_INTF_A.'             DRINTFA1.107    
        do jintf=1,n_intf_a                                                DRINTFA1.108    
        write (6,*) ' Area no ',jintf,                                     DRINTFA1.109    
     &              ' len_intfa_p ',len_intfa_p(jintf),                    DRINTFA1.110    
     &              ' len_intfa_u ',len_intfa_u(jintf)                     DRINTFA1.111    
        enddo                                                              DRINTFA1.112    
        write (6,*) ' n_intf_a ',n_intf_a                                  DRINTFA1.113    
        write (6,*) ' tot_len_intfa_p ',tot_len_intfa_p                    DRINTFA1.114    
        write (6,*) ' tot_len_intfa_u ',tot_len_intfa_u                    DRINTFA1.115    
        write (6,*) ' max_intf_p_levels ',max_intf_p_levels                DRINTFA1.116    
        write (6,*) ' u_field_intfa ',u_field_intfa                        DRINTFA1.117    
                                                                           DRINTFA1.118    
      ELSE                                                                 DRINTFA1.119    
                                                                           DRINTFA1.120    
!       No boundary conditions to be generated.                            DRINTFA1.121    
!       Initialise to prevent zero length dynamic allocation.              DRINTFA1.122    
                                                                           DRINTFA1.123    
        write (6,*) ' n_intf_a ',n_intf_a                                  DRINTFA1.124    
                                                                           DRINTFA1.125    
        N_INTF_A = 1                                                       DRINTFA1.126    
        TOT_LEN_INTFA_P = 1                                                DRINTFA1.127    
        TOT_LEN_INTFA_U = 1                                                DRINTFA1.128    
        MAX_INTF_P_LEVELS = 1                                              DRINTFA1.129    
        U_FIELD_INTFA = 1                                                  DRINTFA1.130    
                                                                           DRINTFA1.131    
      write (6,*) ' n_intf_a ',n_intf_a                                    DRINTFA1.132    
      write (6,*) ' tot_len_intfa_p ',tot_len_intfa_p                      DRINTFA1.133    
      write (6,*) ' tot_len_intfa_u ',tot_len_intfa_u                      DRINTFA1.134    
      write (6,*) ' max_intf_p_levels ',max_intf_p_levels                  DRINTFA1.135    
      write (6,*) ' u_field_intfa ',u_field_intfa                          DRINTFA1.136    
                                                                           DRINTFA1.137    
      ENDIF                                                                DRINTFA1.138    
                                                                           DRINTFA1.139    
      RETURN                                                               DRINTFA1.140    
      END                                                                  DRINTFA1.141    
*ENDIF                                                                     DRINTFA1.142    
*ENDIF                                                                     DRINTFA1.143