New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
cpl_oasis3.F90 in NEMO/branches/UKMO/NEMO_4.0_GC_couple_pkg/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0_GC_couple_pkg/src/OCE/SBC/cpl_oasis3.F90 @ 11105

Last change on this file since 11105 was 11105, checked in by dancopsey, 5 years ago

Merged in changes from dev_merge_2017_GC_couple_pkg branch except for zotx1 and zoty1 changes in sbccpl.F90.

File size: 27.7 KB
RevLine 
[532]1MODULE cpl_oasis3
2   !!======================================================================
3   !!                    ***  MODULE cpl_oasis  ***
[4990]4   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3-MCT
[532]5   !!=====================================================================
[5836]6   !! History :  1.0  !  2004-06  (R. Redler, NEC Laboratories Europe, Germany) Original code
7   !!             -   !  2004-11  (R. Redler, NEC Laboratories Europe; N. Keenlyside, W. Park, IFM-GEOMAR, Germany) revision
8   !!             -   !  2004-11  (V. Gayler, MPI M&D) Grid writing
9   !!            2.0  !  2005-08  (R. Redler, W. Park) frld initialization, paral(2) revision
10   !!             -   !  2005-09  (R. Redler) extended to allow for communication over root only
11   !!             -   !  2006-01  (W. Park) modification of physical part
12   !!             -   !  2006-02  (R. Redler, W. Park) buffer array fix for root exchange
13   !!            3.4  !  2011-11  (C. Harris) Changes to allow mutiple category fields
14   !!            3.6  !  2014-11  (S. Masson) OASIS3-MCT
[532]15   !!----------------------------------------------------------------------
[5836]16   
[532]17   !!----------------------------------------------------------------------
[5407]18   !!   'key_oasis3'                    coupled Ocean/Atmosphere via OASIS3-MCT
19   !!   'key_oa3mct_v3'                 to be added for OASIS3-MCT version 3
[532]20   !!----------------------------------------------------------------------
[4990]21   !!   cpl_init     : initialization of coupled mode communication
22   !!   cpl_define   : definition of grid and fields
[5836]23   !!   cpl_snd      : snd out fields in coupled mode
24   !!   cpl_rcv      : receive fields in coupled mode
[4990]25   !!   cpl_finalize : finalize the coupled mode communication
[532]26   !!----------------------------------------------------------------------
[4990]27#if defined key_oasis3
28   USE mod_oasis                    ! OASIS3-MCT module
29#endif
[1218]30   USE par_oce                      ! ocean parameters
[532]31   USE dom_oce                      ! ocean space and time domain
32   USE in_out_manager               ! I/O manager
[2715]33   USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
34
[532]35   IMPLICIT NONE
[1218]36   PRIVATE
[532]37
[4990]38   PUBLIC   cpl_init
39   PUBLIC   cpl_define
40   PUBLIC   cpl_snd
41   PUBLIC   cpl_rcv
42   PUBLIC   cpl_freq
43   PUBLIC   cpl_finalize
[11105]44#if defined key_mpp_mpi
45   INCLUDE 'mpif.h'
46#endif
47   
48   INTEGER, PARAMETER         :: localRoot  = 0
49   LOGICAL                    :: commRank            ! true for ranks doing OASIS communication
50#if defined key_cpl_rootexchg
51   LOGICAL                    :: rootexchg =.true.   ! logical switch
52#else
53   LOGICAL                    :: rootexchg =.false.  ! logical switch
54#endif
[2715]55
56   INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field
57   INTEGER, PUBLIC            ::   OASIS_idle = 0    !: return code if nothing done by oasis
[4990]58   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
[2715]59   INTEGER                    ::   nerror            ! return error code
[4990]60#if ! defined key_oasis3
61   ! OASIS Variables not used. defined only for compilation purpose
62   INTEGER                    ::   OASIS_Out         = -1
63   INTEGER                    ::   OASIS_REAL        = -1
64   INTEGER                    ::   OASIS_Ok          = -1
65   INTEGER                    ::   OASIS_In          = -1
66   INTEGER                    ::   OASIS_Sent        = -1
67   INTEGER                    ::   OASIS_SentOut     = -1
68   INTEGER                    ::   OASIS_ToRest      = -1
69   INTEGER                    ::   OASIS_ToRestOut   = -1
70   INTEGER                    ::   OASIS_Recvd       = -1
71   INTEGER                    ::   OASIS_RecvOut     = -1
72   INTEGER                    ::   OASIS_FromRest    = -1
73   INTEGER                    ::   OASIS_FromRestOut = -1
74#endif
[2715]75
[5407]76   INTEGER                    ::   nrcv         ! total number of fields received
77   INTEGER                    ::   nsnd         ! total number of fields sent
78   INTEGER                    ::   ncplmodel    ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
[9023]79   INTEGER, PUBLIC, PARAMETER ::   nmaxfld=60   ! Maximum number of coupling fields
[4990]80   INTEGER, PUBLIC, PARAMETER ::   nmaxcat=5    ! Maximum number of coupling fields
81   INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields
[10112]82   LOGICAL, PARAMETER         ::   ltmp_wapatch = .TRUE.   ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define 
83   INTEGER                    ::   nldi_save, nlei_save
84   INTEGER                    ::   nldj_save, nlej_save
[1218]85   
[3294]86   TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
87      LOGICAL               ::   laction   ! To be coupled or not
88      CHARACTER(len = 8)    ::   clname    ! Name of the coupling field   
89      CHARACTER(len = 1)    ::   clgrid    ! Grid type 
90      REAL(wp)              ::   nsgn      ! Control of the sign change
[4990]91      INTEGER, DIMENSION(nmaxcat,nmaxcpl) ::   nid   ! Id of the field (no more than 9 categories and 9 extrena models)
[3294]92      INTEGER               ::   nct       ! Number of categories in field
[4990]93      INTEGER               ::   ncplmodel ! Maximum number of models to/from which this variable may be sent/received
[1218]94   END TYPE FLD_CPL
[532]95
[2715]96   TYPE(FLD_CPL), DIMENSION(nmaxfld), PUBLIC ::   srcv, ssnd   !: Coupling fields
[532]97
[2715]98   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   exfld   ! Temporary buffer for receiving
[11105]99   INTEGER, PUBLIC :: localComm 
100     
[532]101   !!----------------------------------------------------------------------
[9598]102   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[2528]103   !! $Id$
[10068]104   !! Software governed by the CeCILL license (see ./LICENSE)
[532]105   !!----------------------------------------------------------------------
106CONTAINS
107
[5407]108   SUBROUTINE cpl_init( cd_modname, kl_comm )
[532]109      !!-------------------------------------------------------------------
[4990]110      !!             ***  ROUTINE cpl_init  ***
[532]111      !!
112      !! ** Purpose :   Initialize coupled mode communication for ocean
113      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
114      !!
115      !! ** Method  :   OASIS3 MPI communication
116      !!--------------------------------------------------------------------
[5836]117      CHARACTER(len = *), INTENT(in   ) ::   cd_modname   ! model name as set in namcouple file
118      INTEGER           , INTENT(  out) ::   kl_comm      ! local communicator of the model
[1226]119      !!--------------------------------------------------------------------
[1218]120
[1579]121      ! WARNING: No write in numout in this routine
122      !============================================
123
[532]124      !------------------------------------------------------------------
[4990]125      ! 1st Initialize the OASIS system for the application
[532]126      !------------------------------------------------------------------
[5407]127      CALL oasis_init_comp ( ncomp_id, TRIM(cd_modname), nerror )
[4990]128      IF ( nerror /= OASIS_Ok ) &
129         CALL oasis_abort (ncomp_id, 'cpl_init', 'Failure in oasis_init_comp')
[532]130
131      !------------------------------------------------------------------
132      ! 3rd Get an MPI communicator for OPA local communication
133      !------------------------------------------------------------------
134
[4990]135      CALL oasis_get_localcomm ( kl_comm, nerror )
136      IF ( nerror /= OASIS_Ok ) &
137         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' )
[11105]138      localComm = kl_comm 
[2715]139      !
[4990]140   END SUBROUTINE cpl_init
[532]141
142
[4990]143   SUBROUTINE cpl_define( krcv, ksnd, kcplmodel )
[532]144      !!-------------------------------------------------------------------
[4990]145      !!             ***  ROUTINE cpl_define  ***
[532]146      !!
147      !! ** Purpose :   Define grid and field information for ocean
148      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
149      !!
150      !! ** Method  :   OASIS3 MPI communication
151      !!--------------------------------------------------------------------
[2715]152      INTEGER, INTENT(in) ::   krcv, ksnd     ! Number of received and sent coupling fields
[4990]153      INTEGER, INTENT(in) ::   kcplmodel      ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
[1226]154      !
[2715]155      INTEGER :: id_part
156      INTEGER :: paral(5)       ! OASIS3 box partition
[10404]157      INTEGER :: ishape(4)    ! shape of arrays passed to PSMILe
[4990]158      INTEGER :: ji,jc,jm       ! local loop indicees
159      CHARACTER(LEN=64) :: zclname
160      CHARACTER(LEN=2) :: cli2
[532]161      !!--------------------------------------------------------------------
[1218]162
[10112]163      ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define
164      IF ( ltmp_wapatch ) THEN
165         nldi_save = nldi   ;   nlei_save = nlei
166         nldj_save = nldj   ;   nlej_save = nlej
167         IF( nimpp           ==      1 ) nldi = 1
168         IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
169         IF( njmpp           ==      1 ) nldj = 1
170         IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
171      ENDIF
[532]172      IF(lwp) WRITE(numout,*)
[4990]173      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
[532]174      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
175      IF(lwp) WRITE(numout,*)
176
[5407]177      ncplmodel = kcplmodel
[4990]178      IF( kcplmodel > nmaxcpl ) THEN
[5407]179         CALL oasis_abort ( ncomp_id, 'cpl_define', 'ncplmodel is larger than nmaxcpl, increase nmaxcpl')   ;   RETURN
[4990]180      ENDIF
[5407]181
182      nrcv = krcv
183      IF( nrcv > nmaxfld ) THEN
184         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nrcv is larger than nmaxfld, increase nmaxfld')   ;   RETURN
185      ENDIF
186
187      nsnd = ksnd
188      IF( nsnd > nmaxfld ) THEN
189         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nsnd is larger than nmaxfld, increase nmaxfld')   ;   RETURN
190      ENDIF
[532]191      !
192      ! ... Define the shape for the area that excludes the halo
193      !     For serial configuration (key_mpp_mpi not being active)
194      !     nl* is set to the global values 1 and jp*glo.
195      !
[10404]196      ishape(1) = 1
197      ishape(2) = nlei-nldi+1
198      ishape(3) = 1
199      ishape(4) = nlej-nldj+1
[532]200      !
201      ! ... Allocate memory for data exchange
202      !
[1218]203      ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
[2715]204      IF( nerror > 0 ) THEN
[4990]205         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
[532]206      ENDIF
207      !
[1218]208      ! -----------------------------------------------------------------
209      ! ... Define the partition
210      ! -----------------------------------------------------------------
211     
212      paral(1) = 2                                              ! box partitioning
213      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset   
214      paral(3) = nlei-nldi+1                                    ! local extent in i
215      paral(4) = nlej-nldj+1                                    ! local extent in j
216      paral(5) = jpiglo                                         ! global extent in x
217     
218      IF( ln_ctl ) THEN
219         WRITE(numout,*) ' multiexchg: paral (1:5)', paral
220         WRITE(numout,*) ' multiexchg: jpi, jpj =', jpi, jpj
221         WRITE(numout,*) ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
222         WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
223      ENDIF
[7848]224   
225      CALL oasis_def_partition ( id_part, paral, nerror, jpiglo*jpjglo )
[532]226      !
[1218]227      ! ... Announce send variables.
[532]228      !
[4990]229      ssnd(:)%ncplmodel = kcplmodel
230      !
[1226]231      DO ji = 1, ksnd
[4990]232         IF ( ssnd(ji)%laction ) THEN
233
234            IF( ssnd(ji)%nct > nmaxcat ) THEN
235               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
236                  &              TRIM(ssnd(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
237               RETURN
238            ENDIF
239           
[3294]240            DO jc = 1, ssnd(ji)%nct
[4990]241               DO jm = 1, kcplmodel
242
243                  IF ( ssnd(ji)%nct .GT. 1 ) THEN
244                     WRITE(cli2,'(i2.2)') jc
245                     zclname = TRIM(ssnd(ji)%clname)//'_cat'//cli2
246                  ELSE
247                     zclname = ssnd(ji)%clname
248                  ENDIF
249                  IF ( kcplmodel  > 1 ) THEN
250                     WRITE(cli2,'(i2.2)') jm
251                     zclname = 'model'//cli2//'_'//TRIM(zclname)
252                  ENDIF
253#if defined key_agrif
254                  IF( agrif_fixed() /= 0 ) THEN
255                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
256                  END IF
257#endif
258                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_Out
[10404]259                  CALL oasis_def_var (ssnd(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 1 /),   &
[4990]260                     &                OASIS_Out          , ishape , OASIS_REAL, nerror )
261                  IF ( nerror /= OASIS_Ok ) THEN
262                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
263                     CALL oasis_abort ( ssnd(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
264                  ENDIF
265                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
266                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
267               END DO
[3294]268            END DO
[1218]269         ENDIF
270      END DO
271      !
272      ! ... Announce received variables.
273      !
[4990]274      srcv(:)%ncplmodel = kcplmodel
275      !
[1226]276      DO ji = 1, krcv
[1218]277         IF ( srcv(ji)%laction ) THEN
[4990]278           
279            IF( srcv(ji)%nct > nmaxcat ) THEN
280               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
281                  &              TRIM(srcv(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
282               RETURN
283            ENDIF
284           
[3294]285            DO jc = 1, srcv(ji)%nct
[4990]286               DO jm = 1, kcplmodel
287                 
288                  IF ( srcv(ji)%nct .GT. 1 ) THEN
289                     WRITE(cli2,'(i2.2)') jc
290                     zclname = TRIM(srcv(ji)%clname)//'_cat'//cli2
291                  ELSE
292                     zclname = srcv(ji)%clname
293                  ENDIF
294                  IF ( kcplmodel  > 1 ) THEN
295                     WRITE(cli2,'(i2.2)') jm
296                     zclname = 'model'//cli2//'_'//TRIM(zclname)
297                  ENDIF
298#if defined key_agrif
299                  IF( agrif_fixed() /= 0 ) THEN
300                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
301                  END IF
302#endif
303                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_In
[10404]304                  CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 1 /),   &
[4990]305                     &                OASIS_In           , ishape , OASIS_REAL, nerror )
306                  IF ( nerror /= OASIS_Ok ) THEN
307                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
308                     CALL oasis_abort ( srcv(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
309                  ENDIF
310                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
311                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
312
313               END DO
[3294]314            END DO
[1218]315         ENDIF
316      END DO
317     
[532]318      !------------------------------------------------------------------
[1218]319      ! End of definition phase
[532]320      !------------------------------------------------------------------
[1218]321     
[4990]322      CALL oasis_enddef(nerror)
323      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
[2715]324      !
[10112]325      IF ( ltmp_wapatch ) THEN
326         nldi = nldi_save   ;   nlei = nlei_save
327         nldj = nldj_save   ;   nlej = nlej_save
328      ENDIF
[4990]329   END SUBROUTINE cpl_define
[1218]330   
331   
[4990]332   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
[532]333      !!---------------------------------------------------------------------
[4990]334      !!              ***  ROUTINE cpl_snd  ***
[532]335      !!
336      !! ** Purpose : - At each coupling time-step,this routine sends fields
337      !!      like sst or ice cover to the coupler or remote application.
338      !!----------------------------------------------------------------------
[3294]339      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
340      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
341      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
342      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
343      !!
[4990]344      INTEGER                                   ::   jc,jm     ! local loop index
[532]345      !!--------------------------------------------------------------------
[10112]346      ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define
347      IF ( ltmp_wapatch ) THEN
348         nldi_save = nldi   ;   nlei_save = nlei
349         nldj_save = nldj   ;   nlej_save = nlej
350         IF( nimpp           ==      1 ) nldi = 1
351         IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
352         IF( njmpp           ==      1 ) nldj = 1
353         IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
354      ENDIF
[532]355      !
[1218]356      ! snd data to OASIS3
[532]357      !
[3294]358      DO jc = 1, ssnd(kid)%nct
[4990]359         DO jm = 1, ssnd(kid)%ncplmodel
360       
361            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
362               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
363               
364               IF ( ln_ctl ) THEN       
365                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
366                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
367                     WRITE(numout,*) '****************'
368                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
369                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
370                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
371                     WRITE(numout,*) 'oasis_put:   info ', kinfo
372                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
373                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
374                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
375                     WRITE(numout,*) '****************'
376                  ENDIF
377               ENDIF
378               
[3294]379            ENDIF
[4990]380           
381         ENDDO
[3294]382      ENDDO
[10112]383      IF ( ltmp_wapatch ) THEN
384         nldi = nldi_save   ;   nlei = nlei_save
385         nldj = nldj_save   ;   nlej = nlej_save
386      ENDIF
[2715]387      !
[4990]388    END SUBROUTINE cpl_snd
[532]389
390
[4990]391   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
[532]392      !!---------------------------------------------------------------------
[4990]393      !!              ***  ROUTINE cpl_rcv  ***
[532]394      !!
395      !! ** Purpose : - At each coupling time-step,this routine receives fields
396      !!      like stresses and fluxes from the coupler or remote application.
397      !!----------------------------------------------------------------------
[3294]398      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
399      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
400      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
[4990]401      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
[3294]402      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
[532]403      !!
[4990]404      INTEGER                                   ::   jc,jm     ! local loop index
405      LOGICAL                                   ::   llaction, llfisrt
[1218]406      !!--------------------------------------------------------------------
[10112]407      ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define
408      IF ( ltmp_wapatch ) THEN
409         nldi_save = nldi   ;   nlei_save = nlei
410         nldj_save = nldj   ;   nlej_save = nlej
411      ENDIF
[532]412      !
[1218]413      ! receive local data from OASIS3 on every process
414      !
[4990]415      kinfo = OASIS_idle
416      !
[3294]417      DO jc = 1, srcv(kid)%nct
[10112]418         IF ( ltmp_wapatch ) THEN
419            IF( nimpp           ==      1 ) nldi = 1
420            IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
421            IF( njmpp           ==      1 ) nldj = 1
422            IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
423         ENDIF
[4990]424         llfisrt = .TRUE.
[532]425
[4990]426         DO jm = 1, srcv(kid)%ncplmodel
427
428            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
429
430               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )         
431               
432               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
433                  &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
434               
435               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
436               
437               IF ( llaction ) THEN
438                 
439                  kinfo = OASIS_Rcv
440                  IF( llfisrt ) THEN
441                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
442                     llfisrt = .FALSE.
443                  ELSE
444                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
445                  ENDIF
446                 
447                  IF ( ln_ctl ) THEN       
448                     WRITE(numout,*) '****************'
449                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
450                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
451                     WRITE(numout,*) 'oasis_get:   kstep', kstep
452                     WRITE(numout,*) 'oasis_get:   info ', kinfo
453                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
454                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
455                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
456                     WRITE(numout,*) '****************'
[11105]457                     CALL FLUSH(numout)
[4990]458                  ENDIF
459                 
460               ENDIF
461               
462            ENDIF
[3294]463           
[4990]464         ENDDO
[4806]465
[10112]466         IF ( ltmp_wapatch ) THEN
467            nldi = nldi_save   ;   nlei = nlei_save
468            nldj = nldj_save   ;   nlej = nlej_save
469         ENDIF
[4990]470         !--- Fill the overlap areas and extra hallows (mpp)
471         !--- check periodicity conditions (all cases)
[10425]472         IF( .not. llfisrt ) THEN
473            CALL lbc_lnk( 'cpl_oasis3', pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
474         ENDIF
[4990]475 
[3294]476      ENDDO
[2715]477      !
[4990]478   END SUBROUTINE cpl_rcv
[532]479
480
[5407]481   INTEGER FUNCTION cpl_freq( cdfieldname ) 
[2528]482      !!---------------------------------------------------------------------
[4990]483      !!              ***  ROUTINE cpl_freq  ***
[2528]484      !!
485      !! ** Purpose : - send back the coupling frequency for a particular field
486      !!----------------------------------------------------------------------
[5407]487      CHARACTER(len = *), INTENT(in) ::   cdfieldname    ! field name as set in namcouple file
[4990]488      !!
[5407]489      INTEGER               :: id
[4990]490      INTEGER               :: info
491      INTEGER, DIMENSION(1) :: itmp
[5407]492      INTEGER               :: ji,jm     ! local loop index
493      INTEGER               :: mop
[2715]494      !!----------------------------------------------------------------------
[5407]495      cpl_freq = 0   ! defaut definition
496      id = -1        ! defaut definition
[2715]497      !
[5407]498      DO ji = 1, nsnd
499         IF (ssnd(ji)%laction ) THEN
500            DO jm = 1, ncplmodel
501               IF( ssnd(ji)%nid(1,jm) /= -1 ) THEN
502                  IF( TRIM(cdfieldname) == TRIM(ssnd(ji)%clname) ) THEN
503                     id = ssnd(ji)%nid(1,jm)
504                     mop = OASIS_Out
505                  ENDIF
506               ENDIF
507            ENDDO
508         ENDIF
509      ENDDO
510      DO ji = 1, nrcv
511         IF (srcv(ji)%laction ) THEN
512            DO jm = 1, ncplmodel
513               IF( srcv(ji)%nid(1,jm) /= -1 ) THEN
514                  IF( TRIM(cdfieldname) == TRIM(srcv(ji)%clname) ) THEN
515                     id = srcv(ji)%nid(1,jm)
516                     mop = OASIS_In
517                  ENDIF
518               ENDIF
519            ENDDO
520         ENDIF
521      ENDDO
522      !
523      IF( id /= -1 ) THEN
[10577]524#if ! defined key_oa3mct_v1v2
[5407]525         CALL oasis_get_freqs(id, mop, 1, itmp, info)
526#else
[11105]527!         CALL oasis_get_freqs(id,      1, itmp, info)
528         cpl_freq = namflddti( id )
[5407]529#endif
530      ENDIF
531      !
[4990]532   END FUNCTION cpl_freq
[2528]533
534
[4990]535   SUBROUTINE cpl_finalize
[532]536      !!---------------------------------------------------------------------
[4990]537      !!              ***  ROUTINE cpl_finalize  ***
[532]538      !!
539      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
[4990]540      !!      called explicitly before cpl_init it will also close
[532]541      !!      MPI communication.
542      !!----------------------------------------------------------------------
[2715]543      !
544      DEALLOCATE( exfld )
[4990]545      IF (nstop == 0) THEN
546         CALL oasis_terminate( nerror )         
547      ELSE
548         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
549      ENDIF       
[2715]550      !
[4990]551   END SUBROUTINE cpl_finalize
[532]552
[4990]553#if ! defined key_oasis3
554
[1218]555   !!----------------------------------------------------------------------
[4990]556   !!   No OASIS Library          OASIS3 Dummy module...
[1218]557   !!----------------------------------------------------------------------
[4990]558
559   SUBROUTINE oasis_init_comp(k1,cd1,k2)
560      CHARACTER(*), INTENT(in   ) ::  cd1
561      INTEGER     , INTENT(  out) ::  k1,k2
562      k1 = -1 ; k2 = -1
563      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
564   END SUBROUTINE oasis_init_comp
565
566   SUBROUTINE oasis_abort(k1,cd1,cd2)
567      INTEGER     , INTENT(in   ) ::  k1
568      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
569      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
570   END SUBROUTINE oasis_abort
571
572   SUBROUTINE oasis_get_localcomm(k1,k2)
573      INTEGER     , INTENT(  out) ::  k1,k2
574      k1 = -1 ; k2 = -1
575      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
576   END SUBROUTINE oasis_get_localcomm
577
[7851]578   SUBROUTINE oasis_def_partition(k1,k2,k3,k4)
[4990]579      INTEGER     , INTENT(  out) ::  k1,k3
580      INTEGER     , INTENT(in   ) ::  k2(5)
[7851]581      INTEGER     , INTENT(in   ) ::  k4
582      k1 = k2(1) ; k3 = k2(5)+k4
[4990]583      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
584   END SUBROUTINE oasis_def_partition
585
586   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
587      CHARACTER(*), INTENT(in   ) ::  cd1
588      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
589      INTEGER     , INTENT(  out) ::  k1,k7
590      k1 = -1 ; k7 = -1
591      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
592   END SUBROUTINE oasis_def_var
593
594   SUBROUTINE oasis_enddef(k1)
595      INTEGER     , INTENT(  out) ::  k1
596      k1 = -1
597      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
598   END SUBROUTINE oasis_enddef
599 
600   SUBROUTINE oasis_put(k1,k2,p1,k3)
601      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
602      INTEGER                 , INTENT(in   ) ::  k1,k2
603      INTEGER                 , INTENT(  out) ::  k3
604      k3 = -1
605      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
606   END SUBROUTINE oasis_put
607
608   SUBROUTINE oasis_get(k1,k2,p1,k3)
609      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
610      INTEGER                 , INTENT(in   ) ::  k1,k2
611      INTEGER                 , INTENT(  out) ::  k3
612      p1(1,1) = -1. ; k3 = -1
613      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
614   END SUBROUTINE oasis_get
615
[10582]616   SUBROUTINE oasis_get_freqs(k1,k5,k2,k3,k4)
[4990]617      INTEGER              , INTENT(in   ) ::  k1,k2
618      INTEGER, DIMENSION(1), INTENT(  out) ::  k3
[10582]619      INTEGER              , INTENT(  out) ::  k4,k5
620      k3(1) = k1 ; k4 = k2 ; k5 = k2
[4990]621      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
622   END SUBROUTINE oasis_get_freqs
623
624   SUBROUTINE oasis_terminate(k1)
625      INTEGER     , INTENT(  out) ::  k1
626      k1 = -1
627      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
628   END SUBROUTINE oasis_terminate
629   
[532]630#endif
631
[2715]632   !!=====================================================================
[532]633END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.