*IF DEF,C96_1A,OR,DEF,C96_1B                                               GPB3F403.272    
*IF DEF,MPP                                                                GPB3F403.273    
C *****************************COPYRIGHT******************************     FLHALO1A.3      
C (c) CROWN COPYRIGHT 1996, METEOROLOGICAL OFFICE, All Rights Reserved.    FLHALO1A.4      
C                                                                          FLHALO1A.5      
C Use, duplication or disclosure of this code is subject to the            FLHALO1A.6      
C restrictions as set forth in the contract.                               FLHALO1A.7      
C                                                                          FLHALO1A.8      
C                Meteorological Office                                     FLHALO1A.9      
C                London Road                                               FLHALO1A.10     
C                BRACKNELL                                                 FLHALO1A.11     
C                Berkshire UK                                              FLHALO1A.12     
C                RG12 2SZ                                                  FLHALO1A.13     
C                                                                          FLHALO1A.14     
C If no contract has been raised with this copy of the code, the use,      FLHALO1A.15     
C duplication or disclosure of it is strictly prohibited.  Permission      FLHALO1A.16     
C to do so must first be obtained in writing from the Head of Numerical    FLHALO1A.17     
C Modelling at the above address.                                          FLHALO1A.18     
C ******************************COPYRIGHT******************************    FLHALO1A.19     
!+ Parallel UM: Fills halos with number copied from inside the array       FLHALO1A.20     
!                                                                          FLHALO1A.21     
! Subroutine interface:                                                    FLHALO1A.22     

      SUBROUTINE FILL_HALOS(FIELD,P_FIELD,ROW_LENGTH,N_LEVS,FLD_TYPE)      FLHALO1A.23     
                                                                           FLHALO1A.24     
      IMPLICIT NONE                                                        FLHALO1A.25     
!                                                                          FLHALO1A.26     
! Description:                                                             FLHALO1A.27     
! This routine fills the halo areas of the local array with "sensible"     FLHALO1A.28     
! numbers, to stop any references to undefined array elements              FLHALO1A.29     
!                                                                          FLHALO1A.30     
! Method:                                                                  FLHALO1A.31     
! "Sensible numbers" are obtained by copying data one row/column           FLHALO1A.32     
! in from the halo. In the case of the southern halo, data is              FLHALO1A.33     
! copied from two rows up. On a field on a U grid, if the processor        FLHALO1A.34     
! is at the base of the LPG, both the halo area, and the last line         FLHALO1A.35     
! of data are set to "sensible" numbers (because U data has been           FLHALO1A.36     
! stored on a P grid, so there is an extra row of unset data)              FLHALO1A.37     
!                                                                          FLHALO1A.38     
! Current Code Owner: Paul Burton                                          FLHALO1A.39     
!                                                                          FLHALO1A.40     
! History:                                                                 FLHALO1A.41     
!  Model    Date      Modification history from model version 4.1          FLHALO1A.42     
!  version                                                                 FLHALO1A.43     
!    4.1    12/7/95   New DECK created for the Parallel Unified            FLHALO1A.44     
!                     Model. P.Burton                                      FLHALO1A.45     
!                                                                          FLHALO1A.46     
! Subroutine Arguments:                                                    FLHALO1A.47     
                                                                           FLHALO1A.48     
      INTEGER P_FIELD, N_LEVS, ROW_LENGTH ! IN size of FIELD               FLHALO1A.49     
      INTEGER FLD_TYPE  ! indicates type (P or U) of field                 FLHALO1A.50     
                                                                           FLHALO1A.51     
      REAL FIELD(P_FIELD,N_LEVS)   ! IN/OUT field to work on               FLHALO1A.52     
                                                                           FLHALO1A.53     
! Parameters and Common blocks                                             FLHALO1A.54     
                                                                           FLHALO1A.55     
*CALL PARVARS                                                              FLHALO1A.56     
                                                                           FLHALO1A.57     
! Local variables                                                          FLHALO1A.58     
                                                                           FLHALO1A.59     
      INTEGER I,J,K  ! loop counters                                       FLHALO1A.60     
      INTEGER I_off_halo,I_off_data  ! offsets from halo to data           FLHALO1A.61     
      INTEGER J_end  ! loop bound                                          FLHALO1A.62     
      INTEGER I_start,I_end  ! loop bounds                                 FLHALO1A.63     
                                                                           FLHALO1A.64     
