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

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