*IF DEF,FLUXPROC                                                           FPCHKHD1.2      
C ******************************COPYRIGHT******************************    FPCHKHD1.3      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    FPCHKHD1.4      
C                                                                          FPCHKHD1.5      
C Use, duplication or disclosure of this code is subject to the            FPCHKHD1.6      
C restrictions as set forth in the contract.                               FPCHKHD1.7      
C                                                                          FPCHKHD1.8      
C                Meteorological Office                                     FPCHKHD1.9      
C                London Road                                               FPCHKHD1.10     
C                BRACKNELL                                                 FPCHKHD1.11     
C                Berkshire UK                                              FPCHKHD1.12     
C                RG12 2SZ                                                  FPCHKHD1.13     
C                                                                          FPCHKHD1.14     
C If no contract has been raised with this copy of the code, the use,      FPCHKHD1.15     
C duplication or disclosure of it is strictly prohibited.  Permission      FPCHKHD1.16     
C to do so must first be obtained in writing from the Head of Numerical    FPCHKHD1.17     
C Modelling at the above address.                                          FPCHKHD1.18     
C ******************************COPYRIGHT******************************    FPCHKHD1.19     
C                                                                          FPCHKHD1.20     
C Programming standard: Unified Model Documentation Paper No 3             FPCHKHD1.21     
C                       Version No 1 15/1/90                               FPCHKHD1.22     
C History:                                                                 FPCHKHD1.23     
C version  date         change                                             FPCHKHD1.24     
C 4.5      03/09/98     New code                                           FPCHKHD1.25     
C                                                                          FPCHKHD1.26     
! Author:     M. J. Bell                                                   FPCHKHD1.27     
!----------------------------------------------------------------------    FPCHKHD1.28     
! contains routines: check_header                                          FPCHKHD1.29     
!                                                                          FPCHKHD1.30     
! Purpose: Flux processing routine.                                        FPCHKHD1.31     
!          Checks to see if NWP file exists                                FPCHKHD1.32     
!----------------------------------------------------------------------    FPCHKHD1.33     

      subroutine check_header (StCode,Len1_Lookup,                          12,1FPCHKHD1.34     
     #                         Len2_Lookup,Lookup,                         FPCHKHD1.35     
*CALL AVALTIM                                                              FPCHKHD1.36     
     #                         l_present_output)                           FPCHKHD1.37     
                                                                           FPCHKHD1.38     
                                                                           FPCHKHD1.39     
      implicit none                                                        FPCHKHD1.40     
                                                                           FPCHKHD1.41     
! declaration of argument list                                             FPCHKHD1.42     
      integer StCode               ! IN Field code in lookup table         FPCHKHD1.43     
      integer Len1_Lookup,Len2_Lookup     ! IN true lengths of tables      FPCHKHD1.44     
      integer Lookup(Len1_Lookup, Len2_Lookup)  ! IN lookup tables         FPCHKHD1.45     
      logical l_present_output     ! OUT logical to check if item exists   FPCHKHD1.46     
                                                                           FPCHKHD1.47     
! declaration of global parameters used                                    FPCHKHD1.48     
*CALL CLOOKADD                                                             FPCHKHD1.49     
*CALL CVALTIM                                                              FPCHKHD1.50     
                                                                           FPCHKHD1.51     
! declaration of local variables                                           FPCHKHD1.52     
      integer i                    ! loop counter                          FPCHKHD1.53     
      logical l_climate_field      ! F => not a climate field              FPCHKHD1.54     
      logical l_data_time          ! T => search using data time           FPCHKHD1.55     
                                   ! F => search using validity time       FPCHKHD1.56     
                                                                           FPCHKHD1.57     
      external time_to_use                                                 FPCHKHD1.58     
!-----------------------------------------------------------------------   FPCHKHD1.59     
                                                                           FPCHKHD1.60     
! 1. Decide whether to use 1st or second header in lookup table            FPCHKHD1.61     
                                                                           FPCHKHD1.62     
      l_climate_field = .false.                                            FPCHKHD1.63     
      call time_to_use ( StCode, l_climate_field, l_data_time)             FPCHKHD1.64     
                                                                           FPCHKHD1.65     
! 2. Set l_present_output to false                                         FPCHKHD1.66     
      l_present_output = .false.                                           FPCHKHD1.67     
                                                                           FPCHKHD1.68     
! 3. Loop through NWP lookup table to find match with data time            FPCHKHD1.69     
!    If match is found, set l_present_output to true and exit              FPCHKHD1.70     
                                                                           FPCHKHD1.71     
      if ( l_data_time ) then                                              FPCHKHD1.72     
                                                                           FPCHKHD1.73     
        do i = 1,Len2_lookup                                               FPCHKHD1.74     
                                                                           FPCHKHD1.75     
          if ( Lookup(LBYRD,i)  .eq. ValidYear   .and.                     FPCHKHD1.76     
     #      Lookup(LBMOND,i) .eq. ValidMonth  .and.                        FPCHKHD1.77     
     #      Lookup(LBDATD,i) .eq. ValidDay    .and.                        FPCHKHD1.78     
     #      Lookup(LBHRD,i)  .eq. ValidHour   .and.                        FPCHKHD1.79     
     #      Lookup(LBMIND,i) .eq. ValidMin    .and.                        FPCHKHD1.80     
     #      Lookup(ITEM_CODE,i)  .eq. StCode ) then                        FPCHKHD1.81     
            l_present_output = .true.                                      FPCHKHD1.82     
            goto 9999                                                      FPCHKHD1.83     
                                                                           FPCHKHD1.84     
          endif                                                            FPCHKHD1.85     
                                                                           FPCHKHD1.86     
        enddo                                                              FPCHKHD1.87     
                                                                           FPCHKHD1.88     
      else  ! .not. l_data_time                                            FPCHKHD1.89     
                                                                           FPCHKHD1.90     
! 4. Loop through NWP lookup table to find match with validity time        FPCHKHD1.91     
!    If match is found, set output to true and exit                        FPCHKHD1.92     
                                                                           FPCHKHD1.93     
        do i = 1,Len2_lookup                                               FPCHKHD1.94     
                                                                           FPCHKHD1.95     
          if ( Lookup(LBYR,i)  .eq. ValidYear   .and.                      FPCHKHD1.96     
     #      Lookup(LBMON,i) .eq. ValidMonth  .and.                         FPCHKHD1.97     
     #      Lookup(LBDAT,i) .eq. ValidDay    .and.                         FPCHKHD1.98     
     #      Lookup(LBHR,i)  .eq. ValidHour   .and.                         FPCHKHD1.99     
     #      Lookup(LBMIN,i) .eq. ValidMin    .and.                         FPCHKHD1.100    
     #      Lookup(ITEM_CODE,i)  .eq. StCode ) then                        FPCHKHD1.101    
            l_present_output = .true.                                      FPCHKHD1.102    
            goto 9999                                                      FPCHKHD1.103    
          endif                                                            FPCHKHD1.104    
                                                                           FPCHKHD1.105    
        enddo                                                              FPCHKHD1.106    
                                                                           FPCHKHD1.107    
      endif  !  l_data_time                                                FPCHKHD1.108    
                                                                           FPCHKHD1.109    
9999  continue                                                             FPCHKHD1.110    
      return                                                               FPCHKHD1.111    
      end                                                                  FPCHKHD1.112    
!----------------------------------------------------------------------    FPCHKHD1.113    
*ENDIF                                                                     FPCHKHD1.114