*DK N1BNDRY
      SUBROUTINE N1BNDRY(J)
      INCLUDE 'param.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'nestcnt.h'
      INCLUDE 'index.h'
      INCLUDE 'buffe.h'
C     ****
C     ****     SPECIFY BOUNDARY VALUES FOR THE NEST GRID DOMAIN.
C     ****     FOR A RECTENGULAR NESTED GRID DOMAIN, FOR LATERAL
C     ****     BOUNDARIES ARE DEFINED AS FOLLOWS:
C     ****   
C     ****                     PHI2
C     ****         IM _______________________
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |        NESTED        |
C     ****            |         GRID         |
C     ****     PHI1   |        DOMAIN        | PHI3
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****         I1 |______________________|
C     ****            J1                    JM     
C     ****                     PHI4
C     ****
C     ****     WHERE IM > I1 AND J1 > JM  
C     ****     I1 AND IM ARE INDICES OF THE CORASE GRID IN THE 
C     ****     LONGITUDINAL DIRECTION
C     ****     J1 AND JM ARE INDICES OF THE COARSE GRID IN THE
C     ****     LATITUDINAL DIRECTION
C     ****
      NVRK=NVR
C     ****
C     ****     J1 LINE GOES FROM I1 TO IM
C     **** 
      IF(J.EQ.NESTJ1(1))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(1)+1 
       DO K=1,NVRK
        DO I=1,NESTIM(1)-NESTI1(1)+1
         II=NESTI1(1)+I-1
         PHI1(I,K,1)=F(II,NJK)
         PHI1(I,K,2)=F(II,NJPK)
        ENDDO
C       ****
C       ****     CORNER POINT FOR PHI2 AND PHI4
C       **** 
        PHI2(JN,K,1)=F(NESTIM(1),NJK)
        PHI2(JN,K,2)=F(NESTIM(1),NJPK)
        PHI4(JN,K,1)=F(NESTI1(1),NJK)
        PHI4(JN,K,2)=F(NESTI1(1),NJPK)
        NJK=NJK+1        
        NJPK=NJPK+1
       ENDDO
C     ****
C     ****     JM LINE GOES FROM I1 TO IM
C     **** 
      ELSEIF(J.EQ.NESTJM(1))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(1)+1 
       DO K=1,NVRK
        DO I=1,NESTIM(1)-NESTI1(1)+1
         II=NESTI1(1)+I-1
         PHI3(I,K,1)=F(II,NJK)
         PHI3(I,K,2)=F(II,NJPK)
        ENDDO
C       ****
C       ****     CORNER POINT FOR PHI2 AND PHI4
C       **** 
        PHI2(JN,K,1)=F(NESTIM(1),NJK)
        PHI2(JN,K,2)=F(NESTIM(1),NJPK)
        PHI4(JN,K,1)=F(NESTI1(1),NJK)
        PHI4(JN,K,2)=F(NESTI1(1),NJPK)
        NJK=NJK+1        
        NJPK=NJPK+1
       ENDDO
C     ****
C     ****     I1 AND IM LINES SWEEP THROUGH LATITUDES
C     ****
      ELSE IF(J.GT.NESTJ1(1).AND.J.LT.NESTJM(1))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(1)+1 
       DO K=1,NVRK
        PHI2(JN,K,1)=F(NESTIM(1),NJK)
        PHI2(JN,K,2)=F(NESTIM(1),NJPK)
        PHI4(JN,K,1)=F(NESTI1(1),NJK)
        PHI4(JN,K,2)=F(NESTI1(1),NJPK)
        NJK=NJK+1          
        NJPK=NJPK+1
       ENDDO
      ENDIF
      RETURN
      END   
