C
C
      SUBROUTINE CDCH (NSTOP,MHH)
C
C     ------------------------------------------------------------------
C
C       SUBROUTINE PURPOSE:
C       UPDATING CONDITION CHANGES ACCORDING TO USER-SPECIFIED TIME TABL
C
C     ------------------------------------------------------------------
C
      INCLUDE 'CMMNW.DAT'
C
      DIMENSION  QFX(20),PFX(20)
      DATA QFX,PFX / 40*0.0 /
C
C
      IF (TACC.LT.DELTAT.OR.MHH.EQ.1) TS=-1.0
C
C     TS: TIME IN MIN. AT WHICH A CONDITION CHANGE IS EXPECTD TO
C         BE ACTIVATED.
C
1     IF (TS.LT.0.0) READ (9,*,ERR=106,END=107) TS,ICODE
      IF (TS*60.0.GT.TACC) RETURN

C      ICODE: CODE NUMBER. 1: CHANGE TO ORDINARY AIRWAY.   2: CHANGE
C             TO FAN BRANCH.  3: CHANGE TO FIXED PRESSURE FAN BRANCH
C             4: CHANGE TO A FIRE SOURCE.     5: FIRE CEESED.
C      NBR: AIRWAY CALLING NUMBER IN WHICH CONDITION CHANGE HAPPENS.
C
C       ICODE=1 INDICATES THAT AIRWAY NBR BECOMES AN ORDINARY AIRWAY
C     WITH RESISTANCE EQUAL TO RCH AT TS MIN. AFTER EVENT.
C
      WRITE (*,'(2A)') TS,  ICODE
4     IF (ICODE.EQ.1) THEN
         READ (9,*,ERR=105,END=107) NBR,RCH
         DO 5 I=1,NB
            IF (NO(I).EQ.NBR) THEN
               N=I
               GO TO 6
            ENDIF
5        CONTINUE
         WRITE (8,210) NBR
         GO TO 100
6        IF (RCH.GT.0.0) THEN
            RSTD(N)=RCH
            R(N)=RCH*(TMRD(N)+460.0)**2/(TR+460.0)**2
            NWTYP(N)=0
            INIFAN=1
C           ********
9           WRITE (8,110) NO(N),RSTD(N),TS
         ELSE
            WRITE (8,270) NBR,NBR,RCH
            GO TO 100
         ENDIF
C
C       ICODE=2 INDICATES THAT AIRWAY NBR BECOMES A FAN BRANCH WITH
C     CHARACTERISTICS.
C
      ELSE IF (ICODE.EQ.2) THEN
         READ (9,*,ERR=105,END=107) NBR,INDEX
         DO 10 I=1,NB
            IF (NO(I).EQ.NBR) THEN
               N=I
               GO TO 15
            ENDIF
10       CONTINUE
         WRITE (8,210) NBR
         GO TO 100
15       IF (INDEX.LE.1.OR.INDEX.GT.5) THEN
            WRITE (8,120) INDEX,NBR
            GO TO 100
         ENDIF
         READ (9,*,ERR=105,END=107) (QFX(I),PFX(I),I=1,INDEX)
         IF (NFNUM.GT.0) THEN
            DO 20 J=1,NFNUM
               IF (NOF(J).EQ.NO(N)) THEN
                  MPTS(J)=INDEX
                  NSKP(J)=0
                  DO 18 K=1,INDEX
                     QF(J,K)=QFX(K)
                     PF(J,K)=PFX(K)
18                CONTINUE
                  JN=J
                  GO TO 35
               ENDIF
20          CONTINUE
         ENDIF
         IF (NFNUM.EQ.0) INIFAN=1
C        **************************
         NFNUM=NFNUM+1
         IF (NFNUM.GT.IMX) THEN
            NFNUM=NFNUM-1
            NWTYP(N)=1
            R(N)=PFX(1)
            WRITE (8,280) NBR,R(N)
            GO TO 100
         ENDIF
         NWTYP(N)=1
         NOF(NFNUM)=NO(N)
C        **************
         NSKP(NFNUM)=0
         NFREG(NFNUM)=N
C        **************
         MPTS(NFNUM)=INDEX
         DO 30 K=1,INDEX
            QF(NFNUM,K)=QFX(K)
            PF(NFNUM,K)=PFX(K)
30       CONTINUE
         INIFAN=1
C        ********
         JN=NFNUM
         KK=MPTS(JN)
35       WRITE (8,140) NBR,TS,(QF(JN,K),PF(JN,K),K=1,KK)
C
C       ICODE=3 INDICATES THAT BRANCH NBR BECOMES A FIXED PRESSURE
C     FAN BRANCH WITH PRESSURE EQUAL TO RX AT TS MIN. AFTER EVENT.
C
      ELSE IF (ICODE.EQ.3) THEN
         READ (9,*,ERR=105,END=107) NBR,RX
         DO 40 I=1,NB
            IF (NO(I).EQ.NBR) THEN
               N=I
               GO TO 45
            ENDIF
