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/dev_r5518_cleanup_1d_cpl/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_r5518_cleanup_1d_cpl/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 10043

Last change on this file since 10043 was 10043, checked in by dancopsey, 6 years ago

Remove RSRH print statements.

File size: 33.4 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 cpl_rnf_1d, ONLY: nn_cpl_river   ! Variables used in 1D river outflow
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_rcv_1d
43   PUBLIC   cpl_freq
44   PUBLIC   cpl_finalize
45#if defined key_mpp_mpi
46   INCLUDE 'mpif.h'
47#endif
48   
49   INTEGER, PARAMETER         :: localRoot  = 0
50   LOGICAL                    :: commRank            ! true for ranks doing OASIS communication
51#if defined key_cpl_rootexchg
52   LOGICAL                    :: rootexchg =.true.   ! logical switch
53#else
54   LOGICAL                    :: rootexchg =.false.  ! logical switch
55#endif
56
57   INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field
58   INTEGER, PUBLIC            ::   OASIS_idle = 0    !: return code if nothing done by oasis
59   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
60   INTEGER                    ::   nerror            ! return error code
61#if ! defined key_oasis3
62   ! OASIS Variables not used. defined only for compilation purpose
63   INTEGER                    ::   OASIS_Out         = -1
64   INTEGER                    ::   OASIS_REAL        = -1
65   INTEGER                    ::   OASIS_Ok          = -1
66   INTEGER                    ::   OASIS_In          = -1
67   INTEGER                    ::   OASIS_Sent        = -1
68   INTEGER                    ::   OASIS_SentOut     = -1
69   INTEGER                    ::   OASIS_ToRest      = -1
70   INTEGER                    ::   OASIS_ToRestOut   = -1
71   INTEGER                    ::   OASIS_Recvd       = -1
72   INTEGER                    ::   OASIS_RecvOut     = -1
73   INTEGER                    ::   OASIS_FromRest    = -1
74   INTEGER                    ::   OASIS_FromRestOut = -1
75#endif
76
77   INTEGER                    ::   nrcv         ! total number of fields received
78   INTEGER                    ::   nsnd         ! total number of fields sent
79   INTEGER                    ::   ncplmodel    ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
80   INTEGER, PUBLIC, PARAMETER ::   nmaxfld=50   ! Maximum number of coupling fields
81   INTEGER, PUBLIC, PARAMETER ::   nmaxcat=5    ! Maximum number of coupling fields
82   INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields
83   
84   TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
85      LOGICAL               ::   laction   ! To be coupled or not
86      CHARACTER(len = 8)    ::   clname    ! Name of the coupling field   
87      CHARACTER(len = 1)    ::   clgrid    ! Grid type 
88      REAL(wp)              ::   nsgn      ! Control of the sign change
89      INTEGER, DIMENSION(nmaxcat,nmaxcpl) ::   nid   ! Id of the field (no more than 9 categories and 9 extrena models)
90      INTEGER               ::   nct       ! Number of categories in field
91      INTEGER               ::   ncplmodel ! Maximum number of models to/from which this variable may be sent/received
92      INTEGER               ::   dimensions ! Number of dimensions of coupling field
93   END TYPE FLD_CPL
94
95   TYPE(FLD_CPL), DIMENSION(nmaxfld), PUBLIC ::   srcv, ssnd   !: Coupling fields
96
97   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   exfld   ! Temporary buffer for receiving
98   INTEGER, PUBLIC :: localComm 
99     
100   !!----------------------------------------------------------------------
101   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
102   !! $Id$
103   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
104   !!----------------------------------------------------------------------
105CONTAINS
106
107   SUBROUTINE cpl_init( cd_modname, kl_comm )
108      !!-------------------------------------------------------------------
109      !!             ***  ROUTINE cpl_init  ***
110      !!
111      !! ** Purpose :   Initialize coupled mode communication for ocean
112      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
113      !!
114      !! ** Method  :   OASIS3 MPI communication
115      !!--------------------------------------------------------------------
116      CHARACTER(len = *), INTENT(in) ::   cd_modname   ! model name as set in namcouple file
117      INTEGER          , INTENT(out) ::   kl_comm      ! local communicator of the model
118      !!--------------------------------------------------------------------
119
120      ! WARNING: No write in numout in this routine
121      !============================================
122
123      !------------------------------------------------------------------
124      ! 1st Initialize the OASIS system for the application
125      !------------------------------------------------------------------
126      CALL oasis_init_comp ( ncomp_id, TRIM(cd_modname), nerror )
127      IF ( nerror /= OASIS_Ok ) &
128         CALL oasis_abort (ncomp_id, 'cpl_init', 'Failure in oasis_init_comp')
129
130      !------------------------------------------------------------------
131      ! 3rd Get an MPI communicator for OPA local communication
132      !------------------------------------------------------------------
133
134      CALL oasis_get_localcomm ( kl_comm, nerror )
135      IF ( nerror /= OASIS_Ok ) &
136         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' )
137      localComm = kl_comm 
138      !
139   END SUBROUTINE cpl_init
140
141
142   SUBROUTINE cpl_define( krcv, ksnd, kcplmodel )
143      !!-------------------------------------------------------------------
144      !!             ***  ROUTINE cpl_define  ***
145      !!
146      !! ** Purpose :   Define grid and field information for ocean
147      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
148      !!
149      !! ** Method  :   OASIS3 MPI communication
150      !!--------------------------------------------------------------------
151      INTEGER, INTENT(in) ::   krcv, ksnd     ! Number of received and sent coupling fields
152      INTEGER, INTENT(in) ::   kcplmodel      ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
153      !
154      INTEGER :: id_part
155      INTEGER :: id_part_0d     ! Partition for 0d fields
156      INTEGER :: id_part_rnf_1d ! Partition for 1d river outflow fields
157      INTEGER :: id_part_temp   ! Temperary partition used to choose either 0d or 1d partitions
158      INTEGER :: vector_length  ! Length of 0d or 1d variables (0d variables will have vector_length=1)
159      INTEGER :: paral(5)       ! OASIS3 box partition
160      INTEGER :: ishape(2,2)    ! shape of arrays passed to PSMILe
161      INTEGER :: ji,jc,jm       ! local loop indicees
162      CHARACTER(LEN=64) :: zclname
163      CHARACTER(LEN=2) :: cli2
164      !!--------------------------------------------------------------------
165
166      IF(lwp) WRITE(numout,*)
167      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
168      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
169      IF(lwp) WRITE(numout,*)
170
171      ncplmodel = kcplmodel
172      IF( kcplmodel > nmaxcpl ) THEN
173         CALL oasis_abort ( ncomp_id, 'cpl_define', 'ncplmodel is larger than nmaxcpl, increase nmaxcpl')   ;   RETURN
174      ENDIF
175
176      nrcv = krcv
177      IF( nrcv > nmaxfld ) THEN
178         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nrcv is larger than nmaxfld, increase nmaxfld')   ;   RETURN
179      ENDIF
180
181      nsnd = ksnd
182      IF( nsnd > nmaxfld ) THEN
183         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nsnd is larger than nmaxfld, increase nmaxfld')   ;   RETURN
184      ENDIF
185
186      !
187      ! ... Define the shape for the area that excludes the halo
188      !     For serial configuration (key_mpp_mpi not being active)
189      !     nl* is set to the global values 1 and jp*glo.
190      !
191      ishape(:,1) = (/ 1, nlei-nldi+1 /)
192      ishape(:,2) = (/ 1, nlej-nldj+1 /)
193      !
194      ! ... Allocate memory for data exchange
195      !
196      ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
197      IF( nerror > 0 ) THEN
198         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
199      ENDIF     
200      !
201      ! -----------------------------------------------------------------
202      ! ... Define the partition
203      ! -----------------------------------------------------------------
204           
205      paral(1) = 2                                              ! box partitioning
206      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset   
207      paral(3) = nlei-nldi+1                                    ! local extent in i
208      paral(4) = nlej-nldj+1                                    ! local extent in j
209      paral(5) = jpiglo                                         ! global extent in x
210     
211      IF( ln_ctl ) THEN
212         WRITE(numout,*) ' multiexchg: paral (1:5)', paral
213         WRITE(numout,*) ' multiexchg: jpi, jpj =', jpi, jpj
214         WRITE(numout,*) ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
215         WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
216      ENDIF
217     
218      CALL oasis_def_partition ( id_part, paral, nerror, jpiglo*jpjglo)
219
220      ! A special partition is needed for 0D fields
221     
222      paral(1) = 0                                       ! serial partitioning
223      paral(2) = 0   
224      IF ( nproc == 0) THEN
225         paral(3) = 1                   ! Size of array to couple (scalar)
226      ELSE
227         paral(3) = 0                   ! Dummy size for PE's not involved
228      END IF
229      paral(4) = 0
230      paral(5) = 0
231       
232      CALL oasis_def_partition ( id_part_0d, paral, nerror, 1 )
233
234      ! Another partition is needed for 1D river routing fields
235     
236      paral(1) = 0                                       ! serial partitioning
237      paral(2) = 0   
238      IF ( nproc == 0) THEN
239         paral(3) = nn_cpl_river                   ! Size of array to couple (vector)
240      ELSE
241         paral(3) = 0                   ! Dummy size for PE's not involved
242      END IF
243      paral(4) = 0
244      paral(5) = 0
245
246
247      CALL oasis_def_partition ( id_part_rnf_1d, paral, nerror, nn_cpl_river )
248 
249      !
250      ! ... Announce send variables.
251      !
252      ssnd(:)%ncplmodel = kcplmodel
253      !
254      DO ji = 1, ksnd
255         IF ( ssnd(ji)%laction ) THEN
256
257            IF( ssnd(ji)%nct > nmaxcat ) THEN
258               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
259                  &              TRIM(ssnd(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
260               RETURN
261            ENDIF
262           
263            DO jc = 1, ssnd(ji)%nct
264               DO jm = 1, kcplmodel
265
266                  IF ( ssnd(ji)%nct .GT. 1 ) THEN
267                     WRITE(cli2,'(i2.2)') jc
268                     zclname = TRIM(ssnd(ji)%clname)//'_cat'//cli2
269                  ELSE
270                     zclname = ssnd(ji)%clname
271                  ENDIF
272                  IF ( kcplmodel  > 1 ) THEN
273                     WRITE(cli2,'(i2.2)') jm
274                     zclname = 'model'//cli2//'_'//TRIM(zclname)
275                  ENDIF
276#if defined key_agrif
277                  IF( agrif_fixed() /= 0 ) THEN
278                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
279                  END IF
280#endif
281                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_Out
282                  CALL oasis_def_var (ssnd(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
283                     &                OASIS_Out          , ishape , OASIS_REAL, nerror )
284                  IF ( nerror /= OASIS_Ok ) THEN
285                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
286                     CALL oasis_abort ( ssnd(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
287                  ENDIF
288                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
289                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
290               END DO
291            END DO
292         ENDIF
293      END DO     
294      !
295      ! ... Announce received variables.
296      !
297      srcv(:)%ncplmodel = kcplmodel
298      !
299      DO ji = 1, krcv
300         IF ( srcv(ji)%laction ) THEN
301           
302            IF( srcv(ji)%nct > nmaxcat ) THEN
303               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
304                  &              TRIM(srcv(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
305               RETURN
306            ENDIF
307           
308            DO jc = 1, srcv(ji)%nct
309               DO jm = 1, kcplmodel
310                 
311                  IF ( srcv(ji)%nct .GT. 1 ) THEN
312                     WRITE(cli2,'(i2.2)') jc
313                     zclname = TRIM(srcv(ji)%clname)//'_cat'//cli2
314                  ELSE
315                     zclname = srcv(ji)%clname
316                  ENDIF
317                  IF ( kcplmodel  > 1 ) THEN
318                     WRITE(cli2,'(i2.2)') jm
319                     zclname = 'model'//cli2//'_'//TRIM(zclname)
320                  ENDIF
321#if defined key_agrif
322                  IF( agrif_fixed() /= 0 ) THEN
323                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
324                  END IF
325#endif
326                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_In
327flush(numout)
328
329                  ! Define 0D (Greenland or Antarctic ice mass) or 1D (river outflow) coupling fields
330                  IF (srcv(ji)%dimensions <= 1) THEN
331                    IF (nproc == 0) THEN                   
332                       
333                       IF (srcv(ji)%dimensions == 0) THEN
334                       
335                          ! If 0D then set temporary variables to 0D components
336                          id_part_temp = id_part_0d
337                          vector_length = 1
338                       ELSE
339                       
340                          ! If 1D then set temporary variables to river outflow components
341                          id_part_temp = id_part_rnf_1d
342                          vector_length = nn_cpl_river
343                         
344                       END IF
345                       
346                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_temp   , (/ 1, 0 /),   &
347                                   OASIS_In           , (/ 1, vector_length /) , OASIS_REAL, nerror )
348                    ELSE
349                       ! Dummy call to keep OASIS3-MCT happy.
350                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_0d   , (/ 1, 0 /),   &
351                                   OASIS_In           , (/ 0, 0 /) , OASIS_REAL, nerror )
352                    END IF
353                  ELSE 
354                    ! It's a "normal" 2D (or pseudo 3D) coupling field. 
355                    CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
356                                         OASIS_In           , ishape , OASIS_REAL, nerror )
357                  ENDIF
358
359                  IF ( nerror /= OASIS_Ok ) THEN
360                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
361                     CALL oasis_abort ( srcv(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
362                  ENDIF
363                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
364                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
365
366               END DO
367            END DO
368         ENDIF
369      END DO
370     
371      !------------------------------------------------------------------
372      ! End of definition phase
373      !------------------------------------------------------------------
374      CALL oasis_enddef(nerror)
375      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
376      !
377   END SUBROUTINE cpl_define
378   
379   
380   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
381      !!---------------------------------------------------------------------
382      !!              ***  ROUTINE cpl_snd  ***
383      !!
384      !! ** Purpose : - At each coupling time-step,this routine sends fields
385      !!      like sst or ice cover to the coupler or remote application.
386      !!----------------------------------------------------------------------
387      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
388      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
389      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
390      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
391      !!
392      INTEGER                                   ::   jc,jm     ! local loop index
393      !!--------------------------------------------------------------------
394      !
395      ! snd data to OASIS3
396      !
397      DO jc = 1, ssnd(kid)%nct
398         DO jm = 1, ssnd(kid)%ncplmodel
399       
400            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
401               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
402               
403               IF ( ln_ctl ) THEN       
404                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
405                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
406                     WRITE(numout,*) '****************'
407                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
408                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
409                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
410                     WRITE(numout,*) 'oasis_put:   info ', kinfo
411                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
412                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
413                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
414                     WRITE(numout,*) '****************'
415                  ENDIF
416               ENDIF
417               
418            ENDIF
419           
420         ENDDO
421      ENDDO
422      !
423    END SUBROUTINE cpl_snd
424
425
426   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
427      !!---------------------------------------------------------------------
428      !!              ***  ROUTINE cpl_rcv  ***
429      !!
430      !! ** Purpose : - At each coupling time-step,this routine receives fields
431      !!      like stresses and fluxes from the coupler or remote application.
432      !!----------------------------------------------------------------------
433      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
434      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
435      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
436      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
437      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
438      !!
439      INTEGER                                   ::   jc,jm     ! local loop index
440      LOGICAL                                   ::   llaction, llfisrt
441      !!--------------------------------------------------------------------
442      !
443      ! receive local data from OASIS3 on every process
444      !
445      kinfo = OASIS_idle
446      !
447      DO jc = 1, srcv(kid)%nct
448         llfisrt = .TRUE.
449
450         DO jm = 1, srcv(kid)%ncplmodel
451
452            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
453
454               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )   
455               
456               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
457                &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
458               
459               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
460               
461               IF ( llaction ) THEN
462                 
463                  kinfo = OASIS_Rcv
464                  IF( llfisrt ) THEN
465                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm) 
466                     llfisrt = .FALSE.
467                  ELSE
468                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
469                  ENDIF
470                 
471                  IF ( ln_ctl ) THEN       
472                     WRITE(numout,*) '****************'
473                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
474                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
475                     WRITE(numout,*) 'oasis_get:   kstep', kstep
476                     WRITE(numout,*) 'oasis_get:   info ', kinfo
477                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
478                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
479                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
480                     WRITE(numout,*) '****************'
481                  ENDIF
482
483               ENDIF
484
485            ENDIF
486           
487         ENDDO
488
489         !--- Fill the overlap areas and extra hallows (mpp)
490         !--- check periodicity conditions (all cases)
491         IF( .not. llfisrt )   CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
492 
493      ENDDO
494      !
495   END SUBROUTINE cpl_rcv
496
497   SUBROUTINE cpl_rcv_1d( kid, kstep, pdata, nitems, kinfo )
498      !!---------------------------------------------------------------------
499      !!              ***  ROUTINE cpl_rcv_1d  ***
500      !!
501      !! ** Purpose : - A special version of cpl_rcv to deal exclusively with
502      !! receipt of 0D or 1D fields.
503      !! The fields are recieved into a 1D array buffer which is simply a
504      !! dynamically sized sized array (which may be of size 1)
505      !! of 0 dimensional fields. This allows us to pass miltiple 0D
506      !! fields via a single put/get operation. 
507      !!----------------------------------------------------------------------
508      INTEGER , INTENT(in   ) ::   nitems      ! Number of 0D items to recieve
509                                               ! during this get operation. i.e.
510                                               ! The size of the 1D array in which
511                                               ! 0D items are passed.   
512      INTEGER , INTENT(in   ) ::   kid         ! ID index of the incoming
513                                               ! data. 
514      INTEGER , INTENT(in   ) ::   kstep       ! ocean time-step in seconds
515      REAL(wp), INTENT(inout) ::   pdata(1:nitems) ! The original value(s), 
516                                                   ! unchanged if nothing is
517                                                   ! received
518      INTEGER , INTENT(  out) ::   kinfo       ! OASIS3 info argument
519      !!
520      REAL(wp) ::   recvfld(1:nitems)          ! Local receive field buffer
521      INTEGER  ::   jc,jm     ! local loop index
522      INTEGER  ::   ierr
523      LOGICAL  ::   llaction
524      INTEGER  ::   MPI_WORKING_PRECISION
525      INTEGER  ::   number_to_print 
526      !!--------------------------------------------------------------------
527      !
528      ! receive local data from OASIS3 on every process
529      !
530      kinfo = OASIS_idle
531      !
532      ! 0D and 1D fields won't have categories or any other form of "pseudo level"
533      ! so we only cater for a single set of values and thus don't bother
534      ! with a loop over the jc index
535      jc = 1
536
537      DO jm = 1, srcv(kid)%ncplmodel
538
539         IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
540
541            IF ( ( srcv(kid)%dimensions <= 1) .AND. (nproc == 0) ) THEN
542               ! Since there is no concept of data decomposition for zero
543               ! dimension fields, they must only be exchanged through the master PE,
544               ! unlike "normal" 2D field cases where every PE is involved.
545
546               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, recvfld, kinfo )   
547               
548               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
549                           kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
550               
551               IF ( ln_ctl ) WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , &
552                                     llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
553               
554               IF ( llaction ) THEN
555                 
556                  kinfo = OASIS_Rcv
557                  pdata(1:nitems) = recvfld(1:nitems) 
558                 
559                  IF ( ln_ctl ) THEN       
560                     number_to_print = 10
561                     IF ( nitems < number_to_print ) number_to_print = nitems
562                     WRITE(numout,*) '****************'
563                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
564                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
565                     WRITE(numout,*) 'oasis_get:   kstep', kstep
566                     WRITE(numout,*) 'oasis_get:   info ', kinfo
567                     WRITE(numout,*) '     - Minimum Value is ', MINVAL(pdata(:))
568                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:))
569                     WRITE(numout,*) '     - Start of data is ', pdata(1:number_to_print)
570                     WRITE(numout,*) '****************'
571                  ENDIF
572                 
573               ENDIF
574            ENDIF   
575          ENDIF
576           
577       ENDDO
578       
579       ! Set the precision that we want to broadcast using MPI_BCAST
580       SELECT CASE( wp )
581       CASE( sp ) 
582         MPI_WORKING_PRECISION = MPI_REAL                ! Single precision
583       CASE( dp )
584         MPI_WORKING_PRECISION = MPI_DOUBLE_PRECISION    ! Double precision
585       CASE default
586         CALL oasis_abort( ncomp_id, "cpl_rcv_1d", "Could not find precision for coupling 0d or 1d field" )
587       END SELECT
588
589       ! We have to broadcast (potentially) received values from PE 0 to all
590       ! the others. If no new data has been received we're just
591       ! broadcasting the existing values but there's no more efficient way
592       ! to deal with that w/o NEMO adopting a UM-style test mechanism
593       ! to determine active put/get timesteps.
594       CALL mpi_bcast( pdata, nitems, MPI_WORKING_PRECISION, localRoot, mpi_comm_opa, ierr )
595
596      !
597   END SUBROUTINE cpl_rcv_1d
598
599
600   INTEGER FUNCTION cpl_freq( cdfieldname ) 
601      !!---------------------------------------------------------------------
602      !!              ***  ROUTINE cpl_freq  ***
603      !!
604      !! ** Purpose : - send back the coupling frequency for a particular field
605      !!----------------------------------------------------------------------
606      CHARACTER(len = *), INTENT(in) ::   cdfieldname    ! field name as set in namcouple file
607      !!
608      INTEGER               :: id
609      INTEGER               :: info
610      INTEGER, DIMENSION(1) :: itmp
611      INTEGER               :: ji,jm     ! local loop index
612      INTEGER               :: mop
613      !!----------------------------------------------------------------------
614      cpl_freq = 0   ! defaut definition
615      id = -1        ! defaut definition
616      !
617      DO ji = 1, nsnd
618         IF (ssnd(ji)%laction ) THEN
619            DO jm = 1, ncplmodel
620               IF( ssnd(ji)%nid(1,jm) /= -1 ) THEN
621                  IF( TRIM(cdfieldname) == TRIM(ssnd(ji)%clname) ) THEN
622                     id = ssnd(ji)%nid(1,jm)
623                     mop = OASIS_Out
624                  ENDIF
625               ENDIF
626            ENDDO
627         ENDIF
628      ENDDO
629      DO ji = 1, nrcv
630         IF (srcv(ji)%laction ) THEN
631            DO jm = 1, ncplmodel
632               IF( srcv(ji)%nid(1,jm) /= -1 ) THEN
633                  IF( TRIM(cdfieldname) == TRIM(srcv(ji)%clname) ) THEN
634                     id = srcv(ji)%nid(1,jm)
635                     mop = OASIS_In
636                  ENDIF
637               ENDIF
638            ENDDO
639         ENDIF
640      ENDDO
641      !
642      IF( id /= -1 ) THEN
643#if defined key_oa3mct_v3
644         CALL oasis_get_freqs(id, mop, 1, itmp, info)
645#else
646#if defined key_oasis3 
647         itmp(1) = namflddti( id )
648#else
649         CALL oasis_get_freqs(id,      1, itmp, info)
650#endif
651#endif
652         cpl_freq = itmp(1)
653      ENDIF
654      !
655   END FUNCTION cpl_freq
656
657
658   SUBROUTINE cpl_finalize
659      !!---------------------------------------------------------------------
660      !!              ***  ROUTINE cpl_finalize  ***
661      !!
662      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
663      !!      called explicitly before cpl_init it will also close
664      !!      MPI communication.
665      !!----------------------------------------------------------------------
666      !
667      DEALLOCATE( exfld )
668      IF (nstop == 0) THEN
669         CALL oasis_terminate( nerror )         
670      ELSE
671         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
672      ENDIF       
673      !
674   END SUBROUTINE cpl_finalize
675
676#if ! defined key_oasis3
677
678   !!----------------------------------------------------------------------
679   !!   No OASIS Library          OASIS3 Dummy module...
680   !!----------------------------------------------------------------------
681
682   SUBROUTINE oasis_init_comp(k1,cd1,k2)
683      CHARACTER(*), INTENT(in   ) ::  cd1
684      INTEGER     , INTENT(  out) ::  k1,k2
685      k1 = -1 ; k2 = -1
686      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
687   END SUBROUTINE oasis_init_comp
688
689   SUBROUTINE oasis_abort(k1,cd1,cd2)
690      INTEGER     , INTENT(in   ) ::  k1
691      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
692      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
693   END SUBROUTINE oasis_abort
694
695   SUBROUTINE oasis_get_localcomm(k1,k2)
696      INTEGER     , INTENT(  out) ::  k1,k2
697      k1 = -1 ; k2 = -1
698      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
699   END SUBROUTINE oasis_get_localcomm
700
701   SUBROUTINE oasis_def_partition(k1,k2,k3,K4)
702      INTEGER     , INTENT(  out) ::  k1,k3
703      INTEGER     , INTENT(in   ) ::  k2(5)
704      INTEGER     , OPTIONAL, INTENT(in   ) ::  k4
705      k1 = k2(1) ; k3 = k2(5)
706      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
707   END SUBROUTINE oasis_def_partition
708
709   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
710      CHARACTER(*), INTENT(in   ) ::  cd1
711      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
712      INTEGER     , INTENT(  out) ::  k1,k7
713      k1 = -1 ; k7 = -1
714      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
715   END SUBROUTINE oasis_def_var
716
717   SUBROUTINE oasis_enddef(k1)
718      INTEGER     , INTENT(  out) ::  k1
719      k1 = -1
720      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
721   END SUBROUTINE oasis_enddef
722 
723   SUBROUTINE oasis_put(k1,k2,p1,k3)
724      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
725      INTEGER                 , INTENT(in   ) ::  k1,k2
726      INTEGER                 , INTENT(  out) ::  k3
727      k3 = -1
728      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
729   END SUBROUTINE oasis_put
730
731   SUBROUTINE oasis_get(k1,k2,p1,k3)
732      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
733      INTEGER                 , INTENT(in   ) ::  k1,k2
734      INTEGER                 , INTENT(  out) ::  k3
735      p1(1,1) = -1. ; k3 = -1
736      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
737   END SUBROUTINE oasis_get
738
739   SUBROUTINE oasis_get_freqs(k1,k2,k3,k4)
740      INTEGER              , INTENT(in   ) ::  k1,k2
741      INTEGER, DIMENSION(1), INTENT(  out) ::  k3
742      INTEGER              , INTENT(  out) ::  k4
743      k3(1) = k1 ; k4 = k2
744      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
745   END SUBROUTINE oasis_get_freqs
746
747   SUBROUTINE oasis_terminate(k1)
748      INTEGER     , INTENT(  out) ::  k1
749      k1 = -1
750      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
751   END SUBROUTINE oasis_terminate
752   
753#endif
754
755   !!=====================================================================
756END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.