      SUBROUTINE RESIL2(JDIM,KDIM,S,NRES)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C
      COMMON/BASE/
     1  JMAX,       KMAX,     JM,          KM,          JBEGIN,   JEND,
     1  KBEGIN,     KEND,     JPLUS(999),  JMINU (999), JLOW,     JUP,
     1  KLOW,       KUP,      PERIDC  ,    NP,          DT,   CP2TIM,
     1  FSMACH,     ALPHA,    GAMMA,       GAMI,        PI,
     1  DIS2X,      DIS2Y,    DIS4X,       DIS4Y,       PHIDT,    
     1  THETAD ,    RESID,    JACDT,       IPRINT,      NPCP,
     1  JTAIL1,     JTAIL2,   NUMITE ,     ISTART,      NSTEPS
      LOGICAL PERIDC  
      COMMON/GRID/DYM,YMAX,XMIN,XMAX,THICK
C
      DIMENSION S(JDIM,KDIM,4)
C
C       COMPUTE L2  NORM OF DENSITY  RESIDUAL ( RIGHT HAND SIDE )
C
         RESID = 0.
         DO 5 K=KLOW,KUP
         DO 5 J=JLOW,JUP
            RESID = RESID + S(J,K,NRES)**2
5        CONTINUE
         RESID = RESID/( (JUP-JLOW+1)*(KUP-KLOW+1))
         RESID = SQRT( RESID ) / DT
6     CONTINUE

         RETURN
         END
