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.
modupdate.F in trunk/AGRIF/AGRIF_FILES – NEMO

source: trunk/AGRIF/AGRIF_FILES/modupdate.F @ 662

Last change on this file since 662 was 662, checked in by opalod, 17 years ago

RB: update Agrif internal routines with a new update scheme and performance improvment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 87.0 KB
Line 
1!
2! $Id$
3!
4C     AGRIF (Adaptive Grid Refinement In Fortran)
5C
6C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
7C                        Christophe Vouland (Christophe.Vouland@imag.fr)   
8C
9C     This program is free software; you can redistribute it and/or modify
10C     it under the terms of the GNU General Public License as published by
11C     the Free Software Foundation; either version 2 of the License, or
12C     (at your option) any later version.
13C
14C     This program is distributed in the hope that it will be useful,
15C     but WITHOUT ANY WARRANTY; without even the implied warranty of
16C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17C     GNU General Public License for more details.
18C
19C     You should have received a copy of the GNU General Public License
20C     along with this program; if not, write to the Free Software
21C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
22C
23C
24C
25CCC   Module Agrif_Update
26C
27      Module Agrif_Update
28C
29CCC   Description:
30CCC   Module to update a parent grid from its child grids
31C
32C     Modules used:
33C   
34      Use Agrif_Updatebasic
35c      Use Agrif_Boundary
36      Use Agrif_Arrays
37      Use Agrif_CurgridFunctions
38      Use Agrif_Mask
39#ifdef AGRIF_MPI
40      Use Agrif_mpp
41#endif
42C
43      IMPLICIT NONE
44C     
45      CONTAINS
46C     Define procedures contained in this module
47C
48C
49C
50C     **************************************************************************
51CCC   Subroutine Agrif_Update_1d
52C     **************************************************************************
53C 
54      Subroutine Agrif_Update_1d(TypeUpdate,parent,child,tab,deb,fin,
55     &                           procname)
56C
57CCC   Description:
58CCC   Subroutine to update a 1D grid variable on the parent grid.
59C
60C     Declarations:
61C
62     
63C
64C     Arguments     
65      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
66      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
67      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
68      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
69      INTEGER :: deb,fin                      ! Positions where interpolations
70                                              ! are done on the fine grid       
71      External :: procname
72      Optional ::  procname     
73      REAL, DIMENSION(lbound(child%var%array1,1):
74     &                ubound(child%var%array1,1)), Target :: tab  ! Results
75C
76C
77C     Definition of a temporary AGRIF_PVariable data TYPE 
78      allocate(childtemp % var)
79C
80C     Pointer on the root variable
81      childtemp % var % root_var => child % var %root_var
82C     
83C     Number of dimensions of the grid variable
84      childtemp % var % nbdim = 1 
85C     
86C     Values on the current grid used for the update
87      childtemp % var % array1 => tab     
88     
89C      childtemp % var % list_update => child%var%list_update
90             
91C
92     
93      IF (present(procname)) THEN
94      CALL Agrif_UpdateVariable
95     &     (TypeUpdate,parent,child,deb,fin,procname)
96      ELSE
97      CALL Agrif_UpdateVariable
98     &     (TypeUpdate,parent,child,deb,fin)
99      ENDIF     
100C     
101C      child % var % list_update => childtemp%var%list_update
102     
103      deallocate(childtemp % var)
104C
105C       
106      End Subroutine Agrif_Update_1D
107C
108C
109C
110C     **************************************************************************
111CCC   Subroutine Agrif_Update_2d
112C     **************************************************************************
113C 
114
115      Subroutine Agrif_Update_2d(TypeUpdate,parent,child,tab,deb,fin,
116     &                           procname)
117C
118CCC   Description:
119CCC   Subroutine to update a 2D grid variable on the parent grid.
120C
121C     Declarations:
122C
123     
124C
125C     Arguments     
126      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
127      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
128      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
129      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
130      INTEGER :: deb,fin                      ! Positions where interpolations
131                                              ! are done on the fine grid
132                                             
133      External :: procname
134      Optional ::  procname
135                                                         
136      REAL, DIMENSION(
137     &      lbound(child%var%array2,1):ubound(child%var%array2,1),
138     &      lbound(child%var%array2,2):ubound(child%var%array2,2)),
139     &      Target :: tab  ! Results
140C
141C
142C     Definition of a temporary AGRIF_PVariable data TYPE
143      allocate(childtemp % var)
144C
145C     Pointer on the root variable
146      childtemp % var % root_var => child % var %root_var
147C     
148C     Number of dimensions of the grid variable
149      childtemp % var % nbdim = 2 
150C     
151C     Values on the current grid used for the update
152      childtemp % var % array2 => tab     
153     
154C      childtemp % var % list_update => child%var%list_update     
155C
156      IF (present(procname)) THEN
157      CALL Agrif_UpdateVariable
158     &     (TypeUpdate,parent,child,deb,fin,procname)
159      ELSE
160      CALL Agrif_UpdateVariable
161     &     (TypeUpdate,parent,child,deb,fin)
162      ENDIF
163C     
164C      child % var % list_update => childtemp%var%list_update
165     
166      deallocate(childtemp % var)
167C
168C       
169      End Subroutine Agrif_Update_2D
170C
171C
172C
173C     **************************************************************************
174CCC   Subroutine Agrif_Update_3d
175C     **************************************************************************
176C 
177      Subroutine Agrif_Update_3d(TypeUpdate,parent,child,tab,deb,fin,
178     &                           procname)
179C
180CCC   Description:
181CCC   Subroutine to update a 3D grid variable on the parent grid.
182C
183C     Declarations:
184C
185     
186C
187C     Arguments     
188      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
189      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
190      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
191      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
192      INTEGER :: deb,fin                      ! Positions where interpolations
193                                              ! are done on the fine grid   
194      External :: procname
195      Optional ::  procname
196                                                       
197      REAL, DIMENSION(
198     &      lbound(child%var%array3,1):ubound(child%var%array3,1),
199     &      lbound(child%var%array3,2):ubound(child%var%array3,2),
200     &      lbound(child%var%array3,3):ubound(child%var%array3,3)),
201     &      Target :: tab  ! Results   
202C
203C
204C     Definition of a temporary AGRIF_PVariable data TYPE 
205      allocate(childtemp % var)
206C
207C     Pointer on the root variable
208      childtemp % var % root_var => child % var %root_var
209C     
210C     Number of dimensions of the grid variable
211      childtemp % var % nbdim = 3 
212C     
213C     Values on the current grid used for the update
214      childtemp % var % array3 => tab     
215     
216C      childtemp % var % list_update => child%var%list_update     
217C
218      IF (present(procname)) THEN
219      CALL Agrif_UpdateVariable
220     &     (TypeUpdate,parent,child,deb,fin,procname)
221      ELSE
222      CALL Agrif_UpdateVariable
223     &     (TypeUpdate,parent,child,deb,fin)
224      ENDIF
225C     
226C      child % var % list_update => childtemp%var%list_update
227     
228      DEALLOCATE(childtemp % var)
229C
230C       
231      End Subroutine Agrif_Update_3D
232C
233C
234C
235C     **************************************************************************
236CCC   Subroutine Agrif_Update_4d
237C     **************************************************************************
238C 
239      Subroutine Agrif_Update_4d(TypeUpdate,parent,child,tab,deb,fin,
240     &                           procname)
241C
242CCC   Description:
243CCC   Subroutine to update a 4D grid variable on the parent grid.
244C
245C     Declarations:
246C
247     
248C
249C     Arguments     
250      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
251      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
252      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
253      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
254      INTEGER :: deb,fin                      ! Positions where interpolations
255                                              ! are done on the fine grid     
256      External :: procname
257      Optional ::  procname       
258      REAL, DIMENSION(
259     &      lbound(child%var%array4,1):ubound(child%var%array4,1),
260     &      lbound(child%var%array4,2):ubound(child%var%array4,2),
261     &      lbound(child%var%array4,3):ubound(child%var%array4,3),
262     &      lbound(child%var%array4,4):ubound(child%var%array4,4)),
263     &      Target :: tab  ! Results
264C
265C
266C     Definition of a temporary AGRIF_PVariable data TYPE 
267      allocate(childtemp % var)
268C
269C     Pointer on the root variable
270      childtemp % var % root_var => child % var %root_var
271C     
272C     Number of dimensions of the grid variable
273      childtemp % var % nbdim = 4 
274C     
275C     Values on the current grid used for the update
276      childtemp % var % array4 => tab     
277     
278C      childtemp % var % list_update => child%var%list_update
279           
280C
281      IF (present(procname)) THEN
282      CALL Agrif_UpdateVariable
283     &     (TypeUpdate,parent,child,deb,fin,procname)
284      ELSE
285      CALL Agrif_UpdateVariable
286     &     (TypeUpdate,parent,child,deb,fin)
287      ENDIF
288
289C      child % var % list_update => childtemp%var%list_update     
290C
291      deallocate(childtemp % var)
292C
293C       
294      End Subroutine Agrif_Update_4D
295C
296C
297C
298C     **************************************************************************
299CCC   Subroutine Agrif_Update_5d
300C     **************************************************************************
301C 
302      Subroutine Agrif_Update_5d(TypeUpdate,parent,child,tab,deb,fin,
303     &                           procname)
304C
305CCC   Description:
306CCC   Subroutine to update a 5D grid variable on the parent grid.
307C
308C     Declarations:
309C
310     
311C
312C     Arguments     
313      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
314      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
315      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
316      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
317      INTEGER :: deb,fin                      ! Positions where interpolations
318                                              ! are done on the fine grid     
319      External :: procname
320      Optional ::  procname
321             
322      REAL, DIMENSION(
323     &      lbound(child%var%array5,1):ubound(child%var%array5,1),
324     &      lbound(child%var%array5,2):ubound(child%var%array5,2),
325     &      lbound(child%var%array5,3):ubound(child%var%array5,3),
326     &      lbound(child%var%array5,4):ubound(child%var%array5,4),
327     &      lbound(child%var%array5,5):ubound(child%var%array5,5)),
328     &      Target :: tab  ! Results
329C
330C
331C     Definition of a temporary AGRIF_PVariable data TYPE 
332      allocate(childtemp % var)
333C
334C     Pointer on the root variable
335      childtemp % var % root_var => child % var %root_var
336C
337C     Number of dimensions of the grid variable
338      childtemp % var % nbdim = 5 
339C     
340C     Values on the current grid used for the update
341      childtemp % var % array5 => tab     
342     
343C      childtemp % var % list_update => child%var%list_update     
344C
345      IF (present(procname)) THEN
346      CALL Agrif_UpdateVariable
347     &     (TypeUpdate,parent,child,deb,fin,procname)
348      ELSE
349      CALL Agrif_UpdateVariable
350     &     (TypeUpdate,parent,child,deb,fin)
351      ENDIF
352     
353C      child % var % list_update => childtemp%var%list_update
354           
355C     
356      deallocate(childtemp % var)
357C
358C       
359      End Subroutine Agrif_Update_5D
360C
361C
362C
363C
364C     **************************************************************************
365CCC   Subroutine Agrif_Update_6d
366C     **************************************************************************
367C 
368      Subroutine Agrif_Update_6d(TypeUpdate,parent,child,tab,deb,fin)
369C
370CCC   Description:
371CCC   Subroutine to update a 6D grid variable on the parent grid.
372C
373C     Declarations:
374C
375     
376C
377C     Arguments     
378      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
379      TYPE(AGRIF_PVariable) :: parent        ! Variable on the parent grid
380      TYPE(AGRIF_PVariable) :: child         ! Variable on the child grid
381      TYPE(AGRIF_PVariable) :: childtemp     ! Temporary variable on the child
382      INTEGER :: deb,fin                      ! Positions where interpolations
383                                              ! are done on the fine grid       
384      REAL, DIMENSION(
385     &      lbound(child%var%array6,1):ubound(child%var%array6,1),
386     &      lbound(child%var%array6,2):ubound(child%var%array6,2),
387     &      lbound(child%var%array6,3):ubound(child%var%array6,3),
388     &      lbound(child%var%array6,4):ubound(child%var%array6,4),
389     &      lbound(child%var%array6,5):ubound(child%var%array6,5),
390     &      lbound(child%var%array6,6):ubound(child%var%array6,6)),
391     &      Target :: tab  ! Results
392C
393C
394C     Definition of a temporary AGRIF_PVariable data TYPE 
395      allocate(childtemp % var)
396C
397C     Pointer on the root variable
398      childtemp % var % root_var => child % var %root_var
399C     
400C     Number of dimensions of the grid variable
401      childtemp % var % nbdim = 6 
402C     
403C     Values on the current grid used for the update
404      childtemp % var % array6 => tab     
405C      childtemp % var % list_update => child%var%list_update
406C
407      Call Agrif_UpdateVariable
408     &     (TypeUpdate,parent,child,deb,fin)
409     
410C      child % var % list_update => childtemp%var%list_update
411           
412C     
413      deallocate(childtemp % var)
414C
415C       
416      End Subroutine Agrif_Update_6D
417C
418C
419C
420C     ************************************************************************** 
421C     Subroutine Agrif_UpdateVariable   
422C     ************************************************************************** 
423C   
424      Subroutine Agrif_UpdateVariable(TypeUpdate,parent,child,deb,fin,
425     &                   procname)   
426C
427CCC   Description:
428CCC   Subroutine to set arguments of Agrif_UpdatenD, n being the number of
429C         dimensions of the grid variable.
430C
431CC    Declarations:
432C     
433c     
434C     
435C     Scalar argument
436      INTEGER, DIMENSION(6) :: TypeUpdate                  ! TYPE of update (copy or average)
437C     Data TYPE arguments
438      TYPE(AGRIF_PVariable) :: parent   ! Variable on the parent grid
439      TYPE(AGRIF_PVariable) :: child    ! Variable on the child grid
440      INTEGER               :: deb,fin  ! Positions where boundary conditions
441                                        !    are calculated     
442      External :: procname
443      Optional ::  procname
444     
445C
446C     Local scalars     
447      INTEGER :: nbdim                  ! Number of dimensions of the current
448                                        !    grid
449      INTEGER ,DIMENSION(6) :: pttab_child 
450      INTEGER ,DIMENSION(6) :: petab_child     
451      INTEGER ,DIMENSION(6) :: pttab_parent 
452      REAL    ,DIMENSION(6) :: s_child,s_parent
453      REAL    ,DIMENSION(6) :: ds_child,ds_parent
454      INTEGER,DIMENSION(6)          :: loctab_Child ! Indicates if the child
455                                        !    grid has a common border with
456                                        !    the root grid           
457      TYPE(AGRIF_Variable), Pointer :: root               ! Variable on the root grid
458      INTEGER,DIMENSION(6)          :: posvartab_Child    ! Position of the
459                                        !    variable on the cell
460      INTEGER,DIMENSION(6)          :: nbtab_Child        ! Number of the cells   
461      INTEGER :: n             
462      LOGICAL :: wholeupdate
463C
464C 
465
466      loctab_child(:) = 0
467C
468      root => child % var % root_var 
469      nbdim = root % nbdim
470C
471      do n = 1,nbdim
472        posvartab_child(n) = root % posvar(n)
473      enddo
474C     
475     
476      Call PreProcessToInterpOrUpdate(parent,child,
477     &             petab_Child(1:nbdim),
478     &             pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
479     &             s_Child(1:nbdim),s_Parent(1:nbdim),
480     &             ds_Child(1:nbdim),ds_Parent(1:nbdim),
481     &             nbdim)
482C
483C
484      do n = 1,nbdim
485C
486        Select case(root % interptab(n))
487C
488          case('x') ! x DIMENSION
489C
490            nbtab_Child(n) = Agrif_Curgrid % nb(1)
491C
492          case('y') ! y DIMENSION     
493C
494            nbtab_Child(n) = Agrif_Curgrid % nb(2)
495C
496          case('z') ! z DIMENSION
497C
498            nbtab_Child(n) = Agrif_Curgrid % nb(3)
499C
500          case('N') ! No space DIMENSION     
501C
502            select case (nbdim) 
503C     
504              case(1)
505                nbtab_Child(n) = SIZE(child % var % array1,n) - 1
506              case(2)
507                nbtab_Child(n) = SIZE(child % var % array2,n) - 1
508              case(3)
509                nbtab_Child(n) = SIZE(child % var % array3,n) - 1
510              case(4)
511                nbtab_Child(n) = SIZE(child % var % array4,n) - 1
512              case(5)
513                nbtab_Child(n) = SIZE(child % var % array5,n) - 1 
514              case(6)
515                nbtab_Child(n) = SIZE(child % var % array6,n) - 1 
516C
517            end select
518C
519C           No interpolation but only a copy of the values of the grid variable     
520C     
521            posvartab_child(n) = 1
522           
523            loctab_child(n) = -3
524C
525        End select
526C
527      enddo
528     
529C     Call to a procedure of update according to the number of dimensions of
530C     the grid variable
531
532      wholeupdate = .FALSE.
533
534      IF ((deb == -99) .AND. (deb == fin)) THEN
535       wholeupdate = .TRUE.
536      ENDIF
537
538      IF ((deb > fin)) THEN
539       wholeupdate = .TRUE.
540      ENDIF
541     
542       IF (present(procname)) THEN
543
544          IF (wholeupdate) THEN
545
546          Call AGRIF_UpdateWhole
547     &         (TypeUpdate,parent,child,deb,fin,
548     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
549     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
550     &          loctab_Child(1:nbdim),
551     &          s_Child(1:nbdim),s_Parent(1:nbdim),
552     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim,procname) 
553         ELSE
554          Call AGRIF_UpdateBcnD
555     &         (TypeUpdate,parent,child,deb,fin,
556     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
557     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
558     &          loctab_Child(1:nbdim),
559     &          s_Child(1:nbdim),s_Parent(1:nbdim),
560     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim,procname) 
561         ENDIF
562       ELSE
563         IF (wholeupdate) THEN
564          Call AGRIF_UpdateWhole
565     &         (TypeUpdate,parent,child,deb,fin,
566     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
567     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
568     &          loctab_Child(1:nbdim),
569     &          s_Child(1:nbdim),s_Parent(1:nbdim),
570     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim)
571         ELSE
572          Call AGRIF_UpdateBcnD
573     &         (TypeUpdate,parent,child,deb,fin,
574     &          pttab_Child(1:nbdim),pttab_Parent(1:nbdim),
575     &          nbtab_Child(1:nbdim),posvartab_Child(1:nbdim),
576     &          loctab_Child(1:nbdim),
577     &          s_Child(1:nbdim),s_Parent(1:nbdim),
578     &          ds_Child(1:nbdim),ds_Parent(1:nbdim),nbdim)
579         ENDIF
580       ENDIF
581C
582      Return
583C
584C
585      End subroutine Agrif_UpdateVariable
586C
587C     **************************************************************************
588CCC   Subroutine Agrif_UpdateWhole
589C     **************************************************************************               
590C
591      Subroutine AGRIF_UpdateWhole(TypeUpdate,parent,child,deb,fin,
592     &                           pttab_child,pttab_Parent,
593     &                           nbtab_Child,posvartab_Child,
594     &                           loctab_Child,
595     &                           s_Child,s_Parent,
596     &                           ds_Child,ds_Parent,nbdim,procname)
597C
598CCC   Description:
599CCC   Subroutine to calculate the boundary conditions for a nD grid variable on 
600CCC   a fine grid by using a space and time interpolations; it is called by the 
601CCC   Agrif_CorrectVariable procedure.
602C
603C
604C     Declarations:
605C
606     
607C
608#ifdef AGRIF_MPI
609C
610#include "mpif.h"
611C
612#endif
613C
614C     Arguments
615      INTEGER, DIMENSION(6) :: TypeUpdate            ! TYPE of update (copy or
616                                                     !    average)
617      TYPE(AGRIF_PVariable)    :: parent             ! Variable on the parent
618                                                     !    grid
619      TYPE(AGRIF_PVariable)    :: child              ! Variable on the child
620                                                     !    grid
621      INTEGER :: deb, fin
622      INTEGER                  :: nbdim              ! Number of dimensions of
623                                                     !    the grid variable
624      INTEGER,DIMENSION(nbdim) :: pttab_child        ! Index of the first point
625                                                     !    inside the domain for
626                                                     !    the parent grid
627                                                     !    variable
628      INTEGER,DIMENSION(nbdim) :: pttab_Parent       ! Index of the first point
629                                                     !    inside the domain for
630                                                     !    the child grid
631                                                     !    variable
632      INTEGER,DIMENSION(nbdim) :: nbtab_Child        ! Number of cells of the
633                                                     !    child grid
634      INTEGER,DIMENSION(nbdim) :: posvartab_Child    ! Position of the grid
635                                                     !    variable (1 or 2)
636      INTEGER,DIMENSION(nbdim) :: loctab_Child       ! Indicates if the child
637                                                     !    grid has a common
638                                                     !    border with the root
639                                                     !    grid
640      REAL   ,DIMENSION(nbdim) :: s_Child,s_Parent   ! Positions of the parent
641                                                     !    and child grids
642      REAL   ,DIMENSION(nbdim) :: ds_Child,ds_Parent ! Space steps of the parent
643                                                     !    and child grids
644      External :: procname
645      Optional ::  procname     
646C
647C     Local variables     
648      INTEGER,DIMENSION(nbdim,2)   :: lubglob
649      INTEGER                      :: i                 
650      INTEGER,DIMENSION(nbdim,2,2) :: indtab         ! Arrays indicating the
651                                                     !    limits of the child
652      INTEGER,DIMENSION(nbdim,2,2) :: indtruetab     ! grid variable where
653                                                     !   boundary conditions are
654      integer :: coeffraf
655      INTEGER :: debloc, finloc
656C
657#ifdef AGRIF_MPI
658C
659      INTEGER,DIMENSION(nbdim)   :: lb,ub
660      INTEGER,DIMENSION(nbdim,2) :: iminmaxg
661      INTEGER                    :: code
662C
663#endif
664C     
665C
666C indtab contains the limits for the fine grid points that will be used
667C in the update scheme
668
669      DO i = 1, nbdim
670        coeffraf = nint(ds_Parent(i)/ds_Child(i))
671        debloc = 0
672        finloc = nbtab_Child(i)/coeffraf - 1
673
674        IF (posvartab_child(i) == 1) THEN
675           finloc = finloc - 1
676        ENDIF
677
678        IF (deb > fin) THEN
679          debloc = deb
680          finloc = finloc - deb
681        ENDIF
682
683        indtab(i,1,1) = pttab_child(i) + (debloc + 1) * coeffraf
684        indtab(i,1,2) = pttab_child(i) + (finloc + 1) * coeffraf
685
686        IF (posvartab_child(i) == 1) THEN
687          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
688            indtab(i,1,1) = indtab(i,1,1) - (coeffraf - 1)
689            indtab(i,1,2) = indtab(i,1,2) + (coeffraf - 1)       
690          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
691            indtab(i,1,1) = indtab(i,1,1) - coeffraf / 2
692            indtab(i,1,2) = indtab(i,1,2) + coeffraf / 2
693          ENDIF
694        ELSE
695          indtab(i,1,1) = indtab(i,1,1) - coeffraf
696          indtab(i,1,2) = indtab(i,1,2) - 1
697          IF ((TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting)
698     &                            .AND.(mod(coeffraf,2) == 1)) THEN
699            indtab(i,1,1) = indtab(i,1,1) - 1
700            indtab(i,1,2) = indtab(i,1,2) + 1
701          ENDIF
702        ENDIF
703        IF (loctab_child(i) == -3) THEN
704           indtab(i,1,1) = pttab_child(i)
705C
706               if (posvartab_child(i) == 1) then
707C
708               indtab(i,1,2) = pttab_child(i) + nbtab_child(i) 
709C
710               else
711C
712               indtab(i,1,2) = pttab_child(i) + nbtab_child(i) - 1
713               ENDIF
714        ENDIF
715      ENDDO
716
717C lubglob contains the global lbound and ubound of the child array
718C lubglob(:,1) : global lbound for each dimension
719C lubglob(:,2) : global lbound for each dimension
720
721#if !defined AGRIF_MPI
722        Call Agrif_nbdim_Get_bound_dimension(child % var,lubglob(:,1),
723     &               lubglob(:,2),nbdim)
724C
725#else
726C     
727        Call Agrif_nbdim_Get_bound_dimension(child % var,lb,ub,nbdim)
728      DO i = 1,nbdim
729C
730        Call Agrif_Invloc(lb(i),Agrif_Procrank,i,iminmaxg(i,1))
731        Call Agrif_Invloc(ub(i),Agrif_Procrank,i,iminmaxg(i,2))
732C
733      ENDDO
734C
735      iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
736     
737      CALL MPI_ALLREDUCE(iminmaxg,lubglob,2*nbdim,MPI_INTEGER,MPI_MIN,
738     &                     MPI_COMM_WORLD,code)
739
740      lubglob(1:nbdim,2) = - lubglob(1:nbdim,2)     
741C
742#endif
743C
744
745      indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),
746     &     lubglob(1:nbdim,1))
747      indtruetab(1:nbdim,1,2) = min(indtab(1:nbdim,1,2),
748     &     lubglob(1:nbdim,2))
749
750C
751C
752
753           IF (present(procname)) THEN
754              Call Agrif_UpdatenD             
755     &             (TypeUpdate,parent,child,
756     &              indtruetab(1:nbdim,1,1),indtruetab(1:nbdim,1,2),
757     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
758     &              s_Child(1:nbdim),s_Parent(1:nbdim),
759     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
760     &              posvartab_child,loctab_Child,
761     &              nbdim,procname)
762           ELSE
763              Call Agrif_UpdatenD             
764     &             (TypeUpdate,parent,child,
765     &              indtruetab(1:nbdim,1,1),indtruetab(1:nbdim,1,2),
766     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
767     &              s_Child(1:nbdim),s_Parent(1:nbdim),
768     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
769     &              posvartab_child,loctab_Child,
770     &              nbdim)           
771           ENDIF
772C
773C     
774C 
775      End Subroutine Agrif_UpdateWhole
776C
777C     **************************************************************************
778CCC   Subroutine Agrif_UpdateBcnd
779C     **************************************************************************               
780C
781      Subroutine AGRIF_UpdateBcnd(TypeUpdate,parent,child,deb,fin,
782     &                           pttab_child,pttab_Parent,
783     &                           nbtab_Child,posvartab_Child,
784     &                           loctab_Child,
785     &                           s_Child,s_Parent,
786     &                           ds_Child,ds_Parent,nbdim,procname)
787C
788CCC   Description:
789CCC   Subroutine to calculate the boundary conditions for a nD grid variable on
790CCC   a fine grid by using a space and time interpolations; it is called by the 
791CCC   Agrif_CorrectVariable procedure.
792C
793C
794C     Declarations:
795C
796     
797C
798#ifdef AGRIF_MPI
799C
800#include "mpif.h"
801C
802#endif
803C
804C     Arguments
805      INTEGER, DIMENSION(6) :: TypeUpdate            ! TYPE of update
806                                                     !   (copy or average)
807      TYPE(AGRIF_PVariable)    :: parent             ! Variable on the parent
808                                                     !   grid
809      TYPE(AGRIF_PVariable)    :: child              ! Variable on the child
810                                                     !   grid
811      INTEGER                  :: deb,fin            ! Positions where
812                                                     !   interpolations are done
813      INTEGER                  :: nbdim              ! Number of dimensions of
814                                                     !   the grid variable
815      INTEGER,DIMENSION(nbdim) :: pttab_child        ! Index of the first point
816                                                     !   inside the domain for
817                                                     !   the parent grid
818                                                     !   variable
819      INTEGER,DIMENSION(nbdim) :: pttab_Parent       ! Index of the first point
820                                                     !   inside the domain for
821                                                     !   the child grid variable
822      INTEGER,DIMENSION(nbdim) :: nbtab_Child        ! Number of cells of the
823                                                     !   child grid
824      INTEGER,DIMENSION(nbdim) :: posvartab_Child    ! Position of the grid
825                                                     !   variable (1 or 2)
826      INTEGER,DIMENSION(nbdim) :: loctab_Child       ! Indicates if the child
827                                                     !   grid has a common
828                                                     !   border with the root
829                                                     !   grid
830      REAL   ,DIMENSION(nbdim) :: s_Child,s_Parent   ! Positions of the parent
831                                                     !   and child grids
832      REAL   ,DIMENSION(nbdim) :: ds_Child,ds_Parent ! Space steps of the parent
833                                                     !   and child grids
834      External :: procname
835      Optional ::  procname     
836C
837C     Local variables
838      INTEGER,DIMENSION(nbdim,2)   :: lubglob
839      INTEGER                      :: i                 
840      INTEGER,DIMENSION(nbdim,2,2) :: indtab         ! Arrays indicating the
841                                                     !   limits of the child
842      INTEGER,DIMENSION(nbdim,2,2) :: indtruetab     ! grid variable where
843                                                     !  boundary conditions are
844      INTEGER,DIMENSION(nbdim,2,2,nbdim)   :: ptres      ! calculated
845      INTEGER                      :: nb,ndir,n
846      integer :: coeffraf
847C
848#ifdef AGRIF_MPI
849C
850      INTEGER,DIMENSION(nbdim)   :: lb,ub
851      INTEGER,DIMENSION(nbdim,2) :: iminmaxg
852      INTEGER                    :: code
853C
854#endif
855C     
856C
857
858      DO i = 1, nbdim
859        coeffraf = nint(ds_Parent(i)/ds_Child(i))
860        indtab(i,1,1) = pttab_child(i) + (deb + 1) * coeffraf
861        indtab(i,1,2) = pttab_child(i) + (fin + 1) * coeffraf
862
863        indtab(i,2,1) = pttab_child(i) + nbtab_child(i)
864     &    - (fin + 1) *  coeffraf
865        indtab(i,2,2) = pttab_child(i) + nbtab_child(i)
866     &    - (deb + 1) *  coeffraf
867
868        IF (posvartab_child(i) == 1) THEN
869          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
870            indtab(i,:,1) = indtab(i,:,1) - (coeffraf - 1)
871            indtab(i,:,2) = indtab(i,:,2) + (coeffraf - 1)       
872          ELSE IF (TypeUpdate(i) .NE. Agrif_Update_Copy) THEN
873            indtab(i,:,1) = indtab(i,:,1) - coeffraf / 2
874            indtab(i,:,2) = indtab(i,:,2) + coeffraf / 2
875          ENDIF
876        ELSE
877          indtab(i,1,1) = indtab(i,1,1) - coeffraf
878          indtab(i,1,2) = indtab(i,1,2) - 1
879          indtab(i,2,2) = indtab(i,2,2) + coeffraf - 1
880          IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
881            indtab(i,1,1) = indtab(i,1,1) - 1
882            indtab(i,1,2) = indtab(i,1,2) + 1
883            indtab(i,2,1) = indtab(i,2,1) - 1
884            indtab(i,2,2) = indtab(i,2,2) + 1
885          ENDIF         
886        ENDIF
887      ENDDO
888
889#if !defined AGRIF_MPI     
890        Call Agrif_nbdim_Get_bound_dimension(child % var,lubglob(:,1),
891     &               lubglob(:,2),nbdim)
892
893C
894#else
895C     
896        Call Agrif_nbdim_Get_bound_dimension(child % var,lb,ub,nbdim)
897      DO i = 1,nbdim
898C
899        Call Agrif_Invloc(lb(i),Agrif_Procrank,i,iminmaxg(i,1))
900        Call Agrif_Invloc(ub(i),Agrif_Procrank,i,iminmaxg(i,2))
901C
902      ENDDO
903C
904      iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2)
905     
906      CALL MPI_ALLREDUCE(iminmaxg,lubglob,2*nbdim,MPI_INTEGER,MPI_MIN,
907     &                     MPI_COMM_WORLD,code) 
908     
909      lubglob(1:nbdim,2) = - lubglob(1:nbdim,2)     
910C
911#endif
912C     
913      indtruetab(1:nbdim,1,1) = max(indtab(1:nbdim,1,1),
914     &     lubglob(1:nbdim,1))
915      indtruetab(1:nbdim,1,2) = max(indtab(1:nbdim,1,2),
916     &     lubglob(1:nbdim,1))
917      indtruetab(1:nbdim,2,1) = min(indtab(1:nbdim,2,1),
918     &     lubglob(1:nbdim,2))
919      indtruetab(1:nbdim,2,2) = min(indtab(1:nbdim,2,2),
920     &     lubglob(1:nbdim,2))
921                       
922C 
923C
924      do nb = 1,nbdim
925C
926        do ndir = 1,2
927C
928          if (loctab_child(nb) /= -3) then
929C           
930              do n = 1,2
931C
932                ptres(nb,n,ndir,nb) = indtruetab(nb,ndir,n)
933C
934              enddo             
935C
936              do i = 1,nbdim
937C     
938                if (i .NE. nb) then     
939C
940                    if (loctab_child(i) == -3) then
941C
942                        ptres(i,1,ndir,nb) = pttab_child(i)
943C
944                      else
945C
946                        ptres(i,1,ndir,nb) = indtruetab(i,1,1)
947C
948                    endif
949C
950                    if (loctab_child(i) == -3) then
951C
952                        if (posvartab_child(i) == 1) then
953C
954                            ptres(i,2,ndir,nb) = pttab_child(i) 
955     &                                + nbtab_child(i)
956C
957                          else
958C
959                            ptres(i,2,ndir,nb) = pttab_child(i) 
960     &                             + nbtab_child(i) - 1
961C
962                        endif                             
963C
964                      else
965C
966                        ptres(i,2,ndir,nb) = indtruetab(i,2,2)
967C
968                    endif                       
969C     
970                endif
971C     
972              enddo
973     
974C
975           
976        endif
977     
978        enddo
979       enddo
980C
981
982C
983
984      do nb = 1,nbdim
985C
986        do ndir = 1,2               
987C
988          if (loctab_child(nb) /= -3) then
989C
990           IF (present(procname)) THEN
991              Call Agrif_UpdatenD             
992     &             (TypeUpdate,parent,child,
993     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
994     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
995     &              s_Child(1:nbdim),s_Parent(1:nbdim),
996     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
997     &              posvartab_Child,loctab_Child,
998     &              nbdim,procname,nb,ndir)
999           ELSE
1000              Call Agrif_UpdatenD             
1001     &             (TypeUpdate,parent,child,
1002     &              ptres(1:nbdim,1,ndir,nb),ptres(1:nbdim,2,ndir,nb),
1003     &              pttab_child(1:nbdim),pttab_Parent(1:nbdim),
1004     &              s_Child(1:nbdim),s_Parent(1:nbdim),
1005     &              ds_Child(1:nbdim),ds_Parent(1:nbdim),
1006     &              posvartab_Child,loctab_Child,
1007     &              nbdim)           
1008           ENDIF
1009C
1010          endif
1011         
1012C
1013        enddo       
1014C
1015      enddo
1016C
1017C     
1018C 
1019      End Subroutine Agrif_UpdateBcnd
1020C
1021C     ************************************************************************** 
1022CCC   Subroutine Agrif_UpdatenD 
1023C     ************************************************************************** 
1024C 
1025      Subroutine Agrif_UpdatenD(TypeUpdate,parent,child,
1026     &                          pttab,petab,
1027     &                          pttab_Child,pttab_Parent,
1028     &                          s_Child,s_Parent,
1029     &                          ds_Child,ds_Parent,
1030     &                          posvartab_Child,loctab_Child,
1031     &                          nbdim,procname,nb,ndir) 
1032C
1033C     Description:
1034C     Subroutine to update a 2D grid variable on the parent grid of 
1035C        the current grid. 
1036C
1037C     Declarations:
1038C
1039     
1040C
1041#ifdef AGRIF_MPI
1042C
1043#include "mpif.h"
1044C
1045#endif
1046C
1047C     Arguments
1048      INTEGER                    :: nbdim
1049      INTEGER, DIMENSION(6) :: TypeUpdate              ! TYPE of update
1050                                                       !  (copy or average)
1051      TYPE(AGRIF_PVARIABLE)      :: parent             ! Variable of the parent
1052                                                       !   grid   
1053      TYPE(AGRIF_PVARIABLE)      :: child              ! Variable of the child
1054                                                       !   grid
1055      INTEGER,DIMENSION(nbdim)   :: pttab              ! Index of the first
1056                                                       !   point inside the
1057                                                       !   domain
1058      INTEGER,DIMENSION(nbdim)   :: petab              ! Index of the first
1059                                                       !   point inside the
1060                                                       !   domain
1061      INTEGER,DIMENSION(nbdim)   :: pttab_Child        ! Index of the first
1062                                                       !   point inside the
1063                                                       !   domain for the child
1064                                                       !   grid variable
1065      INTEGER,DIMENSION(nbdim)   :: pttab_Parent       ! Index of the first
1066                                                       !   point inside the
1067                                                       !   domain for the parent
1068                                                       !   grid variable
1069      REAL,DIMENSION(nbdim)      :: s_Child,s_Parent   ! Positions of the parent
1070                                                       !   and child grids
1071      REAL,DIMENSION(nbdim)      :: ds_Child,ds_Parent ! Space steps of the
1072                                                       !   parent and child
1073                                                       !   grids
1074      External :: procname
1075      Optional ::  procname
1076      Integer :: nb,ndir
1077      Optional :: nb,ndir
1078     
1079C
1080C     Local pointers
1081      TYPE(AGRIF_PVARIABLE), SAVE      :: tempP      ! Temporary parent grid variable
1082      TYPE(AGRIF_PVARIABLE), SAVE      :: tempC      ! Temporary child grid variable
1083C
1084C     Local scalars
1085      INTEGER,DIMENSION(nbdim)    :: pttruetab,cetruetab
1086      INTEGER,DIMENSION(nbdim)    :: posvartab_Child,loctab_Child
1087      INTEGER,DIMENSION(nbdim)    :: indmin,indmax
1088      INTEGER,DIMENSION(nbdim)    :: indminglob,indmaxglob
1089      REAL   ,DIMENSION(nbdim)    :: s_Child_temp,s_Parent_temp
1090cccccccc      LOGICAL,DIMENSION(nbdim)    :: noraftab
1091      INTEGER,DIMENSION(nbdim)    :: lowerbound,upperbound
1092      LOGICAL :: memberin, member
1093      INTEGER,DIMENSION(nbdim)    :: pttruetabwhole,cetruetabwhole
1094      INTEGER,DIMENSION(nbdim,2,2) :: childarray
1095      INTEGER,DIMENSION(nbdim,2,2) :: parentarray
1096      TYPE(AGRIF_PVARIABLE), SAVE      :: tempCextend,tempPextend ! Temporary child
1097      INTEGER :: nbin, ndirin
1098C
1099#ifdef AGRIF_MPI
1100C
1101      INTEGER,DIMENSION(nbdim)    :: indminglob2,indmaxglob2
1102      INTEGER                              :: code
1103      INTEGER                              :: i,j,k
1104      INTEGER,DIMENSION(nbdim,4)           :: tab3
1105      INTEGER,DIMENSION(nbdim,4,0:Agrif_Nbprocs-1) :: tab4
1106      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
1107      LOGICAL :: find_list_update
1108      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
1109      LOGICAL, DIMENSION(1) :: memberin1     
1110C
1111#endif
1112C
1113 
1114C
1115C     local lbound and ubound of the child array
1116
1117      Call Agrif_nbdim_Get_bound_dimension(child%var,
1118     &                              lowerbound,upperbound,nbdim)
1119
1120C here pttab and petab corresponds to the (global) indices of the points needed
1121C in the update
1122C pttruetab and cetruetab contains only indices that are present
1123C on the local processor
1124
1125      Call Agrif_Childbounds(nbdim,
1126     &                       lowerbound,upperbound,
1127     &                       pttab,petab,
1128     &                       pttruetab,cetruetab,memberin)
1129
1130       Call Agrif_Prtbounds(nbdim,indminglob,indmaxglob,s_Parent_temp,
1131     &                     s_Child_temp,s_Child,ds_Child,
1132     &                     s_Parent,ds_Parent,
1133     &                     pttab,petab,pttab_Child,
1134     &                     pttab_Parent,
1135     &                     posvartab_Child,TypeUpdate,loctab_Child
1136#ifdef AGRIF_MPI
1137     &                 ,pttruetabwhole,cetruetabwhole
1138#endif
1139     &     )
1140
1141#ifdef AGRIF_MPI
1142      IF (memberin) THEN
1143       Call Agrif_GlobtoLocInd2(childarray,
1144     &                     lowerbound,upperbound,
1145     &                     pttruetab,cetruetab,
1146     &                     nbdim,Agrif_Procrank,
1147     &                     member)
1148
1149      ENDIF
1150
1151
1152         Call Agrif_Prtbounds(nbdim,indmin,indmax,s_Parent_temp,
1153     &                     s_Child_temp,s_Child,ds_Child,
1154     &                     s_Parent,ds_Parent,
1155     &                     pttruetab,cetruetab,pttab_Child,
1156     &                     pttab_Parent,
1157     &                     posvartab_Child,TypeUpdate,loctab_Child
1158     &                 ,pttruetabwhole,cetruetabwhole
1159     &     )
1160
1161#else
1162       indmin = indminglob
1163       indmax = indmaxglob
1164       pttruetabwhole = pttruetab
1165       cetruetabwhole = cetruetab
1166       childarray(:,1,2) = pttruetab
1167       childarray(:,2,2) = cetruetab
1168#endif
1169
1170       IF (present(procname)) THEN
1171       IF (.Not.present(nb)) THEN
1172       nbin=0
1173       ndirin=0
1174       ELSE
1175       nbin = nb
1176       ndirin = ndir
1177       ENDIF
1178       ENDIF
1179       
1180      IF (memberin) THEN
1181      IF (.not.associated(tempC%var)) allocate(tempC%var)
1182
1183C
1184      Call Agrif_nbdim_allocation(tempC%var,
1185     &                 pttruetab,cetruetab,nbdim)
1186
1187      Call Agrif_nbdim_Full_VarEQreal(tempC%var,0.,nbdim)
1188
1189
1190
1191      IF (present(procname)) THEN
1192        SELECT CASE (nbdim)
1193        CASE(1)
1194          CALL procname(tempC%var%array1,
1195     &                          childarray(1,1,2),childarray(1,2,2),
1196     &                                   .TRUE.,nbin,ndirin)
1197        CASE(2)
1198          CALL procname(tempC%var%array2,
1199     &                          childarray(1,1,2),childarray(1,2,2),
1200     &                          childarray(2,1,2),childarray(2,2,2),
1201     &                                   .TRUE.,nbin,ndirin)
1202        CASE(3)
1203          CALL procname(tempC%var%array3,
1204     &                          childarray(1,1,2),childarray(1,2,2),
1205     &                          childarray(2,1,2),childarray(2,2,2),
1206     &                          childarray(3,1,2),childarray(3,2,2),
1207     &                                   .TRUE.,nbin,ndirin)
1208        CASE(4)
1209          CALL procname(tempC%var%array4,
1210     &                          childarray(1,1,2),childarray(1,2,2),
1211     &                          childarray(2,1,2),childarray(2,2,2),
1212     &                          childarray(3,1,2),childarray(3,2,2),
1213     &                          childarray(4,1,2),childarray(4,2,2),
1214     &                                   .TRUE.,nbin,ndirin)
1215        CASE(5)
1216          CALL procname(tempC%var%array5,
1217     &                          childarray(1,1,2),childarray(1,2,2),
1218     &                          childarray(2,1,2),childarray(2,2,2),
1219     &                          childarray(3,1,2),childarray(3,2,2),
1220     &                          childarray(4,1,2),childarray(4,2,2),
1221     &                          childarray(5,1,2),childarray(5,2,2),
1222     &                                   .TRUE.,nbin,ndirin)
1223        CASE(6)
1224          CALL procname(tempC%var%array6,
1225     &                          childarray(1,1,2),childarray(1,2,2),
1226     &                          childarray(2,1,2),childarray(2,2,2),
1227     &                          childarray(3,1,2),childarray(3,2,2),
1228     &                          childarray(4,1,2),childarray(4,2,2),
1229     &                          childarray(5,1,2),childarray(5,2,2),
1230     &                          childarray(6,1,2),childarray(6,2,2),
1231     &                                   .TRUE.,nbin,ndirin)
1232        END SELECT
1233      ELSE
1234      Call Agrif_nbdim_VarEQvar(tempC%var,pttruetab,cetruetab,
1235     &          child%var,childarray(:,1,2),childarray(:,2,2),
1236     &                          nbdim)
1237      ENDIF
1238
1239      ENDIF
1240
1241
1242
1243C
1244C
1245#ifdef AGRIF_MPI
1246C
1247C     tab2 contains the necessary limits of the parent grid for each processor
1248
1249      IF (Associated(child%var%list_update)) THEN
1250      Call Agrif_Find_list_update(child%var%list_update,pttab,petab,
1251     &                          pttab_Child,pttab_Parent,nbdim,
1252     &       find_list_update,tab4t,tab5t,memberinall,memberinall2)
1253      ELSE
1254      find_list_update = .FALSE.
1255      ENDIF
1256     
1257      if (.not.find_list_update) then     
1258      tab3(:,1) = pttruetab(:)
1259      tab3(:,2) = cetruetab(:)
1260      tab3(:,3) = pttruetabwhole(:)
1261      tab3(:,4) = cetruetabwhole(:)
1262C
1263C
1264      Call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,
1265     &                   MPI_INTEGER,MPI_COMM_WORLD,code)
1266
1267      IF (.not.associated(tempCextend%var)) Allocate(tempCextend%var)
1268      DO k=0,Agrif_Nbprocs-1
1269       do j=1,4
1270         do i=1,nbdim
1271         tab4t(i,k,j) = tab4(i,j,k)
1272         enddo
1273       enddo
1274      enddo
1275     
1276      memberin1(1) = memberin
1277      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall,
1278     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
1279           
1280      endif
1281     
1282      Call Get_External_Data(tempC,tempCextend,tab4t(:,:,1),
1283     &            tab4t(:,:,2),
1284     &            tab4t(:,:,3),tab4t(:,:,4),nbdim,memberin,memberin,
1285     &            memberinall)
1286
1287#else
1288      tempCextend%var => tempC%var
1289#endif
1290
1291C
1292C
1293C     Update of the parent grid (tempP) from the child grid (tempC)
1294
1295
1296      IF (memberin) THEN
1297
1298      IF (.not.associated(tempP%var)) allocate(tempP%var)
1299      Call Agrif_nbdim_allocation(tempP%var,
1300     &                 indmin,indmax,nbdim)
1301
1302      if ( nbdim .EQ. 1 ) then
1303         Call Agrif_Update_1D_recursive(TypeUpdate,
1304     &           tempP%var%array1,tempCextend%var%array1,
1305     &           indmin,indmax,
1306     &           pttruetabwhole,cetruetabwhole,
1307     &           s_Child_temp,s_Parent_temp,
1308     &           ds_Child,ds_Parent,nbdim)
1309      endif
1310      if ( nbdim .EQ. 2 ) then
1311         Call Agrif_Update_2D_recursive(TypeUpdate,
1312     &           tempP%var%array2,tempCextend%var%array2,
1313     &           indmin,indmax,
1314     &           pttruetabwhole,cetruetabwhole,
1315     &           s_Child_temp,s_Parent_temp,
1316     &           ds_Child,ds_Parent,nbdim)
1317      endif
1318
1319      if ( nbdim .EQ. 3 ) then
1320         Call Agrif_Update_3D_recursive(TypeUpdate,
1321     &           tempP%var%array3,tempCextend%var%array3,
1322     &           indmin,indmax,
1323     &           pttruetabwhole,cetruetabwhole,
1324     &           s_Child_temp,s_Parent_temp,
1325     &           ds_Child,ds_Parent,nbdim)
1326      endif
1327      if ( nbdim .EQ. 4 ) then
1328         Call Agrif_Update_4D_recursive(TypeUpdate,
1329     &           tempP%var%array4,tempCextend%var%array4,
1330     &           indmin,indmax,
1331     &           pttruetabwhole,cetruetabwhole,
1332     &           s_Child_temp,s_Parent_temp,
1333     &           ds_Child,ds_Parent,nbdim)
1334      endif
1335      if ( nbdim .EQ. 5 ) then
1336         Call Agrif_Update_5D_recursive(TypeUpdate,
1337     &           tempP%var%array5,tempCextend%var%array5,
1338     &           indmin,indmax,
1339     &           pttruetabwhole,cetruetabwhole,
1340     &           s_Child_temp,s_Parent_temp,
1341     &           ds_Child,ds_Parent,nbdim)
1342      endif
1343      if ( nbdim .EQ. 6 ) then
1344         Call Agrif_Update_6D_recursive(TypeUpdate,
1345     &           tempP%var%array6,tempCextend%var%array6,
1346     &           indmin,indmax,
1347     &           pttruetabwhole,cetruetabwhole,
1348     &           s_Child_temp,s_Parent_temp,
1349     &           ds_Child,ds_Parent,nbdim)
1350      endif
1351
1352      Call Agrif_nbdim_deallocation(tempCextend%var,nbdim)
1353C      Deallocate(tempCextend%var)
1354
1355      ENDIF
1356
1357#ifdef AGRIF_MPI
1358      Call Agrif_nbdim_Get_bound_dimension(parent%var,
1359     &                              lowerbound,upperbound,nbdim)
1360
1361      Call Agrif_ChildGrid_to_ParentGrid()
1362C
1363      Call Agrif_Childbounds(nbdim,
1364     &                       lowerbound,upperbound,
1365     &                       indminglob,indmaxglob,
1366     &                       indminglob2,indmaxglob2,member)
1367C
1368      IF (member) THEN
1369      Call Agrif_GlobtoLocInd2(parentarray,
1370     &                     lowerbound,upperbound,
1371     &                     indminglob2,indmaxglob2,
1372     &                     nbdim,Agrif_Procrank,
1373     &                     member)
1374      ENDIF
1375
1376      Call Agrif_ParentGrid_to_ChildGrid()
1377
1378      if (.not.find_list_update) then
1379      tab3(:,1) = indmin(:)
1380      tab3(:,2) = indmax(:)
1381      tab3(:,3) = indminglob2(:)
1382      tab3(:,4) = indmaxglob2(:)
1383C
1384      Call MPI_ALLGATHER(tab3,4*nbdim,MPI_INTEGER,tab4,4*nbdim,
1385     &                   MPI_INTEGER,MPI_COMM_WORLD,code)
1386
1387      IF (.not.associated(tempPextend%var)) Allocate(tempPextend%var)
1388      DO k=0,Agrif_Nbprocs-1
1389       do j=1,4
1390         do i=1,nbdim
1391         tab5t(i,k,j) = tab4(i,j,k)
1392         enddo
1393       enddo
1394      enddo
1395 
1396      memberin1(1) = member
1397      CALL MPI_ALLGATHER(memberin1,1,MPI_LOGICAL,memberinall2,
1398     &                  1,MPI_LOGICAL,MPI_COMM_WORLD,code)
1399     
1400      Call Agrif_Addto_list_update(child%var%list_update,pttab,petab,
1401     &                          pttab_Child,pttab_Parent,nbdim
1402     &   ,tab4t,tab5t,memberinall,memberinall2) 
1403         
1404      endif
1405     
1406      Call Get_External_Data(tempP,tempPextend,tab5t(:,:,1),
1407     &            tab5t(:,:,2),
1408     &            tab5t(:,:,3),tab5t(:,:,4),nbdim,memberin,member,
1409     &            memberinall2)
1410
1411#else
1412      tempPextend%var => tempP%var
1413      parentarray(:,1,1) = indmin
1414      parentarray(:,2,1) = indmax
1415      parentarray(:,1,2) = indmin
1416      parentarray(:,2,2) = indmax
1417      member = .TRUE.
1418#endif
1419
1420C
1421C
1422C
1423C     Special values on the child grid
1424      if (Agrif_UseSpecialValueFineGrid) then
1425C
1426ccc         noraftab(1:nbdim) =
1427ccc     &    child % var % root_var % interptab(1:nbdim) .EQ. 'N'
1428C
1429#ifdef AGRIF_MPI
1430C
1431c          Allocate(childvalues% var)
1432C
1433c          Call Agrif_nbdim_allocation(childvalues%var,
1434c     &                      pttruetab,cetruetab,nbdim)
1435c          Call Agrif_nbdim_Full_VarEQvar(childvalues% var,
1436c     &                                tempC% var,
1437c     &                                nbdim)
1438c          Call Agrif_CheckMasknD(tempC,childvalues,
1439c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
1440c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
1441c     &                           noraftab(1:nbdim),nbdim)
1442c          Call Agrif_nbdim_deallocation(childvalues% var,nbdim)
1443c         Deallocate(childvalues % var)
1444C
1445#else
1446C
1447c          Call Agrif_nbdim_Get_bound_dimension(child%var,
1448c     &                              lowerbound,upperbound,nbdim)
1449c          Call Agrif_CheckMasknD(tempC,child,
1450c     &                           pttruetab(1:nbdim),cetruetab(1:nbdim),
1451c     &                           lowerbound,
1452c     &                           upperbound,
1453c     &                           noraftab(1:nbdim),nbdim)
1454C
1455#endif
1456C
1457      endif
1458
1459
1460C
1461C
1462C
1463C
1464C     Special values on the parent grid
1465      if (Agrif_UseSpecialValue) then
1466C
1467#ifdef AGRIF_MPI
1468C
1469c          Call GiveAgrif_SpecialValueToTab_mpi(parent%var,tempP%var,
1470c     &                 parentarray,
1471c     &                 indmin,indmax,
1472c     &                 Agrif_SpecialValue,nbdim)
1473C
1474C
1475#else
1476C
1477c          Call GiveAgrif_SpecialValueToTab(parent%var,tempP%var,
1478c     &                  indmin,indmax,
1479c     &                  Agrif_SpecialValue,nbdim)
1480C
1481#endif
1482C
1483C
1484      endif   
1485C
1486C
1487        IF (member) THEN
1488
1489          IF (present(procname)) THEN
1490            CALL Agrif_ChildGrid_to_ParentGrid()
1491            SELECT CASE(nbdim)
1492            CASE(1)
1493            CALL procname(
1494     &      tempPextend%var%array1(
1495     &                      parentarray(1,1,1):parentarray(1,2,1)),
1496     &                      parentarray(1,1,2),parentarray(1,2,2),
1497     &                                   .FALSE.,nbin,ndirin
1498     &                      )
1499            CASE(2)
1500            CALL procname(
1501     &      tempPextend%var%array2(
1502     &                      parentarray(1,1,1):parentarray(1,2,1),
1503     &                      parentarray(2,1,1):parentarray(2,2,1)),
1504     &                      parentarray(1,1,2),parentarray(1,2,2),
1505     &                      parentarray(2,1,2),parentarray(2,2,2),
1506     &                                   .FALSE.,nbin,ndirin
1507     &                      )
1508            CASE(3)
1509            CALL procname(
1510     &      tempPextend%var%array3(
1511     &                      parentarray(1,1,1):parentarray(1,2,1),
1512     &                      parentarray(2,1,1):parentarray(2,2,1),
1513     &                      parentarray(3,1,1):parentarray(3,2,1)),
1514     &                      parentarray(1,1,2),parentarray(1,2,2),
1515     &                      parentarray(2,1,2),parentarray(2,2,2),
1516     &                      parentarray(3,1,2),parentarray(3,2,2),
1517     &                                   .FALSE.,nbin,ndirin
1518     &                      )
1519            CASE(4)
1520            CALL procname(
1521     &      tempPextend%var%array4(
1522     &                      parentarray(1,1,1):parentarray(1,2,1),
1523     &                      parentarray(2,1,1):parentarray(2,2,1),
1524     &                      parentarray(3,1,1):parentarray(3,2,1),
1525     &                      parentarray(4,1,1):parentarray(4,2,1)),
1526     &                      parentarray(1,1,2),parentarray(1,2,2),
1527     &                      parentarray(2,1,2),parentarray(2,2,2),
1528     &                      parentarray(3,1,2),parentarray(3,2,2),
1529     &                      parentarray(4,1,2),parentarray(4,2,2),
1530     &                                   .FALSE.,nbin,ndirin
1531     &                      )
1532            CASE(5)
1533            CALL procname(
1534     &      tempPextend%var%array5(
1535     &                      parentarray(1,1,1):parentarray(1,2,1),
1536     &                      parentarray(2,1,1):parentarray(2,2,1),
1537     &                      parentarray(3,1,1):parentarray(3,2,1),
1538     &                      parentarray(4,1,1):parentarray(4,2,1),
1539     &                      parentarray(5,1,1):parentarray(5,2,1)),
1540     &                      parentarray(1,1,2),parentarray(1,2,2),
1541     &                      parentarray(2,1,2),parentarray(2,2,2),
1542     &                      parentarray(3,1,2),parentarray(3,2,2),
1543     &                      parentarray(4,1,2),parentarray(4,2,2),
1544     &                      parentarray(5,1,2),parentarray(5,2,2),
1545     &                                   .FALSE.,nbin,ndirin
1546     &                      )
1547            CASE(6)
1548            CALL procname(
1549     &      tempPextend%var%array6(
1550     &                      parentarray(1,1,1):parentarray(1,2,1),
1551     &                      parentarray(2,1,1):parentarray(2,2,1),
1552     &                      parentarray(3,1,1):parentarray(3,2,1),
1553     &                      parentarray(4,1,1):parentarray(4,2,1),
1554     &                      parentarray(5,1,1):parentarray(5,2,1),
1555     &                      parentarray(6,1,1):parentarray(6,2,1)),
1556     &                      parentarray(1,1,2),parentarray(1,2,2),
1557     &                      parentarray(2,1,2),parentarray(2,2,2),
1558     &                      parentarray(3,1,2),parentarray(3,2,2),
1559     &                      parentarray(4,1,2),parentarray(4,2,2),
1560     &                      parentarray(5,1,2),parentarray(5,2,2),
1561     &                      parentarray(6,1,2),parentarray(6,2,2),
1562     &                                   .FALSE.,nbin,ndirin
1563     &                      )
1564            END SELECT
1565            CALL Agrif_ParentGrid_to_ChildGrid()
1566          ELSE
1567            SELECT CASE(nbdim)
1568            CASE(1)
1569            parent%var%array1(parentarray(1,1,2):parentarray(1,2,2)) =
1570     &      tempPextend%var%array1(
1571     &                      parentarray(1,1,1):parentarray(1,2,1))
1572            CASE(2)
1573            parent%var%array2(parentarray(1,1,2):parentarray(1,2,2),
1574     &                      parentarray(2,1,2):parentarray(2,2,2)) =
1575     &      tempPextend%var%array2(
1576     &                      parentarray(1,1,1):parentarray(1,2,1),
1577     &                      parentarray(2,1,1):parentarray(2,2,1))
1578            CASE(3)
1579            parent%var%array3(parentarray(1,1,2):parentarray(1,2,2),
1580     &                      parentarray(2,1,2):parentarray(2,2,2),
1581     &                      parentarray(3,1,2):parentarray(3,2,2)) =
1582     &      tempPextend%var%array3(
1583     &                      parentarray(1,1,1):parentarray(1,2,1),
1584     &                      parentarray(2,1,1):parentarray(2,2,1),
1585     &                      parentarray(3,1,1):parentarray(3,2,1))
1586            CASE(4)
1587            parent%var%array4(parentarray(1,1,2):parentarray(1,2,2),
1588     &                      parentarray(2,1,2):parentarray(2,2,2),
1589     &                      parentarray(3,1,2):parentarray(3,2,2),
1590     &                      parentarray(4,1,2):parentarray(4,2,2)) =
1591     &      tempPextend%var%array4(
1592     &                      parentarray(1,1,1):parentarray(1,2,1),
1593     &                      parentarray(2,1,1):parentarray(2,2,1),
1594     &                      parentarray(3,1,1):parentarray(3,2,1),
1595     &                      parentarray(4,1,1):parentarray(4,2,1))
1596            CASE(5)
1597            parent%var%array5(parentarray(1,1,2):parentarray(1,2,2),
1598     &                      parentarray(2,1,2):parentarray(2,2,2),
1599     &                      parentarray(3,1,2):parentarray(3,2,2),
1600     &                      parentarray(4,1,2):parentarray(4,2,2),
1601     &                      parentarray(5,1,2):parentarray(5,2,2)) =
1602     &      tempPextend%var%array5(
1603     &                      parentarray(1,1,1):parentarray(1,2,1),
1604     &                      parentarray(2,1,1):parentarray(2,2,1),
1605     &                      parentarray(3,1,1):parentarray(3,2,1),
1606     &                      parentarray(4,1,1):parentarray(4,2,1),
1607     &                      parentarray(5,1,1):parentarray(5,2,1))
1608            CASE(6)
1609            parent%var%array6(parentarray(1,1,2):parentarray(1,2,2),
1610     &                      parentarray(2,1,2):parentarray(2,2,2),
1611     &                      parentarray(3,1,2):parentarray(3,2,2),
1612     &                      parentarray(4,1,2):parentarray(4,2,2),
1613     &                      parentarray(5,1,2):parentarray(5,2,2),
1614     &                      parentarray(6,1,2):parentarray(6,2,2)) =
1615     &      tempPextend%var%array6(
1616     &                      parentarray(1,1,1):parentarray(1,2,1),
1617     &                      parentarray(2,1,1):parentarray(2,2,1),
1618     &                      parentarray(3,1,1):parentarray(3,2,1),
1619     &                      parentarray(4,1,1):parentarray(4,2,1),
1620     &                      parentarray(5,1,1):parentarray(5,2,1),
1621     &                      parentarray(6,1,1):parentarray(6,2,1))
1622            END SELECT
1623          ENDIF
1624
1625        Call Agrif_nbdim_deallocation(tempPextend%var,nbdim)
1626       ENDIF
1627C
1628C
1629C     Deallocations
1630
1631      IF (memberin) THEN
1632#ifdef AGRIF_MPI
1633      Call Agrif_nbdim_deallocation(tempP%var,nbdim)
1634      Call Agrif_nbdim_deallocation(tempC%var,nbdim)
1635!      Deallocate(tempC % var)
1636#endif
1637!      Deallocate(tempP % var)
1638      ENDIF
1639#ifdef AGRIF_MPI
1640!      Deallocate(tempPextend%var)
1641!      IF (.Not.memberin) Deallocate(tempCextend%var)
1642#endif
1643
1644C
1645C
1646      End Subroutine Agrif_UpdatenD
1647C
1648C
1649C     **************************************************************************
1650CCC   Subroutine Agrif_Prtbounds
1651C     **************************************************************************
1652C
1653      Subroutine Agrif_Prtbounds(nbdim,indmin,indmax,s_Parent_temp,
1654     &                              s_Child_temp,s_Child,ds_Child,
1655     &                              s_Parent,ds_Parent,
1656     &                              pttruetab,cetruetab,pttab_Child,
1657     &                              pttab_Parent,
1658     &                              posvartab_child,TypeUpdate,
1659     &                              loctab_Child
1660#ifdef AGRIF_MPI
1661     &                 ,pttruetabwhole,cetruetabwhole
1662#endif
1663     &                 )
1664C
1665CCC   Description:
1666CCC   Subroutine calculating the bounds of the parent grid to be updated
1667CCC   by the child grid     
1668C
1669C
1670C     Declarations:
1671C
1672     
1673C
1674#ifdef AGRIF_MPI
1675cccccccccccccccccccccccccc#include "mpif.h"
1676#endif
1677C
1678C     Arguments
1679      INTEGER :: nbdim
1680      INTEGER,DIMENSION(nbdim) :: indmin,indmax
1681      REAL,DIMENSION(nbdim) :: s_Parent_temp,s_child_temp
1682      REAL,DIMENSION(nbdim) :: s_Child,ds_child
1683      REAL,DIMENSION(nbdim) :: s_Parent,ds_Parent
1684      INTEGER,DIMENSION(nbdim) :: pttruetab,cetruetab
1685      INTEGER,DIMENSION(nbdim) :: posvartab_child,TypeUpdate
1686      INTEGER,DIMENSION(nbdim) :: loctab_Child
1687      INTEGER,DIMENSION(nbdim) :: pttab_Child,pttab_Parent
1688C
1689C     Local variables
1690      INTEGER :: i
1691      REAL,DIMENSION(nbdim) :: dim_newmin,dim_newmax     
1692#ifdef AGRIF_MPI
1693      INTEGER,DIMENSION(nbdim)    :: pttruetabwhole,cetruetabwhole
1694      REAL :: positionmin,positionmax
1695      INTEGER :: imin,imax
1696#endif
1697C
1698C
1699      do i = 1,nbdim
1700C
1701        dim_newmin(i) = s_Child(i) + (pttruetab(i) -
1702     &                                pttab_Child(i)) * ds_Child(i)
1703C
1704        dim_newmax(i) = s_Child(i) + (cetruetab(i) - 
1705     &                                pttab_Child(i)) * ds_Child(i)
1706C     
1707        indmin(i) = pttab_Parent(i) +
1708     &        agrif_ceiling((dim_newmin(i)-s_Parent(i))/ds_Parent(i))
1709C
1710        indmax(i) = pttab_Parent(i) +
1711     &        agrif_int((dim_newmax(i)-s_Parent(i))/ds_Parent(i))
1712C
1713#ifdef AGRIF_MPI
1714        positionmin = s_Parent(i) + (indmin(i)-
1715     &                          pttab_Parent(i))*ds_Parent(i)
1716        IF (loctab_Child(i) .NE. -3) THEN
1717        IF (posvartab_child(i) == 1) THEN
1718          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
1719          positionmin = positionmin - ds_Parent(i)/2.
1720          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
1721          positionmin = positionmin - (ds_Parent(i)-ds_Child(i))
1722          ENDIF
1723        ELSE
1724        positionmin = positionmin - ds_Parent(i)/2.
1725        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
1726          positionmin = positionmin - ds_Child(i)
1727        ENDIF
1728        ENDIF
1729        ENDIF
1730        imin = pttab_Child(i) +
1731     &        agrif_ceiling((positionmin-s_Child(i))/ds_Child(i))
1732
1733       positionmin = s_Child(i) + (imin -
1734     &                                pttab_Child(i)) * ds_Child(i)
1735
1736        pttruetabwhole(i) = imin
1737
1738        positionmax = s_Parent(i) + (indmax(i)-
1739     &                          pttab_Parent(i))*ds_Parent(i)
1740        IF (loctab_Child(i) .NE. -3) THEN
1741        IF (posvartab_child(i) == 1) THEN
1742          IF (TypeUpdate(i) .EQ. Agrif_Update_Average) THEN
1743        positionmax = positionmax  + ds_Parent(i)/2.
1744          ELSE IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
1745          positionmax = positionmax  + (ds_Parent(i)-ds_Child(i))
1746          ENDIF
1747        ELSE
1748        positionmax = positionmax  + ds_Parent(i)/2.
1749        IF (TypeUpdate(i) .EQ. Agrif_Update_Full_Weighting) THEN
1750          positionmax = positionmax + ds_Child(i)
1751        ENDIF       
1752        ENDIF
1753        ENDIF
1754        imax = pttab_Child(i) +
1755     &        agrif_int((positionmax-s_Child(i))/ds_Child(i))
1756
1757        positionmax = s_Child(i) + (imax -
1758     &                                pttab_Child(i)) * ds_Child(i)
1759
1760        cetruetabwhole(i) = imax
1761
1762#endif
1763C
1764        s_Parent_temp(i) = s_Parent(i) + 
1765     &                     (indmin(i) - pttab_Parent(i)) * 
1766     &                      ds_Parent(i) 
1767C     
1768        s_Child_temp(i) = dim_newmin(i)
1769
1770#ifdef AGRIF_MPI
1771        s_Child_temp(i) = positionmin
1772#endif
1773C
1774      enddo
1775C
1776      Return
1777C
1778C
1779      End Subroutine Agrif_Prtbounds
1780C
1781C
1782C
1783C
1784
1785C
1786C
1787C
1788C     ************************************************************************** 
1789CCC   Subroutine Agrif_Update_2D_Recursive 
1790C     **************************************************************************
1791C
1792      Subroutine Agrif_Update_2D_recursive(TypeUpdate,tempP,tempC,
1793     &                                     indmin,indmax,
1794     &                                     pttab_child,petab_child,
1795     &                                     s_child,s_parent,
1796     &                                     ds_child,ds_parent,nbdim)
1797C
1798CCC   Description:
1799CCC   Subroutine to update a 2D grid variable on the parent grid. 
1800CCC   It calls Agrif_Update_1D_Recursive and Agrif_UpdateBase.   
1801C
1802CC    Method:
1803C
1804C     Declarations:
1805C
1806     
1807C     
1808      INTEGER                   :: nbdim
1809      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
1810      INTEGER, DIMENSION(nbdim) :: indmin,indmax
1811      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
1812      REAL, DIMENSION(nbdim)    :: s_child,s_parent
1813      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
1814      REAL, DIMENSION(indmin(1):indmax(1),
1815     &                indmin(2):indmax(2))           :: tempP
1816C      REAL, DIMENSION(pttab_child(1):petab_child(1),
1817C     &                pttab_child(2):petab_child(2)) :: tempC
1818     
1819      REAL, DIMENSION(:,:) :: tempC     
1820C
1821C     Local variables     
1822      REAL, DIMENSION(indmin(1):indmax(1),
1823     &                 pttab_child(2):petab_child(2)) :: tabtemp
1824      INTEGER :: i,j
1825      INTEGER :: coeffraf,locind_child_left
1826C
1827      do j = pttab_child(nbdim),petab_child(nbdim)
1828C
1829        Call Agrif_Update_1D_recursive(TypeUpdate(1:nbdim-1),   
1830     &         tabtemp(:,j),
1831     &         tempC(:,j-pttab_child(nbdim)+1),
1832     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
1833     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
1834     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
1835     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
1836C
1837      enddo
1838     
1839      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
1840     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
1841C
1842      do i = indmin(1),indmax(1)
1843C
1844        Call Agrif_UpdateBase(TypeUpdate(2),
1845     &           tempP(i,:),
1846     &          tabtemp(i,:),
1847     &           indmin(nbdim),indmax(nbdim),
1848     &           pttab_child(nbdim),petab_child(nbdim),
1849     &           s_parent(nbdim),s_child(nbdim),
1850     &           ds_parent(nbdim),ds_child(nbdim),
1851     &                  coeffraf,locind_child_left)
1852C       
1853      enddo
1854C
1855      Return
1856C
1857C
1858      End Subroutine Agrif_Update_2D_recursive
1859C
1860C
1861C
1862C     ************************************************************************** 
1863CCC   Subroutine Agrif_Update_3D_Recursive 
1864C     **************************************************************************
1865C
1866      Subroutine Agrif_Update_3D_recursive(TypeUpdate,tempP,tempC,
1867     &                                     indmin,indmax,   
1868     &                                     pttab_child,petab_child,
1869     &                                     s_child,s_parent,
1870     &                                     ds_child,ds_parent,nbdim)
1871C
1872CCC   Description:
1873CCC   Subroutine to update a 3D grid variable on the parent grid. 
1874CCC   It calls Agrif_Update_2D_Recursive and Agrif_UpdateBase.   
1875C
1876CC    Method:
1877C
1878C     Declarations:
1879C
1880     
1881C     
1882      INTEGER                   :: nbdim
1883      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
1884      INTEGER, DIMENSION(nbdim) :: indmin,indmax
1885      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
1886      REAL, DIMENSION(nbdim)    :: s_child,s_parent
1887      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
1888      REAL, DIMENSION(indmin(1):indmax(1),
1889     &                indmin(2):indmax(2),
1890     &                indmin(3):indmax(3))           :: tempP
1891      REAL, DIMENSION(pttab_child(1):petab_child(1),
1892     &                pttab_child(2):petab_child(2),
1893     &                pttab_child(3):petab_child(3)) :: tempC
1894C
1895C     Local variables     
1896      REAL, DIMENSION(indmin(1):indmax(1),
1897     &                 indmin(2):indmax(2), 
1898     &                 pttab_child(3):petab_child(3)) :: tabtemp
1899      INTEGER :: i,j,k
1900      INTEGER :: coeffraf,locind_child_left
1901      INTEGER :: kdeb
1902C
1903C
1904      do k = pttab_child(nbdim),petab_child(nbdim)
1905C
1906        Call Agrif_Update_2D_recursive(TypeUpdate(1:nbdim-1),   
1907     &         tabtemp(:,:,k),
1908     &         tempC(:,:,k),
1909     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
1910     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
1911     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
1912     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
1913C
1914      enddo
1915C
1916      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
1917     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
1918     
1919      IF (coeffraf == 1) THEN
1920     
1921      kdeb = pttab_child(3)+locind_child_left-2
1922      do k=indmin(3),indmax(3)
1923      kdeb = kdeb + 1
1924      do j = indmin(2),indmax(2)
1925        do i = indmin(1),indmax(1)
1926        tempP(i,j,k) = tabtemp(i,j,kdeb)
1927      enddo
1928      enddo
1929      enddo
1930             
1931      ELSE
1932C
1933      do j = indmin(2),indmax(2)
1934C
1935        do i = indmin(1),indmax(1)
1936C
1937          Call Agrif_UpdateBase(TypeUpdate(3),
1938     &           tempP(i,j,:),
1939     &          tabtemp(i,j,:),
1940     &           indmin(nbdim),indmax(nbdim),
1941     &           pttab_child(nbdim),petab_child(nbdim),
1942     &           s_parent(nbdim),s_child(nbdim),
1943     &           ds_parent(nbdim),ds_child(nbdim),
1944     &                  coeffraf,locind_child_left)
1945C
1946        enddo 
1947C       
1948      enddo
1949      ENDIF
1950C
1951      Return
1952C
1953C
1954      End Subroutine Agrif_Update_3D_recursive
1955C
1956C
1957C
1958C     ************************************************************************** 
1959CCC   Subroutine Agrif_Update_4D_Recursive 
1960C     **************************************************************************
1961C
1962      Subroutine Agrif_Update_4D_recursive(TypeUpdate,tempP,tempC,
1963     &                                     indmin,indmax,   
1964     &                                     pttab_child,petab_child,
1965     &                                     s_child,s_parent,
1966     &                                     ds_child,ds_parent,nbdim)
1967C
1968CCC   Description:
1969CCC   Subroutine to update a 4D grid variable on the parent grid. 
1970CCC   It calls Agrif_Update_3D_Recursive and Agrif_UpdateBase.   
1971C
1972CC    Method:
1973C
1974C     Declarations:
1975C
1976     
1977C     
1978      INTEGER                   :: nbdim
1979      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
1980      INTEGER, DIMENSION(nbdim) :: indmin,indmax
1981      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
1982      REAL, DIMENSION(nbdim)    :: s_child,s_parent
1983      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
1984      REAL, DIMENSION(indmin(1):indmax(1),
1985     &                indmin(2):indmax(2),
1986     &                indmin(3):indmax(3),
1987     &                indmin(4):indmax(4))           :: tempP
1988      REAL, DIMENSION(pttab_child(1):petab_child(1),
1989     &                pttab_child(2):petab_child(2),
1990     &                pttab_child(3):petab_child(3),
1991     &                pttab_child(4):petab_child(4)) :: tempC
1992C
1993C     Local variables     
1994      REAL, DIMENSION(:,:,:,:), Allocatable :: tabtemp
1995      INTEGER :: i,j,k,l
1996      INTEGER :: coeffraf,locind_child_left
1997C
1998C
1999      Allocate(tabtemp(indmin(1):indmax(1),
2000     &                 indmin(2):indmax(2),
2001     &                 indmin(3):indmax(3), 
2002     &                 pttab_child(4):petab_child(4)))
2003C
2004      do l = pttab_child(nbdim),petab_child(nbdim)
2005C
2006        Call Agrif_Update_3D_recursive(TypeUpdate(1:nbdim-1),   
2007     &         tabtemp(indmin(nbdim-3):indmax(nbdim-3),
2008     &                 indmin(nbdim-2):indmax(nbdim-2),
2009     &                 indmin(nbdim-1):indmax(nbdim-1),l),
2010     &         tempC(pttab_child(nbdim-3):petab_child(nbdim-3),
2011     &               pttab_child(nbdim-2):petab_child(nbdim-2),
2012     &               pttab_child(nbdim-1):petab_child(nbdim-1),l),
2013     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
2014     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
2015     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
2016     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
2017C
2018      enddo
2019     
2020      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
2021     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
2022C
2023      do k = indmin(3),indmax(3)
2024C
2025        do j = indmin(2),indmax(2)
2026C
2027          do i = indmin(1),indmax(1)
2028C
2029            Call Agrif_UpdateBase(TypeUpdate(4),
2030     &           tempP(i,j,k,indmin(nbdim):indmax(nbdim)),
2031     &          tabtemp(i,j,k,pttab_child(nbdim):petab_child(nbdim)),
2032     &           indmin(nbdim),indmax(nbdim),
2033     &           pttab_child(nbdim),petab_child(nbdim),
2034     &           s_parent(nbdim),s_child(nbdim),
2035     &           ds_parent(nbdim),ds_child(nbdim),
2036     &                  coeffraf,locind_child_left)
2037C
2038          enddo 
2039C
2040        enddo 
2041C       
2042      enddo
2043C
2044      Deallocate(tabtemp)
2045C
2046      Return
2047C
2048C
2049      End Subroutine Agrif_Update_4D_recursive
2050C
2051C
2052C
2053C     ************************************************************************** 
2054CCC   Subroutine Agrif_Update_5D_Recursive 
2055C     **************************************************************************
2056C
2057      Subroutine Agrif_Update_5D_recursive(TypeUpdate,tempP,tempC,
2058     &                                     indmin,indmax,   
2059     &                                     pttab_child,petab_child,
2060     &                                     s_child,s_parent,
2061     &                                     ds_child,ds_parent,nbdim)
2062C
2063CCC   Description:
2064CCC   Subroutine to update a 5D grid variable on the parent grid. 
2065CCC   It calls Agrif_Update_4D_Recursive and Agrif_UpdateBase.   
2066C
2067CC    Method:
2068C
2069C     Declarations:
2070C
2071     
2072C     
2073      INTEGER                   :: nbdim
2074      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
2075      INTEGER, DIMENSION(nbdim) :: indmin,indmax
2076      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
2077      REAL, DIMENSION(nbdim)    :: s_child,s_parent
2078      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
2079      REAL, DIMENSION(indmin(1):indmax(1),
2080     &                indmin(2):indmax(2),
2081     &                indmin(3):indmax(3),
2082     &                indmin(4):indmax(4),
2083     &                indmin(5):indmax(5))           :: tempP
2084      REAL, DIMENSION(pttab_child(1):petab_child(1),
2085     &                pttab_child(2):petab_child(2),
2086     &                pttab_child(3):petab_child(3),
2087     &                pttab_child(4):petab_child(4),
2088     &                pttab_child(5):petab_child(5)) :: tempC
2089C
2090C     Local variables     
2091      REAL, DIMENSION(:,:,:,:,:), Allocatable :: tabtemp
2092      INTEGER :: i,j,k,l,m
2093      INTEGER :: coeffraf,locind_child_left
2094C
2095C
2096      Allocate(tabtemp(indmin(1):indmax(1),
2097     &                 indmin(2):indmax(2),
2098     &                 indmin(3):indmax(3),
2099     &                 indmin(4):indmax(4),   
2100     &                 pttab_child(5):petab_child(5)))
2101C
2102      do m = pttab_child(nbdim),petab_child(nbdim)
2103C
2104        Call Agrif_Update_4D_recursive(TypeUpdate(1:nbdim-1),   
2105     &         tabtemp(indmin(nbdim-4):indmax(nbdim-4),
2106     &                 indmin(nbdim-3):indmax(nbdim-3),
2107     &                 indmin(nbdim-2):indmax(nbdim-2),
2108     &                 indmin(nbdim-1):indmax(nbdim-1),m),
2109     &         tempC(pttab_child(nbdim-4):petab_child(nbdim-4),
2110     &               pttab_child(nbdim-3):petab_child(nbdim-3),
2111     &               pttab_child(nbdim-2):petab_child(nbdim-2),
2112     &               pttab_child(nbdim-1):petab_child(nbdim-1),m),
2113     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
2114     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
2115     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
2116     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
2117C
2118      enddo
2119     
2120      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
2121     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
2122C
2123      do l = indmin(4),indmax(4)
2124C
2125        do k = indmin(3),indmax(3)
2126C
2127          do j = indmin(2),indmax(2)
2128C
2129            do i = indmin(1),indmax(1)
2130C
2131              Call Agrif_UpdateBase(TypeUpdate(5),
2132     &           tempP(i,j,k,l,indmin(nbdim):indmax(nbdim)),
2133     &          tabtemp(i,j,k,l,
2134     &                   pttab_child(nbdim):petab_child(nbdim)),
2135     &           indmin(nbdim),indmax(nbdim),
2136     &           pttab_child(nbdim),petab_child(nbdim),
2137     &           s_parent(nbdim),s_child(nbdim),
2138     &           ds_parent(nbdim),ds_child(nbdim),
2139     &                  coeffraf,locind_child_left)
2140C
2141            enddo
2142C
2143          enddo 
2144C
2145        enddo 
2146C       
2147      enddo
2148C
2149      Deallocate(tabtemp)
2150C
2151      Return
2152C
2153C
2154      End Subroutine Agrif_Update_5D_recursive
2155C
2156C
2157C
2158C
2159C     ************************************************************************** 
2160CCC   Subroutine Agrif_Update_6D_Recursive 
2161C     **************************************************************************
2162C
2163      Subroutine Agrif_Update_6D_recursive(TypeUpdate,tempP,tempC,
2164     &                                     indmin,indmax,   
2165     &                                     pttab_child,petab_child,
2166     &                                     s_child,s_parent,
2167     &                                     ds_child,ds_parent,nbdim)
2168C
2169CCC   Description:
2170CCC   Subroutine to update a 6D grid variable on the parent grid. 
2171CCC   It calls Agrif_Update_5D_Recursive and Agrif_UpdateBase.   
2172C
2173CC    Method:
2174C
2175C     Declarations:
2176C
2177     
2178C     
2179      INTEGER                   :: nbdim
2180      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
2181      INTEGER, DIMENSION(nbdim) :: indmin,indmax
2182      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
2183      REAL, DIMENSION(nbdim)    :: s_child,s_parent
2184      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
2185      REAL, DIMENSION(indmin(1):indmax(1),
2186     &                indmin(2):indmax(2),
2187     &                indmin(3):indmax(3),
2188     &                indmin(4):indmax(4),
2189     &                indmin(5):indmax(5),
2190     &                indmin(6):indmax(6))           :: tempP
2191      REAL, DIMENSION(pttab_child(1):petab_child(1),
2192     &                pttab_child(2):petab_child(2),
2193     &                pttab_child(3):petab_child(3),
2194     &                pttab_child(4):petab_child(4),
2195     &                pttab_child(5):petab_child(5),
2196     &                pttab_child(6):petab_child(6)) :: tempC
2197C
2198C     Local variables     
2199      REAL, DIMENSION(:,:,:,:,:,:), Allocatable :: tabtemp
2200      INTEGER :: i,j,k,l,m,n
2201      INTEGER :: coeffraf,locind_child_left
2202C
2203C
2204      Allocate(tabtemp(indmin(1):indmax(1),
2205     &                 indmin(2):indmax(2),
2206     &                 indmin(3):indmax(3),
2207     &                 indmin(4):indmax(4),   
2208     &                 indmin(5):indmax(5),   
2209     &                 pttab_child(6):petab_child(6)))
2210C
2211      do n = pttab_child(nbdim),petab_child(nbdim)
2212C
2213        Call Agrif_Update_5D_recursive(TypeUpdate(1:nbdim-1),   
2214     &         tabtemp(indmin(nbdim-5):indmax(nbdim-5),
2215     &                 indmin(nbdim-4):indmax(nbdim-4),
2216     &                 indmin(nbdim-3):indmax(nbdim-3),
2217     &                 indmin(nbdim-2):indmax(nbdim-2),
2218     &                 indmin(nbdim-1):indmax(nbdim-1),n),
2219     &         tempC(pttab_child(nbdim-5):petab_child(nbdim-5),
2220     &               pttab_child(nbdim-4):petab_child(nbdim-4),
2221     &               pttab_child(nbdim-3):petab_child(nbdim-3),
2222     &               pttab_child(nbdim-2):petab_child(nbdim-2),
2223     &               pttab_child(nbdim-1):petab_child(nbdim-1),n),
2224     &         indmin(1:nbdim-1),indmax(1:nbdim-1),
2225     &         pttab_child(1:nbdim-1),petab_child(1:nbdim-1),
2226     &         s_child(1:nbdim-1),s_parent(1:nbdim-1),
2227     &         ds_child(1:nbdim-1),ds_parent(1:nbdim-1),nbdim-1)
2228C
2229      enddo
2230     
2231      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
2232     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
2233C
2234      do m = indmin(5),indmax(5)
2235      do l = indmin(4),indmax(4)
2236C
2237        do k = indmin(3),indmax(3)
2238C
2239          do j = indmin(2),indmax(2)
2240C
2241            do i = indmin(1),indmax(1)
2242C
2243              Call Agrif_UpdateBase(TypeUpdate(6),
2244     &           tempP(i,j,k,l,m,indmin(nbdim):indmax(nbdim)),
2245     &          tabtemp(i,j,k,l,m,
2246     &                   pttab_child(nbdim):petab_child(nbdim)),
2247     &           indmin(nbdim),indmax(nbdim),
2248     &           pttab_child(nbdim),petab_child(nbdim),
2249     &           s_parent(nbdim),s_child(nbdim),
2250     &           ds_parent(nbdim),ds_child(nbdim),
2251     &                  coeffraf,locind_child_left)
2252C
2253            enddo
2254C
2255          enddo 
2256C
2257        enddo 
2258C       
2259      enddo
2260      enddo
2261C
2262      Deallocate(tabtemp)
2263C
2264      Return
2265C
2266C
2267      End Subroutine Agrif_Update_6D_recursive
2268C
2269C
2270C
2271C     ************************************************************************** 
2272CCC   Subroutine Agrif_UpdateBase 
2273C     ************************************************************************** 
2274C 
2275      Subroutine Agrif_UpdateBase(TypeUpdate,
2276     &                            parenttab,childtab,
2277     &                            indmin,indmax,pttab_child,petab_child,
2278     &                            s_parent,s_child,ds_parent,ds_child,
2279     &                            coeffraf,locind_child_left)
2280C
2281CCC   Description:
2282CCC   Subroutine calling the updating method chosen by the user (copy, average
2283CCC   or full-weighting).   
2284C
2285CC    Method:
2286C
2287C     Declarations:
2288C
2289     
2290C
2291      INTEGER :: TypeUpdate
2292      INTEGER :: indmin,indmax
2293      INTEGER :: pttab_child,petab_child
2294      REAL,DIMENSION(indmin:indmax)           :: parenttab       
2295      REAL,DIMENSION(pttab_child:petab_child) :: childtab     
2296      REAL    :: s_parent,s_child
2297      REAL    :: ds_parent,ds_child     
2298      INTEGER :: coeffraf,locind_child_left
2299C
2300C
2301      if (TypeUpdate == AGRIF_Update_copy) then
2302C             
2303          Call agrif_copy1D
2304     &       (parenttab,childtab,
2305     &          indmax-indmin+1,petab_child-pttab_child+1,
2306     &          s_parent,s_child,ds_parent,ds_child)     
2307C
2308        elseif (TypeUpdate == AGRIF_Update_average) then
2309C             
2310          Call average1D
2311     &       (parenttab,childtab,
2312     &          indmax-indmin+1,petab_child-pttab_child+1,
2313     &          s_parent,s_child,ds_parent,ds_child)   
2314C
2315        elseif (TypeUpdate == AGRIF_Update_full_weighting) then
2316C             
2317          Call full_weighting1D
2318     &       (parenttab,childtab,
2319     &          indmax-indmin+1,petab_child-pttab_child+1,
2320     &          s_parent,s_child,ds_parent,ds_child,
2321     &          coeffraf,locind_child_left)
2322C
2323      endif
2324C
2325      Return               
2326C
2327C     
2328      End Subroutine Agrif_UpdateBase
2329C
2330C
2331
2332      Subroutine Agrif_Compute_nbdim_update(s_parent,s_child,
2333     &  ds_parent,ds_child,coeffraf,locind_child_left)
2334      real :: s_parent,s_child,ds_parent,ds_child
2335      integer :: coeffraf,locind_child_left
2336     
2337      coeffraf = nint(ds_parent/ds_child)
2338      locind_child_left = 1 + agrif_int((s_parent-s_child)/ds_child)
2339     
2340      End Subroutine Agrif_Compute_nbdim_update
2341 
2342#if defined AGRIF_MPI     
2343      Subroutine Agrif_Find_list_update(list_update,pttab,petab,
2344     &                          pttab_Child,pttab_Parent,nbdim,
2345     &     find_list_update,tab4t,tab5t,memberinall,memberinall2)     
2346      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
2347      INTEGER :: nbdim
2348      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
2349      LOGICAL :: find_list_update
2350      Type(Agrif_List_Interp_loc), Pointer :: parcours
2351      INTEGER :: i
2352C
2353      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
2354      LOGICAL, DIMENSION(0:Agrif_Nbprocs-1) :: memberinall,memberinall2
2355                   
2356      find_list_update = .FALSE.
2357     
2358      parcours => list_update
2359     
2360      Find_loop :   Do While (associated(parcours))
2361        Do i=1,nbdim
2362          IF ((pttab(i) /= parcours%interp_loc%pttab(i)).OR.
2363     &        (petab(i) /= parcours%interp_loc%petab(i)).OR.
2364     &        (pttab_child(i) /= parcours%interp_loc%pttab_child(i)).OR.
2365     &        (pttab_parent(i) /= parcours%interp_loc%pttab_parent(i)))
2366     &               THEN
2367            parcours=>parcours%suiv
2368            Cycle Find_loop
2369          ENDIF
2370        EndDo
2371       
2372        tab4t = parcours%interp_loc%tab4t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
2373        memberinall = parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1)
2374       
2375        tab5t = parcours%interp_loc%tab5t(1:nbdim,0:Agrif_Nbprocs-1,1:4)
2376        memberinall2 = 
2377     &       parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1)
2378       
2379        find_list_update = .TRUE.   
2380        Exit Find_loop
2381      End Do Find_loop 
2382                             
2383      End Subroutine Agrif_Find_list_update 
2384     
2385      Subroutine Agrif_AddTo_list_update(list_update,pttab,petab,
2386     &                          pttab_Child,pttab_Parent,nbdim
2387     &      ,tab4t,tab5t,memberinall,memberinall2)
2388         
2389      TYPE(Agrif_List_Interp_Loc), Pointer :: list_update
2390      INTEGER :: nbdim
2391      INTEGER,DIMENSION(nbdim)   :: pttab,petab,pttab_Child,pttab_Parent
2392      INTEGER,DIMENSION(nbdim,0:Agrif_Nbprocs-1,4) :: tab4t, tab5t
2393      LOGICAL,DIMENSION(0:Agrif_Nbprocs-1) :: memberinall, memberinall2
2394
2395      Type(Agrif_List_Interp_loc), Pointer :: parcours
2396           
2397       Allocate(parcours)
2398      Allocate(parcours%interp_loc)
2399     
2400      parcours%interp_loc%pttab(1:nbdim) = pttab(1:nbdim)
2401      parcours%interp_loc%petab(1:nbdim) = petab(1:nbdim)
2402      parcours%interp_loc%pttab_child(1:nbdim) = pttab_child(1:nbdim)
2403      parcours%interp_loc%pttab_parent(1:nbdim) = pttab_parent(1:nbdim)
2404      Allocate(parcours%interp_loc%tab4t(nbdim,0:Agrif_Nbprocs-1,4))
2405      Allocate(parcours%interp_loc%memberinall(0:Agrif_Nbprocs-1))
2406     
2407      Allocate(parcours%interp_loc%tab5t(nbdim,0:Agrif_Nbprocs-1,4))
2408      Allocate(parcours%interp_loc%memberinall2(0:Agrif_Nbprocs-1))
2409           
2410      parcours%interp_loc%tab4t=tab4t   
2411      parcours%interp_loc%memberinall=memberinall
2412 
2413      parcours%interp_loc%tab5t=tab5t   
2414      parcours%interp_loc%memberinall2=memberinall2
2415           
2416      parcours%suiv => list_update
2417     
2418      list_update => parcours
2419     
2420      End Subroutine Agrif_Addto_list_update
2421#endif
2422           
2423      End Module Agrif_Update
2424
2425C     **************************************************************************
2426CCC   Subroutine Agrif_Update_1D_Recursive
2427C     **************************************************************************
2428C
2429      Subroutine Agrif_Update_1D_recursive(TypeUpdate,tempP,tempC,
2430     &                                     indmin,indmax,
2431     &                                     pttab_child,petab_child,
2432     &                                     s_child,s_parent,
2433     &                                     ds_child,ds_parent,nbdim)
2434C
2435CCC   Description:
2436CCC   Subroutine to update a 1D grid variable on the parent grid.
2437C
2438CC    Method:
2439C
2440C     Declarations:
2441C
2442     
2443C
2444C     Arguments
2445      USE Agrif_Update
2446      INTEGER                   :: nbdim
2447      INTEGER, DIMENSION(nbdim) :: TypeUpdate            ! TYPE of update (copy or average)
2448      INTEGER, DIMENSION(nbdim) :: indmin,indmax
2449      INTEGER, DIMENSION(nbdim) :: pttab_child,petab_child
2450      REAL, DIMENSION(nbdim)    :: s_child,s_parent
2451      REAL, DIMENSION(nbdim)    :: ds_child,ds_parent
2452      REAL, DIMENSION(indmin(nbdim):indmax(nbdim))           :: tempP
2453      REAL, DIMENSION(pttab_child(nbdim):petab_child(nbdim)) :: tempC
2454      INTEGER :: coeffraf,locind_child_left
2455C
2456C
2457      Call Agrif_Compute_nbdim_update(s_parent(nbdim),s_child(nbdim),
2458     &  ds_parent(nbdim),ds_child(nbdim),coeffraf,locind_child_left)
2459     
2460      Call Agrif_UpdateBase(TypeUpdate(1),
2461     &                  tempP(indmin(nbdim):indmax(nbdim)),
2462     &                  tempC(pttab_child(nbdim):petab_child(nbdim)),
2463     &                  indmin(nbdim),indmax(nbdim),           
2464     &                  pttab_child(nbdim),petab_child(nbdim),
2465     &                  s_parent(nbdim),s_child(nbdim),
2466     &                  ds_parent(nbdim),ds_child(nbdim),
2467     &                  coeffraf,locind_child_left)
2468C
2469      Return
2470C
2471C
2472      End Subroutine Agrif_Update_1D_recursive     
Note: See TracBrowser for help on using the repository browser.