40       CONTINUE
         WRITE (8,210) NBR
         GO TO 100
45       IF (NFNUM.GT.0) THEN
            DO 50 J=1,NFNUM
               IF (NOF(J).EQ.NBR) NOF(J)=30000
50          CONTINUE
         ENDIF
         NWTYP(N)=1
         R(N)=RX
         WRITE (8,150) NBR,R(N)
C
C       ICODE=4 INDICATES THAT BRANCH NBR BECOMES A FIRE SOURCE AT
C     TS MIN. AFTER EVENT.
C
      ELSE IF (ICODE.EQ.4) THEN
         IF (NHM.EQ.0) THEN
            READ (9,*,ERR=105,END=107) NBR,CONTX,CONCX,HEATX,O2MINX,
     .        SMPO2X,HTPO2X,QCENTX,TPRX
         ELSE
            READ (9,*,ERR=105,END=107) NBR,CONTX,CONCX,HEATX,O2MINX,
     .        SMPO2X,HTPO2X,QCENTX,TPRX,CNX,HNX
         ENDIF
         DO 55 I=1,NB
            IF (NO(I).EQ.NBR) THEN
               N=I
               GO TO 58
            ENDIF
55       CONTINUE
         WRITE (8,210) NBR
         GO TO 100
58       IF (INFLOW.GT.0) THEN
            DO 60 J=1,INFLOW
               IF (NCENT(J).EQ.NBR) THEN
                  CONT(J)=CONTX
                  CONC(J)=CONCX
                  HEAT(J)=HEATX
                  O2MIN(J)=O2MINX
                  SMPO2(J)=SMPO2X
                  HTPO2(J)=HTPO2X
                  TPR(J)=TPRX
                  QCENT(J)=QCENTX
                  CN(J)=CNX
                  HN(J)=HNX
                  JN=J
                  GO TO 70
               ENDIF
60          CONTINUE
         ENDIF
         INFLOW=INFLOW+1
         IF (INFLOW.LE.IMX) THEN
            NCENT(INFLOW)=NBR
            CONT(INFLOW)=CONTX
            CONC(INFLOW)=CONCX
            HEAT(INFLOW)=HEATX
            O2MIN(INFLOW)=O2MINX
            SMPO2(INFLOW)=SMPO2X
            HTPO2(INFLOW)=HTPO2X
            TPR(INFLOW)=TPRX
            QCENT(INFLOW)=QCENTX
            CN(INFLOW)=CNX
            HN(INFLOW)=HNX
            JN=INFLOW
         ELSE
            INFLOW=INFLOW-1
            WRITE (8,290) NBR
            GO TO 100
         ENDIF
70       NWTYP(N)=10
         DO 75 K=1,NB
            IF (NO(K).EQ.NBR.AND.LA(K).GT.30.0)
     .         WRITE (8,220) NO(K),LA(K)
75       CONTINUE
         WRITE (8,160) NBR,TS,NBR,CONT(JN),CONC(JN),HEAT(JN),O2MIN(JN),
     .                 SMPO2(JN),HTPO2(JN),TPR(JN),QCENT(JN)
C
C       ICODE=5 INDICATES THAT BRANCH NBR BECOMES AN ORDINARY AIRWAY
C     WITHOUT A FIRE SOURCE AT TS MIN. AFTER EVENT.
C
      ELSE IF (ICODE.EQ.5) THEN
         READ (9,*,ERR=105,END=107) NBR
         DO 77 I=1,NB
            IF (NO(I).EQ.NBR) THEN
               N=I
               GO TO 78
            ENDIF
77       CONTINUE
         WRITE (8,210) NBR
         GO TO 100
78       IF (INFLOW.GT.0) THEN
            DO 90 I=1,INFLOW
               IF (NCENT(I).EQ.NBR) THEN
                  NCENT(I)=30005
                  NWTYP(N)=0
                  WRITE (8,170) NBR,TS
                  GO TO 100
               ENDIF
90          CONTINUE
         ELSE
            WRITE (8,230) NBR
         ENDIF
      ELSE IF (ICODE.EQ.6) THEN
         READ (9,*,ERR=105,END=107) DELT
         IF (DELT.GT.1.0.AND.DELT.LT.60.0) THEN
            WRITE (8,190) DELTAT,DELT,TS
         ELSE
            IF (DELT.GT.60.0) WRITE (8,200) DELT
         ENDIF
         IF (DELT.GT.1.0) DELTAT=DELT
C     ELSE IF (ICODE.EQ.7) THEN
C        JDP=JDP+1
C        IF (JDP.GT.IMX) THEN
C           WRITE (8,240)
C           JDP=JDP-1
C        ELSE
C           JDPP(JDP)=NBR
C        ENDIF
      ELSE
         WRITE (8,180) ICODE, NBR
      ENDIF
