














































c
c
C $Header$










































































 


































































































































































 





























































































































































































 



















































 










 








































































































































































































































 










                                
                                

                                
                                

                                
                                

                                






































      subroutine Linear_extrap_one_bndry(doBC, lsh, var)

      implicit none

      integer doBC(6)
      integer lsh(3)
      REAL*8 var(lsh(1),lsh(2),lsh(3))

      integer nx,ny,nz

C     Grid parameters.

      nx = lsh(1)
      ny = lsh(2)
      nz = lsh(3)

C     Linear extrapolation from the interiors to the boundaries.
C     Does not support octant or quadrant.

C     6 faces.

      if (doBC(1).eq.1) then 
         var(1,:,:) = 2.d0 * var(2,:,:) - var(3,:,:)
      endif
      if (doBC(3).eq.1) then 
         var(:,1,:) = 2.d0 * var(:,2,:) - var(:,3,:)
      endif
      if (doBC(5).eq.1) then 
         var(:,:,1) = 2.d0 * var(:,:,2) - var(:,:,3)
      endif
      if (doBC(2).eq.1) then 
         var(nx,:,:) = 2.d0 * var(nx-1,:,:) - var(nx-2,:,:)
      endif
      if (doBC(4).eq.1) then 
         var(:,ny,:) = 2.d0 * var(:,ny-1,:) - var(:,ny-2,:)
      endif
      if (doBC(6).eq.1) then 
         var(:,:,nz) = 2.d0 * var(:,:,nz-1) - var(:,:,nz-2)
      endif

C     12 edges.
C     4 round face x=min.
      if ( doBC(1).eq.1
     $     .and. doBC(3).eq.1) then 
         var(1,1,:) = 2.d0 * var(2,2,:) - var(3,3,:)
      end if

      if ( doBC(1).eq.1
     $     .and. doBC(4).eq.1) then 
         var(1,ny,:) = 2.d0 * var(2,ny-1,:) - var(2,ny-2,:)
      end if

      if ( doBC(1).eq.1
     $     .and. doBC(5).eq.1) then 
         var(1,:,1) = 2.d0 * var(2,:,2) - var(3,:,3)
      end if

      if ( doBC(1).eq.1
     $     .and. doBC(6).eq.1) then 
         var(1,:,nz) = 2.d0 * var(2,:,nz-1) - var(3,:,nz-2)
      end if

C     4 around face x=max.
      if ( doBC(2).eq.1
     $     .and. doBC(3).eq.1) then 
         var(nx,1,:) = 2.d0 * var(nx-1,2,:) - var(nx-2,3,:)
      end if

      if ( doBC(2).eq.1
     $     .and. doBC(4).eq.1) then 
         var(nx,ny,:) = 2.d0 * var(nx-1,ny-1,:) - var(nx-2,ny-2,:)
      end if

      if ( doBC(2).eq.1
     $     .and. doBC(5).eq.1) then 
         var(nx,:,1) = 2.d0 * var(nx-1,:,2) - var(nx-2,:,3)
      end if

      if ( doBC(2).eq.1
     $     .and. doBC(6).eq.1) then 
         var(nx,:,nz) = 2.d0 * var(nx-1,:,nz-1) - var(nx-2,:,nz-2)
      end if

C     Remaining 2 in y=min.
      if ( doBC(3).eq.1 .and. ny.ge.4
     $     .and. doBC(5).eq.1) then
         var(:,1,1) = 2.d0 * var(:,2,2) - var(:,3,3)
      end if

      if ( doBC(3).eq.1 .and. ny.ge.4
     $     .and. doBC(6).eq.1) then 
         var(:,1,nz) = 2.d0 * var(:,2,nz-1) - var(:,2,nz-2)
      end if

C     Remaining 2 in y=ymax.      
      if ( doBC(4).eq.1 .and. ny.ge.4
     $     .and. doBC(5).eq.1) then
         var(:,ny,1) = 2.d0 * var(:,ny-1,2) - var(:,ny-2,3)  
      end if

      if ( doBC(4).eq.1 .and. ny.ge.4
     $     .and. doBC(6).eq.1) then 
         var(:,ny,nz) = 2.d0 * var(:,ny-1,nz-1) - var(:,ny-2,nz-2)
      end if

C     8 corners.

      if (doBC(1).eq.1 .and. doBC(3).eq.1 .and. doBC(5).eq.1) then
         var(1,1,1) = 2.d0*var(2,2,2) - var(3,3,3)
      end if
      if (doBC(1).eq.1 .and. doBC(3).eq.1 .and. doBC(6).eq.1) then
         var(1,1,nz) = 2.d0*var(2,2,nz-1) - var(3,3,nz-2)
      end if
      if (doBC(1).eq.1 .and. doBC(4).eq.1 .and. doBC(5).eq.1) then
         var(1,ny,1) = 2.d0*var(2,ny-1,2) - var(3,ny-2,3)
      end if
      if (doBC(1).eq.1 .and. doBC(4).eq.1 .and. doBC(6).eq.1) then
         var(1,ny,nz) = 2.d0*var(2,ny-1,nz-1) - var(3,ny-2,nz-2)
      end if
      if (doBC(2).eq.1 .and. doBC(3).eq.1 .and. doBC(5).eq.1) then
         var(nx,1,1) = 2.d0*var(nx-1,2,2) - var(nx-2,3,3)
      end if
      if (doBC(2).eq.1 .and. doBC(3).eq.1 .and. doBC(6).eq.1) then
         var(nx,1,nz) = 2.d0*var(nx-1,2,nz-1) - var(nx-2,3,nz-2)
      end if
      if (doBC(2).eq.1 .and. doBC(4).eq.1 .and. doBC(5).eq.1) then
         var(nx,ny,1) = 2.d0*var(nx-1,ny-1,2) - var(nx-2,ny-2,3)
      end if
      if (doBC(2).eq.1 .and. doBC(4).eq.1 .and. doBC(6).eq.1) then
         var(nx,ny,nz) = 2.d0*var(nx-1,ny-1,nz-1) - var(nx-2,ny-2,nz-2)
      end if
      
      return
      end
