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.1_NGMS_couple_stage2/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage2/src/OCE/SBC/cpl_oasis3.F90 @ 13443

Last change on this file since 13443 was 13443, checked in by frrh, 4 years ago

Commit changes which allow first working 2 way coupling exchanges between GO8
and LFRic aquaplanet.

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