! ------------------------------------------------------------------       FLHALO1A.65     
                                                                           FLHALO1A.66     
! Do North halo                                                            FLHALO1A.67     
      I_off_data=ROW_LENGTH*Offy                                           FLHALO1A.68     
        DO K=1,N_LEVS                                                      FLHALO1A.69     
          DO J=1,Offy                                                      FLHALO1A.70     
            I_off_halo=(J-1)*ROW_LENGTH                                    FLHALO1A.71     
            DO I=1,ROW_LENGTH                                              FLHALO1A.72     
              FIELD(I+I_off_halo,K)=FIELD(I+I_off_data,K)                  FLHALO1A.73     
            ENDDO                                                          FLHALO1A.74     
          ENDDO                                                            FLHALO1A.75     
        ENDDO                                                              FLHALO1A.76     
                                                                           FLHALO1A.77     
! Now South halo                                                           FLHALO1A.78     
                                                                           FLHALO1A.79     
      I_off_data=ROW_LENGTH*(Offy+1)  ! Offy+1 in case it is at the        FLHALO1A.80     
!                                     ! base of a U grid - this makes      FLHALO1A.81     
!                                     ! sure we get some proper data       FLHALO1A.82     
      DO K=1,N_LEVS                                                        FLHALO1A.83     
        IF ((FLD_TYPE .EQ. fld_type_u) .AND. atbase) THEN                  FLHALO1A.84     
          J_end=Offy+1                                                     FLHALO1A.85     
        ELSE                                                               FLHALO1A.86     
          J_end=Offy                                                       FLHALO1A.87     
        ENDIF                                                              FLHALO1A.88     
        DO J=1,J_end                                                       FLHALO1A.89     
          I_off_halo=(J-1)*ROW_LENGTH                                      FLHALO1A.90     
          DO I=1,ROW_LENGTH                                                FLHALO1A.91     
            FIELD(P_FIELD+1-I-I_off_halo,K)=                               FLHALO1A.92     
     &        FIELD(P_FIELD+1-I-I_off_data,K)                              FLHALO1A.93     
          ENDDO                                                            FLHALO1A.94     
        ENDDO                                                              FLHALO1A.95     
      ENDDO                                                                FLHALO1A.96     
                                                                           FLHALO1A.97     
! Now West halo                                                            FLHALO1A.98     
      I_start=1                                                            FLHALO1A.99     
      I_end=P_FIELD-ROW_LENGTH+1                                           FLHALO1A.100    
      DO K=1,N_LEVS                                                        FLHALO1A.101    
         DO I=I_start,I_end,ROW_LENGTH                                     FLHALO1A.102    
           DO J=I, I+(Offx-1)                                              FLHALO1A.103    
             FIELD(J,K)=FIELD(I+Offx,K)                                    FLHALO1A.104    
           ENDDO                                                           FLHALO1A.105    
         ENDDO                                                             FLHALO1A.106    
       ENDDO                                                               FLHALO1A.107    
                                                                           FLHALO1A.108    
                                                                           FLHALO1A.109    
! and finally East halo                                                    FLHALO1A.110    
       I_start=ROW_LENGTH                                                  FLHALO1A.111    
       I_end=P_FIELD                                                       FLHALO1A.112    
       DO K=1,N_LEVS                                                       FLHALO1A.113    
         DO I=I_start,I_end,ROW_LENGTH                                     FLHALO1A.114    
           DO J=I-(Offx-1),I                                               FLHALO1A.115    
             FIELD(J,K)=FIELD(I-Offx,K)                                    FLHALO1A.116    
           ENDDO                                                           FLHALO1A.117    
         ENDDO                                                             FLHALO1A.118    
       ENDDO                                                               FLHALO1A.119    
                                                                           FLHALO1A.120    
       RETURN                                                              FLHALO1A.121    
       END                                                                 FLHALO1A.122    
                                                                           FLHALO1A.123    
*ENDIF                                                                     FLHALO1A.124    
*ENDIF                                                                     GPB3F403.274