*IF DEF,OCEAN                                                              SEND_REM.2      
C *****************************COPYRIGHT******************************     SEND_REM.3      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    SEND_REM.4      
C                                                                          SEND_REM.5      
C Use, duplication or disclosure of this code is subject to the            SEND_REM.6      
C restrictions as set forth in the contract.                               SEND_REM.7      
C                                                                          SEND_REM.8      
C                Meteorological Office                                     SEND_REM.9      
C                London Road                                               SEND_REM.10     
C                BRACKNELL                                                 SEND_REM.11     
C                Berkshire UK                                              SEND_REM.12     
C                RG12 2SZ                                                  SEND_REM.13     
C                                                                          SEND_REM.14     
C If no contract has been raised with this copy of the code, the use,      SEND_REM.15     
C duplication or disclosure of it is strictly prohibited.  Permission      SEND_REM.16     
C to do so must first be obtained in writing from the Head of Numerical    SEND_REM.17     
C Modelling at the above address.                                          SEND_REM.18     
C ******************************COPYRIGHT******************************    SEND_REM.19     
CLL                                                                        SEND_REM.20     
CLL   Subroutine : SEND_REM                                                SEND_REM.21     
CLL                                                                        SEND_REM.22     
CLL   Author : M J Roberts                                                 SEND_REM.23     
CLL                                                                        SEND_REM.24     
CLL   Modification history:                                                SEND_REM.25     
CLL   Implemented at UM vn 4.5 20 May 1998                                 SEND_REM.26     
CLL                                                                        SEND_REM.27     
CLL   Programming standards use Cox naming convention for Cox variables    SEND_REM.28     
CLL   with the addition that lower case variables are local to the         SEND_REM.29     
CLL   routine.                                                             SEND_REM.30     
CLL                                                                        SEND_REM.31     
CLL   This routine sends data to possibly remote PE's from                 SEND_REM.32     
CLL   the current PE. Need to include all the sending arrays in            SEND_REM.33     
CLL   the argument list, else they will not be communicated.               SEND_REM.34     
CLL                                                                        SEND_REM.35     
CLL                                                                        SEND_REM.36     
CLLEND-----------------------------------------------------------------    SEND_REM.37     
C*                                                                         SEND_REM.38     
C*L   -----------------Arguments---------------------------------------    SEND_REM.39     
C                                                                          SEND_REM.40     

      SUBROUTINE SEND_REM(                                                  1,2SEND_REM.41     
*CALL ARGSIZE                                                              SEND_REM.42     
*CALL ARGD1                                                                SEND_REM.43     
*CALL ARGDUMO                                                              SEND_REM.44     
*CALL ARGPTRO                                                              SEND_REM.45     
*CALL ARGOCALL                                                             SEND_REM.46     
*CALL ARGOINDX                                                             SEND_REM.47     
     &  NSLAB_ARG                                                          SEND_REM.48     
     & ,TENDIN,ATTEND,HUDTEND                                              SEND_REM.49     
     & ,imsend,jmsend,J_PE_IND_OUT,medorhud                                SEND_REM.50     
     &  )                                                                  SEND_REM.51     
C                                                                          SEND_REM.52     
      IMPLICIT NONE                                                        SEND_REM.53     
C                                                                          SEND_REM.54     
C Subroutine SEND_REM. This routine sends data to possibly remote PE's     SEND_REM.55     
C from the current PE.                                                     SEND_REM.56     
c                                                                          SEND_REM.57     
*CALL TYPSIZE                                                              SEND_REM.58     
*CALL OARRYSIZ                                                             SEND_REM.59     
*CALL TYPD1                                                                SEND_REM.60     
*CALL TYPDUMO                                                              SEND_REM.61     
*CALL TYPPTRO                                                              SEND_REM.62     
*CALL TYPOINDX                                                             PXORDER.47     
*CALL TYPOCALL                                                             SEND_REM.63     
*CALL OTIMER                                                               SEND_REM.65     
                                                                           SEND_REM.66     
C Input and Output variables                                               SEND_REM.67     
       REAL TENDIN(KM,NT,4)  ! Contains input tracer tendencies            SEND_REM.68     
       REAL ATTEND(KM,NT,4)  ! Will contain the tracer tendencies for      SEND_REM.69     
C                               both Atlantic and Med points               SEND_REM.70     
       REAL HUDTEND(KM,NT,4)  ! Will contain the tracer tendencies for     SEND_REM.71     
C                               both Atlantic and Hudson Bay points        SEND_REM.72     
                                                                           SEND_REM.73     
C Input variables                                                          SEND_REM.74     
       INTEGER NSLAB_ARG                                                   SEND_REM.75     
     & ,medorhud       ! whether calculating Med outflow or Hudson Bay     SEND_REM.76     
     & ,imsend(4),jmsend(4)  ! where the outflow occurs (i,j)              SEND_REM.77     
                                                                           SEND_REM.78     
