source: trunk/AGRIFZOOM/AGRIF_YOURFILES/modupdate.f @ 2

Last change on this file since 2 was 2, checked in by pinsard, 17 years ago

initial import from official romsagrif distribution without any svn and CVS directories

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