*DK N1CSTOFN
      SUBROUTINE N1CSTOFN
      INCLUDE 'n1param.h'
      INCLUDE 'n1const.h'
      INCLUDE 'nestcnt.h'
      INCLUDE 'n1nestg.h'
      NVRK=NVR
      LEVEL=1
      RATIO=FLOAT(NESTRI(LEVEL))
      DO I=1,INX
       II=NESTRI(LEVEL)*(I-1)+1
       IF(I.LT.INX)THEN
        DO K=1,NVRK
         FIN1(II,K,1)=PHI1(I,K,1)
         FIN1(II,K,2)=PHI1(I,K,2)
         FIN3(II,K,1)=PHI3(I,K,1)
         FIN3(II,K,2)=PHI3(I,K,2)
         DO L=1,NESTRI(LEVEL)-1
          IL=II+L
          FIN1(IL,K,1)=PHI1(I,K,1)+FLOAT(L)*(PHI1(I+1,K,1)-
     &                 PHI1(I,K,1))/RATIO
          FIN1(IL,K,2)=PHI1(I,K,2)+FLOAT(L)*(PHI1(I+1,K,2)-
     &                 PHI1(I,K,2))/RATIO
          FIN3(IL,K,1)=PHI3(I,K,1)+FLOAT(L)*(PHI3(I+1,K,1)-
     &                 PHI3(I,K,1))/RATIO
          FIN3(IL,K,2)=PHI3(I,K,2)+FLOAT(L)*(PHI3(I+1,K,2)-
     &                 PHI3(I,K,2))/RATIO
         ENDDO
        ENDDO 
       ELSE
        DO K=1,NVRK
         FIN1(II,K,1)=PHI1(I,K,1)
         FIN1(II,K,2)=PHI1(I,K,2)
         FIN3(II,K,1)=PHI3(I,K,1) 
         FIN3(II,K,2)=PHI3(I,K,2)              
        ENDDO         
       ENDIF
      ENDDO
      DO J=1,JNX
       JJ=NESTRI(LEVEL)*(J-1)+1
       IF(J.LT.JNX)THEN
        DO K=1,NVRK
         FIN2(JJ,K,1)=PHI2(J,K,1)
         FIN2(JJ,K,2)=PHI2(J,K,2)
         FIN4(JJ,K,1)=PHI4(J,K,1)
         FIN4(JJ,K,2)=PHI4(J,K,2)
         DO L=1,NESTRI(LEVEL)-1
          JL=JJ+L
          FIN2(JL,K,1)=PHI2(J,K,1)+FLOAT(L)*(PHI2(J+1,K,1)-
     &                 PHI2(J,K,1))/RATIO
          FIN2(JL,K,2)=PHI2(J,K,2)+FLOAT(L)*(PHI2(J+1,K,2)-
     &                 PHI2(J,K,2))/RATIO              
          FIN4(JL,K,1)=PHI4(J,K,1)+FLOAT(L)*(PHI4(J+1,K,1)-
     &                 PHI4(J,K,1))/RATIO
          FIN4(JL,K,2)=PHI4(J,K,2)+FLOAT(L)*(PHI4(J+1,K,2)-
     &                 PHI4(J,K,2))/RATIO
         ENDDO
        ENDDO 
       ELSE
        DO K=1,NVRK
         FIN2(JJ,K,1)=PHI2(J,K,1)
         FIN2(JJ,K,2)=PHI2(J,K,2)
         FIN4(JJ,K,1)=PHI4(J,K,1) 
         FIN4(JJ,K,2)=PHI4(J,K,2)              
        ENDDO         
       ENDIF
      ENDDO 
      RETURN
      END  
C
*DK NESTBOUN
      SUBROUTINE N1NESTBOUN(J,NX,NTIME)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n1const.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'nestcnt.h'
      NJNPX=NJNP+NX
      NJBK=NX+1
      RATIO=DBLE(NESTRI(1))
      DO K=1,KMAXP1
        F(1,NJNPX)=FIN4(J,NJBK,1)+FLOAT(NTIME)*(FIN4(J,NJBK,2)-FIN4(J,
     1            NJBK,1))/RATIO
        F(LEN1,NJNPX)=FIN2(J,NJBK,1)+FLOAT(NTIME)*(FIN2(J,NJBK,2)
     1               -FIN2(J,NJBK,1))/RATIO
        NJNPX=NJNPX+1
        NJBK=NJBK+1
      ENDDO
      RETURN
      END
*DK NESTBOUN
      SUBROUTINE NESTBOUN(J,NX,LEVEL,NTIME)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n1const.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'nestcnt.h'
      NJNPX=NJNP+NX
      NJBK=NX+1
      RATIO=DBLE(NESTRI(LEVEL))
      DO K=1,KMAXP1
        F(1,NJNPX)=FIN4(J,NJBK,1)+FLOAT(NTIME)*(FIN4(J,NJBK,2)-FIN4(J,
     1            NJBK,1))/RATIO
        F(LEN1,NJNPX)=FIN2(J,NJBK,1)+FLOAT(NTIME)*(FIN2(J,NJBK,2)
     1               -FIN2(J,NJBK,1))/RATIO
        NJNPX=NJNPX+1
        NJBK=NJBK+1
      ENDDO
      RETURN
      END
