      SUBROUTINE RESETE(NRM,N2,NK2,NK2I,IDBG) 
C 
C  RESET ENCLOSURE ARRAYS TO REDUCE STORAGE 
C 
C  INPUTS 
C    NRM  ZONE NO.
C    N2   TOTAL NO. OF ENCLOSURE ELE IN ZONE NRM BEFORE CONSOLIDATION 
C    NK2  NO. OF EFFECTIVE ENCLOSURE ELEMENTS IN THIS ZONE
C    NK2I ARRAY OF EFFECTIVE K2 VALUES FOR THIS ZONE
C 
C  OUTPUTS
C    RESET ENCLOSURE ARRAYS 
C    IZT  IZW INDICE NO. AT END OF THIS ZONE
C 
C - - - CONSTANTS 
CMDK NWL
CMDK NZN
CMDK NZW
C 
C - - - COMMON BLOCKS 
CMDK ENCBK1
CMDK IZPART
CMDK IZZQ
C 
      DIMENSION NK2I(NWL) 
      IDBGSV=IDBG 
C     IDBG=1
C 
C   RESET ENCLOSURE ARRAYS
      IF(IDBG.NE.0)THEN 
          WRITE(60,501)NRM 
          WRITE(60,512)NRM,(NK2I(NK),NK=1,NK2) 
          WRITE(60,513)NRM,(NK,NENC(NRM,NK),NK=1,N2) 
          ENDIF 
      DO 2 JT=1,NROOMS
      NRMQ=NRMA(JT) 
      IF(NRMQ.EQ.NRM)GO TO 2
      N2Q=NWALLA(NRMQ)
      IF(N2Q.EQ.0)GO TO 2 
      IF(IDBG.NE.0)WRITE(60,513)NRMQ,(NK,NENC(NRMQ,NK),NK=1,N2Q) 
    2 CONTINUE
      IZ=IZT
      DO 4 K2I=1,NK2
      K2=NK2I(K2I)
    4 IZWACT(K2I)=NENC(NRM,K2)
C  SORT THESE VALUES IN ASCENDING ORDER W/ BUBBLE SORT
      DO 6 I=1,NK2
      DO 6 J=1,NK2-1
      IF(IZWACT(J+1).LT.IZWACT(J))THEN
          IDUM=IZWACT(J+1)
          IZWACT(J+1)=IZWACT(J) 
          IZWACT(J)=IDUM
          ENDIF 
    6     CONTINUE
      IF(IDBG.NE.0)WRITE(60,514)NRM,(I,IZWACT(I),I=1,NK2)
      DO 40 K2I=1,NK2 
      IZW=IZWACT(K2I) 
      IZ=IZ+1 
      CALL RESUTL(NRM,K2I,IZW,IZ,IDBG)
C *    *     *    *   *   *  BOTTOM OF MAIN LOOP!!!!
   40 CONTINUE
C  NOW CHECK TO SEE IF IZW IN OTHER ZONES CAN BE MOVED TO LOWER IZ
C  NEXT STMT:  NO POINT IN MOVING IZW S IN LAST ZONE TO LOWER VALUES 
C              BECAUSE CONSOLID WONT REDUCE STORAGE REQD TO THIS POINT
      IF(NRM.EQ.NROOMS)GO TO 70 
      NRM1=NRM+1
      DO 60 JT=NRM1,NROOMS
      NRMQ=NRMA(JT) 
      IF(NRMQ.EQ.0)GO TO 60 
      N2Q=NWALLA(NRMQ)
      IF(N2Q.EQ.0)GO TO 60
      DO 50 K2Q=1,N2Q 
      IZWQ=NENC(NRMQ,K2Q) 
      IF(IZWQ.EQ.(IZ+1))THEN
          IZ=IZ+1 
          IF(IDBG.NE.0)WRITE(60,506)IZWQ 
          GO TO 50
          ENDIF 
      IF(IZWQ.GT.(IZ+1))THEN
          IZ=IZ+1 
          CALL RESUTL(NRMQ,K2Q,IZWQ,IZ,IDBG)
          ENDIF 
   50 CONTINUE
   60 CONTINUE
C  SET NO. OF ENCLOSURE ELEMENTS AT END OF THIS ZONE
   70 IZT=IZ
      IDBG=IDBGSV 
      RETURN
  500 FORMAT(20X,'FOR ZONE ',I4,' ENCLOSURE NO.(IZW) ',I3,
     +'  CHANGED TO ',I4) 
  501 FORMAT(1H0,9(1H*),'RESET ENCLOSURE ARRAYS TO REDUCE STORAGE', 
     +' FOR ZONE ',I4)
  502 FORMAT(10X,'BEGIN SEARCH FOR FEASIBLE IZ; K2I,IZW,IZ= ',3I5)
  503 FORMAT(12X,'IZW=IZ, SO NO NEED TO RESET;IZW= ',I3)
  504 FORMAT(15X,'NRMQ,K2Q,IZWQ,IZ= ',4I5)
  505 FORMAT(12X,'IZW LT IZ, SO DONT RESET:IZW,IZ= ',2I3) 
  506 FORMAT(15X,'FOUND IZW IN ZONE ',I3,' THAT = IZ, SO ', 
     +'INCREMENT IZ;IZW FOUND= ',I3)
  507 FORMAT(20X,'POINTER FOR OLD IZ(K2J)= ',I5,'  POINTER FOR NEW',
     +' IZ(K2I)= ',I5/20X,'IZW AT OLD IZ(NENC(NRM,K2I))= ',I4)
  508 FORMAT(15X,'LOOKING FOR EXISTING IZW=IZ IN ZONE ',I4) 
  509 FORMAT(15X,'   **DIDNT FIND AN EXISTING IZW=IZ IN ZONE ',I4)
  510 FORMAT(20X,'LOOKING FOR K2 AT ORIG IZW=NEW IZ') 
  511 FORMAT(20X,'  K2J,IZWQ,IZ= ',3I4) 
  512 FORMAT(1X,'K2 POINTERS TO ACTIVE IZWS IN ZONE ',I3,' ARE:'/ 
     +2X,24I3)
  513 FORMAT(1X,'FOR ZONE ',I3,' AVAILABLE IZW S ARE: '/
     +(20X,'K2,IZW= ',2I4)) 
  514 FORMAT(10X,'HERE ARE SORTED ACTIVE IZW S IN ZONE =',I3/ 
     +(20X,'K2,IZW= ',2I4)) 
      END 
