*IF DEF,C84_1A                                                             STMIN1A.2      
C ******************************COPYRIGHT******************************    GTS2F400.9703   
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.9704   
C                                                                          GTS2F400.9705   
C Use, duplication or disclosure of this code is subject to the            GTS2F400.9706   
C restrictions as set forth in the contract.                               GTS2F400.9707   
C                                                                          GTS2F400.9708   
C                Meteorological Office                                     GTS2F400.9709   
C                London Road                                               GTS2F400.9710   
C                BRACKNELL                                                 GTS2F400.9711   
C                Berkshire UK                                              GTS2F400.9712   
C                RG12 2SZ                                                  GTS2F400.9713   
C                                                                          GTS2F400.9714   
C If no contract has been raised with this copy of the code, the use,      GTS2F400.9715   
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.9716   
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.9717   
C Modelling at the above address.                                          GTS2F400.9718   
C ******************************COPYRIGHT******************************    GTS2F400.9719   
C                                                                          GTS2F400.9720   
CLL  Routine: STMIN ----------------------------------------------------   STMIN1A.3      
CLL                                                                        STMIN1A.4      
CLL  Purpose: Computes the point-by-point minimum in time of a field       STMIN1A.5      
CLL           by comparing the field at the current time with the          STMIN1A.6      
CLL           minimum so far (STASH TEMPORAL service routine)              STMIN1A.7      
CLL                                                                        STMIN1A.8      
CLL  Tested under compiler:   cft77                                        STMIN1A.9      
CLL  Tested under OS version: UNICOS 5.1                                   STMIN1A.10     
CLL                                                                        STMIN1A.11     
CLL  Author:   S.Tett/T.Johns                                              STMIN1A.12     
CLL                                                                        STMIN1A.13     
CLL  Model            Modification history from model version 3.0:         STMIN1A.14     
CLL version  date                                                          STMIN1A.15     
CLL                                                                        STMIN1A.16     
CLL  Programming standard: UM Doc Paper 3, version 2 (7/9/90)              STMIN1A.17     
CLL                                                                        STMIN1A.18     
CLL  Logical components covered: D722                                      STMIN1A.19     
CLL                                                                        STMIN1A.20     
CLL  Project task: D7                                                      STMIN1A.21     
CLL                                                                        STMIN1A.22     
CLL  External documentation:                                               STMIN1A.23     
CLL    Unified Model Doc Paper C4 - Storage handling and diagnostic        STMIN1A.24     
CLL                                 system (STASH)                         STMIN1A.25     
CLL                                                                        STMIN1A.26     
C*L  Interface and arguments: ------------------------------------------   STMIN1A.27     
C                                                                          STMIN1A.28     

      SUBROUTINE STMIN(fieldin,result,size,masking,amdi)                    1STMIN1A.29     
C                                                                          STMIN1A.30     
      IMPLICIT NONE                                                        STMIN1A.31     
C                                                                          STMIN1A.32     
      INTEGER size             ! IN size of fieldin and result.            STMIN1A.33     
      REAL fieldin(size)       ! IN input field                            STMIN1A.34     
      REAL result(size)        ! OUT output field (minimum)                STMIN1A.35     
      LOGICAL masking          ! IN true if masked (ie. MDI possible)      STMIN1A.36     
      REAL amdi                ! IN missing data indicator                 STMIN1A.37     
C*----------------------------------------------------------------------   STMIN1A.38     
C                                                                          STMIN1A.39     
C Local variables                                                          STMIN1A.40     
C                                                                          STMIN1A.41     
      INTEGER i ! loop count                                               STMIN1A.42     
C-----------------------------------------------------------------------   STMIN1A.43     
CL 1.1 loop over array size, if either result or fieldin is amdi set       STMIN1A.44     
CL     result to amdi, else set result to minimum of fieldin and result    STMIN1A.45     
CL                                                                         STMIN1A.46     
      IF (masking) THEN                                                    STMIN1A.47     
        DO i=1,size                                                        STMIN1A.48     
          IF ((result(i).ne.amdi).and.(fieldin(i).ne.amdi)) THEN           STMIN1A.49     
            result(i)=min(result(i),fieldin(i))                            STMIN1A.50     
          ELSE                                                             STMIN1A.51     
            result(i)=amdi                                                 STMIN1A.52     
          ENDIF                                                            STMIN1A.53     
        ENDDO                                                              STMIN1A.54     
      ELSE                                                                 STMIN1A.55     
CL                                                                         STMIN1A.56     
CL 1.2 loop over array size, set result to minimum of fieldin and result   STMIN1A.57     
CL     without checking for missing data                                   STMIN1A.58     
CL                                                                         STMIN1A.59     
        DO i=1,size                                                        STMIN1A.60     
          result(i)=min(result(i),fieldin(i))                              STMIN1A.61     
        ENDDO                                                              STMIN1A.62     
      ENDIF                                                                STMIN1A.63     
C                                                                          STMIN1A.64     
      RETURN                                                               STMIN1A.65     
      END                                                                  STMIN1A.66     
*ENDIF                                                                     STMIN1A.67