100   TS=-1.0
      GO TO 1
105   NSTOP=1
      WRITE (6,260)
      WRITE (8,260)
      RETURN
106   continue
107   RETURN
C
C
110   FORMAT (//,' * ATTN * AIRWAY',I5,' BECAME AN ORDINARY AIRWAY',
     .        ' WITH RESISTANCE EQUAL',/,' TO ',F9.3,' AT',F6.2,
     .        ' MIN. AFTER SIMULATION.',/)
120   FORMAT (//,' * ATTN * CAPACITY OF FAN CURVE ARRAYS QF AND PF',
     .       ' EXCEEDED.',/,' INPUT DATA FOR CONDITION CHANGE IGNORED.')
130   FORMAT (//,' * ATTN * NUMBER OF FAN CHARACTERISTICS BECAME',
     .        ' EXCEESIVE.',/,' BRANCH',I5,' IS TAKEN AS A FAN WITH',
     .        'FIXED PRESSURE ',F6.2,' IN. W.G.',/)
140   FORMAT (//,' * ATTN * THE FOLLOWING DATA FOR FAN',
     .        I5,' ACTIVATED AT',F6.2,' MIN. AFTER EVENT:',//,
     .        5(F8.0,F6.2),/,5(F8.0,F6.2),/,5(F8.0,F6.2),/)
150   FORMAT (//,' * ATTN * AIRWAY',I5,' BECAME A FAN BRANCH WITH ',
     .        'FIXED P ',F6.2,' IN. W.G.',/,' AT',F6.2,' MIN.',
     .        ' AFTER SIMULATION.',/)
160   FORMAT (//,' * ATTN * BRANCH',I5,' BECAME A FIRE SOURCE AT',
     .        F6.2,' MIN. AFTER EVENT',//,
     .       12X,'FIXED INFLUX',T31,'O2-RICH',T41,'FUEL-RICH',T55,
     .       'LEADING T',T67,'REF. Q',/,' AIRWAY  FLUX  %CONC',
     .       3X,'HEAT',5X,'%O2',4X,'FUMES',2X,'HEAT',//,
     .        I5,F8.1,F6.2,1X,E9.3,F7.2,F7.2,F7.1,F10.2,F12.0)
170   FORMAT (//,' * ATTN * FIRE',I5,' CEESED AT',F6.2,' MIN. AFTER'
     .        ,' EVENT.',/)
180   FORMAT (//,' * ATTN * INVALID CONDITION CODE',I5,' FOR AIRWAY',I5,
     .        ' IGNORED.',/)
190   FORMAT (//,' * ATTN * SIMULATION STEP WAS CHANGED FROM',1X,
     .        F6.2,' SEC.',/,' TO ',F6.2,' SEC. AT',F6.2,' MIN. AFTER',
     .        ' EVENT.'/)
200   FORMAT (//,' * ATTN * LARGE SIMULATION STEP (',F6.2,' SEC.',
     .        ' ) WILL AFFECT',/,' SIMULATION ACCURACY.',/)
210   FORMAT (//,' * ATTN * AIRWAY',I5,' NOT FOUND, DATA IGNORED.')
220   FORMAT (//,' * ATTN * AIRWAY',I5,' OF LENGTH',F7.0,' FT CONTAIN',
     .        ' A HEAT SOURCE.',/,' IT IS ADVISED TO DIVIDE THE ',
     .        'AIRWAY INTO TWO AND LOCATE THE',/,' FIRE SOURCE IN THE',
     .        ' ONE SHORTER THAN 30 FT.',/)
230   FORMAT (//,' * ATTN * FIRE BRANCH ',I5,' NOT FOUND, CHANGE ',
     .        'IGNORED.',/)
240   FORMAT (//,' * ATTN * VALUE OF JDP EXCEEDED CAPACITY, INPUT ',
     .        'IGNORED.',/)
250   FORMAT (//,' * ATTN * JUNCTION',I6,' NOT FOUND, CHANGE IGNORED.')
260   FORMAT (//,' * ERR * ERROR READING INPUT DATA.',/)
270   FORMAT (/,' * ATTN * NEGATIVE RESISTANCE INPUT FOR AIRWAY ',I5,
     .        ' IGNORED.',/,' CURRENT NBR= ',I5,'  RCH= ',F9.3)
280   FORMAT (/,' * ATTN * CAPACITY OF FAN ARRAYS EXCEEDED. BRANCH ',I4,
     .       ' IS ASSUMED',/,' AS A FIXED-P FAN WITH PRESSURE EQUAL TO',
     .       F9.3,' IN.W.G.',/)
290   FORMAT (/,' * ATTN * CAPACITY OF HEAT SOURCE ARRAYS EXCEEDED.',/,
     .       ' DATA FOR HEAT',/,' SOURCE ',I4,' IN THE TIME TABLE ',
     .       'IGNORED.',/)
C
      END
