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 branches/UKMO/2017_dev_r7573_oasis/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/2017_dev_r7573_oasis/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 8975

Last change on this file since 8975 was 8975, checked in by andmirek, 6 years ago

#1868 first working branch

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