C Local variables                                                          SEND_REM.79     
       INTEGER PE_RECV,PE_SEND,tag,info  ! variables used in MPP coding    SEND_REM.80     
       INTEGER J_PE_IND_OUT(4)                                             SEND_REM.81     
                                                                           SEND_REM.82     
       INTEGER                                                             SEND_REM.83     
     +  m,k,n,i         ! indexing variables                               SEND_REM.84     
     +, index_med(4)  ! used for indexing points in slab                   SEND_REM.85     
     +, jread_med     ! local row to read data from dump                   SEND_REM.86     
     +, LABS_MED      ! Unit number for disk, depends if mixing timestep   SEND_REM.87     
     &, nmedpt        ! Number of points mixed                             SEND_REM.88     
     &, imedpt        ! Loop index over such points                        SEND_REM.89     
     &, kmoffset      ! Offset into slab of data                           SEND_REM.90     
                                                                           SEND_REM.91     
       REAL                                                                SEND_REM.92     
     +  FXA1,FXA2,FXB1,FXB2,FX  ! local constants                          SEND_REM.93     
     +, TMED(KM,NT)           ! mean tracer value of Atl and Med points    SEND_REM.94     
                                                                           SEND_REM.95     
C*--------------------------------------------------------------------     SEND_REM.96     
C  BEGIN EXECUTABLE CODE                                                   SEND_REM.97     
C---------------------------------------------------------------------     SEND_REM.98     
      IF (L_OTIMER) CALL TIMER('SEND_REM',3)                               SEND_REM.99     
                                                                           SEND_REM.100    
*IF DEF,MPP                                                                SEND_REM.101    
       IF (medorhud.eq.1) then  ! send attend                              SEND_REM.102    
                                                                           SEND_REM.103    
c  need to send the values in ATTEND back to the                           SEND_REM.104    
c  appropriate processors                                                  SEND_REM.105    
                                                                           SEND_REM.106    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(2)) THEN                       SEND_REM.107    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.108    
          PE_RECV = J_PE_IND_OUT(2)                                        SEND_REM.109    
          CALL GC_RSEND(6007,km*nt*4,pe_recv,info,attend,attend)           SEND_REM.110    
        endif                                                              SEND_REM.111    
        ENDIF                                                              SEND_REM.112    
                                                                           SEND_REM.113    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.114    
                                                                           SEND_REM.115    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(2)) THEN                       SEND_REM.116    
          if ((jst.le.jmsend(2)).and.(jfin.ge.jmsend(2))) then             SEND_REM.117    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.118    
            CALL GC_RRECV(6007,km*nt*4,pe_send,info,attend,attend)         SEND_REM.119    
          endif                                                            SEND_REM.120    
        ENDIF                                                              SEND_REM.121    
                                                                           SEND_REM.122    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.123    
                                                                           SEND_REM.124    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.125    
                                                                           SEND_REM.126    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(3)                             SEND_REM.127    
     &  .and.jmsend(3).ne.0) THEN                                          SEND_REM.128    
          PE_RECV = J_PE_IND_OUT(3)                                        SEND_REM.129    
          CALL GC_RSEND(6008,km*nt*4,pe_recv,info,attend,attend)           SEND_REM.130    
        ENDIF                                                              SEND_REM.131    
                                                                           SEND_REM.132    
        endif  ! on processor local to jmsend(1)                           SEND_REM.133    
                                                                           SEND_REM.134    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.135    
                                                                           SEND_REM.136    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(3)) THEN                       SEND_REM.137    
          if ((jst.le.jmsend(3)).and.(jfin.ge.jmsend(3))) then             SEND_REM.138    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.139    
            CALL GC_RRECV(6008,km*nt*4,pe_send,info,attend,attend)         SEND_REM.140    
          endif                                                            SEND_REM.141    
        ENDIF                                                              SEND_REM.142    
                                                                           SEND_REM.143    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.144    
                                                                           SEND_REM.145    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.146    
                                                                           SEND_REM.147    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(4)                             SEND_REM.148    
     &  .and.jmsend(4).ne.0) THEN                                          SEND_REM.149    
          PE_RECV = J_PE_IND_OUT(4)                                        SEND_REM.150    
          CALL GC_RSEND(6009,km*nt*4,pe_recv,info,attend,attend)           SEND_REM.151    
        ENDIF                                                              SEND_REM.152    
                                                                           SEND_REM.153    
        endif  ! on processor local to jmsend(1)                           SEND_REM.154    
                                                                           SEND_REM.155    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.156    
                                                                           SEND_REM.157    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(4)) THEN                       SEND_REM.158    
          if ((jst.le.jmsend(4)).and.(jfin.ge.jmsend(4))) then             SEND_REM.159    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.160    
            CALL GC_RRECV(6009,km*nt*4,pe_send,info,attend,attend)         SEND_REM.161    
          endif                                                            SEND_REM.162    
        ENDIF                                                              SEND_REM.163    
                                                                           SEND_REM.164    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.165    
                                                                           SEND_REM.166    
       ELSE  ! medorhud=2, send HUDTEND                                    SEND_REM.167    
                                                                           SEND_REM.168    