*DK NESTBOUN1
      SUBROUTINE N1NEBOUN1(NTIME)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n1const.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'index.h'
      INCLUDE 'nestcnt.h'
      NVRK=NVR
      LEVEL=1
      NJNPX=NJNP+NT
      RATIO=FLOAT(NESTRI(LEVEL))
      DO K=1,NVRK
       DO I=1,IMAX
        F(I,NJNPX)=FIN1(I,K,1)+FLOAT(NTIME)*(FIN1(I,K,2)-
     1             FIN1(I,K,1))/RATIO
       ENDDO
       NJNPX=NJNPX+1
      ENDDO
      RETURN
      END
*DK NESTBOUN1
      SUBROUTINE NEBOUN1(LEVEL,NTIME,NTER)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n1const.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'index.h'
      INCLUDE 'nestcnt.h'
      NVRK=NVR
      LEVEL=1
      NJNPX=NJNP+NT
      RATIO=FLOAT(NESTRI(LEVEL))
      DO K=1,NVRK
        DO I=1,IMAX
          F(I,NJNPX)=FIN1(I,K,1)+FLOAT(NTIME)*(FIN1(I,K,2)-
     1               FIN1(I,K,1))/RATIO
        ENDDO
        NJNPX=NJNPX+1
      ENDDO
      RETURN
      END
C
*DK NESTBOUN1
      SUBROUTINE N2NEBOUN1(NTIME)
      INCLUDE 'n2param.h'
      INCLUDE 'n2array.h'
      INCLUDE 'n2const.h'
      INCLUDE 'n2nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'index.h'
      INCLUDE 'nestcnt.h'
      NVRK=NVR
      LEVEL=2
      NJNPX=NJNP+NT
      RATIO=FLOAT(NESTRI(LEVEL))
      DO K=1,NVRK
        DO I=1,IMAX
          F(I,NJNPX)=FIN1(I,K,1)+FLOAT(NTIME)*(FIN1(I,K,2)-
     1               FIN1(I,K,1))/RATIO
        ENDDO
        NJNPX=NJNPX+1
      ENDDO
      RETURN
      END
C      
*DK NESTBOUN2
      SUBROUTINE NEBOUN2(LEVEL,NTIME,NTER)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n1const.h'
      INCLUDE 'n1nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'index.h'
      INCLUDE 'nestcnt.h'
      NVRK=NVR
      NJNPX=NJNP+NT
      RATIO=FLOAT(NESTRI(LEVEL))
      DO K=1,NVRK
        DO I=1,IMAX
          F(I,NJNPX)=FIN3(I,K,1)+FLOAT(NTIME)*(FIN3(I,K,2)-
     1               FIN3(I,K,1))/RATIO
        ENDDO
        NJNPX=NJNPX+1
      ENDDO
      RETURN
      END
C
*DK N1BNDRY
      SUBROUTINE N2BNDRY(J)
      INCLUDE 'n1param.h'
      INCLUDE 'n1array.h'
      INCLUDE 'n2nestg.h'
      INCLUDE 'nestcnt.h'
      INCLUDE 'index.h'
      INCLUDE 'buffe.h'
C     ****
C     ****     SPECIFY BOUNDARY VALUES FOR THE NEST GRID DOMAIN.
C     ****     FOR A RECTENGULAR NESTED GRID DOMAIN, FOR LATERAL
C     ****     BOUNDARIES ARE DEFINED AS FOLLOWS:
C     ****   
C     ****                     PHI2
C     ****         IM _______________________
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |        NESTED        |
C     ****            |         GRID         |
C     ****     PHI1   |        DOMAIN        | PHI3
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****            |                      |
C     ****         I1 |______________________|
C     ****            J1                    JM     
C     ****                     PHI4
C     ****
C     ****     WHERE IM > I1 AND J1 > JM  
C     ****     I1 AND IM ARE INDICES OF THE CORASE GRID IN THE 
C     ****     LONGITUDINAL DIRECTION
C     ****     J1 AND JM ARE INDICES OF THE COARSE GRID IN THE
C     ****     LATITUDINAL DIRECTION
C     ****
      NVRK=NVR
