
C
C
      SUBROUTINE RGLT
C
C     ------------------------------------------------------------------
C
C       SUBROUTINE PURPOSE:
C       CALCULATION OF VENTILATION RESISTANCES OF REGULATORS REQUIRED
C     BY THE USER-SPECIFIED AIRFLOW RATES IN THE AIRWAYS.
C
C     ------------------------------------------------------------------
C
      INCLUDE 'CMMNW.DAT'
C
      MBEGW=1
      DO 20 K=1,MNO
         DPSUM=0.
         MENDW=MEND(K)
         NX=MSL(MBEGW)
         IF (NX.LT.0) NX=-NX
C
C       NWTYP(I)=-1 INDICATES THAT AIRWAY NO(I) IS A FIXED QUANTITY
C     AIRWAY SPECIFIED BY USER. AFTER THE RESISTANCE OF REGULATOR
C     IS DETERMINED, THE AIRWAY TYPE WILL BE TURNED INTO THE
C     CATAGORY OF "REGULAR AIRWAY" (NWTYP(I)=0) OR A "FAN BRANCH"
C     IN THIS SUBROUTINE.
C
         IF (NWTYP(NX).LT.0) THEN
            M=MBEGW+1
            DO 10 J=M,MENDW
               IF (MSL(J).GT.0) THEN
                  N=MSL(J)
                  FACT=1.
               ELSE
                  N=-MSL(J)
                  FACT=-1.
               ENDIF
               IF (NWTYP(N).EQ.1) THEN
                  DP=-R(N)
               ELSE
                  DP=R(N)*Q(N)*ABS(Q(N))*1.E-10
               ENDIF
               DPSUM=DPSUM+DP*FACT
10          CONTINUE
            IF (NVPN.GT.0) DPSUM=DPSUM-FNVP(K)
C
C     RSTD(I): VENTILATION RESISTANCE OF AIRWAY NO(I) AT THE REFERENCE
C              TEMP.
C     R(I): RESISTANCE OF AIRWAY NO(I) AT THE MEAN TEMP. IN AIRWAY.
C
            RSTD(NX) =-DPSUM*1.E10/(Q(NX)*Q(NX))
            R(NX)=RSTD(NX)
            IF (R(NX).LT.0.0) THEN
               R(NX)=DPSUM
               RSTD(NX)=R(NX)
               NWTYP(NX)=1
               WRITE (8,30) R(NX),NO(NX)
            ELSE
               NWTYP(NX)=0
               IF (MARKY.LE.0) WRITE (8,40) R(NX),NO(NX)
            ENDIF
         ENDIF
         MBEGW=MENDW+1
20    CONTINUE
C
30    FORMAT (//,' * ATTN * A FAN WITH CONST. PRESSURE',F6.3,' IN.W.G.'
     .        ,/,' IS INSTALLED IN PREVIOUSLY FIXED-Q AIRWAY',I6)
40    FORMAT (//,1X,'* ATTN * RESISTANCE OF ',E10.3,' IN.W.G./CFM2',/,
     .        ' IS PROVIDED TO PREVIOUSLY FIXED-Q AIRWAY ',I5)
C
      RETURN
      END