c  need to send the values in HUDTEND back to the                          SEND_REM.169    
c  appropriate PE's                                                        SEND_REM.170    
                                                                           SEND_REM.171    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(2)) THEN                       SEND_REM.172    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.173    
          PE_RECV = J_PE_IND_OUT(2)                                        SEND_REM.174    
          CALL GC_RSEND(6007,km*nt*4,pe_recv,info,hudtend,hudtend)         SEND_REM.175    
        endif                                                              SEND_REM.176    
        ENDIF                                                              SEND_REM.177    
                                                                           SEND_REM.178    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.179    
                                                                           SEND_REM.180    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(2)) THEN                       SEND_REM.181    
          if ((jst.le.jmsend(2)).and.(jfin.ge.jmsend(2))) then             SEND_REM.182    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.183    
            CALL GC_RRECV(6007,km*nt*4,pe_send,info,hudtend,hudtend)       SEND_REM.184    
          endif                                                            SEND_REM.185    
        ENDIF                                                              SEND_REM.186    
                                                                           SEND_REM.187    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.188    
                                                                           SEND_REM.189    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.190    
                                                                           SEND_REM.191    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(3)                             SEND_REM.192    
     &  .and.jmsend(3).ne.0) THEN                                          SEND_REM.193    
          PE_RECV = J_PE_IND_OUT(3)                                        SEND_REM.194    
          CALL GC_RSEND(6008,km*nt*4,pe_recv,info,hudtend,hudtend)         SEND_REM.195    
        ENDIF                                                              SEND_REM.196    
                                                                           SEND_REM.197    
        endif  ! on processor local to jmsend(1)                           SEND_REM.198    
                                                                           SEND_REM.199    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.200    
                                                                           SEND_REM.201    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(3)) THEN                       SEND_REM.202    
          if ((jst.le.jmsend(3)).and.(jfin.ge.jmsend(3))) then             SEND_REM.203    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.204    
            CALL GC_RRECV(6008,km*nt*4,pe_send,info,hudtend,hudtend)       SEND_REM.205    
          endif                                                            SEND_REM.206    
        ENDIF                                                              SEND_REM.207    
                                                                           SEND_REM.208    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.209    
                                                                           SEND_REM.210    
        if ((jst.le.jmsend(1)).and.(jfin.ge.jmsend(1))) then               SEND_REM.211    
                                                                           SEND_REM.212    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(4)                             SEND_REM.213    
     &  .and.jmsend(4).ne.0) THEN                                          SEND_REM.214    
          PE_RECV = J_PE_IND_OUT(4)                                        SEND_REM.215    
          CALL GC_RSEND(6009,km*nt*4,pe_recv,info,hudtend,hudtend)         SEND_REM.216    
        ENDIF                                                              SEND_REM.217    
                                                                           SEND_REM.218    
        endif  ! on processor local to jmsend(1)                           SEND_REM.219    
                                                                           SEND_REM.220    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.221    
                                                                           SEND_REM.222    
        IF (J_PE_IND_OUT(1).NE.J_PE_IND_OUT(4)) THEN                       SEND_REM.223    
          if ((jst.le.jmsend(4)).and.(jfin.ge.jmsend(4))) then             SEND_REM.224    
            PE_SEND = J_PE_IND_OUT(1)                                      SEND_REM.225    
            CALL GC_RRECV(6009,km*nt*4,pe_send,info,hudtend,hudtend)       SEND_REM.226    
          endif                                                            SEND_REM.227    
        ENDIF                                                              SEND_REM.228    
                                                                           SEND_REM.229    
        CALL GC_GSYNC(O_NPROC,INFO)                                        SEND_REM.230    
                                                                           SEND_REM.231    
       ENDIF ! medorhud                                                    SEND_REM.232    
                                                                           SEND_REM.233    
*ENDIF                                                                     SEND_REM.234    
                                                                           SEND_REM.235    
       IF (L_OTIMER) CALL TIMER('SEND_REM',4)                              SEND_REM.236    
                                                                           SEND_REM.237    
       RETURN                                                              SEND_REM.238    
       END                                                                 SEND_REM.239    
                                                                           SEND_REM.240    
*ENDIF                                                                     SEND_REM.241