C     ****
C     ****     J1 LINE GOES FROM I1 TO IM
C     **** 
      LEVEL=2
      IF(J.EQ.NESTJ1(LEVEL))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(LEVEL)+1 
       DO K=1,NVRK
        DO I=1,NESTIM(LEVEL)-NESTI1(LEVEL)+1
         II=NESTI1(LEVEL)+I-1
         PHI1(I,K,1)=F(II,NJK)
         PHI1(I,K,2)=F(II,NJPK)
        ENDDO
C       ****
C       ****     CORNER POINT FOR PHI2 AND PHI4
C       **** 
        PHI2(JN,K,1)=F(NESTIM(LEVEL),NJK)
        PHI2(JN,K,2)=F(NESTIM(LEVEL),NJPK)
        PHI4(JN,K,1)=F(NESTI1(LEVEL),NJK)
        PHI4(JN,K,2)=F(NESTI1(LEVEL),NJPK)
        NJK=NJK+1        
        NJPK=NJPK+1
       ENDDO
C     ****
C     ****     JM LINE GOES FROM I1 TO IM
C     **** 
      ELSEIF(J.EQ.NESTJM(LEVEL))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(LEVEL)+1 
       DO K=1,NVRK
        DO I=1,NESTIM(LEVEL)-NESTI1(LEVEL)+1
         II=NESTI1(LEVEL)+I-1
         PHI3(I,K,1)=F(II,NJK)
         PHI3(I,K,2)=F(II,NJPK)
        ENDDO
C       ****
C       ****     CORNER POINT FOR PHI2 AND PHI4
C       **** 
        PHI2(JN,K,1)=F(NESTIM(LEVEL),NJK)
        PHI2(JN,K,2)=F(NESTIM(LEVEL),NJPK)
        PHI4(JN,K,1)=F(NESTI1(LEVEL),NJK)
        PHI4(JN,K,2)=F(NESTI1(LEVEL),NJPK)
        NJK=NJK+1        
        NJPK=NJPK+1
       ENDDO
C     ****
C     ****     I1 AND IM LINES SWEEP THROUGH LATITUDES
C     ****
      ELSE IF(J.GT.NESTJ1(LEVEL).AND.J.LT.NESTJM(LEVEL))THEN
       NJK=NJ+NT
       NJPK=NJNP+NT
       JN=J-NESTJ1(LEVEL)+1 
       DO K=1,NVRK
        PHI2(JN,K,1)=F(NESTIM(LEVEL),NJK)
        PHI2(JN,K,2)=F(NESTIM(LEVEL),NJPK)
        PHI4(JN,K,1)=F(NESTI1(LEVEL),NJK)
        PHI4(JN,K,2)=F(NESTI1(LEVEL),NJPK)
        NJK=NJK+1          
        NJPK=NJPK+1
       ENDDO
      ENDIF
      RETURN
      END   
*DK NESTBOUN2
      SUBROUTINE N2NEBOUN2(LEVEL,NTIME,NTER)
      INCLUDE 'n2param.h'
      INCLUDE 'n2array.h'
      INCLUDE 'n2const.h'
      INCLUDE 'n2nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'index.h'
      INCLUDE 'nestcnt.h'
      NVRK=NVR
      NJNPX=NJNP+NT
      RATIO=FLOAT(NESTRI(LEVEL))
      DO K=1,NVRK
        DO I=1,IMAX
          F(I,NJNPX)=FIN3(I,K,1)+FLOAT(NTIME)*(FIN3(I,K,2)-
     1               FIN3(I,K,1))/RATIO
        ENDDO
        NJNPX=NJNPX+1
      ENDDO
      RETURN
      END
C            
*DK N1CSTOFN
      SUBROUTINE N2CSTOFN
      INCLUDE 'n2param.h'
      INCLUDE 'n2const.h'
      INCLUDE 'nestcnt.h'
      INCLUDE 'n2nestg.h'
      NVRK=NVR
      LEVEL=2
      RATIO=FLOAT(NESTRI(LEVEL))
      DO I=1,INX
       II=NESTRI(LEVEL)*(I-1)+1
       IF(I.LT.INX)THEN
        DO K=1,NVRK
         FIN1(II,K,1)=PHI1(I,K,1)
         FIN1(II,K,2)=PHI1(I,K,2)
         FIN3(II,K,1)=PHI3(I,K,1)
         FIN3(II,K,2)=PHI3(I,K,2)
         DO L=1,NESTRI(LEVEL)-1
          IL=II+L
          FIN1(IL,K,1)=PHI1(I,K,1)+FLOAT(L)*(PHI1(I+1,K,1)-
     &                 PHI1(I,K,1))/RATIO
          FIN1(IL,K,2)=PHI1(I,K,2)+FLOAT(L)*(PHI1(I+1,K,2)-
     &                 PHI1(I,K,2))/RATIO
          FIN3(IL,K,1)=PHI3(I,K,1)+FLOAT(L)*(PHI3(I+1,K,1)-
     &                 PHI3(I,K,1))/RATIO
          FIN3(IL,K,2)=PHI3(I,K,2)+FLOAT(L)*(PHI3(I+1,K,2)-
     &                 PHI3(I,K,2))/RATIO
         ENDDO
        ENDDO 
       ELSE
        DO K=1,NVRK
         FIN1(II,K,1)=PHI1(I,K,1)
         FIN1(II,K,2)=PHI1(I,K,2)
         FIN3(II,K,1)=PHI3(I,K,1) 
         FIN3(II,K,2)=PHI3(I,K,2)              
        ENDDO         
       ENDIF
      ENDDO
      DO J=1,JNX
       JJ=NESTRI(LEVEL)*(J-1)+1
       IF(J.LT.JNX)THEN
        DO K=1,NVRK
         FIN2(JJ,K,1)=PHI2(J,K,1)
         FIN2(JJ,K,2)=PHI2(J,K,2)
         FIN4(JJ,K,1)=PHI4(J,K,1)
         FIN4(JJ,K,2)=PHI4(J,K,2)
         DO L=1,NESTRI(LEVEL)-1
          JL=JJ+L
          FIN2(JL,K,1)=PHI2(J,K,1)+FLOAT(L)*(PHI2(J+1,K,1)-
     &                 PHI2(J,K,1))/RATIO
          FIN2(JL,K,2)=PHI2(J,K,2)+FLOAT(L)*(PHI2(J+1,K,2)-
     &                 PHI2(J,K,2))/RATIO              
          FIN4(JL,K,1)=PHI4(J,K,1)+FLOAT(L)*(PHI4(J+1,K,1)-
     &                 PHI4(J,K,1))/RATIO
          FIN4(JL,K,2)=PHI4(J,K,2)+FLOAT(L)*(PHI4(J+1,K,2)-
     &                 PHI4(J,K,2))/RATIO
         ENDDO
        ENDDO 
       ELSE
        DO K=1,NVRK
         FIN2(JJ,K,1)=PHI2(J,K,1)
         FIN2(JJ,K,2)=PHI2(J,K,2)
         FIN4(JJ,K,1)=PHI4(J,K,1) 
         FIN4(JJ,K,2)=PHI4(J,K,2)              
        ENDDO         
       ENDIF
      ENDDO 
      RETURN
      END  
C
*DK NESTBOUN
      SUBROUTINE N2NESTBOUN(J,NX,LEVEL,NTIME)
      INCLUDE 'n2param.h'
      INCLUDE 'n2array.h'
      INCLUDE 'n2const.h'
      INCLUDE 'n2nestg.h'
      INCLUDE 'buffe.h'
      INCLUDE 'nestcnt.h'
      NJNPX=NJNP+NX
      NJBK=NX+1
      RATIO=DBLE(NESTRI(LEVEL))
      DO K=1,KMAXP1
        F(1,NJNPX)=FIN4(J,NJBK,1)+FLOAT(NTIME)*(FIN4(J,NJBK,2)-FIN4(J,
     1            NJBK,1))/RATIO
        F(LEN1,NJNPX)=FIN2(J,NJBK,1)+FLOAT(NTIME)*(FIN2(J,NJBK,2)
     1               -FIN2(J,NJBK,1))/RATIO
        NJNPX=NJNPX+1
        NJBK=NJBK+1
      ENDDO
      RETURN
      END
C