*APP PRC01
      SUBROUTINE INITAL
C...
C...  SIMULATION OF A LINEAR SYSTEM WITH A TIME DELAY
C...
C...  THE DIFFERENTIAL EQUATIONS FOR TWO CSTR*S WITH A LONG CONNECTING
C...  LINE ARE
C...
C...  DCA1/DT = (F0/V1)*CA0 - (F0/V1+K)*CA1, CA1(0) = 0        (1)(2)
C...
C...  DCA2/DT = (F0/V2)*CA1(T-D) - (F0/V2+K)*CA2, CA2(0) = 0   (3)(4)
C...
C...  WHERE
C...
C...     CA1     CONCENTRATION IN THE FIRST AND SECOND CSTR*S
C...     CA2     RESPECTIVELY
C...
C...     CA0     CONCENTRATION ENTERING THE FIRST CSTR
C...
C...     F0      FLOW RATE THROUGH THE SYSTEM
C...
C...     V1      VOLUMES OF THE FIRST AND SECOND CSTR*S, RESPECTIVELY
C...     V2      (V1 = V2 = V)
C...
C...     K       RATE CONSTANT FOR A FIRST-ORDER REACTION IN THE TWO
C...             CSTR*S
C...
C...     D       PURE TIME DELAY PRODUCED BY THE FLOW THROUGH THE LONG
C...             CONNECTING PIPE
C...
C...     T       TIME
C...
C...  THE NUMERICAL SOLUTION COMPUTED BY THE FOLLOWING CODE IS TO BE
C...  COMPARED WITH THE FOLLOWING ANALYTICAL SOLUTION TO EQUATIONS (1)
C...  TO (4) (WHICH CAN BE DERIVED BY THE LAPLACE TRANSFORM)
C...
C...  CA2(T) = C1*U(T-D)*(1 - EXP(-C2*(T-D)) - C3*EXP(-C2*(T-D)))
C...
C...     C1 = (F0/(F0+V*K))**2, C2 = (F0/V+K), C3 = (F0+V*K)
C...
C...            0, T LE 0
C...     U(T) =            (UNIT STEP FUNCTION)
C...            1, T GT 0
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
C...
C...  SET THE MODEL CONSTANTS
      F0=0.1
      V=1.
      D=5.
      K=0.1
      CA0=1.
      C1=(F0/(F0+V*K))**2
      C2= F0/V+K
      C3= F0+V*K
      F0V=F0/V
      IS=0
C...
C...  SET THE INITIAL CONDITIONS
      CA1=0.
      CA2=0.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
C...
C...  DIFFERENTIAL EQUATIONS
      DCA1DT=F0V*CA0-(F0V+K)*CA1
      DCA2DT=F0V*CA1D(T-D)-(F0V+K)*CA2
      RETURN
      END
      FUNCTION CA1D(DT)
C...
C...  FUNCTION CA1D SIMULATES THE PURE TIME DELAY
C...
      COMMON/DELAY/CA1S(2,161)
      COMMON/C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
C...
C...  IF THE DELAYED TIME IS NEGATIVE, THE OUTPUT OF THE TIME DELAY
C...  IS THE INITIAL CONDITION (ZERO IN THE CASE OF EQUATIONS (2) AND
C...  (4))
      IF(DT.GT.0.)GO TO 1
      CA1D=0.
      RETURN
C...
C...  IF THE DELAYED TIME IS NONNEGATIVE, THE DELAYED VARIABLE IS
C...  IN ARRAY CA1S WHICH TO THIS POINT IN TIME HAS BEEN FILLED
C...  IN SUBROUTINE PRINT WITH THE SECOND SUBSCRIPT EQUAL TO IS, I.E.,
C...  THE CURRENT VALUE OF T CORRESPONDS TO IS FOR THE SECOND SUBSCRIPT
1     DO 2 I=1,IS
C...
C...  IF THE DELAYED TIME EXCEEDS THE STORED TIME CA1S(1,I), THE SEARCH
C...  IN THE ARRAY CA1S CONTINUES UNTIL THE DELAYED TIME IS LESS THAN
C...  THE STORED TIME.  FOR THIS LATTER CONDITION, THE DELAYED VARIABLE
C...  (CA1D) EQUALS THE STORED VARIABLE (CA1S(2,I))
      IF(DT.GE.CA1S(1,I))CA1D=CA1S(2,I)
C...
C...  SINCE THE DELAYED VARIABLE HAS BEEN DEFINED, THE SEARCH NEED NOT
C...  CONTINUE
C...  IF(DT.LT.CA1S(1,I))RETURN
2     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
      COMMON/DELAY/CA1S(2,161)
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(41), CP(2,41)
      DATA IP/0/
C...
C...  STORE THE CURRENT VALUES OF T AND CA1 IN ARRAY CA1S FOR USE IN
C...  FUNCTION CA1D
      IS=IS+1
      CA1S(1,IS)=T
      CA1S(2,IS)=CA1
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS EVERY FOURTH CALL
C...  TO SUBROUTINE PRINT
      IF(((IS-1)/4*4).NE.(IS-1))RETURN
C...
C...  EVALUATE CA1(T-D) FOR PRINTING
      DELAY=CA1D(T-D)
C...
C...  EVALUATE THE ANALYTICAL SOLUTION TO EQUATIONS (1) TO (4) FOR
C...  PRINTING AND PLOTTING
      IF((T-D).LE.0.)CA2A=0.
      IF((T-D).GT.0.)CA2A=C1*(1.-EXP(-C2*(T-D))-C3*(T-D)*EXP(-C2*(T-D)))
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(9X,1HT,9X,3HCA1,5X,8HCA1(T-D),8X,3HCA2,4X,10HCA2 (ANAL))
      WRITE(NO,1)T,CA1,DELAY,CA2,CA2A
1     FORMAT(F10.2,4F12.4)
C...
C...  STORE THE NUMERICAL AND ANALYTICAL SOLUTIONS FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      CP(1,IP)=CA2
      CP(2,IP)=CA2A
C...
C...  PLOT THE NUMERICAL AND ANALYTICAL SOLUTIONS FOR COMPARISON
      IF(IP.LT.41)RETURN
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER PLOTTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,CP,IP,3H*T*,16H*CA2, CA2(ANAL)*,2H**,2)
C...
C...  ******************************************************************
C...
      IP=0
      RETURN
      END
SIMULATION OF A LINEAR SYSTEM WITH A TIME DELAY
0.        40.       0.25
    2 1000    1    1  ABS 0.0001
END OF RUNS
*APP PRC02
      SUBROUTINE INITAL
C...
C...  PROPORTIONAL-INTEGRAL CONTROL OF A HUMIDIFICATION COLUMN
C...
C...  A HUMIDIFICATION COLUMN (A PACKED COLUMN WITH WATER FLOWING DOWN
C...  AND AIR FLOWING UP) IS DIAGRAMMED BELOW
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE VARIABLES AND PARAMETERS FOR THIS SYSTEM ARE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     ZL      LENGTH OF THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...  THE DEPENDENT VARIABLES OF PARTICULAR INTEREST ARE Y(Z,T), TG(Z,T)
C...  TL(Z,T).  IN ORDER TO COMPUTE THESE VARIABLES, BASIC CONSERVATION
C...  PRINCIPLES ARE APPLIED TO THE AIR AND WATER STREAMS WITHIN THE
C...  COLUMN OVER THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE DIAGRAM)
C...  AND THEN THE LIMIT OF DZ ---+ 0 GIVES THE MODEL DIFFERENTIAL EQUA-
C...  TIONS.  SINCE THE MODEL IS DYNAMIC, TIME, T, AND AXIAL POSITION,
C...  Z, APPEAR IN THE EQUATIONS AS INDEPENDENT VARIABLES AND THEREFORE
C...  PARTIAL DIFFERENTIAL EQUATIONS (PDES) MUST BE USED.
C...
C...  THE PDES ARE DERIVED AS FOLLOWS.  A H20 BALANCE ON THE GAS PHASE
C...  GIVES
C...
C...     (Y*G*S*DZ)  = V*Y  - V*Y     + KY*AV*(YS - Y)*S*DZ     (1A)
C...               T      Z      Z+DZ
C...
C...  WHERE THE SUBSCRIPT T ON THE LHS DENOTES A PARTIAL DERIVATIVE WITH
C...  RESPECT TO TIME, T.
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (1A) IS INDICATED BELOW
C...
C...     (Y*G*S*DZ)
C...               T
C...
C...        = (MOLS H20/MOL DRY AIR)*(MOLS DRY AIR/CM**3)*(CM**2)*
C...          CM*(1/HR) = MOLS H20/HR ACCUMULATING IN THE GAS PHASE
C...          WITHIN THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE
C...          DIAGRAM BELOW)
C...
C...     V*Y
C...        Z
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DRY AIR) = MOLS H20/HR
C...          FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     V*Y
C...        Z+DZ
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DAY AIR) = MOLS H20/HR
C..           FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     KY*AV*(YS - Y)*S*DZ
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...           AIR)*(CM**2)*(CM) = MOLS H20/HR TRANSFERRED TO OR FROM
C...           THE AIR STREAM IN THE INCREMENTAL SECTION (THE DIRECTION
C...           OF TRANSFER DEPENDS ON THE SIGN OF (YS - Y))
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (1A) BECOMES
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                (1)
C...      T                Z
C...
C...  AN ENERGY BALANCE ON THE GAS PHASE GIVES
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))*G*S*DZ)  =
C...                                          T
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V  -
C...                                    Z                       (2A)
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V     -
C...                                    Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ + KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (2A) IS INDICATED BELOW
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))G*S*DZ
C...                                        T
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/
C...          CM**3)*(CM**2)*CM*(1/HR) = CAL/HR ACCUMULATING IN THE
C...          GAS PHASE WITHIN THE INCREMENTAL SECTION
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z+DZ
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (2A) BECOMES
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                    (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THERE THE ENERGY GROUPS, EV (ENERGY AT CONSTANT VOLUME) AND EP
C...  (ENERGY AT CONSTANT PRESSURE) HAVE BEEN USED TO SIMPLIFY THE
C...  TERMS IN EQUATION (2).  EV AND EP ARE DEFINED IN THE TABLE OF
C...  NOMENCLATURE GIVEN EARLIER.
C...
C...  AN ENERGY BALANCE ON THE LIQUID GIVES
C...
C...     (CL*TL*H*S*DZ)  = (CL*TL*L)     - (CL*TL*L)
C...                   T            Z+DZ            Z           (3A)
C...
C...     -H*AV*(TL - TG)*S*DZ - KY(AV*(YS - Y)*S*DZ*(CVV*TG + HDVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (3A) IS GIVEN BELOW
C...
C...     (CL*TL*H*S*DZ)
C...                   T
C...
C...        (CAL/MOL H20-C)*(C)*(MOLS H20/CM**3)*(CM**2)*CM*(1/HR)
C...        = CAL/HR ACCUMULATING IN THE H20 PHASE WITHIN THE
C...        INCREMENTAL SECTION OF LENGTH DZ
C...
C...     (CL*TL*L)
C...              Z+DZ
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING INTO
C...          THE INCREMENTAL SECTION AT Z+DZ
C...
C...     (CL*TL*L)
C...              Z
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING OUT OF
C...          THE INCREMENTAL SECTION AT Z
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (3A) BECOMES
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                    (3)
C...
C...            - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  AN EXTENSION OF THE PRECEDING SYSTEM IS ALSO SIMULATED IN THE
C...  FOLLOWING CODING.  SPECIFICALLY, THE EXITING WATER TEMPERATURE
C...  TL(0,T), IS SENSED, COMPARED WITH A SET POINT VALUE, TLSET,
C...  AND THE DIFFERENCE (ERROR), E = TL(0,T) - TLSET, IS USED TO
C...  ADJUST THE ENTERING AIR FLOW RATE, V, TO MOVE TL(0,T) TO TLSET.
C...  THE ADJUSTMENT OF V IS ACHIEVED WITH A PROPORTIONAL-INTEGRAL (PI)
C...  CONTROLLER.  THE FOLLOWING DIAGRAM ILLUSTRATES THE CONTROLLER
C...  AT THE BOTTOM OF THE HUMIDIFICATION COLUMN
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +             PI
C...                          .           .         CONTROLLER
C...                          .           .          .........
C...            TEMPERATURE .....         .          .       .
C...              SENSOR    .   .......... ........... KC,TI .+--- TLSET
C...                        .....         .          .       .
C...                          .           .          .........
C...                          .           .              .
C...                          .          ...   ..        .
C...                          .           ...... .........
C...                          .          ...   ..
C...                          .           . CONTROL VALVE
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE PURPOSE OF THE SIMULATION IS ESSENTIALLY TO DETERMINE, THE
C...  VALUES OF THE CONTROLLER GAIN, KC, AND INTEGRAL TIME, TI, SO
C...  THAT THE EXITING LIQUID TEMPERATURE, TL(0,T), IS CONTROLLED CLOSE
C...  TO THE SET POINT, TLSET.
C...
C...  THE CONTROLLER EQUATIONS ARE
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TLSET
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TLSET   CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS IN ENGLISH UNITS ARE
C...  LISTED BELOW, FOLLOWED BY EQUIVALENT VALUES IN METRIC UNITS.  THE
C...  CAN BE EXECUTED WITH EITHER SET BY SELECTING THE VALUE OF THE
C...  VARIABLE METRIC IN THE PROGRAM (METRIC = 0 FOR ENGLISH UNITS,
C...  METRIC = 1 FOR METRIC UNITS)
C...
C...  ******************************************************************
C...
C...   ENGLISH UNITS
C...
C...   H*AV = 50 BTU/(HR-FT**3-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2
C...
C...   H = 0.5 LB MOLS/FT**3 , G = 0.01 LB MOLS/FT**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TLSET = 90 F
C...
C...  ******************************************************************
C...
C...   METRIC UNITS
C...
C...   H*AV = 0.8015 CAL/(HR-CM**3-C)
C...
C...   KY*AV = 0.06573 GM MOLS DRY AIR/(HR-CM**3)
C...
C...   Z = 243.8 CM, CL = 18 CAL/(GM MOL-C), DHVAP = 9443.6 CAL/GM MOL
C...
C...   CPV = 7.3 CAL/(GM MOL-C), CPA = 7.3 CAL/(GM MOL-C)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   L = 22700 GM MOLS/HR, S = 929.03 CM**2
C...
C...   H = 0.008015 GM MOLS/CM**3, G = 0.0001603 GM MOLS/CM**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + 1.8*TL + 32)) MM HG
C...                                                    (TL IS IN C)
C...
C...   YS = P/(760 - P) GM MOLS H20/GM MOL DRY AIR
C...
C...   TG(0,T) = 43.33 C, TL(8,T) = 43.33 C, Y(0,T) = 0.01 GM MOL H20/
C...                                                  GM MOL DRY AIR)
C...
C...   TG(Z,0) = TL(Z,0) = 43.33 C, Y(Z,0) = 0.01
C...
C...   KC = 0.036 (1/C), TI = 0.1 HR, CV*(DP**0.5) = 22700 GM MOLS/HR
C...
C...   XSS = 0.5, TLSET = 32.22 C
C...
C...  ******************************************************************
C...
C...  THE CONVERSION FACTORS USED TO GO FROM ONE SET OF UNITS TO THE
C...  OTHER ARE
C...
C...     1 BTU = 252.2 CAL
C...
C...     1 BTU/LB MOL-F = 1 CAL/GM MOL-C
C...
C...     1 LB = 454 GM
C...
C...     1 LB MOL = 454 GM MOL
C...
C...     1 F = 1/1.8 C
C...
C...     1 FT = 30.48 CM
C...
C...     1 FT**3 = 28316.8 CM**3
C...
C...     TF = 1.8*TC + 32
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  SELECT ENGLISH (METRIC = 0) OR METRIC (METRIC = 1) UNITS
      IF(NORUN.EQ.1)METRIC=0
      IF(NORUN.EQ.2)METRIC=1
C...
C...  SET THE MODEL PARAMETERS IN THE UNITS SELECTED
C...
C...  ENGLISH UNITS
      IF(METRIC.EQ.0)THEN
      N=11
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.02
      TI=0.1
      CVDP=50.
      XSS=0.5
      TLSET=90.
C...
C...  METRIC UNITS
      ELSE
      N=11
      L=22700.
      G=0.0001603
      H=0.008015
      HLAV=0.8015
      KYAV=0.06573
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=243.8
      DHVAP=9443.6
      S=929.03
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.036
      TI=0.1
      CVDP=22700.
      XSS=0.5
      TLSET=32.22
      END IF
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      IF(METRIC.EQ.0)THEN
      TL(I)=110.
      TG(I)=110.
      ELSE
      TL(I)=43.33
      TG(I)=43.33
      END IF
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TLSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      IF(METRIC.EQ.0)THEN
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      ELSE
      P=10.**(7.96681-3002.4/(378.4+1.8*TL(I)+32.))
      END IF
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      IF(METRIC.EQ.0)THEN
      TL(N)=110.
      TG(1)=110.
      ELSE
      TL(N)=43.33
      TG(1)=43.33
      END IF
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
C...
C...  ZERO THE TIME DERIVATIVES TO MAINTAIN THE BOUNDARY CONDITIONS
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  ABSOLUTE DIMENSIONING OF THE ARRAYS REQUIRED BY SUBROUTINE JMAP
C...  (A, Y, YOLD, F, FOLD) AND SUBROUTINE EIGEN (WI, WR, Z, RW, IW)
      REAL
     1       A( 34, 34), WR( 34), WI( 34), Z( 34, 34), RW( 34),
     2                            SV( 34), SVOLD( 34),
     3                             F( 34),  FOLD( 34)
      INTEGER                     IW( 34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  PRINT A DETAILED SOLUTION (THE INDIVIDUAL TERMS IN THE PDES AND
C...  THE DEPENDENT VARIABLES) FOR IP = 1, 51, 101 CALLS TO SUBROUTINE
C...  PRINT.  FIRST, UPDATE ALL OF THE MODEL CALCULATIONS BY A CALL
C...  TO SUBROUTINE DERV (THE INITIAL-VALUE INTEGRATION THROUGH COMMON
C...  /Y/ AND /F/ IS DONE CORRECTLY WITHOUT THIS UPDATE, BUT SOME OF THE
C...  MODEL VARIABLES MAY BE ONE INTEGRATION TIME STEP BEHIND IN TIME,
C...  T, WHEN THEY ARE PRINTED OUT IN SUBROUTINE PRINT IF THE FOLLOWING
C...  CALL TO SUBROUTINE DERV IS NOT EXECUTED)
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  ***************************************************************
C...  GAS-PHASE MATERIAL BALANCE
C...  ************************************************************(1)
C...
C...     -(V/(G*S))*Y
C...                 Z
         DO 1 I=1,N
         TEP(I)=-P1*EPZ(I)
1        CONTINUE
         N2=1
         WRITE(NO,2)T,(TEP(I),I=1,N,N2)
2        FORMAT( 1H1,5H T = ,F7.3,//,
     1          25H -(V/(G*S))*YZ           ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(2)
C...
C...     (KY*AV/G)*(YS - Y)
         DO 3 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
3        CONTINUE
         WRITE(NO,4)(TEP(I),I=1,N,N2)
4        FORMAT(25H (KA*AV/G)*(YS - Y)      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(3)
C...
C...     Y
C...      T
         WRITE(NO,5)(YT(I),I=1,N,N2)
5        FORMAT(25H YT                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(4)
C...
C...     Y
         WRITE(NO,6)(Y(I),I=1,N,N2)
6        FORMAT(25H Y                       ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  EQUILIBRIUM RELATIONSHIP
C...  ************************************************************(5)
C...
C...     YS
         WRITE(NO,7)(YS(I),I=1,N,N2)
7        FORMAT(25H YS                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  GAS-PHASE ENERGY BALANCE
C...  ************************************************************(6)
C...
C...     -(V/(G*S))*EP  = -(V/(G*S))*(CPA*TG + Y*(CPV*TG + DHVAP))
C...                  Z                                           Z
         DO 8 I=1,N
         TEP(I)=-P1*EPZ(I)
8        CONTINUE
         WRITE(NO,9)(TEP(I),I=1,N,N2)
9        FORMAT(25H -(V/(G*S))*EPZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(7)
C...
C...     (H*AV/G)*(TL - TG)
         DO 10 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
10       CONTINUE
         WRITE(NO,11)(TEP(I),I=1,N,N2)
11       FORMAT(25H -(H*AV/G)*(TL - TG)     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(8)
C...
C...     (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
         DO 12 I=1,N
         TEP(I)=-P2*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
12       CONTINUE
         WRITE(NO,13)(TEP(I),I=1,N,N2)
13       FORMAT(25H (KY*AV/G)*(YS - Y)*(...),5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(9)
C...
C...     EV  = (CVA*TG + Y*(CVV*TG + DHVAP))
C...       T                                T
         WRITE(NO,14)(EVT(I),I=1,N,N2)
14       FORMAT(25H EVT                     ,5E12.4,/,13X,6E12.4,//)
C...  ************************************************************(10)
C...
C...     TG
         WRITE(NO,15)(TG(I),I=1,N,N2)
15       FORMAT(25H TG                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...  LIQUID-PHASE ENERGY BALANCE
C...  ************************************************************(11)
C...
C...     -(L/(H*S))*TL
C...                  Z
         DO 16 I=1,N
         TEP(I)=P4*TLZ(I)
16       CONTINUE
         WRITE(NO,17)(TEP(I),I=1,N,N2)
17       FORMAT(25H -(L/(H*S))*TLZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(12)
C...
C...     -(H*AV/(CL*H))*(TL - TG)
         DO 18 I=1,N
         TEP(I)=-P5*(TL(I)-TG(I))
18       CONTINUE
         WRITE(NO,19)(TEP(I),I=1,N,N2)
19       FORMAT(25H -(H*AV/(CL*H))*(TL-TG)  ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(13)
C...
C...     -(KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
         DO 20 I=1,N
         TEP(I)=-P6*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
20       CONTINUE
         WRITE(NO,21)(TEP(I),I=1,N,N2)
21       FORMAT(25H -(KY*AV/(CL*H))*(YS-Y)..,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(14)
C...
C...     TL
C...       T
         WRITE(NO,22)(TLT(I),I=1,N,N2)
22       FORMAT(25H TLT                     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(15)
C...
C...     TL
         WRITE(NO,23)(TL(I),I=1,N,N2)
23       FORMAT(25H TL                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,WR,WI,Z,RW,IW)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
PI CONTROL OF A HUMIDIFICATION COLUMN - ENGLISH UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
PI CONTROL OF A HUMIDIFICATION COLUMN - METRIC UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP PRC03
      SUBROUTINE INITAL
C...
C...  CONTROL OF A DEISOBUTANIZER
C...
C...  THIS SIMULATION INCLUDES THE FOLLOWING DETAILS
C...
C...     (1)  FOUR COMPONENTS - (1) PROPANE
C...                            (2) ISOBUTANE
C...                            (3) NORMAL BUTANE
C...                            (4) OCTANE
C...
C...     (2)  NONLINEAR, BUT IDEALIZED VAPOR-LIQUID EQUILBRIUM
C...          RELATIONSHIPS
C...
C...     (3)  PRINCIPAL HEAT EFFECTS
C...
C...     (4)  TRAY HYDRAULICS
C...
C...     (5)  FEEDBACK CONTROL OF THE REFLUX
C...
C...  THE EQUATIONS WHICH MODEL THE DEISOBUTANIZER ARE SUMMARIZED BELOW
C...  FOLLOWED BY A TABLE OF NOMENCLATURE WHICH DEFINES THE SYSTEM
C...  VARIABLES
C...
C...  (1)  REBOILER (REBOILER HOLDUP, XMB, ASSUMED CONSTANT)
C...
C...       (1.1)  HEAT BALANCE
C...
C...       VB = (QB - XL(1)*(HLIQB - HLIQ(1)))/(HVAPB - HLIQB)       (1)
C...
C...       (1.2)  TOTAL MATERIAL BALANCE
C...
C...       B = XL(1) - VB                                            (2)
C...
C...       (1.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DXB(J)/DT = (XL(1)*X(1,J) - VB*YB(J) - B*XB(J))/XMB       (3)
C...
C...  (2)  TRAY 1
C...
C...       (2.1)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(1) = (VB*HVAPB + XL(2)*HLIQ(2) - XL(1)*HLIQ(1))/HVAP(1) (4)
C...
C...       (2.2)  TOTAL MATERIAL BALANCE
C...
C...       DM(1)/DT = XL(2) - XL(1) + VB - V(1)                      (5)
C...
C...       (2.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(1,J)/DT = XL(2)*X(2,J) - XL(1)*X(1,J) +
C...                                                                 (6)
C...                     VB*YB(J)     - V(1)*Y(1,J)
C...
C...  (3)  STRIPPING SECTION (2 LE N LE 18)
C...
C...       (3.1)  HEAT BALANCES (TIME DERIVATIVES NEGLECTED)
C...
C...       V(N) = (V(N-1)*HVAP(N-1) + XL(N+1)*HLIQ(N+1) -
C...                                                                 (7)
C...              XL(N)*HLIQ(N))/HVAP(N)
C...
C...       (3.3)  TOTAL MATERIAL BALANCES
C...
C...       DM(N)/DT = XL(N+1) - XL(N) + V(N-1) - V(N)                (8)
C...
C...       (3.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(N,J)/DT = XL(N+1)*X(N+1,J) - XL(N)*X(N,J) +
C...                                                                 (9)
C...                     V(N-1)*Y(N-1,J)  - V(N)*Y(N,J)
C...
C...  (4)  FEED PLATE (NF = 19)
C...
C...       (4.1)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(NF) = (V(NF-1)*HVAP(NF-1) + XL(NF+1)*HLIQ(NF+1) -
C...                                                                (10)
C...               XL(NF)*HLIQ(NF)     + FL*HLF)/HVAP(NF)
C...
C...       (4.2)  TOTAL MATERIAL BALANCE
C...
C...       DM(NF)/DT = XL(NF+1) - XL(NF) + V(NF-1) - V(NF) + FL     (11)
C...
C...       (4.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(NF,J)/DT = XL(NF+1)*X(NF+1,J) - XL(NF)*X(NF,J) +
C...
C...                      V(NF-1)*Y(NF-1,J)  - V(NF)*Y(NF,J) +      (12)
C...
C...                      FL*XF(J)
C...
C...  (5)  RECTIFYING SECTION (20 LE N LE 24)
C...
C...       (5.1)  HEAT BALANCES (TIME DERIVATIVES NEGLECTED)
C...
C...       V(N) = (V(N-1)*HVAP(N-1) + XL(N+1)*HLIQ(N+1) -
C...                                                                (13)
C...              XL(N)*HLIQ(N))/HVAP(N)
C...
C...       (5.2)  TOTAL MATERIAL BALANCES
C...
C...       DM(N)/DT = XL(N+1) - XL(N) + V(N-1) - V(N)               (14)
C...
C...       (5.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(N,J)/DT = XL(N+1)*X(N+1,J) - XL(N)*X(N,J) +
C...                                                                (15)
C...                     V(N-1)*Y(N-1,J)  - V(N)*Y(N,J)
C...
C...  (6)  TOP TRAY
C...
C..        (6.1)  ERROR FOR THE PROPORTIONAL-INTEGRAL CONTROLLER
C...              BASED ON THE MEASUREMENT OF PLATE 21 TEMPERATURE
C...
C...       ERROR = T0(21) - T(21)                                   (16)
C...
C...       (6.2)  MANIPULATION OF REFLUX RATE BY PROPORTIONAL-INTEGRAL
C...              CONTROLLER
C...
C...       R = R0 - XKC*(ERROR + ERINT/TAU1)
C...
C...       (6.3)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(NT) = (V(NT-1)*HVAP(NT-1) + R*HLIQD -
C...                                                                (18)
C...               XL(NT)*HLIQ(NT))/HVAP(NT)
C...
C...       (6.4)  TOTAL MATERIAL BALANCE
C...
C...       DM(NT)/DT = R - XL(NT) + V(NT-1) - V(NT)                 (19)
C...
C...       (6.5)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(NT,J)/DT = R*XD(J)           - XL(NT)*X(NT,J) +
C...                                                                (20)
C...                      V(NT-1)*Y(NT-1,J) - V(NT)*Y(NT,J)
C...
C...  (7)  CONDENSER (CONDENSER HOLDUP, XMD, ASSUMED CONSTANT)
C...
C...       (7.1)  HEAT BALANCE
C...
C...       QD = V(NT)*(HVAP(NT) - HLIQD)                            (21)
C...
C...       (7.2)  TOTAL MATERIAL BALANCE
C...
C...       D = V(NT) - R
C...
C...       (7.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DXD(J)/DT = V(NT)*(Y(NT,J) - XD(J))/XMD                  (23)
C...
C...  (8)  LIQUID PHASE COMPOSITIONS (1 LE N LE 25, J = 1, 2, 3, 4)
C...
C...       X(N,J) = XMX(N,J)/XM(N)
C...
C...  (9)  EQUILBRIUM VAPOR COMPOSITIONS
C...
C...       (9.1)  REBOILER
C...
C...       YB = EQUIL(XB,TB)                                        (25)
C...
C...       (9.2)  TRAYS (1 LE N LE 25)
C...
C...       YY = EQUIL(XX,T(N))                                      (26)
C...
C... (10)  LIQUID ENTHALPIES
C...
C...       (10.1)  REBOILER
C...
C...       HLIQB = ENTHL(XB,TB)                                     (27)
C...
C...       (10.2)  TRAYS (1 LE N LE 25)
C...
C...       HLIQ(N) = ENTHL(XX,T(N))                                 (28)
C...
C...       (10.3)  CONDENSER
C...
C...       HLIQD = ENTHL(XD,TD)                                     (29)
C...
C...       (10.4)  FEED
C...
C...       HLF = ENTHL(XF,TF)                                       (30)
C...
C... (11)  VAPOR ENTHALPIES
C...
C...       (11.1)  REBOILER
C...
C...       HVAPB = ENTHV(YB,TB)                                     (31)
C...
C...       (11.2)  TRAYS (1 LE N LE 25)
C...
C...       HVAP(N) = ENTHV(YY,T(N))                                 (32)
C...
C... (12)  TRAY HYDRAULICS
C...
C...       (12.1)  STRIPPING SECTION (1 LE N LE 19)
C...
C...       XL(N) = 1800*(XM(N)/127.0 - 0.1667)**(3/2)               (33)
C...
C...       (12.1)  RECTIFYING SECTION (20 LE N LE 25)
C...
C...       XL(N) = 1200*(XM(N)/127.0 - 0.1667)**(3/2)               (34)
C...
C...
C...  TABEL OF NOMENCLATURE
C...
C...     B          BOTTOMS FLOW RATE (MOLES/MIN)
C...
C...     D          DISTILLATE FLOW RATE (MOLES/MIN)
C...
C...     DM(N)      TIME DERIVATIVE OF TOTAL LIQUID MOLAR FLOW RATE ON
C...                NTH PLATE (= DM(N)/DT) (MOLES/MIN)
C...
C...     DMX(N,J)   TIME DERIVATIVE OF JTH COMPONENT LIQUID MOLAR
C...                HOLDUP ON NTH PLATE (I.E. PRODUCT OF JTH COMPONENT
C...                MOLE FRACTION AND TOTAL LIQUID MOLAR HOLDUP ON NTH
C...                PLATE) (= DMX(N,J)/DT) (MOLES/MIN)
C...
C...     DXB(J)     TIME DERIVATIVE OF JTH COMPONENT MOLE FRACTION IN
C...                BOTTOMS (= DXB(J)/DT) (1/MIN)
C...
C...     DXD(J)     TIME DERIVATIVE OF JTH COMPONENT MOLE FRACTION IN
C...                DISTILLATE (= DXD(J)/DT) (1/MIN)
C...
C...     ERINT      INTEGRATED OUTPUT ERROR FROM FEEDBACK CONTROLLER
C...                (F-MIN)
C...
C...     ERROR      OUTPUT ERROR FROM FEEDBACK CONTROLLER (F)
C...
C...     FL         FEED FLOW RATE (MOLES/MIN)
C...
C...     HLF        FEED ENTHALPY (BTU/MOLE)
C...
C...     HLIQB      BOTTOMS LIQUID ENTHALPY (BTU/MOLE)
C...
C...     HLIQD      DISTILLATE ENTHALPY (BTU/MOLE)
C...
C...     HLIQ(N)    ENTHALPY OF LIQUID FROM NTH PLATE (BTU/MOLE)
C...
C...     HVAPB      BOTTOMS EQUILIBRIUM VAPOR ENTHALPY (BTU/MOLE)
C...
C...     HVAP(N)    ENTHALPY OF VAPOR FROM NTH PLATE (BTU/MOLE)
C...
C...     J          INDEX INDICATING JTH COMPONENT (J = 1, 2, 3, 4)
C...
C...     N          INDEX INDICATING PLATE NUMBER
C...
C...     NF         NUMBER OF FEED PLATE
C...
C...     NT         TOTAL NUMBER OF PLATES IN COLUMN
C...
C...     QB         REBOILER HEAT DUTY (BTU/MIN)
C...
C...     QD         CONDENSER HEAT DUTY (BTU/MIN)
C...
C...     R          REFLUX FLOW RATE (MOLES/MIN)
C...
C...     RO         INITIAL REFLUX FLOW RATE (MOLES/MIN)
C...
C...     T(N)       EQUILIBRIUM TEMPERATURE ON NTH PLATE (F)
C...
C...     TAU1       INTEGRAL TIME OF FEEDBACK CONTROLLER (MIN)
C...
C...     TB         REBOILER TEMPERATURE (F)
C...
C...     TBO        INITIAL REBOILER TEMPERATURE (F)
C...
C...     TD         DISTILLATE TEMPERATURE (F)
C...
C...     TDO        INITIAL DISTILLATE TEMPERATURE (F)
C...
C...     TF         FEED TEMPERATURE (F)
C...
C...     TO(N)      INITIAL TEMPERATURE ON NTH PLATE (F)
C...
C...     V(N)       VAPOR FLOW RATE FROM NTH PLATE (MOLES/MIN)
C...
C...     VB         VAPOR FLOW RATE FROM REBOILER (MOLES/MIN)
C...
C...     X(N,J)     MOLE FRACTION OF JTH COMPONENT IN LIQUID ON NTH
C...                PLATE
C...
C...     XB(J)      MOLE FRACTION OF JTH COMPONENT IN REBOILER
C...
C...     XBO(J)     INITIAL MOLE FRACTION OF JTH COMPONENT IN REBOILER
C...
C...     XD(J)      MOLE FRACTION OF JTH COMPONENT IN CONDENSER
C...
C...     XDO(J)     INITIAL MOLE FRACTION OF JTH COMPONENT IN CONDENSER
C...
C...     XF(J)      MOLE FRACTION OF JTH COMPONENT IN FEED
C...
C...     XKC        GAIN OF FEEDBACK CONTROLLER (MOLES/(MIN-F))
C...
C...     XL(N)      MOLAR LIQUID FLOW RATE FROM NTH PLATE (MOLES/HR)
C...
C...     XLO(N)     INITIAL MOLAR LIQUID FLOW RATE FROMNTH PLATE
C...                (MOLES/MIN)
C...
C...     XM(N)      TOTAL MOLAR LIQUID HOLDUP ON NTH PLATE (MOLES)
C...
C...     XMB        TOTAL MOLAR LIQUID HOLDUP IN REBOILER (MOLES)
C...
C...     XMD        TOTAL MOLAR LIQUID HOLDUP IN CONDENSER (MOLES)
C...
C...     XMO(N)     INITIAL TOTAL MOLAR LIQUID HOLDUP ON NTH PLATE
C...                (MOLES)
C...
C...     XO(N,J)    INITIAL MOLE FRACTION OF JTH COMPONENT IN LIQUID
C...                ON NTH PLATE
C...
C...     XX(J)      ONE-DIMENSIONAL WORKING VECTOR OF LIQUID MOLE
C...                FRACTIONS USED FOR TEMPORARY STORAGE
C...
C...     Y(N,J)     MOLE FRACTION OF JTH COMPONENT IN VAPOR FROM NTH
C...                PLATE
C...
C...     YB(J)      MOLE FRACTION OF JTH COMPONENT IN VAPOR FROM
C...                REBOILER
C...
C...     YY(J)      ONE-DIMENSIONAL WORKING VECTOR OF VAPOR MOLE
C...                FRACTIONS USED FOR TEMPORARY STORAGE
C...
C...  /T/, /Y/ AND /F/ COMMON AREAS
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
C...
C...  COMMON TO PASS MODEL PARAMETERS, VARIABLES BETWEEN SUBROUTINES
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  COMMON AREA WITH THE INPUT/OUTPUT UNIT (DEVICE) NUMBERS
      COMMON/IO/NI,NO
C...
C...  THE MODEL PARAMETERS, INITIALIZED VARIABLES ARE SET IN A BLOCK
C...  DATA ROUTINE
C...
C...
C...  CALCULATE INITIAL PLATE HOLDUPS (XMO(N)) BY INVERTING EQUATIONS
C...  (33) AND (34)
      DO 2 N=1,NT
C...
C...  CONSTANT IN HYDRAULIC EQUATIONS (33) AND (34) IS 1800 AND 1200
C...  RESPECTIVELY
      CONST=1800.
      IF(N.GT.NF)CONST=1200.
2     XMO(N)=127.*((XLO(N)/CONST)**.667+.1667)
C...
C...  INITIALIZE BOTTOMS COMPOSITION (XB(J)), DISTILLATE COMPOSITION
C...  (XD(J))
      DO 6 J=1,4
      XB(J)=XBO(J)
6     XD(J)=XDO(J)
C...
C...  INITIALIZE ON EACH PLATE VAPOR FLOW (V(N)), LIQUID FLOW (XL(N)),
C...  TEMPERATURE (T(N)), TOTAL LIQUID HOLDUP (XM(N)), LIQUID COMPOSI-
C...  TION (X(N,J)), HOLDUP OF EACH COMPONENT (XMX(N,J))
      DO 8 N=1,NT
      V(N)=0.
      XL(N)=XLO(N)
      T(N)=TO(N)
      XM(N)=XMO(N)
      DO 8 J=1,4
      X(N,J)=XO(N,J)
8     XMX(N,J)=XM(N)*X(N,J)
C...
C...  INITIALIZE BOTTOMS TEMPERATURE (TB), DISTILLATE TEMPERATURE (TD),
C...  REFLUX RATIO (R), INTEGRATED ERROR FROM FEEDBACK CONTROLLER
C...  (ERINT)
      TB=TBO
      TD=TDO
      R=RO
      ERINT=1.0E-05
C...
C...  READ AND PRINT FEED PARAMETERS - TEMPERATURE (TF), COMPOSITION
C...  (XF(J)), FLOW RATE (FL)
       READ(NI,1)TF,(XF(J),J=1,4),FL
1     FORMAT(8E10.3)
      WRITE(NO,3)TF,(XF(J),J=1,4),FL
3     FORMAT(//,10X,15HFEED CONDITIONS,/,15X,14HTEMPERATURE = ,E10.3,/,
     115X,24HCOMPOSITION - PROPANE = ,E10.3,/,29X,12HISOBUTANE = ,E10.3,
     2/,29X,16HNORMAL BUTANE = ,E10.3,/,29X,9HOCTANE = ,E10.3,/,15X,
     47HFLOW = ,E10.3)
C...
C...  CALCULATE FEED ENTHALPY (HLF), EQUATION (30)
      CALL ENTHL(XF,TF,HLF)
C...
C...  READ AND PRINT CONTROLLER GAIN (XKC), CONTROLLER INTEGRAL TIME
C...  (TAU1)
       READ(NI,1)XKC,TAU1
      WRITE(NO,4)XKC,TAU1
4     FORMAT(//,10X,21HCONTROLLER PARAMETERS,/,15X,7HGAIN = ,E10.3,/,
     115X,16HINTEGRAL TIME = ,E10.3)
      RETURN
      END
      SUBROUTINE DERV
C...
C...  SUBROUTINE DERV INPUTS LIQUID COMPOSITIONS, TOTAL LIQUID HOLDUPS
C...  AND COMPONENT LIQUID HOLDUPS TO COMPUTE THE TIME DERIVATIVES OF
C...  THESE VARIABLES VIA THE ENTHALPY, TOTAL MOLAR AND COMPONENT MOLAR
C...  BALANCES FOR THE COLUMN
C...
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
      DIMENSION HLIQ(25),HVAP(25),Y(25,4),YB(4),YD(4),XX(4),YY(4)
C...
C...  CALCULATE THE LIQUID COMPOSITION ON EACH PLATE (X(N,J)), EQUATION
C...  (24)
      DO 1 N=1,NT
      DO 1 J=1,4
1     X(N,J)=XMX(N,J)/XM(N)
C...
C...  CALCULATE THE EQUILIBRIUM VAPOR COMPOSITION (YB), EQUATION (25),
C...  LIQUID ENTHALPY (HLIQB), EQUATION (27), AND VAPOR ENTHALPY
C...  (HVAPB), EQUATION (31), OF THE BOTTOMS
      CALL EQUIL(XB,TB,YB)
      CALL ENTHL(XB,TB,HLIQB)
      CALL ENTHV(YB,TB,HVAPB)
C...
C...  CALCULATE THE LIQUID ENTHALPY (HLIQD) OF THE DISTILLATE, EQUATION
C...  (29)
      CALL ENTHL(XD,TD,HLIQD)
C...
C...  PUT THE LIQUID COMPOSITION FOR EACH PLATE (X(N,J)) IN A ONE-
C...  DIMENSIONAL ARRAY (XX(J)) FOR CALCULATION OF THE EQUILBRIUM VAPOR
C...  COMPOSITION (YY(J) = Y(N,J)), EQUATION (26), LIQUID AND VAPOR
C...  ENTHALPHIES (HLIQ(N), HVAP(N)), EQUATIONS (28), (32)
      DO 20 N=1,NT
      DO 21 J=1,4
21    XX(J)=X(N,J)
      CALL EQUIL(XX,T(N),YY)
      DO 22 J=1,4
22    Y(N,J)=YY(J)
      CALL ENTHL(XX,T(N),HLIQ(N))
      CALL ENTHV(YY,T(N),HVAP(N))
20    CONTINUE
C...
C...  IF THE DYNAMIC LIQUID HEAD ON THE TRAYS IS NEGATIVE, SET THE HEAD
C...  TO ZERO BEFORE CALCULATING THE LIQUID FLOW RATES FROM THE PLATES
C...  ABOVE AND BELOW THE FEED PLATE, EQUATIONS (33), (34)
      DO 23 N=1,NF
      HEAD=XM(N)/127.-.1667
      IF(HEAD.LE.0.)HEAD=0.
23    XL(N)=1800.*HEAD**1.5
      NFP1=NF+1
      DO 24 N=NFP1,NT
      HEAD=XM(N)/127.-.1667
      IF(HEAD.LE.0.)HEAD=0.
24    XL(N)=1200.*HEAD**1.5
C...
C...
C...  REBOILER
C...     REBOILER VAPOR RATE (VB), EQUATION (1)
      VB=(QB-XL(1)*(HLIQB-HLIQ(1)))/(HVAPB-HLIQB)
C...
C...     BOTTOMS RATE (B), EQUATION (2)
      B=XL(1)-VB
      IF(B.LT.0.)B=0.
C...
C...     BOTTOMS COMPOSITION DERIVATIVES (DXB(J)), EQUATION (3)
      DO 30 J=1,4
30    DXB(J)=(XL(1)*X(1,J)-VB*YB(J)-B*XB(J))/XMB
C...
C...
C...  TRAY 1
C...     VAPOR RATE (V(1)), EQUATION (4)
      V(1)=(VB*HVAPB+XL(2)*HLIQ(2)-XL(1)*HLIQ(1))/HVAP(1)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(1)), EQUATION (5)
      DM(1)=XL(2)-XL(1)+VB-V(1)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(1,J)), EQUATION (6)
      DO 31 J=1,4
31    DMX(1,J)=XL(2)*X(2,J)-XL(1)*X(1,J)+VB*YB(J)-V(1)*Y(1,J)
C...
C...
C...  STRIPPING SECTION
      NFM1=NF-1
      DO 40 N=2,NFM1
C...
C...     VAPOR RATES (V(N)), EQUATION (7)
      V(N)=(V(N-1)*HVAP(N-1)+XL(N+1)*HLIQ(N+1)-XL(N)*HLIQ(N))/HVAP(N)
C...
C...     MOLAR HOLDUP DERIVATIVES (DM(N)), EQUATION (8)
      DM(N)=XL(N+1)-XL(N)+V(N-1)-V(N)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(N,J)), EQUATION (9)
      DO 40 J=1,4
40    DMX(N,J)=XL(N+1)*X(N+1,J)-XL(N)*X(N,J)+V(N-1)*Y(N-1,J)-V(N)*Y(N,J)
C...
C...
C...  FEED PLATE
C...     VAPOR RATE (V(NF)), EQUATION (10)
      V(NF)=(V(NF-1)*HVAP(NF-1)+XL(NF+1)*HLIQ(NF+1)-XL(NF)*HLIQ(NF)
     1+FL*HLF)/HVAP(NF)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(NF)), EQUATION (11)
      DM(NF)=XL(NF+1)-XL(NF)+V(NF-1)-V(NF)+FL
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(NF,J)), EQUATION (12)
      DO 50 J=1,4
50    DMX(NF,J)=XL(NF+1)*X(NF+1,J)-XL(NF)*X(NF,J)+V(NF-1)*Y(NF-1,J)
     1-V(NF)*Y(NF,J)+FL*XF(J)
C...
C...
C...  RECTIFYING SECTION
      NTM1=NT-1
      DO 60 N=NFP1,NTM1
C...
C...     VAPOR RATES (V(N)), EQUATION (13)
      V(N)=(V(N-1)*HVAP(N-1)+XL(N+1)*HLIQ(N+1)-XL(N)*HLIQ(N))/HVAP(N)
C...
C...     MOLAR HOLDUP DERIVATIVES (DM(N)), EQUATION (14)
      DM(N)=XL(N+1)-XL(N)+V(N-1)-V(N)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(N,J)), EQUATION (15)
      DO 60 J=1,4
60    DMX(N,J)=XL(N+1)*X(N+1,J)-XL(N)*X(N,J)+V(N-1)*Y(N-1,J)-V(N)*Y(N,J)
C...
C...
C...  TOP TRAY
C...     ERROR FOR PROPORTIONAL-INTEGRAL CONTROLLER (ERROR) BASED ON THE
C...     MEASUREMENT OF PLATE 21 TEMPERATURE (T(21)), EQUATION (16)
      ERROR=TO(21)-T(21)
C...
C...     MANIPULATION OF REFLUX RATE (R) BY CONTROLLER WITH GAIN XKC
C...     AND RESET TIME TAU1, EQUATION (17)
      R=RO-XKC*(ERROR+ERINT/TAU1)
C...
C...     VAPOR RATE (V(NT)), EQUATION (18)
      V(NT)=(V(NT-1)*HVAP(NT-1)+R*HLIQD-XL(NT)*HLIQ(NT))/HVAP(NT)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(NT)), EQUATION (19)
      DM(NT)=R-XL(NT)+V(NT-1)-V(NT)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(NT,J)), EQUATION (20)
      DO 70 J=1,4
70    DMX(NT,J)=R*XD(J)-XL(NT)*X(NT,J)+V(NT-1)*Y(NT-1,J)-V(NT)*Y(NT,J)
C...
C...
C...  CONDENSER
C...     CONDENSER HEAT DUTY (QD), EQUATION (21)
      QD=V(NT)*(HVAP(NT)-HLIQD)
C...
C...     DISTILLATE RATE (D), EQUATION (22)
      D=V(NT)-R
      IF(D.LT.0.)D=0.
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DXD(J)), EQUATION (23)
      DO 71 J=1,4
71    DXD(J)=V(NT)*(Y(NT,J)-XD(J))/XMD
      RETURN
      END
      BLOCK DATA
C...
C...  THE MODEL PARAMETERS, INITIALIZE VARIABLES ARE SET IN THIS BLOCK
C...  DATA ROUTINE
C...
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  INITIALIZE TOTAL NUMBER OF PLATES (NT), NUMBER OF FEED PLATE (NF)
      DATA NT,NF/25,19/
C...
C...  INITIALIZE REFLUX (RO), REBOILER HEAT DUTY (QB)
      DATA RO/8.580E+01/,QB/8.500E+05/
C...
C...  INITIALIZE BOTTOMS TEMPERATURE (TBO), BOTTOMS COMPOSITION (XBO),
C...  BOTTOMS FLOW (B), REBOILER HOLDUP (XMB)
      DATA TBO/1.780E+02/,XBO(1),XBO(2),XBO(3),XBO(4)/
     15.604E-09,9.910E-02,6.459E-01,2.550E-01/,B/9.471E+00/
     2,XMB/3.200E+02/
C...
C...  INITIALIZE TEMPERATURE (TO), LIQUID COMPOSITION (XO), LIQUID FLOW
C...  (XLO) FOR EACH PLATE
      DATA TO( 1)/1.502E+02/,XO( 1,1),XO( 1,2),XO( 1,3),XO( 1,4)/
     11.560E-08,1.487E-01,8.185E-01,3.280E-02/,XLO( 1)/1.100E+02/
      DATA TO( 2)/1.485E+02/,XO( 2,1),XO( 2,2),XO( 2,3),XO( 2,4)/
     13.568E-08,1.736E-01,8.058E-01,2.052E-02/,XLO( 2)/1.240E+02/
      DATA TO( 3)/1.479E+02/,XO( 3,1),XO( 3,2),XO( 3,3),XO( 3,4)/
     18.003E-08,1.985E-01,7.815E-01,1.999E-02/,XLO( 3)/1.248E+02/
      DATA TO( 4)/1.474E+02/,XO( 4,1),XO( 4,2),XO( 4,3),XO( 4,4)/
     11.782E-07,2.248E-01,7.553E-01,1.995E-02/,XLO( 4)/1.250E+02/
      DATA TO( 5)/1.469E+02/,XO( 5,1),XO( 5,2),XO( 5,3),XO( 5,4)/
     13.946E-07,2.524E-01,7.277E-01,1.992E-02/,XLO( 5)/1.251E+02/
      DATA TO( 6)/1.463E+02/,XO( 6,1),XO( 6,2),XO( 6,3),XO( 6,4)/
     18.694E-07,2.810E-01,6.991E-01,1.990E-02/,XLO( 6)/1.252E+02/
      DATA TO( 7)/1.458E+02/,XO( 7,1),XO( 7,2),XO( 7,3),XO( 7,4)/
     11.906E-06,3.103E-01,6.698E-01,1.987E-02/,XLO( 7)/1.253E+02/
      DATA TO( 8)/1.452E+02/,XO( 8,1),XO( 8,2),XO( 8,3),XO( 8,4)/
     14.158E-06,3.401E-01,6.401E-01,1.985E-02/,XLO( 8)/1.254E+02/
      DATA TO( 9)/1.446E+02/,XO( 9,1),XO( 9,2),XO( 9,3),XO( 9,4)/
     19.030E-06,3.699E-01,6.102E-01,1.982E-02/,XLO( 9)/1.255E+02/
      DATA TO(10)/1.440E+02/,XO(10,1),XO(10,2),XO(10,3),XO(10,4)/
     11.951E-05,3.995E-01,5.807E-01,1.979E-02/,XLO(10)/1.256E+02/
      DATA TO(11)/1.435E+02/,XO(11,1),XO(11,2),XO(11,3),XO(11,4)/
     14.197E-05,4.285E-01,5.517E-01,1.977E-02/,XLO(11)/1.258E+02/
      DATA TO(12)/1.429E+02/,XO(12,1),XO(12,2),XO(12,3),XO(12,4)/
     18.985E-05,4.565E-01,5.236E-01,1.974E-02/,XLO(12)/1.259E+02/
      DATA TO(13)/1.424E+02/,XO(13,1),XO(13,2),XO(13,3),XO(13,4)/
     11.915E-04,4.833E-01,4.968E-01,1.972E-02/,XLO(13)/1.260E+02/
      DATA TO(14)/1.419E+02/,XO(14,1),XO(14,2),XO(14,3),XO(14,4)/
     14.063E-04,5.087E-01,4.713E-01,1.969E-02/,XLO(14)/1.261E+02/
      DATA TO(15)/1.414E+02/,XO(15,1),XO(15,2),XO(15,3),XO(15,4)/
     18.583E-04,5.322E-01,4.473E-01,1.967E-02/,XLO(15)/1.263E+02/
      DATA TO(16)/1.409E+02/,XO(16,1),XO(16,2),XO(16,3),XO(16,4)/
     11.805E-03,5.538E-01,4.248E-01,1.965E-02/,XLO(16)/1.264E+02/
      DATA TO(17)/1.402E+02/,XO(17,1),XO(17,2),XO(17,3),XO(17,4)/
     13.781E-03,5.729E-01,4.038E-01,1.963E-02/,XLO(17)/1.265E+02/
      DATA TO(18)/1.394E+02/,XO(18,1),XO(18,2),XO(18,3),XO(18,4)/
     17.877E-03,5.888E-01,3.838E-01,1.961E-02/,XLO(18)/1.266E+02/
      DATA TO(19)/1.382E+02/,XO(19,1),XO(19,2),XO(19,3),XO(19,4)/
     11.629E-02,5.999E-01,3.642E-01,1.958E-02/,XLO(19)/1.266E+02/
      DATA TO(20)/1.362E+02/,XO(20,1),XO(20,2),XO(20,3),XO(20,4)/
     11.666E-02,6.250E-01,3.576E-01,7.198E-04/,XLO(20)/8.370E+01/
      DATA TO(21)/1.358E+02/,XO(21,1),XO(21,2),XO(21,3),XO(21,4)/
     11.713E-02,6.425E-01,3.403E-01,2.538E-05/,XLO(21)/8.470E+01/
      DATA TO(22)/1.353E+02/,XO(22,1),XO(22,2),XO(22,3),XO(22,4)/
     11.828E-02,6.623E-01,3.195E-01,8.872E-07/,XLO(22)/8.483E+01/
      DATA TO(23)/1.346E+02/,XO(23,1),XO(23,2),XO(23,3),XO(23,4)/
     12.130E-02,6.841E-01,2.946E-01,3.069E-08/,XLO(23)/8.494E+01/
      DATA TO(24)/1.333E+02/,XO(24,1),XO(24,2),XO(24,3),XO(24,4)/
     12.927E-02,7.061E-01,2.646E-01,1.045E-09/,XLO(24)/8.508E+01/
      DATA TO(25)/1.307E+02/,XO(25,1),XO(25,2),XO(25,3),XO(25,4)/
     15.028E-02,7.220E-01,2.277E-01,3.432E-11/,XLO(25)/8.530E+01/
C...
C...  INITIALIZE DISTILLATE TEMPERATURE (TDO), DISTILLATE COMPOSITION
C...  (XDO), DISTILLATE FLOW (D), CONDENSER HOLDUP (XMD)
      DATA TDO/1.252E+02/,XDO(1),XDO(2),XDO(3),XDO(4)/
     11.030E-01,7.118E-01,1.853E-01,8.410E-13/,D/2.423E+01/
     2,XMD/5.600E+02/
      END
      SUBROUTINE EQUIL(XX,TEMP,YY)
C...
C...  SUBROUTINE EQUIL COMPUTES THE EQUILBRIUM TEMPERATURE AND VAPOR
C...  COMPOSITION CORRESPONDING TO A GIVEN LIQUID COMPOSITION
C...
C...  SOURCE OF EQUILBRIUM DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     XX    ONE-DIMENSIONAL INPUT ARRAY OF LIQUID COMPOSITIONS
C...
C...     TEMP  OUTPUT EQUILIBRIUM TEMPERATURE (F)
C...
C...     YY    ONE-DIMENSIONAL OUTPUT ARRAY OF VAPOR COMPOSITIONS
C...
      DIMENSION XX(4),YY(4)
C...
C...  THE K VS T CURVE FOR EACH PURE COMPONENT IS APPROXIMATED BY A
C...  LINEAR RELATIONSHIP OF THE FORM K = A + B*T OVER A TEMPERATURE
C...  RANGE OF 100 TO 200 F, 120 PSIA
C...
C...  PROPANE - MAXWELL, PAGE 53
      A1=-.492
      B1=.01956
C...
C...  ISOBUTANE - MAXWELL, PAGE 54
      A2=-.478
      B2=.01124
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 55
      A3=-.573
      B3=.01049
C...
C...  OCTANE - MAXWELL, PAGE 60
      A4=-.04916
      B4=.0005623
C...
C...  THE TEMPERATURE IS COMPUTED EXPLICITLY FROM
C...
C...     (1)  THE LINEAR APPROXIMATION OF K VS T
C...
C...     (2)  ASSUMED IDEAL SOLUTIONS
C...
C...     (3)  SUM OF VAPOR MOLE FRACTIONS IS UNITY
C...
C...  I.E. SUM(YY) = 1 OR SUM((A + B*T)*XX) = 1 SOLVED EXPLICITLY FOR T
      TEMP=(1.-A1*XX(1)-A2*XX(2)-A3*XX(3)-A4*XX(4))/(B1*XX(1)+B2*XX(2)+
     1B3*XX(3)+B4*XX(4))
C...
C...  THE VAPOR MOLE FRACTION OF EACH COMPONENT IS GIVEN BY YY = K*XX =
C...  (A + B*T)*XX
      YY(1)=(A1+B1*TEMP)*XX(1)
      YY(2)=(A2+B2*TEMP)*XX(2)
      YY(3)=(A3+B3*TEMP)*XX(3)
      YY(4)=(A4+B4*TEMP)*XX(4)
      RETURN
      END
      SUBROUTINE ENTHL(XX,TEMP,HL)
C...
C...  SUBROUTINE ENTHL COMPUTES THE LIQUID ENTHALPY CORRESPONDING TO A
C...  GIVEN LIQUID COMPOSITION AND TEMPERATURE
C...
C...  SOURCE OF ENTHALPY DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     XX    ONE-DIMENSIONAL INPUT ARRAY OF LIQUID COMPOSITIONS
C...
C...     TEMP  INPUT TEMPERATURE (F)
C...
C...     HL    OUTPUT LIQUID ENTHALPY (BTU/MOLE)
C...
      DIMENSION XX(4),CHL(4)
C...
C...  THE LIQUID ENTHALPY (CHL) VS T CURVES FOR THE PURE COMPONENTS ARE
C...  APPROXIMATED BY A LINEAR RELATIONSHIP OF THE FORM CHL = B*T OVER A
C...  TEMPERATURE RANGE OF 100 TO 200 F.  NOTE THAT T = 0 CORRESPONDS TO
C...  CHL = 0 (I.E. THE REFERENCE STATE OF THE ENTHALPY CURVES GIVEN BY
C...  MAXWELL HAS BEEN REDEFINED)
C...
C...  PROPANE - MAXWELL, PAGE 100
      CHL(1)=31.*TEMP
C...
C...  ISOBUTANE - MAXWELL, PAGE 101
      CHL(2)=35.*TEMP
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 101
      CHL(3)=35.*TEMP
C...
C...  OCTANE - MAXWELL, PAGE 105
      CHL(4)=63.*TEMP
C...
C...  THE LIQUID ENTHALPY IS COMPUTED FROM
C...
C...     (1)  THE LINEAR APPROXIMATION OF CHL VS T
C...
C...     (2)  ASSUMED IDEAL SOLUTIONS
C...
C...     (3)  SUM OF ENTHALPIES OF THE PURE COMPONENTS
      HL=0.
      DO1 J=1,4
    1 HL=HL+XX(J)*CHL(J)
      RETURN
      END
      SUBROUTINE ENTHV(YY,TEMP,HV)
C...
C...  SUBROUTINE ENTHV COMPUTES THE VAPOR ENTHALPY CORRESPONDING TO A
C...  GIVEN VAPOR COMPOSITION
C...
C...  SOURCE OF ENTHALPY DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     YY    ONE-DIMENSIONAL INPUT ARRAY OF VAPOR COMPOSITIONS
C...
C...     TEMP  INPUT TEMPERATURE (F)
C...
C...     HV    OUTPUT VAPOR ENTHALPY (BTU/MOLE)
C...
      DIMENSION     YY(4),CHV(4)
C...
C...  THE VAPOR ENTHALPY (CHV) VS T RELATIONSHIPS FOR THE PURE COM-
C...  PONENTS ARE THE CORRESPONDING LIQUID RELATIONSHIPS USED IN
C...  SUBROUTINE ENTHL PLUS AN AVERAGE HEAT OF VAPORIZATION FOR THE
C...  TEMPERATURE RANGE 100 TO 200 F
C...
C...  PROPANE - MAXWELL, PAGE 100
      CHV(1)=31.*TEMP+5070.
C...
C...  ISOBUTANE - MAXWELL, PAGE 101
      CHV(2)=35.*TEMP+7000.
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 101
      CHV(3)=35.*TEMP+7300.
C...
C...  OCTANE - MAXWELL, PAGE 105
      CHV(4)=63.*TEMP+16000.
C...
C...  THE VAPOR ENTHALPY IS COMPUTED FROM
C...
C...     (1)  THE LINEAR APPROXIMATIONS FOR THE LIQUID COMPONENTS PLUS
C...          AN AVERAGE HEAT OF VAPORIZATION
C...
C...     (2)  ASSUMED IDEAL GAS MIXTURE
C...
C...     (3)  SUM OF ENTHALPIES OF THE PURE COMPONENTS
      HV=0.
      DO 1 J=1,4
    1 HV=HV+YY(J)*CHV(J)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TPLOT(31),XBPLOT(4,31),XDPLOT(4,31)
C...
C...  INITIALIZE A COUNTER FOR PRINTED LINES, PLOTTED SOLUTION
      DATA NLINE,IP/0,0/
C...
C...  PRINT TIME, HEADING FOR THE COMPUTED RESPONSE
      WRITE(NO,12)TIME
12    FORMAT(/,3X,7HTIME = ,E9.2)
      WRITE(NO,7)
7     FORMAT(3X,9HPLATE NO.,8X,2HX1,10X,2HX2,10X,2HX3,10X,2HX4,8X,4HTEMP
     1,6X,9HLIQ  FLOW,3X,9HVAP  FLOW,3X,9HLIQ  HOLD,3X,9HHEAT DUTY)
C...
C...  PRINT RESPONSE OF THE REBOILER
      WRITE(NO,13)(XB(J),J=1,4),TB,B,VB,XMB,QB
13    FORMAT(3X,8HREBOILER,2X,9E12.3)
C...
C...  PRINT RESPONSE OF PLATES 1, 7, 13, 19, 25
      DO 14 N=1,NT,6
      WRITE(NO,15)N,(X(N,J),J=1,4),T(N),XL(N),V(N),XM(N)
15    FORMAT(6X,I2,5X,9E12.3)
14    CONTINUE
C...
C...  PRINT RESPONSE OF THE CONDENSER
      WRITE(NO,16)(XD(J),J=1,4),TD,D,R,XMD,QD
16    FORMAT(2X,9HCONDENSER,2X,9E12.3)
      NLINE=NLINE+10
      IF(NLINE.LT.50)GO TO 18
      WRITE(NO,17)
17    FORMAT(1H1)
      NLINE=0
C...
C...  STORE THE BOTTOMS AND DISTILLATE COMPOSITIONS FOR SUBSEQUENT
C...  PLOTTING
18    IP=IP+1
      TPLOT(IP)=TIME
      DO 1 J=1,4
      XBPLOT(J,IP)=XB(J)
1     XDPLOT(J,IP)=XD(J)
C...
C...  PLOT THE TRANSIENT RESPONSE OF THE BOTTOMS AND DISTILLATE
C...  COMPOSITIONS
      IF(IP.LT.31)RETURN
      CALL PLOTS(4,31,TPLOT,XBPLOT)
      WRITE(NO,3)
3     FORMAT(//,16X,27HBOTTOMS COMPOSITION VS TIME,/,
     1          16X,11H1 - PROPANE,3X,13H2 - ISOBUTANE,3X,
     2              17H3 - NORMAL BUTANE,3X,10H4 - OCTANE)
      CALL PLOTS(4,31,TPLOT,XDPLOT)
      WRITE(NO,4)
4     FORMAT(//,16X,30HDISTILLATE COMPOSITION VS TIME,/,
     1          16X,11H1 - PROPANE,3X,13H2 - ISOBUTANE,3X,
     2              17H3 - NORMAL BUTANE,3X,10H4 - OCTANE)
      IP=0
      RETURN
      END
DEISOBUTANIZER SIMULATION, RESPONSE TO STEP CHANGE IN FEED FLOW RATE
0.        60.0      2.0
  134  100    1    1  REL 0.005
 8.200E+01 7.410E-02 5.380E-01 3.162E-01 7.170E-02 4.000E+01
 0.000E+00 5.000E+00
END OF RUNS
*APP PRC04
      SUBROUTINE INITAL
C...
C...  STARTUP AND CONTROL OF A PLATE ABSORBER
C...
C...  AN 8-TRAY TOWER IS BEING PLANNED TO REMOVE NH3 FROM AIR USING
C...  WATER AT A RATE OF 0.1 LB MOL/SEC.  THE ENTERING GAS CONTAINS
C...  4 O/O NH3 AND ITS FLOW RATE IS REGULATED WITH A PI CONTROLLER
C...  SO THAT THE NH3 CONCENTRATION IN THE EXITING GAS IS 0.1 O/O.
C...  INITIALLY, THERE ARE 0.1 LB MOLS OF WATER ON EACH TRAY.  THE
C...  MOLAR LIQUID FLOW RATE, LN, OUT OF EACH TRAY IS GIVEN BY
C...
C...               LN = 0.2*(HN - 2.5)**1.5
C...
C...  WHERE HN IS THE MOLAR LIQUID HOLDUP ON TRAY N.  THUS A MINIMUM
C...  OF 2.5 LB MOLS OF LIQUID IS NEEDED ON EACH TRAY BEFORE LIQUID
C...  STARTS FLOWING FROM EACH TRAY.  THE EQUILIBRIUM RELATIONSHIP
C...  AT THE CONDITIONS IN THE COLUMN IS
C...
C...                      Y = 0.78*X
C...
C...  THE MOLAR FLOW RATE OF THE ENTERING GAS IS GIVEN BY
C...
C...                      VO = 0.2*Z
C...
C...           Z = 0.5 + 10*(E + (1/20)*INT(E*DT))
C...
C...                     E = YSET - Y8
C...
C...  THUS, THE CONTROLLER GAIN, AKC, INTEGRAL TIME, TI, AND SET
C...  POINT, YSET, ARE 10, 20 AND 0.001, RESPECTIVELY.  INT(E*DT)
C...  DENOTES THE INTEGRAL OF E WITH RESPECT TO T.  THE MODEL PRO-
C...  GRAMMED IN SUBROUTINE DERV IS BASED ON THE ASSUMPTIONS
C...
C...                    IDEAL TRAYS
C...
C...                    NEGLIGIBLE GAS HOLDUP
C...
C...                    ISOTHERMAL OPERATION
C...
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  SET THE MODEL PARAMETERS
      FN=0.1
      HMIN=2.5
      YSET=0.001
      WEIR=0.2
      AKC=10.
      RTI=1./20.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 K=1,8
C...
C...  SET THE INITIAL TOTAL LIQUID HOLDUPS ON THE TRAYS
      H(K)=0.1
C...
C...  SET THE INITIAL NH3 HOLDUPS ON THE TRAYS ((TOTAL HOLDUP)*
C...  NH3 MOL FRACTION IN THE LIQUID) = HX)
      HX(K)=0.
    1 CONTINUE
C...
C...  SET THE INITIAL INTEGRAL OF THE ERROR, INT(E*DT)
      EI=0.
C...
C...  SET THE ENTERING GAS AND LIQUID COMPOSITIONS
      YO=0.04
      XN=0.
C...
C...  INITIALIZE THE CALCULATIONS IN DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  MODEL ALGEBRA
      DO 2 K=1,8
C...
C...  LIQUID COMPOSITIONS, X(K), FROM THE PRODUCTS H(K)*X(K) (=
C...  HX(K)) AND THE LIQUID HOLDUPS, H(K)
      X(K)=HX(K)/H(K)
C...
C...  GAS COMPOSITIONS
      Y(K)=0.78*X(K)
C...
C...  LIQUID FLOW RATES
      FL(K)=0.
      IF(H(K).GT.HMIN)FL(K)=WEIR*(SQRT(H(K)-HMIN))**3
2     CONTINUE
C...
C...  CONTROLLER ERROR, DERIVATIVE OF THE INTEGRAL INT(E*DT)
      ERROR=YSET-Y(8)
      DEIDT=ERROR
C...
C...  GAS FLOW RATE ENTERING THE TOWER
      VO=0.2*(0.5+AKC*(ERROR+RTI*EI))
      IF(VO.LT.0.)VO=0.
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MATERIAL BALANCE
C...
C...        DH(N)/DT = L(N+1) - L(N)
C...
C...     COMPONENT (NH3) BALANCE
C...
C...        D(H(N)*X(N))/DT = L(N+1)*X(N+1) + VO*Y(N-1)
C...
C...                        - L(N)*X(N) - VO*Y(N)
C...
C...     WHERE N = 1, 2,..., 8 FOR THE EIGHT TRAYS
C...
C...  TRAY 1
      DHDT(1)=FL(2)-FL(1)
      DHXDT(1)=FL(2)*X(2)+VO*YO-FL(1)*X(1)-VO*Y(1)
C...
C...  TRAY 8
      DHDT(8)=FN-FL(8)
      DHXDT(8)=FN*XN+VO*Y(7)-FL(8)*X(8)-VO*Y(8)
C...
C...  TRAYS 2 TO 7
      DO 1 K=2,7
      DHDT(K)=FL(K+1)-FL(K)
      DHXDT(K)=FL(K+1)*X(K+1)+VO*Y(K-1)-FL(K)*X(K)-VO*Y(K)
    1 CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  DIMENSION THE ARRAYS FOR STORING THE PLOTTED SOLUTION
      DIMENSION EP(101), X1P(101), VP(101), Y8P(101), TP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY SECOND CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/2*2).NE.(IP-1))GO TO 2
      WRITE(NO,1)T,VO,(Y(I),I=1,8),(X(I),I=1,8),(H(I),I=1,8),
     1                (FL(I),I=1,8)
1     FORMAT(1H ,//,5H T = ,F5.0,5X,5HVO = ,F8.5,/,
     1              5H Y = ,8E11.3,/,
     2              5H X = ,8E11.3,/,
     3              5H H = ,8E11.3,/,
     4              5H L = ,8E11.3,/)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2      EP(IP)=DEIDT
      X1P(IP)=X(1)
       VP(IP)=VO
      Y8P(IP)=Y(8)
       TP(IP)=T
C...
C...  AT THE END OF THE RUN, PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,26H ERROR (MOL FR) VS T (SEC))
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,23H X1 (MOL FR) VS T (SEC))
      CALL TPLOTS(1,IP,TP,VP)
      WRITE(NO,12)
12    FORMAT(1H ,//,24H V (MOLS/SEC) VS T (SEC))
      CALL TPLOTS(1,IP,TP,Y8P)
      WRITE(NO,13)
13    FORMAT(1H ,//,23H Y8 (MOL FR) VS T (SEC))
      IP=IP+1
      RETURN
      END
PLATE ABSORBER
0.        1000.     10.
   17 1000    1    1  REL 0.001
END OF RUNS
*APP PRC05
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
C...
C...  THE FOLLOWING EQUATIONS MODEL A BATCH DISTILLATION COLUMN WITH
C...  PI CONTROL OF THE DISTILLATE RATE
C...
C...  KETTLE       HB*DXB/DT = R*X1 - V*YB, XB(0) = XB0
C...
C...  PLATE 1      H*DX1/DT = R*X2 + V*YB - R*X1 - V*Y1, X1(0) = X10
C...
C...  PLATE 2      H*DX2/DT = R*X3 + V*Y1 - R*X2 - V*Y2, X2(0) = X20
C...
C...  PLATE N      H*DXN/DT = R*XD + V*YN-1 - R*XN - V*YN, XN(0) = XN0
C...
C...  CONDENSER    HC*DXD/DT = V*YN - R*XD - D*XD, XD(0) = XD0
C...
C...  EQUILIBRIUM  YN = A*XN/(1 + (A - 1)*XN)
C...
C...                                        T
C...  CONTROLLER   Z = ZS + KC*(E + (1/TI)*INT E*DT)
C...                                        0
C...               E = XD - XDSET
C...
C...               D = CV*Z*(HC**0.5)
C...
C...               R = V - D
C...
C...  WHERE
C...
C...     X1,X2,    LIQUID COMPOSITIONS ON TRAYS 1, 2 ..., N
C...     ...,XN
C...
C...     Y1,Y2,    VAPOR COMPOSITIONS ABOVE TRAYS 1, 2,..., N
C...     ...,YN
C...
C...     A         RELATIVE VOLATILITY
C...
C...     XB,XD     REBOILER, CONDENSER LIQUID COMPOSITIONS, RESPECTIVELY
C...
C...     XDSET     CONDENSER LIQUID COMPOSITION SET POINT
C...
C...     YB        COMPOSITION OF VAPOR FROM THE REBOILER
C...
C...     T         TIME
C...
C...     HB,H,HC   REBOILER HOLDUP, HOLDUPS ON TRAYS 1 TO N, CONDENSER
C...               HOLDUP, RESPECTIVELY
C...
C...     V         VAPOR BOILUP RATE
C...
C...     R         REFLUX RATE (LIQUID RATE)
C...
C...     D         DISTILLATE RATE
C...
C...     CV        CONTROL VALVE CONSTANT
C...
C...     Z         VALVE STEM POSITION
C...
C...     ZS        STEADY STATE VALVE STEM POSITION
C...
C...     KC        CONTROLLER GAIN
C...
C...     TI        CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN DISTILLATE COMPOSITION = XD - XDSET
C...
C...  THE PROBLEM IS BASICALLY TO SELECT THE CONTROLLER GAIN AND
C...  INTEGRAL TIME TO MAINTAIN SATISFACTORY CONTROL OF THE DISTILLATE
C...  COMPOSITION.  TWO FIGURES OF MERIT FOR THE CONTROLLER PERFORMANCE
C...  ARE TO BE COMPUTED
C...
C...           T              T
C...     I1 = INT D*DT, I2 = INT (XD*D)*DT
C...           0              0
C...
C...  INTEGRAL I2 GIVES THE TOTAL YIELD OF THE LIGHT COMPONENT (WITH
C...  MOL FRACTION XD IN THE DISTLLATE), AND THE RATIO I2/I1 GIVES THE
C...  TIME AVERAGE DISTILLATE COMPOSITION.  THESE INTEGRALS CAN BE
C...  EVALUATED BY PROGRAMMING THEM AS DIFFERENTIAL EQUATIONS, I.E.,
C...
C...    DI1/DT = D, I1(0) = 0, DI2/DT = XD*D, I2(0) = 0
C...
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  SET THE MODEL PARAMETERS
      N=10
      A=2.5
      V=5.
      H=0.5
      HC=3.
      HB=100.
      CV=2.309
      ZS=0.5
      XDSET=0.85
      GO TO(1,2),NORUN
1     KC=0.
      TI=1.0E+10
      GO TO 10
2     KC=10.
      TI=25.
      GO TO 10
C...
C...  SET THE INITIAL CONDITIONS
10    XD=0.5
      DO 11 I=1,N
      X(I)=0.5
11    CONTINUE
      XB=0.5
      IE=0.
      I1=0.
      I2=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  MODEL ALGEBRA
C...
C...  VAPOR COMPOSITIONS
      DO 1 I=1,N
      Y(I)=EQUIL(A,X(I))
1     CONTINUE
C...
C...  CONTROLLER EQUATIONS
      YB=EQUIL(A,XB)
      E=XD-XDSET
      Z=ZS+KC*(E+(1./TI)*IE)
      IF(Z.LT.0.)Z=0.
      IF(Z.GT.1.)Z=1.
      D=CV*Z*SQRT(HC)
      R=V-D
C...
C...  CONDENSER
      XDT=(1./HC)*(V*Y(N)-R*XD-D*XD)
C...
C...  PLATE N
      XT(N)=(1./H)*(R*XD+V*Y(N-1)-R*X(N)-V*Y(N))
C...
C...  PLATES 2 TO N-1
      NM1=N-1
      DO 2 I=2,NM1
      XT(I)=(1./H)*(R*X(I+1)+V*Y(I-1)-R*X(I)-V*Y(I))
2     CONTINUE
C...
C...  PLATE 1
      XT(1)=(1./H)*(R*X(2)+V*YB-R*X(1)-V*Y(1))
C...
C...  KETTLE
      XBT=(1./HB)*(R*X(1)-V*YB)
C...
C...  TIME INTEGRALS
      DIEDT=E
      DI1DT=D
      DI2DT=XD*D
      RETURN
      END
      FUNCTION EQUIL(A,X)
C...
C...  FUNCTION EQUIL CALCULATES THE EQUILIBRIUM VAPOR COMPOSITION
C...  FROM ROAULT*S LAW
C...
C...  ARGUMENT LIST
C...
C...     A     RELATIVE VOLATILITY (INPUT)
C...
C...     X     LIQUID MOL FRACTION, FOR WHICH THE EQUILIBRIUM VAPOR
C...           COMPOSITION IS TO BE COMPUTED (INPUT)
C...
      EQUIL=A*X/(1.+(A-1.)*X)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION PT(51), PXD(51), PD(51), PZ(51), PE(51), PI1(51),
     1         PI2(51),  PR(51)
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,10X,2HXD,11X,1HD,11X,1HZ,11X,1HE,10X,2HIE,
     1      10X,2HI1,10X,2HI2,7X,5HI2/I1)
C...
C...  RPINT THE NUMERICAL SOLUTION.  NOTE - THE RATIO I2/I1 CAN BE
C...  INDETERMINATE (0/0).  IF THIS OCCURS, THIS RATIO IS ARBITRARILY
C...  SET TO ZERO
      IF((I1.EQ.0.).AND.(I2.EQ.0.))RATIO=0.
      IF((I1.EQ.0.).AND.(I2.NE.0.))STOP
      IF((I1.NE.0.).AND.(I2.NE.0.))RATIO=I2/I1
      WRITE(NO,2)TIME,XD,D,Z,E,IE,I1,I2,RATIO
2     FORMAT(F10.2,8F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
       IP=IP+1
       PT(IP)=TIME
      PXD(IP)=XD
       PD(IP)=D
       PZ(IP)=Z
       PE(IP)=E
      PI1(IP)=I1
      PI2(IP)=I2
       PR(IP)=RATIO
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL TPLOTS(1,IP,PT,PXD)
      WRITE(NO,10)
10    FORMAT(1H ,//,8H XD VS T)
      CALL TPLOTS(1,IP,PT,PD )
      WRITE(NO,11)
11    FORMAT(1H ,//,8H  D VS T)
      CALL TPLOTS(1,IP,PT,PZ )
      WRITE(NO,12)
12    FORMAT(1H ,//,8H  Z VS T)
      CALL TPLOTS(1,IP,PT,PE )
      WRITE(NO,13)
13    FORMAT(1H ,//,8H  E VS T)
      CALL TPLOTS(1,IP,PT,PI1)
      WRITE(NO,14)
14    FORMAT(1H ,//,8H I1 VS T)
      CALL TPLOTS(1,IP,PT,PI2)
      WRITE(NO,15)
15    FORMAT(1H ,//,8H I2 VS T)
      CALL TPLOTS(1,IP,PT,PR )
      WRITE(NO,16)
16    FORMAT(1H ,//,11H I2/I1 VS T)
      IP=0
      RETURN
      END
PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
0.        50.       1.
   15 1000    1    1  REL 0.001
PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
0.        50.       1.
   15 1000    1    1  REL 0.001
END OF RUNS
*APP PRC06
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A DOUBLE EFFECT EVAPORATOR
C...
C...  CONSIDER THE FOLLOWING DOUBLE EFFECT EVAPORATOR
C...
C...                          WS1                    WS2
C...                      ............           ..........+
C...                      .          .           .
C...                   ......        .        ......
C...                  .      .       .       .      .
C...                 .        .      .      .        .
C...                .          .     .     .          .
C...                .          .     .     .          .
C...                .  EVAP 1  .     .     .  EVAP 2  .
C...                .          .     .     .          .
C...                .          .     .     .          .
C...                ............     .     ............
C...                .       M1 .     .     .       M2 .
C...                .          .     .     .          .
C...      WS0 ............  T1 .     ............  T2 .+....... WF
C...                .   .      +...        .   .      .
C...                .    .  A1 .  .        .    .  A2 .
C...                .   .      .  .        .   .      .
C...                .    .  X1 .  .        .    .  X2 .
C...          ...........      .  .  ...........      .
C...          .     .          .  .  .     .          .
C...          +      .        .   .  +      .        .
C...                  .      .    .          .      .
C...                   ......     .           ......
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...               ...    .       .     ...      .
C...          +..... ......       ....... ........
C...               ...                  ...
C...                .                    .
C...               ...                  ...
C...            (PUMP FOR            (PUMP FOR
C...               W1)                  W2)
C...  WHERE
C...
C...     M1,M2       MASS HOLDUP IN EVAPORATORS 1 AND 2, RESPECTIVELY
C...
C...     T1,T2       SOLUTION TEMPERATURES IN EVAPORATORS 1 AND 2
C...
C...     H1,H2       SOLUTION ENTHALPIES IN EVAPORATORS 1 AND 2
C...
C...     X1,X2       SOLUTE MASS FRACTIONS IN EVAPORATORS 1 AND 2
C...
C...     WS1,WS2     STEAM MASS FLOW RATES FROM EVAPORATORS 1 AND 2
C...
C...     W1,W2       SOLUTION MASS FLOW RATES FROM EVAPORATORS 1 AND 2
C...
C...     WF          FEED MASS FLOW RATE TO EVAPORATOR 2
C...
C...     WS0         STEAM MASS FLOW RATE THROUGH THE COIL IN EVAPORATOR
C...                 1 (WS1 IS THE STEAM MASS FLOW RATE THROUGH THE COIL
C...                 IN EVAPORATOR 2)
C...
C...     TS0,TS1     STEAM TEMPERATURES IN THE COILS IN EVAPORATORS 1
C...                 AND 2
C...
C...     HS1,HS2     ENTHALPY OF THE VAPOR LEAVING EVAPORATORS 1 AND 2
C...
C...     H1,H2       ENTHALPY OF THE SOLUTION IN EVAPORATORS 1 AND 2
C...
C...     DVS0,       HEAT OF VAPORIZATION OF STEAM IN THE COILS OF
C...     DVS1        EVAPORATORS 1 AND 2
C...
C...     HF          ENTHALPY OF THE FEED
C...
C...     TF,TS0      TEMPERATURE OF THE FEED AND ENTERING STEAM
C...
C...     XF          MASS FRACTION OF THE FEED
C...
C...     A1,A2       HEAT TRANSFER AREAS OF THE COILS IN EVAPORATOR 1
C...                 AND 2
C...
C...     U1,U2       HEAT TRANSFER COEFFICIENTS FOR THE COILS IN
C...                 EVAPORATORS 1 AND 2
C...
C...     X1SET       SET POINT FOR X1
C...
C...     M1SET,      SET POINTS FOR M1, M2
C...     M2SET
C...
C...     T2SET       SET POINT FOR T2
C...
C...     EX1 = X1 - X1SET
C...
C...     EM1 = M1 - M1SET
C...
C...     EM2 = M2 - M2SET
C...
C...     ET2 = T2 - T2SET
C...
C...     WFSS        WF AT STEADY STATE
C...
C...     W1SS,       W1 AND W2 AT STEADY STATE
C...     W2SS
C...
C...     WS2SS       WS2 AT STEADY STATE
C...
C...     KCF,KC1     GAINS FOR THE FEED FLOW RATE CONTROLLER, M1 AND M2
C...     KC2,KCS     LIQUID LEVEL CONTROLLERS, STEAM FLOW RATE (FROM THE
C...                 SECOND EVAPORATOR) CONTROLLER
C...
C...     TIF,TI1     INTEGRAL TIMES FOR THE FEED FLOW RATE CONTROLLER,
C...     TI2,TIS     M1 AND M2 LIQUID LEVEL CONTROLLERS, STEAM FLOW RATE
C...                 (FROM THE SECOND EVAPORATOR) CONTROLLER
C...
C...  THE MODEL FOR THIS SYSTEM CONSISTS OF THE FOLLOWING EQUATIONS
C...
C...     (A)  TOTAL MASS BALANCE AROUND EACH EVAPORATOR
C...
C...          DM1/DT = W2 - W1 - WS1, M1(0)                       (1)
C...
C...          DM2/DT = WF - W2 - WS2, M2(0)                       (2)
C...
C...     (B)  COMPONENT BALANCE AROUND EACH EVAPORATOR
C...
C...          D(M1*X1)/DT = W2*X2 - W1*X1, M1(0)*X1(0)            (3)
C...
C...          D(M2*X2)/DT = WF*XF - W2*X2, M2(0)*X2(0)            (4)
C...
C...     (C)  EQUATION FOR THE OUTLET VALVE OF EACH EVAPORATOR
C...
C...          W1 = CV1*SQRT(M1), W2 = CV2*SQRT(M2)             (5)(6)
C...
C...     (D)  ENERGY BALANCE ON THE COILS IN EACH EVAPORATOR
C...          (NEGLECTING VAPOR DYNAMICS)
C...
C...          WS1*HVS1 = U2*A2*(TS1 - T2)                         (7)
C...
C...          WS0*HVS0 = U1*A1*(TS0 - T1)                         (8)
C...
C...     (E)  ENERGY BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*H1)/DT = W2*H2 - W1*H1 - WS1*HS1 + U1*A1*(TS0 - T1)
C...                                                              (9)
C...                        M1(0)*H1(0)
C...
C...          D(M2*H2)/DT = WF*HF - W2*H2 - WS2*HS2 + U2*A2*(TS1 - T2)
C...                                                             (10)
C...                        M2(0)*H2(0)
C...
C...     (F)  AUXILIARY EQUATIONS
C...
C...          TS1 = T1, TS2 = T2 (ASSUMING NO BOILING        (11)(12)
C...                                  POINT RISE)
C...
C...          LIQUID ENTHALPY
C...
C...             H1 = CP*(T1 - TR), H2 = CP*(T2 - TR)
C...
C...             OR FOR WATER (CP = 1) WITH TR = 32
C...
C...             H1 = T1 - 32, H2 = T2 - 32                  (13)(14)
C...
C...          VAPOR ENTHALPY
C...
C...             HS1 = 0.42*TS1 + 1062, HS2 = 0.42*TS2 + 1062 (15)(16)
C...
C...          HEAT OF VAPORIZATION
C...
C...             HVS0 = 1092 - 0.57*TS0, HVS1 = 1092 - 0.57*TS1 (17)(18)
C...
C...     (G)  CONTROLLER EQUATIONS
C...
C...                                          T
C...          WF = WFSS + KCF*(EX1 + (1/TIF)*INT EX1*DT)         (19)
C...                                          0
C...
C...                                          T
C...          W1 = W1SS + KC1*(EM1 + (1/TI1)*INT EM1*DT)         (20)
C...                                          0
C...
C...                                          T
C...          W2 = W2SS + KC2*(EM2 + (1/TI2)*INT EM2*DT)         (21)
C...                                          0
C...
C...                                            T
C...          WS2 = WS2SS + KCS*(ET2 + (1/TIS)*INT ET2*DT)       (22)
C...                                            0
C...
C...          NOTE THAT THE FEED FLOW RATE, WF, THE VAPOR RATE FROM THE
C...          SECOND EVAPORATOR, WS2, AND THE MASS HOLDUPS IN THE TWO
C...          EVAPORATORS, M1 AND M2, ARE CONTROLLED TO BRING THE SYSTEM
C...          TO A STEADY STATE CONDITION (BECAUSE OF THE INTEGRAL
C...          ACTION IN THE PI CONTROLLERS).  THE CONTROLLERS ARE NOT
C...          SHOWN IN THE PRECEDING DIAGRAM, BUT THEIR OPERATION IS
C...          CLEAR FROM EQUATIONS (19) TO (22).
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  MODEL CONSTANTS
      A1=2000.
      A2=2000.
      U1=500./3600.
      U2=700./3600.
      TS0=328.
      TF=100.
      XF=0.02
      WFSS=40.
      W1SS=30.
      W2SS=30.
      WS2SS=10.
      X1SET=0.25
      M1SET=250.
      M2SET=250.
      T2SET=101.
      KCF=100.
      KC1=1.
      KC2=1.
      KCS=1.
      TIF=250.
      TI1=250.
      TI2=250.
      TIS=250.
C...
C...  INITIAL CONDITIONS
      M1=250.
      M2=250.
      M1X1=250.*0.1
      M2X2=250.*0.1
      M1H1=250.*(95.-32.)
      M2H2=250.*(95.-32.)
      EX1INT=0.
      EM1INT=0.
      EM2INT=0.
      ET2INT=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  MODEL ALGEBRA
C...
C...     THE MASS OF LIQUID IN EACH EVAPORATOR MUST BE NONNEGATIVE
         IF(M1.LT.0.)M1=0.
         IF(M2.LT.0.)M2=0.
C...
C...     MASS FRACTION IN EACH EVAPORATOR
         X1=M1X1/M1
         X2=M2X2/M2
C...
C...     THE MASS FRACTION IN EACH EVAPORATOR MUST BE NONNEGATIVE
         IF(X1.LT.0.)X1=0.
         IF(X2.LT.0.)X2=0.
C...
C...     LIQUID TEMPERATURE IN EACH EVAPORATOR
         H1=M1H1/M1
         H2=M2H2/M2
         T1=H1+32.
         T2=H2+32.
C...
C...     TEMPERATURE OF VAPOR FROM EACH EVAPORATOR
         TS1=T1
         TS2=T2
C...
C...     HEAT OF VAPORIZATION OF THE STEAM IN EACH EVAPORATOR COIL
         HVS0=1092.-0.57*TS0
         HVS1=1092.-0.57*TS1
C...
C...     VAPOR FLOW IN THE COIL OF EACH EVAPORATOR
         WS0=(U1*A1/HVS0)*(TS0-T1)
         WS1=(U2*A2/HVS1)*(TS1-T2)
C...
C...     CONTROLLER ERRORS
         EX1=X1-X1SET
         EM1=M1-M1SET
         EM2=M2-M2SET
         ET2=T2-T2SET
C...
C...     CONTROLLER EQUATIONS
         WF=WFSS+KCF*(EX1+(1./TIF)*EX1INT)
         W1=W1SS+KC1*(EM1+(1./TI1)*EM1INT)
         W2=W2SS+KC2*(EM2+(1./TI2)*EM2INT)
         WS2=WS2SS+KCS*(ET2+(1./TIS)*ET2INT)
C...
C...     THE MANIPULATED VARIABLES MUST BE NONNEGATIVE
         IF(WF.LT.0.)WF=0.
         IF(W1.LT.0.)W1=0.
         IF(W2.LT.0.)W2=0.
         IF(WS2.LT.0.)WS2=0.
C...
C...     VAPOR ENTHALPIES
         HS1=0.42*TS1+1062.
         HS2=0.42*TS2+1062.
C...
C...     FEED ENTHALPY
         HF=TF-32.
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MASS BALANCES
         M1T=W2-W1-WS1
         M2T=WF-W2-WS2
C...
C...     COMPONENT MASS BALANCES
         M1X1T=W2*X2-W1*X1
         M2X2T=WF*XF-W2*X2
C...
C...     ENERGY BALANCES
         M1H1T=W2*H2-W1*H1-WS1*HS1+U1*A1*(TS0-T1)
         M2H2T=WF*HF-W2*H2-WS2*HS2+U2*A2*(TS1-T2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE SOLUTION
      DIMENSION   TMP(51),  XP(2,51),  TP(2,51),  MP(2,51),
     1            WFP(51),  WP(2,51), WSP(3,51)
      REAL MP
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF((IP/5*5).NE.IP)GO TO 3
      WRITE(NO,1)
1     FORMAT(1H ,/,
     1 9X,1HT,10X,2HM1,10X,2HM2,10X,2HX1,10X,2HX2,10X,2HT1,10X,2HT2,
     2      /,20X,2HWF,10X,2HW1,10X,2HW2,9X,3HWS0,9X,3HWS1,9X,3HWS2,
     3      /,19X,3HM1T,9X,3HM2T,7X,5HM1X1T,7X,5HM2X2T,7X,5HM1H1T,
     4       7X,5HM2H2T)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,2)T,M1,M2,X1,X2,T1,T2,
     1          WF,W1,W2,WS0,WS1,WS2,
     2         M1T,M2T,M1X1T,M2X2T,M1H1T,M2H2T
2     FORMAT(F10.2,2F12.1,2F12.4,2F12.1,/,
     1       10X,6F12.1,/,10X,4F12.4,2F12.1)
3     IP=IP+1
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TMP(IP)=T
      XP(1,IP)=X1
      XP(2,IP)=X2
      TP(1,IP)=T1
      TP(2,IP)=T2
      MP(1,IP)=M1
      MP(2,IP)=M2
      WFP(IP)=WF
      WP(1,IP)=W1
      WP(2,IP)=W2
      WSP(1,IP)=WS0
      WSP(2,IP)=WS1
      WSP(3,IP)=WS2
      IF(IP.LT.51)RETURN
C...
C...  PLOT THE SOLUTION
      CALL TPLOTS(2,IP,TMP, XP)
      WRITE(NO,10)
10    FORMAT(1H ,//,35H X1, X2 VS T                       )
      CALL TPLOTS(2,IP,TMP, TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,35H T1, T2 VS T                       )
      CALL TPLOTS(2,IP,TMP, MP)
      WRITE(NO,12)
12    FORMAT(1H ,//,35H M1, M2 VS T                       )
      CALL TPLOTS(1,IP,TMP,WFP)
      WRITE(NO,13)
13    FORMAT(1H ,//,35H WF VS T                           )
      CALL TPLOTS(2,IP,TMP, WP)
      WRITE(NO,14)
14    FORMAT(1H ,//,35H W1, W2 VS T                       )
      CALL TPLOTS(3,IP,TMP,WSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,35H WS0, WS1, WS2 VS T                )
      IP=0
      RETURN
      END
PI CONTROL OF A DOUBLE EFFECT EVAPORATOR
0.        2500.     50.
   10 9999    1    1  REL 0.001
END OF RUNS
*APP PRC07
      SUBROUTINE INITAL
C...
C...  THREE CONTINUOUS STIRRED TANK REACTORS WITH PI CONTROL
C...
C...  THE PROBLEM IS COMPLETELY DEFINED IN THE REFERENCE CITED ON THE
C...  FIRST DATA LINE.  THEREFORE ONLY THE EQUATIONS ARE SUMMARIZED
C...  BELOW
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1, CA1(0) = 0.4      (1)(2)
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2, CA2(0) = 0.2      (3)(4)
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3, CA3(0) = 0.1      (5)(6)
C...
C...     DEI/DT = (1/TAUI)*E, EI(0) = 0                           (7)(8)
C...
C...     CA0 = CAD + CAM, CAM = 0.4 + KC*(E + EI)                (9)(10)
C...
C...  FOR WHICH THE MODEL PARAMETERS HAVE THE NUMERICAL VALUES
C...
C...     TAU     2 MINUTES
C...
C...     K       0.5 1/MIN
C...
C...     TAUI    4 MIN
C...
C...     KC      0, 20, 30, 40 (4 CASES TO BE RUN)
C...
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  SET THE MODEL PARAMETERS
      TAU=2.0
      K=0.5
      TAUI=4.0
      IF(NORUN.EQ.1)KC=0.0
      IF(NORUN.EQ.2)KC=20.
      IF(NORUN.EQ.3)KC=30.
      IF(NORUN.EQ.4)KC=40.
      IP=0
C...
C...  SET THE DISTURBANCE
      CAD=0.6
C...
C...  SET THE INITIAL CONDITIONS, EQUATIONS (2), (4), (6), (8)
      CA1=0.4
      CA2=0.2
      CA3=0.1
       EI=1.0E-10
C...
C...  SET THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  COMPUTE THE MODEL ALGEBRAIC VARIABLES
      E=0.1-CA3
      CAM=0.4+KC*(E+EI)
      CA0=CAD+CAM
C...
C...  COMPUTE THE MODEL DERIVATIVES DEFINED BY EQUATIONS (1), (3), (5),
C...  (7)
      DCA1DT=(1./TAU)*(CA0-CA1)-K*CA1
      DCA2DT=(1./TAU)*(CA1-CA2)-K*CA2
      DCA3DT=(1./TAU)*(CA2-CA3)-K*CA3
       DEIDT=(1./TAUI)*E
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51),CA3P(4,51),EP(4,51)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,9X,3HCA1,9X,3HCA2,9X,3HCA3,7X,5HERROR)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,CA1,CA2,CA3,E
2     FORMAT(F10.1,3F12.4,F12.5)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      CA3P(NORUN,IP)=CA3
        EP(NORUN,IP)=E
        TP(IP)=T
C...
C...  TEST FOR THE END OF A RUN
      IF(IP.LT.51)RETURN
C...
C...  TEST FOR THE END OF THE FOURTH RUN
      IF(NORUN.LT.4)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL PLOTS(4,IP,TP,CA3P)
      WRITE(NO,3)
3     FORMAT(1H ,//,48H CA3(T) VS T FOR KC = 0, 20, 30, 40             )
      CALL PLOTS(4,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,48H E(T) VS T FOR KC = 0, 20, 30, 40               )
      RETURN
      END
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
END OF RUNS
*APP PRC08
      SUBROUTINE INITAL
C...
C...  THREE CSTR*S WITH PROPORTIONAL-INTEGRAL CONTROL
C...
C...  THREE CSTR*S (CONTINUOUS-STIRRED-TANK REACTORS) ARE MODELLED
C...  BY THE FOLLOWING DIFFERENTIAL EQUATIONS
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION WHICH STEPS FROM 0.4 TO 0.6
C...               AT T = 0 (IF CAD REMAINS AT 0.4, THE ENTIRE SYSTEM
C...               REMAINS AT STEADY STATE, I.E., THE DERIVATIVES IN THE
C...               DIFFERENTIAL EQUATIONS REMAIN AT ZERO OR DCA1/DT =
C...               DCA2/DT = DCA3/DT = 0)
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM = CAMSS + AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     CAMSS     STEADY STATE VALUE OF CAM = 0.4
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION CA3 = CA3SET - CA3
C...
C...     CA3SET    SET POINT FOR CA3 = 0.1
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE TO BE SOLVED FOR THE FOLLOWING CASES
C...
C...     (1)  CAD = 0.4 (NORUN = 1)
C...          TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE.
C...          ALL SUBSEQUENT RUNS ARE FOR CAD = 0.6, I.E., A +0.2 STEP
C...          DISTURBANCE IN THE ENTERING CONCENTRATION
C...
C...     (2)  AK =  0, TAUI = INFINITY (NORUN = 2)
C...
C...     (3)  AK = 20, TAUI = INFINITY (NORUN = 3)
C...
C...     (4)  AK = 40, TAUI = INFINITY (NORUN = 4)
C...
C...     (5)  AK = 20, TAUI = 5        (NORUN = 5)
C...
C...     (6)  AK = 40, TAUI = 5        (NORUN = 6)
C...
C...  FOR ALL OF THE RUNS, THE INITIAL CONDITIONS FOR THE DIFFERENTIAL
C...  EQUATIONS ARE
C...
C...     CA1(0) = 0.4, CA2(0) = 0.2, CA3(0) = 0.1
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
C...
C...  THE FOLLOWING PARAMETERS VARY FROM RUN TO RUN
      GO TO(1,2,3,4,5,6),NORUN
C...
C...  RUN (1)
1     CAD=0.4
      AK=0.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (2)
2     CAD=0.6
      AK=0.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (3)
3     CAD=0.6
      AK=20.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (4)
4     CAD=0.6
      AK=40.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (5)
5     CAD=0.6
      AK=20.
      TAUI=5.
      GO TO 10
C...
C...  RUN (6)
6     CAD=0.6
      AK=40.
      TAUI=5.
      GO TO 10
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
10    CA(1)=0.4
      CA(2)=0.2
      CA(3)=0.1
      ERINT=0.
C...
C...  INITIALIZE THE REMAINDER OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  MODEL ALGEBRA
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
      DCADT(1)=(CA0  -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA(1)-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA(2)-CA(3))/TAU-RK*CA(3)
C...
C...  NOTE THAT THE DIFFERENTIAL EQUATION D(ERINT)/DT = E IS ALREADY
C...  PROGRAMMED BY SETTING E WHICH APPEARS IN THE DERIVATIVE SECTION
C...  (COMMON/F/ ABOVE).  THE INTEGRATED RESULT, ERINT, IN COMMON/Y/
C...  CAN THEN BE USED IN THE CONTROLLER EQUATION FOR CAM
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(6,101), EP(6,101),    TP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,11X,1HE,7X,5HERINT,7X,5HCA(1),4X,8HDCADT(1),
     1                                 7X,5HCA(2),4X,8HDCADT(2),
     2                                 7X,5HCA(3),4X,8HDCADT(3))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP)
     1  WRITE(NO,2)T,E,ERINT,(CA(I),DCADT(I),I=1,3)
2     FORMAT(F10.1,8F12.3)
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(NORUN,IP)=CA(3)
       EP(NORUN,IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      IF(NORUN.LT.6)RETURN
      CALL PLOTS(6,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,46H CA3(T) VS T FOR THE SIX RUNS LISTED IN INITAL)
      CALL PLOTS(6,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,44H E(T) VS T FOR THE SIX RUNS LISTED IN INITAL)
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
END OF RUNS
*APP PRC09
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A CSTR WITH COMPETING REACTIONS
C...
C...  A CSTR (CONTINUOUS STIRRED TANK REACTOR) IS OPERATED WITH TWO
C...  CONSECUTIVE, COMPETING REACTIONS.  THE OVERALL OBJECTIVE IN
C...  OPERATING THE REACTOR IS TO CONTROL IT SO AS TO MAXIMIZE THE
C...  YIELD OF THE INTERMEDIATE PRODUCT, B.  A PI (PROPORTIONAL-
C...  INTEGRAL) CONTROLLER IS USED TO CONTROL THE REACTOR TEMPERATURE
C...  VIA A STEAM COIL.  THE OBJECTIVE OF THIS SIMULATION IS TO DETER-
C...  MINE THE CONTROLLER PARAMETERS WHICH WILL MINIMIZE UNDESIRABLE
C...  TRANSIENTS, AND IF POSSIBLE, MAXIMIZE THE YIELD OF B.
C...
C...          K       K
C...           1       2
C...       A ----+ B ----+ C
C...
C...  THE ALGEBRAIC/DIFFERENTIAL EQUATIONS WHICH MODEL THE CSTR ARE
C...
C...  COMPONENT A BALANCE
C...
C...     V1*DA1/DT = M*(A0 - A1) - V1*RATE1
C...
C...  COMPONENT B BALANCE
C...
C...     V1*DB1/DT = M*(B0 - B1) + V1*RATE1 - V1*RATE2
C...
C...  ENERGY BALANCE
C...
C...     V1*CP*DT1/DT = M*CP*(T0 - T1) - DH1*V1*RATE1 - DH2*V1*RATE2
C...
C...                  + QS1
C...
C...  RATES OF REACTION
C...
C...     RATE1 = A1*K10*EXP(-E1/(R*T1))
C...
C...     RATE2 = B1*K20*EXP(-E2/(R*T1))
C...
C...  CONTROLLER EQUATIONS
C...
C...                                  T
C...     X1 = XS1 + KC*(ER1 + (1/TI1)*INT(ER1*DT))
C...                                  0
C...
C...     ER1 = TR1 - T1
C...
C...  VALVE/STEAM COIL EQUATIONS
C...
C...     FS1 = CV*X1*(PS1**0.5)
C...
C...     QS1 = FS1*DHS
C...
C...  WHERE
C...
C...   A1      CONCENTRATION OF REACTANT A IN THE CSTR (LB MOL/FT**3)
C...
C...   B1      CONCENTRATION OF INTERMEDIATE PRODUCT B IN THE CSTR
C...           (LB MOL/FT**3)
C...
C...   T1      TEMPERATURE IN THE CSTR (R)
C...
C...   T       TIME (S)
C...
C...   QS1     STEAM RATE TO THE HEATING COIL (LB/S)
C...
C...   V1      VOLUME OF LIQUID IN THE CSTR (100 FT**3)
C...
C...   CP      HEAT CAPACITY OF THE LIQUID (60 BTU/FT**3-R)
C...
C...   M       VOLUMTERIC FLOW RATE THROUGH THE CSTR (0.1 FT**3/S)
C...
C...   K10     FREQUENCY FACTOR FOR THE FIRST REACTION (3.0E+13/S)
C...
C...   K20     FREQUENCY FACTOR FOR THE SECOND REACTION (5.0E+13/S)
C...
C...   E1      ACTIVATION ENERGY FOR THE FIRST REACTION (44,700 BTU/
C...           LB MOL)
C...
C...   E2      ACTIVATION ENERGY FOR THE SECOND REACTION (40,000 BTU/
C...           LB MOL)
C...
C...   TR1     REFERENCE TEMPERATURE (600 R)
C...
C...   T0      ENTERING TEMPERATURE (575 R)
C...
C...   A0      ENTERING CONCENTRATION OF REACTANT A (1 LB MOL/FT**3)
C...
C...   B0      ENTERING CONCENTRATION OF INTERMEDIATE PRODUCT B (0 LB
C...           MOL/FT**3)
C...
C...   DH1     HEAT OF REACTION OF THE FIRST REACTION (10,000 BTU/
C...           MOL A REACTED)
C...
C...   DH2     HEAT OF REACTION OF THE SECOND REACTION (12,000 BTU/
C...           MOL B REACTED)
C...
C...   FS1     FLOW RATE OF STEAM IN THE COIL (LB/S)
C...
C...   CV      CONSTANT FOR THE VALVE ON THE STEAM LINE (0.70 (LB/SEC)
C...           /((LB/IN**2)**0.5))
C...
C...   X1      VALVE STEM POSITION (DIMENSIONLESS)
C...
C...   XS1     STEADY STATE VALVE STEM POSITION (0.5 DIMENSIONLESS)
C...
C...   PS1     STEAM PRESSURE (100 LB/IN**2)
C...
C...   DHS     STEAM HEAT OF VAPORIZATION (960 BTU/LB)
C...
C...   KC      CONTROLLER GAIN (1/R)
C...
C...   TI1     CONTROLLER INTEGRAL TIME (1/S)
C...
C...   R       GAS CONSTANT (1.987 BTU/LB MOL-R)
C...
C...  THE INITIAL CONDITIONS FOR THE SYSTEM ARE
C...
C...     A1(0) = 1, B1(0) = 0, T1(0) = 575
C...
C...  THE OBJECTIVE OF THE SIMULATION IS TWO-FOLD
C...
C...     (1)  TO DETERMINE VALUES OF THE CONTROLLER GAIN, KC, AND
C...     INTEGRAL TIME, TI1, WHICH WILL BRING THE REACTOR TO THE
C...     REFERENCE TEMPERATURE, TR1, QUICKLY WITHOUT SIGNIFICANT
C...     OVERSHOOT, AND ELIMINATE OFFSET (STEADY STATE ERROR).
C...
C...     (2)  TO DETERMINE THE OPTIMUM OPERATING TEMPERATURE, TR1, TO
C...     MAXIMIZE THE YIELD OF INTERMEDIATE PRODUCT, B.
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  SET THE MODEL PARAMETERS
      V1=100.
      M=0.1
      CP=60.
      DH1=10000.
      DH2=12000.
      K10=3.0E+13
      K20=5.0E+13
      E1=44700.
      E2=40000.
      XS1=0.5
      CV=0.70
      PS1=100.
      DHS=960.
      A0=1.
      B0=0.
      T0=575.
      R=1.987
      IP=0
C...
C...  SET THE CONTROLLER PARAMETERS
      GO TO(1,2,3,4),NORUN
1     TR1=600.
      AKC=0.
      TI1=1.0E+2
      GO TO 10
2     TR1=600.
      AKC=0.01
      TI1=1.0E+2
      GO TO 10
3     TR1=600.
      AKC=0.1
      TI1=1.0E+2
      GO TO 10
4     TR1=600.
      AKC=1.0
      TI1=1.0E+2
10    CONTINUE
C...
C...  SET THE MODEL INITIAL CONDITIONS
      A1=1.
      B1=0.
      T1=575.
      ER1I=0.
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  MODEL ALGEBRA
      ER1=TR1-T1
      X1=XS1+AKC*(ER1+(1./TI1)*ER1I)
      IF(X1.LT.0.)X1=0.
      IF(X1.GT.1.)X1=1.
      FS1=CV*X1*SQRT(PS1)
      QS1=FS1*DHS
C...
C...  DIFFERENTIAL EQUATIONS
      RATE1=V1*A1*K10*EXP(-E1/(R*T1))
      RATE2=V1*B1*K20*EXP(-E2/(R*T1))
      DA1DT=(1./V1)*(M*(A0-A1)-RATE1)
      DB1DT=(1./V1)*(M*(B0-B1)+RATE1-RATE2)
      DT1DT=(1./(V1*CP))*(M*CP*(T0-T1)-DH1*RATE1-DH2*RATE2+QS1)
C...
C...  NOTE THAT THE FOURTH DIFFERENTIAL EQUATION IS PROGRAMMED ABOVE
C...  WITH THE CALCULATION OF ER1 (D(ER1I)/DT = ER1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION    B1P(4,101),   T1P(4,101),  ER1P(4,101),
     1             X1P(4,101),  QS1P(4,101),      TP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HB1,8X,2HT1,7X,3HER1,8X,2HX1,7X,3HQS1)
C...
C...  PRINT THE NUMERICAL SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 2
      WRITE(NO,3)T,B1,T1,ER1,X1,QS1
3     FORMAT(F10.1,F10.4,2F10.1,F10.4,F10.1)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2     B1P(NORUN,IP)=B1
      T1P(NORUN,IP)=T1
      ER1P(NORUN,IP)=ER1
      X1P(NORUN,IP)=X1
      QS1P(NORUN,IP)=QS1
      TP(IP)=T
      IF(IP.NE.101)RETURN
C...
C...  PLOT THE SOLUTION AT THE END OF THE FOURTH RUN
      IF(NORUN.EQ.4)GO TO 4
      IP=0
      RETURN
C...
C...  PLOT THE SOLUTION
4     CALL TPLOTS(NORUN,IP,TP,B1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,12H  B1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,T1P)
      WRITE(NO,12)
12    FORMAT(1H ,//,12H  T1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,ER1P)
      WRITE(NO,13)
13    FORMAT(1H ,//,12H ER1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,X1P)
      WRITE(NO,14)
14    FORMAT(1H ,//,12H  X1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,QS1P)
      WRITE(NO,15)
15    FORMAT(1H ,//,12H QS1 VS TIME)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MAY HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, B1P,IP,3H*T*,8H* B1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, T1P,IP,3H*T*,8H* T1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ER1P,IP,3H*T*,8H*ER1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, X1P,IP,3H*T*,8H* X1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QS1P,IP,3H*T*,8H*QS1(T)*,2H**,NORUN)
C...
C...  ******************************************************************
C...
      RETURN
      END
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
END OF RUNS
*APP PRC10
      SUBROUTINE INITAL
C...
C...  CSTR WITH PROPORTIONAL TEMPERATURE CONTROL AND PLOTTING
C...
C...  THE FOLLOWING PROGRAMMING IMPLEMENTS THE DIFFERENTIAL EQUATIONS
C...  FOR A CONTINUOUS STIRRED TANK REACTOR (CSTR) WITH PROPORTIONAL
C...  CONTROL OF THE OUTLET TEMPERATURE.  THE DETAILS OF THE MATHE-
C...  MATICAL MODEL ARE GIVEN IN THE COMMENTS.
C...
C...  CONTENTS OF THE USUAL DSS/2 COMMON AREAS
C...
C...     /T/   T       TIME (SEC)
C...
C...           NFIN    RUN TERMINATOR
C...
C...           NRUN    RUN COUNTER
C...
C...     /Y/   A       REACTANT CONCENTRATION (LB MOL/CU FT)
C...
C...           TE      REACTOR TEMPERATURE (R)
C...
C...     /F/   DADT    DERIVATIVE OF A WITH RESPECT TO T (LB MOL/CU FT
C...                   /SEC)
C...
C...           DTEDT   DERIVATIVE OF TE WITH RESPECT TO T (R/SEC)
C...
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
C...
C...  COMMON/C/ CONTAINS CONSTANTS AND VARIABLES OF THE MODEL
C...
C...           AKC  ECONTROLLER GAIN (LB/SEC-R)
C...
C...           QS       STEAM FLOW RATE IN THE HEATING COIL (LB/SEC)
C...
      COMMON/C/AKC,QS
C...
C...  SET THE CONTROLLER GAIN FOR THREE RUNS OF THE MODEL
      IF(NRUN.EQ.1) AKC=0.
      IF(NRUN.EQ.2) AKC=0.03
      IF(NRUN.EQ.3) AKC=0.3
C...
C...  SET THE MODEL INITIAL CONDITIONS
      A=1.
      TE=575.
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
      COMMON/C/AKC,QS
C...
C...  ******************************************************************
C...
C...  MODEL ALGEBRA (CONTROLLER EQUATION)
C...
C...     QS = (MS + AKC*(TR - TE))*DHV
C...
C...        MS      STEADY-STATE STEAM FLOW RATE = 0.711 LB/SEC
C...
C...        AKC     PROPORTIONAL CONTROLLER GAIN (LB/SEC-R)
C...
C...        TR      REFERENCE (SET-POINT) TEMPERATURE = 600 R
C...
C...        DHV     HEAT OF VAPORIZATION OF STEAM AT 5 PSIG = 960
C...                BTU/LB
C...
C...  SUBSTITUTION OF THE PRECEDING CONSTANTS IN THE CONTROLLER EQUATION
C...  GIVES
      QS=682.+960.*AKC*(600.-TE)
C...
C...  ******************************************************************
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     MATERIAL BALANCE
C...
C...     V*DA/DT = M*(A0 - A) - V*(A**2)*K0*EXP(-E/(R*TE))
C...
C...        V       REACTOR VOLUME = 100 CU FT
C...
C...        M       FEED AND WITHDRAWAL RATES OF THE PROCESS MATERIAL
C...                = 0.1 CU FT/SEC
C...
C...        A0      REACTANT FEED CONCENTRATION = 1 LB MOL/CU FT
C...
C...        K0      FREQUENCY FACTOR IN SECOND-ORDER RATE EXPRESSION
C...                = 1.907E+13 CU FT/SEC-LB MOL
C...
C...        E       ACTIVATION ENERGY = 44,700 BTU/LB MOL A REACTED
C...
C...        R       GAS CONSTANT = 1.987 BTU/LB MOL-R
C...
C...  THE REACTION RATE GROUP IS FIRST CALCULATED SINCE IT IS USED IN
C...  BOTH DIFFERENTIAL EQUATIONS
      RATE=(A**2)*(1.907E+13)*EXP(-44700./(1.987*TE))
C...
C...  THE REACTION RATE IS THEN SUBSTITUTED IN THE MATERIAL BALANCE
C...  ALONG WITH THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY V)
      DADT=0.001*(1.-A)-RATE
C...
C...     ENERGY BALANCE
C...
C...     V*C*DTE/DT = M*C*(T0 - TE) - DH*V*(A**2)*K0*EXP(-E/(R*TE)) + QS
C...
C...        C       VOLUMETRIC SPECIFIC HEAT OF THE PROCESS = 60
C...                BTU/CU FT-R
C...
C...        T0      REACTOR FEED TEMPERATURE = 575 R
C...
C...        DH      HEAT OF REACTION = 10,000 BTU/LB MOL A REACTED
C...                (ENDOTHERMIC)
C...
C...  THE REACTION RATE IS SUBSTITUTED IN THE ENERGY BALANCE ALONG WITH
C...  THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY C*V)
      DTEDT=0.001*(575.-TE)-(10000./60.)*RATE+QS/(6.0E+03)
C...
C...  ALL OF THE MODEL DERIVATIVES HAVE BEEN DEFINED NUMERICALLY, SO
C...  RETURN FROM DERV
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
      COMMON/C/AKC,QS
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TEP(3,51),TDP(3,51),QSP(3,51),TP(51),AKCP(3)
C...
C...  INITIALIZE A COUNTER FOR THE PRINTED AND PLOTTED SOLUTIONS
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.10.)WRITE(NO,2)
2     FORMAT(11X,1HT,11X,1HA,10X,2HTE,7X,5HTR-TE,10X,2HQS)
C...
C...  STORE THE SOLUTION IN EACH CALL TO SUBROUTINE PRINT FOR SUBSEQUENT
C...  PLOTTING
      IP=IP+1
      TEP(NRUN,IP)=TE
      TDP(NRUN,IP)=600.-TE
      QSP(NRUN,IP)=QS
       TP(IP)=T
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY FIFTH CALL TO SUBROUTINE
C...  PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      TD=600.-TE
      WRITE(NO,1)T,A,TE,TD,QS
1     FORMAT(F12.0,4F12.3)
C...
C...  TEST FOR THE END OF A RUN
3     IF(IP.LT.51)RETURN
      AKCP(NRUN)=AKC
C...
C...  AT THE END OF THE THIRD RUN, PLOT THE THREE NUMERICAL SOLUTIONS
C...  TOGETHER
      IF(NRUN.EQ.3)GO TO 5
      IP=0
      RETURN
C...
C...  PLOT TE VS T
5     CALL TPLOTS(NRUN,IP,TP,TEP)
      WRITE(NO,10)
10    FORMAT(1H ,//,18H TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
4     FORMAT(1H , /,17H CONTROLLER GAINS,3F6.3)
C...
C...  PLOT TR-TE VS T
      CALL TPLOTS(NRUN,IP,TP,TDP)
      WRITE(NO,11)
11    FORMAT(1H ,//,21H TR-TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT QS VS T
      CALL TPLOTS(NRUN,IP,TP,QSP)
      WRITE(NO,12)
12    FORMAT(1H ,//,24H QS (BTU/SEC) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
      RETURN
      END
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP
0.        2000.     40.
    2 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        2000.     40.
    2 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        2000.     40.
    2 5000    1    1  REL  0.001
END OF RUNS
*APP PRC11
      SUBROUTINE INITAL
C...
C...  THREE-COMPONENT CSTR WITH TEMPERATURE CONTROL
C...
C...  THE FOLLOWING PROGRAMMING IMPLEMENTS THE DIFFERENTIAL EQUATIONS
C...  FOR A CONTINUOUS STIRRED TANK REACTOR (CSTR) WITH PROPORTIONAL
C...  CONTROL OF THE OUTLET TEMPERATURE.  THE DETAILS OF THE MATHE-
C...  MATICAL MODEL ARE GIVEN IN THE COMMENTS.
C...
C...  CONTENTS OF THE USUAL DSS/2 COMMON AREAS
C...
C...     /T/   T       TIME (SEC)
C...
C...           NFIN    RUN TERMINATOR
C...
C...           NRUN    RUN COUNTER
C...
C...     /Y/  BC(1)    CONCENTRATION OF COMPONENTS A, B AND C, RESPECT-
C...           C(2)    IVELY, IN THE REACTION A + B --+ C (LB MOL/CU FT)
C...           C(3)
C...
C...           TE      REACTOR TEMPERATURE (R)
C...
C...     /F/  DCDT(1)  DERIVATIVES OF C(1), C(2) AND C(3), RESPECTIVELY,
C...          DCDT(2)  WITH RESPECT TO T (LB MOL/CU FT/SEC)
C...          DCDT(3)
C...
C...           DTEDT   DERIVATIVE OF TE WITH RESPECT TO T (R/SEC)
C...
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
C...
C...  COMMON/C/ CONTAINS CONSTANTS AND VARIABLES OF THE MODEL
C...
C...           AKC  ECONTROLLER GAIN (LB/SEC-R)
C...
C...           QS       STEAM FLOW RATE IN THE HEATING COIL (LB/SEC)
C...
      COMMON/C/AKC,QS
C...
C...  SET THE CONTROLLER GAIN FOR THREE RUNS OF THE MODEL
      IF(NRUN.EQ.1) AKC=0.
      IF(NRUN.EQ.2) AKC=0.05
      IF(NRUN.EQ.3) AKC=0.5
C...
C...  SET THE MODEL INITIAL CONDITIONS
      C(1)=1.
      C(2)=0.
      C(3)=0.
      TE=575.
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
      COMMON/C/AKC,QS
C...
C...  ******************************************************************
C...
C...  MODEL ALGEBRA (CONTROLLER EQUATION)
C...
C...     QS = (MS + AKC*(TR - TE))*DHV
C...
C...        MS      STEADY-STATE STEAM FLOW RATE = 0.711 LB/SEC
C...
C...        AKC     PROPORTIONAL CONTROLLER GAIN (LB/SEC-R)
C...
C...        TR      REFERENCE (SET-POINT) TEMPERATURE = 600 R
C...
C...        DHV     HEAT OF VAPORIZATION OF STEAM AT 5 PSIG = 960
C...                BTU/LB
C...
C...  SUBSTITUTION OF THE PRECEDING CONSTANTS IN THE CONTROLLER EQUATION
C...  GIVES
      QS=682.+960.*AKC*(600.-TE)
C...
C...  ******************************************************************
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     MATERIAL BALANCES
C...
C...     V*DC(1)/DT = M*(C0(1) - C(1)) - V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...     V*DC(2)/DT = M*(C0(2) - C(2)) - V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...     V*DC(3)/DT = M*(C0(3) - C(3)) + V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...        V       REACTOR VOLUME = 100 CU FT
C...
C...        M       FEED AND WITHDRAWAL RATES OF THE PROCESS MATERIAL
C...                = 0.1 CU FT/SEC
C...
C...        C0(1)   FEED COMPOSITIONS FOR COMPONENTS A, B AND C, RE-
C...        C0(2)   SPECTIVELY, = 1, 1, 0 LB MOL/CU FT
C...        C0(3)
C...
C...        K0      FREQUENCY FACTOR IN SECOND-ORDER RATE EXPRESSION
C...                = 1.907E+13 CU FT/SEC-LB MOL
C...
C...        E       ACTIVATION ENERGY = 44,700 BTU/LB MOL A REACTED
C...
C...        R       GAS CONSTANT = 1.987 BTU/LB MOL-R
C...
C...  THE REACTION RATE GROUP IS FIRST CALCULATED SINCE IT IS USED IN
C...  ALL FOUR DIFFERENTIAL EQUATIONS
      RATE=C(1)*C(2)*(1.907E+13)*EXP(-44700./(1.987*TE))
C...
C...  THE REACTION RATE IS THEN SUBSTITUTED IN THE MATERIAL BALANCES
C...  ALONG WITH THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY V)
      DCDT(1)=0.001*(1.-C(1))-RATE
      DCDT(2)=0.001*(1.-C(2))-RATE
      DCDT(3)=0.001*(0.-C(3))+RATE
C...
C...     ENERGY BALANCE
C...
C...     V*C*DTE/DT = M*C*(T0 - TE) - DH*V*(A**2)*K0*EXP(-E/(R*TE)) + QS
C...
C...        C       VOLUMETRIC SPECIFIC HEAT OF THE PROCESS = 60
C...                BTU/CU FT-R
C...
C...        T0      REACTOR FEED TEMPERATURE = 575 R
C...
C...        DH      HEAT OF REACTION = 10,000 BTU/LB MOL A REACTED
C...                (ENDOTHERMIC)
C...
C...  THE REACTION RATE IS SUBSTITUTED IN THE ENERGY BALANCE ALONG WITH
C...  THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY C*V)
      DTEDT=0.001*(575.-TE)-(10000./60.)*RATE+QS/(6.0E+03)
C...
C...  ALL OF THE MODEL DERIVATIVES HAVE BEEN DEFINED NUMERICALLY, SO
C...  RETURN FROM DERV
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
      COMMON/C/AKC,QS
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION C1P(3,51),C2P(3,51),C3P(3,51),TEP(3,51),QSP(3,51),
     1             TP(51),  AKCP(3)
C...
C...  INITIALIZE A COUNTER FOR THE PRINTED AND PLOTTED SOLUTIONS
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.10.)WRITE(NO,2)
2     FORMAT(11X,1HT,10X,2HCA,10X,2HCB,10X,2HC3,10X,2HTE,10X,2HQS)
C...
C...  STORE THE SOLUTION IN EACH CALL TO SUBROUTINE PRINT FOR SUBSEQUENT
C...  PLOTTING
      IP=IP+1
      C1P(NRUN,IP)=C(1)
      C2P(NRUN,IP)=C(2)
      C3P(NRUN,IP)=C(3)
      TEP(NRUN,IP)=TE
      QSP(NRUN,IP)=QS
       TP(IP)=T
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY FIFTH CALL TO SUBROUTINE
C...  PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      WRITE(NO,1)T,(C(I),I=1,3),TE,QS
1     FORMAT(F12.0,5F12.3)
C...
C...  TEST FOR THE END OF A RUN
3     IF(IP.LT.51)RETURN
      AKCP(NRUN)=AKC
C...
C...  AT THE END OF THE THIRD RUN, PLOT THE THREE NUMERICAL SOLUTIONS
C...  TOGETHER
      IF(NRUN.EQ.3)GO TO 5
      IP=0
      RETURN
C...
C...  PLOT C(1) VS T
5     CALL TPLOTS(NRUN,IP,TP,C1P)
      WRITE(NO,10)
10    FORMAT(1H ,//,29H C1 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT C(2) VS T
      CALL TPLOTS(NRUN,IP,TP,C2P)
      WRITE(NO,11)
11    FORMAT(1H ,//,29H C2 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT C(3) VS T
      CALL TPLOTS(NRUN,IP,TP,C3P)
      WRITE(NO,12)
12    FORMAT(1H ,//,29H C3 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
4     FORMAT(1H , /,17H CONTROLLER GAINS,3F6.3)
C...
C...  PLOT TE VS T
      CALL TPLOTS(NRUN,IP,TP,TEP)
      WRITE(NO,13)
13    FORMAT(1H ,//,18H TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT QS VS T
      CALL TPLOTS(NRUN,IP,TP,QSP)
      WRITE(NO,14)
14    FORMAT(1H ,//,24H QS (BTU/SEC) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
      RETURN
      END
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP
0.        4000.     80.
    4 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        4000.     80.
    4 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        4000.     80.
    4 5000    1    1  REL  0.001
END OF RUNS
*APP PRC12
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF THE LIQUID LEVELS IN TWO INTERACTING HOLDING TANKS
C...
C...  CONSIDER THE PI CONTROL OF THE LIQUID LEVELS IN TWO INTERACTING
C...  HOLDING TANKS MODELED BY THE EQUATIONS
C...
C...     A1*DH1/DT = (F0 - F1), H1(0) = 200
C...
C...     A2*DH2/DT = (F1 - F2), H2(0) = 100
C...
C...     F1 = SIGN(H1 - H2)*CV1*X1*((ABS(H1 - H2))**0.5)
C...
C...     F2 = CV2*X2*(H2**0.5)
C...
C...                                   T
C...     X2 = X2SS + KC2*(E1 + (1/TI)*INT E1*DT)
C...                                   0
C...
C...     E1 = H1 - H1SET
C...
C...     A1 = A2 = CV1 = CV2 = 1, X1 = 0.5, X2SS = 0.5, H1SET = 200
C...
C...  RUN THIS MODEL FOR TWO CASES AND PLOT E1(T) VS T FOR EACH CASE
C...
C...     (1)  F0 = 5
C...
C...     (2)  F0 = 6
C...
C...  FOR BOTH CASES, IT WILL BE NECESSARY TO CHOOSE REASONABLE VALUES
C...  OF THE CONTROLLER GAIN, KC, AND INTEGRAL TIME, TI, I.E., YOU ARE
C...  TO DESIGN OR TUNE THE CONTROLLER BY COMPUTER SIMULATION.
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    H1,    H2,   E1I
     2      /F/ DH1DT, DH2DT,    E1
     3      /C/    A1,    A2,   CV1,   CV2,    X1,  X2SS, H1SET,    F0,
     4            AKC,    TI,    X2,    IP
C...
C...  SET THE MODEL PARAMETERS
      A1=1.
      A2=1.
      CV1=1.
      CV2=1.
      X1=0.5
      X2SS=0.5
      H1SET=200.
      AKC=0.01
      TI=100.
      IF(NORUN.EQ.1)F0=5.
      IF(NORUN.EQ.2)F0=6.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      H1=200.
      H2=100.
      E1I=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES AND INITIALIZE A COUNTER FOR
C...  THE PLOTTED SOLUTION
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    H1,    H2,   E1I
     2      /F/ DH1DT, DH2DT,    E1
     3      /C/    A1,    A2,   CV1,   CV2,    X1,  X2SS, H1SET,    F0,
     4            AKC,    TI,    X2,    IP
C...
C...  MODEL ALGEBRA
      IF(H1.GE.H2)SIGN =1.
      IF(H1.LT.H2)SIGN=-1.
      F1=SIGN*CV1*X1*SQRT(ABS(H1-H2))
      E1=H1-H1SET
      X2=X2SS+AKC*(E1+(1./TI)*E1I)
      IF(X2.LT.0.)X2=0.
      IF(X2.GT.1.)X2=1.
      F2=CV2*X2*SQRT(H2)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DH1DT=(1./A1)*(F0-F1)
      DH2DT=(1./A2)*(F1-F2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    H1,    H2,   E1I
     2      /F/ DH1DT, DH2DT,    E1
     3      /C/    A1,    A2,   CV1,   CV2,    X1,  X2SS, H1SET,    F0,
     4            AKC,    TI,    X2,    IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION E1P(21),TP(21)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HH1,8X,2HH2,5X,5HDH1DT,5X,5HDH2DT,8X,2HE1,
     1       8X,2HX2)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,H1,H2,DH1DT,DH2DT,E1,X2
2     FORMAT(7F10.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      E1P(IP)=E1
      TP(IP)=T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.21)RETURN
      CALL TPLOTS(1,IP,TP,E1P)
      WRITE(NO,3)
3     FORMAT(1H ,//,11H E1(T) VS T)
      RETURN
      END
PI CONTROL OF TWO INTERACTING HOLDING TANKS
0.        1000.     50.
    3 1000    1    1  REL 0.001
PI CONTROL OF TWO INTERACTING HOLDING TANKS
0.        1000.     50.
    3 1000    1    1  REL 0.001
END OF RUNS
*APP PRC13
      SUBROUTINE INITAL
C...
C...  COMPARATIVE EVALUATION OF CONTROLLING THE INLET VS OUTLET
C...  FLOWS OF A DYNAMIC UNIT
C...
C...  CONSIDER THE FOLLOWING MODELS FOR THE CONTROL OF LIQUID LEVEL
C...  IN A HOLDING TANK
C...
C...  (1)  CONTROL OF THE OUTLET FLOW
C...
C...       TANK TOTAL MATERIAL BALANCE
C...
C...         DH/DT = (1/A)*(F0 - F1), H(0) = 100
C...
C...       TANK OUTLET VALVE
C...
C...         F1 = CV1*X1*H**0.5
C...
C...       PROPORTIONAL CONTROLLER
C...
C...         X1 = XSS + KC*(H - HSET)
C...
C...       MODEL PARAMETERS
C...
C...         A = 5000, F0 = 10000, CV1 = 1000, XSS = 0.5, HSET = 180
C...
C...         KC - TO BE DETERMINED FROM THE SIMULATION
C...
C...  (2)  CONTROL OF THE INLET FLOW
C...
C...       TANK TOTAL MATERIAL BALANCE
C...
C...         DH/DT = (1/A)*(F0 - F1), H(0) = 100
C...
C...       TANK OUTLET VALVE
C...
C...         F1 = CV1*X1*H**0.5
C...
C...       PROPORTIONAL CONTROLLER
C...
C...         X0 = XSS + KC*(HSET - H)
C...
C...       TANK INLET VALVE
C...
C...         F0 = CV0*X0*CF
C...
C...       MODEL PARAMETERS
C...
C...       A = 5000, CV1 = 1000, X1 = 0.5, XSS = 0.5, HSET = 180,
C...
C...       CV0 = 1000, CF = 10, KC - TO BE DETERMINED FROM THE
C...       SIMULATION
C...
C...  STUDY THE TWO PROPOSED CONTROL SYSTEMS (I.E., THE CONTROLLER
C...  GAIN, KC, IN EACH CASE) TO DETERMINE IF ONE SYSTEM IS APPARENTLY
C...  BETTER THAN THE OTHER.  THE BASIC PURPOSE OF THE TANK IS TO
C...  MINIMIZE DOWNSTREAM DISTURBANCES WITHOUT HAVING THE TANK OVER-
C...  FLOW (THE TANK HEIGHT IS 200, SO THE SET POINT FOR H(T) IS
C...  180)
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/     H
     2      /F/  DHDT
     3      /C/     A,     F0,     F1,   CV0,   CV1,    X0,    X1,
     4            XSS,     KC,   HSET,    CF,    IP
      REAL KC
C...
C...  DEFINE THE MODEL CONSTANTS
      GO TO(1,2),NORUN
C...
C...  CASE (1)
1     A=5000.
      F0=10000.
      CV1=1000.
      XSS=0.5
      HSET=180.
      KC=0.1
      GO TO 10
C...
C...  CASE (2)
2     A=5000.
      CV1=1000.
      X1=0.5
      XSS=0.5
      HSET=180.
      CV0=1000.
      CF=10.
      KC=0.1
C...
C...  INITIAL CONDITION
10    H=100.
C...
C...  CALCULATE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/     H
     2      /F/  DHDT
     3      /C/     A,     F0,     F1,   CV0,   CV1,    X0,    X1,
     4            XSS,     KC,   HSET,    CF,    IP
      REAL KC
C...
C...  DEFINE THE MODEL FOR EACH CASE
      GO TO(1,2),NORUN
C...
C...  CASE (1)
C...
C...     ALGEBRA
1        X1=XSS+KC*(H-HSET)
         IF(X1.LT.0.)X1=0.
         IF(X1.GT.1.)X1=1.
         F1=CV1*X1*SQRT(H)
C...
C...     DIFFERENTIAL EQUATION
         DHDT=(1./A)*(F0-F1)
         RETURN
C...
C...  CASE (2)
C...
C...     ALGEBRA
2        X0=XSS+KC*(HSET-H)
         IF(X0.LT.0.)X0=0.
         IF(X0.GT.1.)X0=1.
         F0=CV0*X0*CF
         F1=CV1*X1*SQRT(H)
C...
C...     DIFFERENTIAL EQUATION
         DHDT=(1./A)*(F0-F1)
         RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/     H
     2      /F/  DHDT
     3      /C/     A,     F0,     F1,   CV0,   CV1,    X0,    X1,
     4            XSS,     KC,   HSET,    CF,    IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION HP(2,21), FP(2,21), XP(21), TP(21)
      REAL KC
C...
C...  SELECT THE PRINTOUT FOR THE TWO CASES
      GO TO(1,2),NORUN
C...
C...  CASE (1)
1     IF(IP.EQ.0)WRITE(NO,11)
11    FORMAT(9X,1HT,9X,1HH,5X,5HDH/DT,8X,2HF0,8X,2HF1,8X,2HX1)
      WRITE(NO,12)T,H,DHDT,F0,F1,X1
12    FORMAT(F10.0,F10.1,F10.3,2F10.0,F10.3)
      GO TO 30
C...
C...  CASE (2)
2     IF(IP.EQ.0)WRITE(NO,21)
21    FORMAT(9X,1HT,9X,1HH,5X,5HDH/DT,8X,2HF0,8X,2HF1,8X,2HX0)
      WRITE(NO,22)T,H,DHDT,F0,F1,X0
22    FORMAT(F10.0,F10.1,F10.3,2F10.0,F10.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
30    IP=IP+1
      HP(1,IP)=HSET
      HP(2,IP)=H
      FP(1,IP)=F0
      FP(2,IP)=F1
      IF(NORUN.EQ.1)XP(IP)=X1
      IF(NORUN.EQ.2)XP(IP)=X0
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.21)RETURN
      CALL TPLOTS(2,IP,TP,HP)
      WRITE(NO,41)
41    FORMAT(1H ,//,17H HSET, H VS T    )
      CALL TPLOTS(2,IP,TP,FP)
      WRITE(NO,42)
42    FORMAT(1H ,//,17H F0, F1 VS T     )
      CALL TPLOTS(1,IP,TP,XP)
      WRITE(NO,43)
43    FORMAT(1H ,//,17H X VS T          )
      RETURN
      END
CONTROL OF THE OUTLET FLOW
0.        100.      5.
    1 1000    1    1  REL 0.001
CONTROL OF THE INLET FLOW
0.        100.      5.
    1 1000    1    1  REL 0.001
END OF RUNS
*APP PRC14
      SUBROUTINE INITAL
C...
C...  TRANSIENT RESPONSE OF A PNEUMATIC SYSTEM WITH A CENTRIFUGAL
C...  COMPRESSOR
C...
C...  THE PNEUMATIC SYSTEM IS COMPLETELY DESCRIBED IN PROBLEM 4-6 OF THE
C...  REFERENCE CITED BELOW* AND IN THE FIRST LINE OF DATA.  THEREFORE,
C...  ONLY THE EQUATIONS FOR CALCULATING THE COMPRESSOR CONSTANTS A0,
C...  A1 AND A2 ARE SUMMARIZED BELOW
C...
C...  *LUYBEN, W. L., PROCESS MODELING, SIMULATION AND CONTROL FOR
C...  CHEMICAL ENGINEERS, MCGRAW-HILL BOOK COMPANY, NEW YORK, 1973,
C...  PROB. 4-6, P119.
C...
C...     187 = A0 +  50*A1 +  50**2*A2
C...
C...     170 = A0 + 100*A1 + 100**2*A2
C...
C...       0 =  IA1 +   2*50*A2
C...
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/    P1,    P2,    P3,    EI
     2           /F/ DP1DT, DP2DT, DP3DT, DEIDT
     3           /C/    A0,    A1,    A2,    KC,  TAUI,   MRT,    IP,
     4                  W0,    W1,    W2,    W3,     E,     X,    V1,
     5                  V2,    V3
      REAL              KC,   MRT
C...
C...  SET THE MODEL PARAMETERS
      MRT=29./(10.73*(460.+100.))
C...
C...  THREE FLOWS ARE OF INTEREST IN THIS PROBLEM
C...
C...     W3 = 100000     (STEADY STATE FLOW WHICH ZEROES THE DERIVATIVES
C...                      DP1DT, DP2DT, DP3DT, DEIDT IN COMMON/F/)
C...
C...     W3 = 100000*0.8 (A 20 PERCENT DECREASE IN FLOW W3)
C...
C...     W3 = 100000*1.2 (A 20 PERCENT INCREASE IN FLOW W3)
C...
C...  THE RESPONSES FOR THE LAST TWO CASES ARE NOT SYMMETRICAL BECAUSE
C...  OF THE NONLINEARITIES OF THE PROBLEM SYSTEM.  THUS A CONTROLLER
C...  WHICH PERFORMS SATISFACTORILY FOR A FLOW INCREASE (I.E., A PARTI-
C...  CULAR CHOICE OF THE CONTROLLER GAIN KC AND INTEGRAL TIME TAUI) MAY
C...  NOT BE SATISFACTORY FOR A FLOW DECREASE.
C...
      W3=100000.*1.2
      V1=10.
      V2=10.
      V3=(3.1415927*(8.**2)/4.)*20.
      A2=17./(3.*50000.**2-100000.**2)
      A1=-2.*A2*50000.
      A0=187.0-50000.*A1-50000.**2*A2
C...
C...  SET THE CONTROLLER PARAMETERS FOR A SERIES OF RUNS
      GO TO(1,2,3),NORUN
1     KC=0.
      TAUI=1.0E+10
      GO TO 10
2     KC=0.1
      TAUI=1.0E+10
      GO TO 10
3     KC=0.1
      TAUI=0.05
10    IP=0
C...
C...  SET THE INITIAL CONDITIONS
      P1=50.0
      P2=220.0
      P3=200.0
      EI=1.0E-10
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/    P1,    P2,    P3,    EI
     2           /F/ DP1DT, DP2DT, DP3DT, DEIDT
     3           /C/    A0,    A1,    A2,    KC,  TAUI,   MRT,    IP,
     4                  W0,    W1,    W2,    W3,     E,     X,    V1,
     5                  V2,    V3
      REAL              KC,   MRT
      E=200.-P3
      X=0.5+KC*(E+EI)
      W0=40000.*X*SQRT(75.-P1)
      W1=(-A1-SQRT(A1**2 - 4.*A2*(A0+P1-P2)))/(2.*A2)
      W2=SQRT(1.0E+10*(P2-P3)/20.)
      DP1DT=1./(V1*MRT)*(W0-W1)
      DP2DT=1./(V2*MRT)*(W1-W2)
      DP3DT=1./(V3*MRT)*(W2-W3)
      DEIDT=1./TAUI*E
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/    P1,    P2,    P3,    EI
     2           /F/ DP1DT, DP2DT, DP3DT, DEIDT
     3           /C/    A0,    A1,    A2,    KC,  TAUI,   MRT,    IP,
     4                  W0,    W1,    W2,    W3,     E,     X,    V1,
     5                  V2,    V3
      REAL              KC,   MRT
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE SOLUTION
      DIMENSION TP(51),EP(3,51)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)A2,A1,A0
1     FORMAT(1H ,//,6H A2 = ,E10.2,5X,6H A1 = ,E10.3,5X,6H A0 = ,E10.3,/
     1/,5X,5H TIME,/,10X,2HP1,10X,2HP2,10X,2HP3,7X,5HDP1DT,7X,5HDP2DT,7X
     2,5HDP3DT,10X,2HW0,10X,2HW1,10X,2HW2,10X,2HW3,11X,1HE)
C...
C...  PRINT THE NUMERICAL SOLUTION INITIALLY AND IN EVERY FIFTH CALL TO
C...  SUBROUTINE PRINT
      IF(((IP/5*5).NE.IP).AND.(IP.NE.0))GO TO 4
      WRITE(NO,3)T,P1,P2,P3,DP1DT,DP2DT,DP3DT,W0,W1,W2,W3,E
3     FORMAT(1H ,F10.3,/,11E12.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
4     IP=IP+1
      TP(IP)=T
      EP(NORUN,IP)=E
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.3)RETURN
      CALL PLOTS(NORUN,IP,TP,EP)
      WRITE(NO,2)
2     FORMAT(1H ,//,48H E(T) VS T FOR KC AND TAUI SET IN INITAL        )
      RETURN
      END
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-6
0.        0.1       0.002
    4 1000    1    1  REL 0.001
REPEATS                                                                  H
    2
END OF RUNS
*APP PRC15
      SUBROUTINE INITAL
C...
C...  SINUSOIDAL RESPONSE OF A NONLINEAR SYSTEM
C...
C...  THIS PROBLEM IS AN EXTENSION OF THE EARLIER PROBLEM EVAPORATION
C...  FROM A TANK IN WHICH THE SINUSOIAL VARIATION OF THE AMBIENT TEMP-
C...  IS ALLOWED TO GO THROUGH ENOUGH CYCLES TO OBSERVE THE FREQUENCY
C...  RESPONSE
C...
C...  EVAPORATION FROM A TANK DEPICTED BELOW IS TO BE SIMULATED
C...
C...                                          CONVECTION
C...                         EVAPORATION         AND
C...                              +         . RADIATION
C...  AMBIENT TEMPERATURE = TA   .         .
C...  AMBIENT HUMIDITY = YA     .         .
C...                           .         .
C...              + .    TF   .         +   YI   .
C...              . ..............................
C...              . .                            .
C...              . .                            .
C...              Z .             TF             .+...........
C...              . .                            .           .
C...              . .                            .           .
C...              . .                            .           .
C...              + ..............................           .
C...                              .         RECIRCULATION .......
C...                              .              PUMP     .     .
C...                              .                       .......
C...                              .                          +
C...                              ............................
C...
C...  THE LIQUID (WATER) IN THE TANK CAN BE ASSUMED TO BE AT A UNIFORM
C...  TEMPERATURE, TF, THROUGHOUT THE TANK (PERFECTLY MIXED).
C...
C...  AN ENERGY BALANCE ON THE TANK GIVES
C...
C...     D(V*RHO*CP*TF)/DT = -KY*A*HVAP*(YI - YA) + H*A*(TA - T)
C...                                                                (1)
C...                         +U*P*Z*(TA - T)
C...
C...  WHERE
C...
C...     TF     TEMPERATURE OF LIQUID IN THE TANK
C...
C...     TA     AMBIENT TEMPERATURE
C...
C...     YA     AMBIENT HUMIDITY
C...
C...     YI     HUMIDITY AT THE LIQUID SURFACE (SATURATION HUMIDITY
C...            AT TEMPERATURE TF)
C...
C...     T      TIME
C...
C...     V      VOLUME OF LIQUID IN THE TANK
C...
C...     RHO    LIQUID DENSITY
C...
C...     CP     LIQUID HEAT CAPACITY
C...
C...     KY     MASS TRANSFER COEFFICIENT FOR EVAPORATION
C...
C...     A      TANK CROSS SECTIONAL AREA (AREA FOR HEAT AND MASS
C...            TRANSFER FROM THE SURFACE OF THE LIQUID TO THE
C...            SURROUNDING AIR)
C...
C...     HVAP   HEAT OF VAPORIZATION OF THE LIQUID
C...
C...     H      COEFFICIENT FOR HEAT TRANSFER FROM THE LIQUID SURFACE
C...
C...     U      COEFFICIENT FOR HEAT TRANSFER FROM THE WALL OF THE TANK
C...
C...     P      PERIMETER OF THE TANK
C...
C...     Z      HEIGHT OF THE TANK
C...
C...  THE INITIAL CONDITION FOR EQUATION (1) IS
C...
C...     TF(0) = 65 F                                               (2)
C...
C...  THE AMBIENT TEMPERATURE AND HUMIDITY, TA AND YA, VARY SINUSOIDALLY
C...  WITH TIME.  THE RESPONSE OF THE TANK LIQUID TEMPERATURE, TF, AND
C...  THE INTERFACIAL HUMIDITY, YI, CAN BE OBSERVED, PRINCIPALLY THROUGH
C...  PLOTS PRODUCED IN SUBROUTINE PRINT.
C...
C...  THE VAPOR PRESSURE OF WATER IS GIVEN BY THE EQUATION
C...
C...     PV = 51.7*3206.7*EXP(6.53247 - 7173.79/(T + 389.4747))     (3)
C...
C...  WHICH IS USED IN THE CALCUATION OF THE HUMIDITIES, YA AND YI
C...  (SEE THE CODING IN SUBROUTINE DERV FOR THE DETAILS).  T IS THE
C...  TEMPERATURE IN F (T = TA OR TF WHEN THE AMBIENT HUMIDITY OR
C...  HUMIDITY AT THE LIQUID SURFACE ARE COMPUTED, RESPECTIVELY).
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  SET THE MODEL PARAMETERS
      V=808.
      RHO=62.3
      CP=1.0
      KYA=7.69*200.
      H=2.0
      A=200.
      U=H
      P=60.
      Z=4.
      HVAP=970.
C...
C...  SET THE MODEL INITIAL CONDITION
      TF=65.
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  AMBIENT TEMPERATURE
      TA=TAMB(T)
C...
C...  VAPOR PRESSURE IN ATMOSPHERES AT TEMPERATURES TF AND TA
      PVTF=51.7*3206.7*EXP(6.53247-7173.79/(TF+389.4747))/760.0
      PVTA=51.7*3206.7*EXP(6.53247-7173.79/(TA+389.4747))/760.0
C...
C...  CONVERSION OF PERCENT RELATIVE HUMIDITY TO RELATIVE HUMIDITY
      RH=PRH(T)/100.
C...
C...  HUMIDITIES AS WEIGHT OF WATER/UNIT WEIGHT OF AIR
      YI=PVTF*1./(1.0-PVTF*1.)*18./29.
      YA=PVTA*RH/(1.0-PVTA*RH)*18./29.
C...
C...  MODEL DIFFERENTIAL EQUATION
      DTFDT=(1./(V*RHO*CP))*(-KYA*HVAP*(YI-YA)+H*A*(TA-TF)
     1                     +U*P*Z*(TA-TF))
      RETURN
      END
      FUNCTION TAMB(T)
C...
C...  FUNCTION TAMB COMPUTES THE AMBIENT TEMPERATURE AS A FUNCTION OF
C...  TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=1.
      IF(NORUN.EQ.2)FREQ=3.
      PI=3.1415927
      TAMB=80.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      FUNCTION PRH(T)
C...
C...  FUNCTION PRH COMPUTES THE PERCENT RELATIVE HUMIDITY AS A FUNCTION
C...  OF TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=1.
      IF(NORUN.EQ.2)FREQ=3.
      PI=3.1415927
      PRH=44.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TIMEP(501), TP(2,501), YP(2,501), EP(501)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HTF,4X,6HDTF/DT,8X,2HTA,8X,2HRH,8X,2HYI,8X,2HYA)
C...
C...  PRINT THE SOLUTION EVERY 50TH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/50*50).NE.(IP-1))GO TO 3
      WRITE(NO,2)T,TF,DTFDT,TA,RH,YI,YA
2     FORMAT(1H ,/,7E10.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TIMEP(IP)=T
      TP(1,IP)=TA
      TP(2,IP)=TF
      YP(1,IP)=YA
      YP(2,IP)=YI
      EP(IP)=KYA*(YI-YA)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.501)RETURN
C...
C...  TA AND TF VS T
      CALL PLOTS(2,IP,TIMEP,TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,48H 1 - TA, 2 - TF VS T                            )
C...
C...  YA AND YI VS T
      CALL PLOTS(2,IP,TIMEP,YP)
      WRITE(NO,12)
12    FORMAT(1H ,//,48H 1 - YA, 2 - YI VS T                            )
C...
C...  KYA*(YI - YA) VS T
      CALL PLOTS(1,IP,TIMEP,EP)
      WRITE(NO,13)
13    FORMAT(1H ,//,48H KYA*(YI - YA) VS T                             )
C...
C...  ******************************************************************
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND WILL HAVE TO BE CONVERTED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TIMEP,TP,IP,6H*TIME*,8H*TA, TF*,2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TIMEP,YP,IP,6H*TIME*,8H*YA, YI*, 2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TIMEP,EP,IP,6H*TIME*,15H*KYA*(YI - YA)*,2H**,1)
C...
C...  ******************************************************************
C...
      IP=0
      RETURN
      END
EVAPORATION FROM A TANK, FREQUENCY = 1
0.        500.      1.
    1 1000    1    1  REL 0.001
EVAPORATION FROM A TANK, FREQUENCY = 3
0.        500.      1.
    1 1000    1    1  REL 0.001
END OF RUNS
*APP PRC16
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=0.1
         TI=30.0
      ELSE
      END IF
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      QS=QSS+KC*(E+(1./TI)*EI)
      IF(QS.LT.0.)QS=0.
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  QSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      QSP(IP)=QS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QSP,IP,3H*T*,10H* QS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP PRC17
      SUBROUTINE INITAL
C...
C...  ULTIMATE GAIN OF A FEEDBACK CONTROL SYSTEM
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  OF PARTICULAR INTEREST IN THIS STUDY IS THE ULTI-
C...  MATE GAIN OF THE CONTROLLER, I.E., THE VALUE OF THE GAIN FOR
C...  WHICH THE CONTROLLED SYSTEM IS ON THE THRESHOLD OF INSTABILITY
C...  AND THERFORE UNDERGOES SUSTAINED OSCILLATION.
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH MODEL THE HEAT
C...  EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      N=11
      IP=0
C...
C...  THE FOLLOWING VALUE FOR THE CONTROLLER GAIN WAS DETERMINED BY
C...  TRIAL AND ERROR TO PUT THE SYSTEM NEAR SUSTAINED OSCILLATION.
C...  IT IS THEREFORE AN APPROXIMATE VALUE FOR THE ULTIMATE GAIN,
C...  BUT IT IS NOT A HIGHLY REFINED VALUE (I.E., IT IS ACCURATE TO
C...  ONLY ABOUT ONE FIGURE).  ALSO, THE INTEGRAL ACTION HAS BEEN
C...  ESSENTIALLY REMOVED BY SETTING TI TO A LARGE VALUE.  THE SUS-
C...  TAINED OSCILLATION WHICH RESULTS IS OF SMALL AMPLITUDE (FRACTIONS
C...  OF A DEGREE), AND CAN THEREFORE BEST BE VIEWED WITH A CONTINUOUS
C...  PLOTTER, E.G., THE CALLS TO QIKPLT, RATHER THAN THE LINE PRINTER
C...  PLOTTING, I.E., THE CALLS TO TPLOTS IN SUBROUTINE PRINT.
      KC=0.6
      TI=1.0E+10
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      QS=QSS+KC*(E+(1./TI)*EI)
      IF(QS.LT.0.)QS=0.
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  QSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      QSP(IP)=QS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QSP,IP,3H*T*,10H* QS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
ULTIMATE GAIN OF A FEEDBACK CONTROL SYSTEM
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP PRC18
      SUBROUTINE INITAL
C...
C...  EFFECT OF SATURATION ON CONTROL SYSTEM PERFORMANCE
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
C...  OF PARTICULAR INTEREST IN THIS STUDY IS THE EFFECT OF SATURATION
C...  OF THE CONTROL VALVE.  IN OTHER WORDS, THE VALVE HAS A FINITE
C...  CAPACITY WHEN IT IS FULLY OPEN, AND IF THE CONTROL SYSTEM COMMANDS
C...  A GREATER OPENING, THE CONTROL ACTION IS LIMITED BY THE VALVE.
C...
C...  THREE RUNS ARE PROGRAMNMED
C...
C...     (1)  NORUN = 1
C...
C...          THE VALVE HAS UNLIMITED CAPACITY
C...
C...     (2)  NORUN = 2
C...
C...          THE VALVE HAS FOUR TIMES THE CAPACITY OF THE NORMAL STEADY
C...          STATE FLOW
C...
C...     (3)  NORUN = 3
C...
C...          THE VALVE HAS TWO TIMES THE CAPACITY OF THE NORAML STEADY
C...          STATE FLOW.
C...
C...  FOR EACH RUN, THE INTEGRAL OF THE ABSOLUTE ERROR IS COMPUTED TO
C...  GIVE A MEASURE OF THE OVERALL CONTROL SYSTEM PERFORMANCE.  AT THE
C...  OF THE THIRD RUN, THIS INTEGRATED ERROR IS PLOTTED VS TIME FOR ALL
C...  THREE RUNS SO THE EFFECT OF VALVE SATURATION CAN BE OBSERVED.
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      KC=0.1
      TI=30.0
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      E1I=0.
      E2I=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E1=T3SET-T3(N)
      QS=QSS+KC*(E1+(1./TI)*E1I)
      IF(QS.LT.0.)QS=0.
C...
C...  VALVE SATURATION
C...
C...  NORUN = 1
      IF(NORUN.EQ.1)THEN
         GO TO 10
C...
C...  NORUN = 2
      ELSE IF(NORUN.EQ.2)THEN
         IF(QS.GT.4.0*QSS)QS=4.0*QSS
         GO TO 10
C...
C...  NORUN = 3
      ELSE
         IF(QS.GT.2.0*QSS)QS=2.0*QSS
      END IF
10    CONTINUE
C...
C...  INTEGRAL OF THE ABSOLUTE ERROR
      E2=ABS(E1)
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11),
     1          T3P(3,101),TSP(3,101),QSP(3,101),E2P(3,101),
     2             TP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(NORUN,IP)=T3(N)
      TSP(NORUN,IP)=TS(1)
      QSP(NORUN,IP)=QS
      E2P(NORUN,IP)=E2I
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE PROFILES AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  PLOT THE TIME RESPONSES FOR THE THREE CASES (NORUN = 1, 2, 3)
      IF(NORUN.LT.3)RETURN
      CALL TPLOTS(3,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(3,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(3,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(3,IP,TP,E2P)
      WRITE(NO,10)
10    FORMAT(1H ,//,31H INTEGRAL OF ABS(E) VS T       )
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
END OF RUNS
*APP PRC19
      SUBROUTINE INITAL
C...
C...  THE QUASI STEADY STATE APPROXIMATION
C...
C...  THE QUASI STEADY STATE APPROXIMATION IS A COMPUTATIONAL PROCEDURE
C...  IN WHICH THE DERIVATIVES OF SELECTED ORDINARY DIFFERENTIAL EQUA-
C...  TIONS (ODES) IN A SET OF ODES ARE SET TO ZERO.  THUS, THESE SE-
C...  LECTED ODES ARE CONVERTED TO ALGEBRAIC EQUATIONS, WHICH ARE THEN
C...  SOLVED ALONG WITH THE REMAINING ODES.
C...
C...  THE CHOICE OF WHICH DERIVATIVES TO SET TO ZERO IS MADE LARGELY
C...  ON PHYSICAL GROUNDS, E.G. THE ZEROED DERIVATIVES ARE FOR SO-CALLED
C...  FAST ODES, FOR WHICH THE DEPENDENT VARIABLES ARE ESSENTIALLY AT
C...  A STEADY STATE CONDITION THROUGHOUT THE ENTIRE SOLUTION OF THE
C...  ODE SYSTEM.  THE ARGUMENT IS SIMPLY THAT IF THESE DEPENDENT VARI-
C...  ABLES ESSENTIALLY ALWAYS HAVE AN INSTANTANEOUS STEADY STATE VALUE,
C...  THEY MAY AS WELL BE COMPUTED FROM STEADY STATE EQUATIONS, I.E.,
C...  ODES FOR WHICH THE DERIVATIVES HAVE BEEN SET TO ZERO.
C...
C...  THE MOST COMMON REASON ADVANCED FOR USING THE QUASI STEADY STATE
C...  APPROXIMATION IS THAT IT CAN REDUCE THE TOTAL NUMBER OF ODES, AND
C...  FURTHER, IT ELIMINATES THE FAST ODES SO THAT THE NUMERICAL INTE-
C...  GRATION OF THE REMAINING ODES IS FACILITATED.  IT IS NOT CLEAR
C...  WHETHER THE QUASI STEADY STATE APPROXIMATION DOES IN FACT FACILI-
C...  TATE THE SOLUTION OF THE ORIGINAL ODE MODEL SINCE THE CURRENT
C...  STATE-OF-THE-ART ODE INTEGRATORS CAN EASILY ACCOMMODATE LARGE
C...  SETS OF ODES WITH SLOW AND FAST EQUATIONS WHICH ARE, LOOSELY
C...  SPEAKING, CALLED STIFF ODE SYSTEMS.
C...
C...  IN ANY CASE, THE FOLLOWING EXAMPLE ILLUSTRATES HOW THE QUASI
C...  STEADY STATE APPROXIMATION IS USED.  THE PROBLEM IS FIRST SOLVED
C...  WITH TWO ODES (THE FULL SET OF ODES), AND THEN IS SOLVED WITH ONE
C...  OF THE TWO ODES CONVERTED TO AN ALGEBRAIC EQUATION BY SETTING THE
C...  DERIVATIVE TO ZERO.  THUS, A COMPARISON OF THE TWO SOLUTIONS GIVES
C...  A DIRECT INDICATION OF THE EFFECT OF THE QUASI STEADY STATE APPRO-
C...  XIMATION ON THE SOLUTION.
C...
C...  THE PHYSICAL PROBLEM INVOLVES THE DRAINAGE OF A CYLINDRICAL TANK
C...  THROUGH A PIPE CONNECTED TO THE BOTTOM OF THE TANK.  A MATHEMATI-
C...  CAL MODEL FOR THE TANK IS DERIVED AS FOLLOWS
C...
C...  MASS BALANCE ON THE LIQUID IN THE TANK
C...
C...     D(RHO*AT*H)/DT = 0 - (-V)*AP*RHO                          (1)
C...
C...  WHERE
C...
C...     H       HEIGHT OF LIQUID IN THE TANK (CM)
C...
C...     T       TIME (SEC)
C...
C...     AT      TANK CROSS SECTIONAL AREA (CM**2)
C...
C...     RHO     LIQUID DENSITY (GM/CM**3)
C...
C...     V       VELOCITY OF LIQUID IN THE PIPE (CM/SEC)
C...
C...     AP      PIPE CROSS SECTIONAL AREA (CM**2)
C...
C...  MOMENTUM BALANCE ON THE LIQUID IN THE PIPE (NEWTON*S SECOND LAW),
C...  ASSUMING AN INCOMPRESSIBLE LIQUID
C...
C...     (1/GC)*D(L*AP*RHO*V)/DT = -(PA + (G/GC)*RHO*H)*AP
C...                                                               (2)
C...                               -(1/GC)*L*AP*RHO*G + PA*AP + FF
C...
C...     GC      CONVERSION FACTOR BETWEEN FORCE AND MASS = 1 GM-CM/
C...             DYNE-SEC**2
C...
C...     L       PIPE LENGTH (CM)
C...
C...     PA      ATMOSPHERIC PRESSURE (DYNES/CM**2)
C...
C...     G       ACCELERATION OF GRAVITY = 980 CM/SEC**2
C...
C...     FF      FRICTIONAL FORCE = F*RHO*(V**2)*L*AP/(2*DP*GC) (DYNES)
C...
C...     F       FRICTION FACTOR (A FUNCTION OF THE REYNOLDS NUMBER, RE)
C...             (DIMENSIONLESS)
C...
C...     RE      REYNOLDS NUMBER = DP*V*RHO/VIS (DIMENSIONLESS)
C...
C...     VIS  DLIQUID VISCOSITY (GM/CM-SEC)
C...
C...  IF THE CONSTANTS ARE DIVIDED OUT OF THE DERIVATIVE OF EQUATION
C...  (1), THE RESULTING EQUATION (WITH AN INITIAL CONDITION) IS
C...
C...     DH/DT = (AP/AT)*V, H(0) = H0                              (3)
C...
C...  IF THE CONSTANTS ARE DIVIDED OUT OF THE DERIVATIVE OF EQUATION
C...  (2), THE RESULTING EQUATION (WITH AN INITIAL CONDITION) IS
C...
C...  DV/DT = -G*(1 + H/L) + (F*V**2)/(2*DP), V(0) = V0            (4)
C...
C...  THE FRICTION FACTOR CORRELATIONS ARE
C...
C...  F = 64/RE, 0 LE RE LE 2000, F = 0.189/RE**0.2, RE GT 2000
C...
C...  EQUATIONS (3) AND (4) ARE THE FULL (TWO) ODE MODEL.  THE EFFLUX
C...  TIME (THE TIME FOR THE TANK TO DRAIN) IS COMPUTED FOR THE FOLLOW-
C...  ING CASES
C...
C...     (A)  DP = 0.5 CM, DV/DT NE 0
C...
C...     (B)  DP = 1.0 CM, DV/DT NE 0
C...
C...     (C)  DP = 0.5 CM, DV/DT = 0
C...
C...     (D)  DP = 1.0 CM, DV/DT = 0
C...
C...  THE LIQUID IS WATER AT ROOM TEMPERATURE.  THE OTHER MODEL PARA-
C...  METERS ARE - TANK DIAMETER = 25 CM, PIPE LENGTH = 1 METER, H(0) =
C...  50 CM, V(0) = 0.  THE NUMERICAL VALUES OF THESE PARAMETERS ARE
C...  SET BELOW.
C...
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      H,      V
     2      /F/   DHDT,   DVDT
     3      /C/     AP,     AT,      G,      L,     DP,    RHO,    VIS,
     4              RE,      F,     FF,     IP
      REAL           L
C...
C...  SET THE MODEL PARAMETERS
      PI=4.*ATAN(1.)
      DT=25.
      AT=PI*(DT**2)/4.
      G=980.
      L=100.
      RHO=1.
      VIS=0.01
      IF(NORUN.EQ.1)DP=0.5
      IF(NORUN.EQ.2)DP=1.0
      IF(NORUN.EQ.3)DP=0.5
      IF(NORUN.EQ.4)DP=1.0
      AP=PI*(DP**2)/4.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      H=50.
      V=0.
C...
C...  INITIALIZE A COUNTER FOR USE IN SUBROUTINE PRINT
      IP=0
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      IF(NORUN.GT.2)GO TO 1
      CALL DERV
      RETURN
C...
C...  FOR THE RUNS USING THE QUASI STEADY STATE APPROXIMATION, SET AN
C...  ESTIMATE OF THE FRICTION FACTOR (WHICH IS THEN UPDATED OR CORRECT-
C...  ED IN SUBROUTINE DERV) AND ZERO THE DERIVATIVE DV/DT (SO THAT IT
C...  IS NOT PRINTED AS A NONZERO VALUE REMAINING FROM THE RUNS WITH
C...  DV/DT NE 0)
1     F=0.03
      DVDT=0.
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,   NFIN,  NORUN
C...
C...  MODEL WITH DV/DT NE 0
      IF(NORUN.LE.2)CALL DERV1
C...
C...  MODEL WITH DV/DT = 0
      IF(NORUN.GT.2)CALL DERV2
      RETURN
      END
      SUBROUTINE DERV1
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      H,      V
     2      /F/   DHDT,   DVDT
     3      /C/     AP,     AT,      G,      L,     DP,    RHO,    VIS,
     4              RE,      F,     FF,     IP
      REAL           L
C...
C...  MODEL WITH FULL (TWO) ODE SYSTEM
C...
C...  IF THE VELOCITY IS ZERO, THE FRICTION TERM IS ZERO
      RE=0.
      F=0.
      FF=0.
      IF(ABS(V).LT.1.0E-04)GO TO 1
C...
C...  REYNOLDS NUMBER
      RE=DP*ABS(V)*RHO/VIS
C...
C...  SELECT THE EQUATION FOR THE FRICTION FACTOR
      IF(RE.LE.2000)F=64./RE
      IF(RE.GT.2000)F=0.189/RE**0.2
C...
C...  FRICTION TERM FOR NONZERO VELOCITY
      FF=F*(V**2)/(2.*DP)
C...
C...  DIFFERENTIAL EQUATIONS
1     DHDT=(AP/AT)*V
      DVDT=-G*(1.+H/L)+FF
C...
C...  TEST IF THE TANK HAS DRAINED
      IF(H.LE.0.)NFIN=1
      RETURN
      END
      SUBROUTINE DERV2
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      H,      V
     2      /F/   DHDT,   DVDT
     3      /C/     AP,     AT,      G,      L,     DP,    RHO,    VIS,
     4              RE,      F,     FF,     IP
      REAL           L
      COMMON/IO/    NI,     NO
C...
C...  MODEL WITH QUASI STEADY STATE APPROXIMATION
C...
C...  COMPUTE THE VELOCITY ITERATIVELY BY ALGEBRAIC EQUATIONS (RATHER
C...  THAN VIA A DIFFERENTIAL EQUATION AS IN THE PRECEDING CODING)
C...
C...  BEGIN THE ITERATIVE CALCULATION OF THE VELOCITY
      ITER=0
C...
C...  UPDATE THE VELOCITY IN THE ITERATIVE CALCULATION OF THE VELOCITY
1     VOLD=V
      V=-SQRT(2.*DP*G*(1.+H/L)/F)
C...
C...  CHECK FOR CONVERGENCE OF THE VELOCITY CALCULATION
      IF(ABS(V-VOLD).LT.1.)GO TO 2
C...
C...  UPDATE THE FRICTION FACTOR
      RE=DP*ABS(V)*RHO/VIS
      IF(RE.LE.2000.)F=64./RE
      IF(RE.GT.2000.)F=0.189/RE**0.2
C...
C...  CHECK FOR LACK OF CONVERGENCE
      ITER=ITER+1
      IF(ITER.LT.100)GO TO 1
C...
C...  PRINT AN ERROR MESSAGE THAT THE ITERATION HAS NOT CONVERGED
C...  AND GO ON TO THE NEXT RUN
      WRITE(NO,3)ITER
3     FORMAT(1H ,//,36H CONVERGENCE OF V NOT ACHIEVED AFTER,I5,
     1              11H ITERATIONS)
      NFIN=1
      RETURN
C...
C...  CONTINUE THE CALCULATIONS WITH THE NEW VELOCITY
2     DHDT=(AP/AT)*V
C...
C...  COMPUTE THE FRICTION FORCE TERM SO THAT IT CAN BE PRINTED IN
C...  SUBROUTINE PRINT
      FF=F*(V**2)/(2.*DP)
C...
C...  TEST IF THE TANK HAS DRAINED
      IF(H.LE.0.)NFIN=1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      H,      V
     2      /F/   DHDT,   DVDT
     3      /C/     AP,     AT,      G,      L,     DP,    RHO,    VIS,
     4              RE,      F,     FF,     IP
      REAL           L
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,9X,1HH,9X,1HV,5X,5HDH/DT,5X,5HDV/DT,
     1       8X,2HRE,9X,1HF,8X,2HFF)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,2)T,H,V,DHDT,DVDT,RE,F,FF
2     FORMAT(F10.1,F10.3,F10.2,F10.4,F10.2,F10.0,F10.4,F10.1)
      IP=IP+1
      RETURN
      END
THE QUASI STEADY STATE APPROXIMATION, DV/DT NE 0, DP = 0.5
0.        1000.     100.
    2 1000    1    1  REL 0.001
THE QUASI STEADY STATE APPROXIMATION, DV/DT NE 0, DP = 1.0
0.        200.      20.
    2 1000    1    1  REL 0.001
THE QUASI STEADY STATE APPROXIMATION, DV/DT = 0, DP = 0.5
0.        1000.     100.
    1 1000    1    1  REL 0.001
THE QUASI STEADY STATE APPROXIMATION, DV/DT = 0, DP = 1.0
0.        200.      20.
    1 1000    1    1  REL 0.001
END OF RUNS
*APP PRC20
      SUBROUTINE INITAL
C...
C...  EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
C...
C...  THE FOLLOWING EQUATIONS DESCRIBE THE DYNAMICS OF A HUMIDIFIER
C...  (A PACKED COLUMN WITH WATER AND AIR FLOWING COUNTERCURRENTLY)
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                  (1)
C...      T                Z
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                      (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                      (3)
C...
C...                          - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THE GAS FLOW RATE, V, IS TO BE CONTROLLED BY A PROPORTIONAL-
C...  INTEGRAL CONTROLLER ACCORDING TO THE EQUATIONS
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TSET
C...
C...  WHERE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TSET    CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS ARE
C...
C...   H*AV = 50 BTU/(HR-FT**3 OF COLUMN-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3 COLUMN)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2 COLUMN
C...
C...   H = 0.5 LB MOLS/(FT**3 COLUMN), G = 0.01 LB MOLS/(FT**3 COLUMN)
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TSET = 90 F
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  ALSO, THREE RUNS  ARE PROGRAMMED
C...
C...     (1)  KC AND TI ARE SELECTED FOR A WELL-TUNED CONTROLLER
C...          SO THE HUMIDIFICATION COLUMN RESPONDS NEARLY OPTIMALLY
C...          (FAST RESPONSE WITH LITTLE OVERSHOOT).
C...
C...     (2)  PROPORTIONAL CONTROL ONLY WITH THE GAIN NEAR THE
C...          ULTIMATE VALUE FOR SUSTAINED OSCILLATION.
C...
C...     (3)  ONE HALF THE GAIN OF (2) WITH INTEGRAL ACTION ADDED
C...          TO AGAIN PRODUCE NEARLY SUSTAINED OSCILLATION.
C...
C...  AS THE SYSTEM MOVES CLOSER TO SUSTAINED OSCILLATION, I.E., CASES
C...  (2) AND (3), THE TEMPORAL EIGENVALUES COMPUTED BY CALLS TO SUB-
C...  ROUTINE EIGEN IN SUBROUTINE PRINT, SHOULD MOVE CLOSER TO PURE
C...  IMAGINARY VALUES.  THIS EFFECT CAN BE CHECKED BY COMPARING THE
C...  EIGENVALUES COMPUTED AND PRINTED FOR THE THREE RUNS.
C...
C...  THESE THREE RUNS CAN BE RUN CONSECUTIVELY, BUT THE TOTAL RUN
C...  TIME IS RATHER LARGE.  THEREFORE, THEY ARE PROGRAMMED TO RUN
C...  INDIVIDUALLY (SEE THE SUBSEQUENT CODING FOR SETTING KC AND TI
C...  IN SUBROUTINE INITIAL), AND ONLY ONE SET OF DATA IS USED.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  SET THE COLUMN PARAMETERS
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS (NOTE THAT THE CONTROLLER PARA-
C...  METERS ARE SELECTED FOR A SINGLE RUN BY REMOVING COMMENTS
C...  RATHER THAN EXECUTION OF THREE SUCCESSIVE RUNS VIA THE IF-
C...  THEN-ELSE CONSTRUCT)
C...
C...  WELL TUNED CONTROLLER
C...  IF(NORUN.EQ.1)THEN
         KC=0.02
         TI=0.1
C...
C...  ULTIMATE GAIN
C...  ELSE IF(NORUN.EQ.2)THEN
C...     KC=0.4
C...     TI=1.0E+10
C...
C...  ULTIMATE PERIOD (WITH INTEGRAL ACTION)
C...  ELSE
C...     KC=0.2
C...     TI=0.02
C...  END IF
      CVDP=50.
      XSS=0.5
      TSET=90.
      IP=0
      N=11
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      TL(I)=110.
      TG(I)=110.
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      TL(N)=110.
      TG(1)=110.
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINE JMAP AND EIGEN
      DIMENSION       A(34,34),         WF(34),
     1                  SV(34),      SVOLD(34),
     2                   F(34),       FOLD(34)
      COMPLEX       EIGENV(34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  MAP THE ODE JACOBIAN MATRIX AND COMPUTE THE TEMPORAL EIGENVALUES
C...  AT T = 0, 0.25, 0.5 TO OBSERVE THE CHANGE IN THE MODEL STRUCTURE
C...  AND EIGENVALUES DUE TO THE NONLINEARITIES
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,EIGENV,WF)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP PRC21
      SUBROUTINE INITAL
C...
C...  EFFECT OF TIME DELAYS ON THE PERFORMANCE OF FEEDBACK CONTROL
C...  SYSTEMS
C...
C...  THREE CSTR*S (CONTINUOUS-STIRRED-TANK REACTORS) ARE MODELLED
C...  BY THE FOLLOWING DIFFERENTIAL EQUATIONS
C...
C...     DCA1/DT = (1/TAU)*(CA0(T)       - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1(T - TD1) - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2(T - TD2) - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     TD1       TIME DELAY FOR THE LINE CONNECTING THE FIRST AND
C...               SECOND CSTR*S
C...
C...     TD2       TIME DELAY FOR THE LINE CONNECTING THE SECOND AND
C...               THIRD CSTR*S
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION WHICH STEPS FROM 0.4 TO 0.6
C...               AT T = 0 (IF CAD REMAINS AT 0.4, THE ENTIRE SYSTEM
C...               REMAINS AT STEADY STATE, I.E., THE DERIVATIVES IN THE
C...               DIFFERENTIAL EQUATIONS REMAIN AT ZERO OR DCA1/DT =
C...               DCA2/DT = DCA3/DT = 0)
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM = CAMSS + AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     CAMSS     STEADY STATE VALUE OF CAM = 0.4
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION CA3 = CA3SET - CA3
C...
C...     CA3SET    SET POINT FOR CA3 = 0.1
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE TO BE SOLVED FOR THE FOLLOWING CASES
C...
C...     (1)  CAD = 0.4, AK = 20, TAUI = 5, TD1 = TD2 = 0 (NORUN = 1)
C...
C...         (TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE
C...          WITHOUT TIME DELAYS)
C...
C...     (2)  CAD = 0.4, AK = 20, TAUI = 5, TD1 = 2, TD2 = 4 (NORUN = 2)
C...
C...         (TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE
C...          WITH TIME DELAYS)
C...
C...     (3)  CAD = 0.6, AK = 20, TAUI = 5, TD1 = TD2 = 0 (NORUN = 3)
C...
C...         (WELL TUNED CONTROLLER WITHOUT TIME DELAYS)
C...
C...     (4)  CAD = 0.6, AK = 20, TAUI = 5, TD1 = 2, TD2 = 4 (NORUN = 4)
C...
C...         (EFFECT ON THE WELL TUNED CONTROLLER OF (3) WHEN TIME
C...          DELAYS ARE INTRODUCED)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
C...
C...  THE FOLLOWING PARAMETERS VARY FROM RUN TO RUN
C...
C...  NORUN = 1
      IF(NORUN.EQ.1)THEN
         CAD=0.4
         AK=20.
         TAUI=5.0
         TD1=0.
         TD2=0.
C...
C...  NORUN = 2
      ELSE IF(NORUN.EQ.2)THEN
         CAD=0.4
         AK=20.
         TAUI=5.0
         TD1=2.
         TD2=4.
C...
C...  NORUN = 3
      ELSE IF(NORUN.EQ.3)THEN
         CAD=0.6
         AK=20.
         TAUI=5.0
         TD1=0.
         TD2=0.
C...
C...  NORUN = 4
      ELSE
         CAD=0.6
         AK=20.
         TAUI=5.0
         TD1=2.
         TD2=4.
      END IF
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
      CA10=0.4
      CA20=0.2
      CA30=0.1
      CA(1)=CA10
      CA(2)=CA20
      CA(3)=CA30
      ERINT=0.
C...
C...  INITIALIZE TWO COUNTERS USED IN SUBROUTINE PRINT
      IP=0
      IS=0
C...
C...  INITIALIZE THE ALGEBRAIC VARIABLES COMPUTED IN SUBROUTINE
C...  DERV FOR PRINTING AT THE INITIAL CONDITION
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  CONTROLLER
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
C...
C...  CONSTRAIN THE CONCENTRATIONS TO MEANINGFUL VALUES
      IF(CA0  .LT.0.)CA0  =0.
      IF(CA(1).LT.0.)CA(1)=0.
      IF(CA(2).LT.0.)CA(2)=0.
      IF(CA(3).LT.0.)CA(3)=0.
C...
C...  THE REMAINDER OF SUBROUTINE DERV IS NOT EXECUTED THE FIRST
C...  TIME DERV IS CALLED FROM SUBROUTINE INITAL SINCE THE DELAYED
C...  DEPENDENT VARIABLES HAVE NOT BEEN STORED (IN SUBROUTINE
C...  PRINT) FOR USE IN THE FOLLOWING CALLS TO FUNCTION DELAY1
      IF(IS.EQ.0)RETURN
C...
C...  IN COMPUTING THE DELAYED VARIABLES, IF ANY TIME DELAY IS LESS
C...  THAN THE PRINT INTERVAL, 0.2 IN THIS CASE, WHICH IS THE RESOLU-
C...  TION OF FUNCTION DELAY1, THE VARIABLE IS ASSUMED TO BE UNDELAYED
C...
C...  DELAYED CA1(T)
      IF(TD1.LT.0.2)THEN
         CA1DEL=CA(1)
      ELSE
         CA1DEL=DELAY1(1,T-TD1)
      END IF
C...
C...  DELAYED CA2(T)
      IF(TD2.LT.0.2)THEN
         CA2DEL=CA(2)
      ELSE
         CA2DEL=DELAY1(2,T-TD2)
      END IF
C...
C...  DIFFERENTIAL EQUATIONS
      DCADT(1)=(CA0   -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA1DEL-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA2DEL-CA(3))/TAU-RK*CA(3)
      RETURN
      END
      FUNCTION DELAY1(I,DT)
C...
C...  FUNCTION DELAY1 SIMULATES A PURE TIME DELAY
C...
C...  ARGUMENT LIST
C...
C...     I       INDEX FOR THE DEPENDENT VARIABLE TO BE DELAYED (I = 1
C...             FOR THE FIRST VARIABLE TO BE DELAYED, I = 2 FOR THE
C...             SECOND VARIABLE TO BE DELAYED, ETC.) (INPUT)
C...
C...     DT      THE DELAY IN TIME OF DEPENDENT VARIABLE I (INPUT)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  IF THE DELAYED TIME IS NEGATIVE, THE OUTPUT OF THE TIME DELAY
C...  IS THE INITIAL CONDITION
      IF(DT.LT.0.)THEN
         IF(I.EQ.1)THEN
            DELAY1=CA10
            RETURN
         ELSE IF(I.EQ.2)THEN
            DELAY1=CA20
            RETURN
C...
C...     MORE DELAYED VARIABLES (I GT 2) CAN BE ADDED HERE
         ELSE
         END IF
C...
C...  IF THE DELAYED TIME IS NONNEGATIVE, THE DELAYED VARIABLES ARE
C...  IN ARRAYS IN COMMON/DELAY/, WHICH TO THIS POINT IN TIME HAVE
C...  BEEN FILLED IN SUBROUTINE PRINT WITH THE SUBSCRIPT IS, I.E.,
C...  THE CURRENT VALUE OF T CORRESPONDS TO IS
      ELSE
C...     STEP THROUGH THE IS STORED VALUES OF TIME TO FIND THE PAST
C...     TIME CORRESPONDING TO DT AND SET FUNCTION DELAY1 TO THE
C...     CORRESPONDING VALUE OF THE DELAYED VARIABLE
         DO 2 J=1,IS
C...        IF DT EXCEEDS THE TIME IN TIMED(J), A LATER STORED VALUE
C...        OF THE DELAYED VARIABLE IS REQUIRED
            IF(DT.GT.TIMED(J))GO TO 2
C...
C...        DT IS NOW EQUAL TO OR LESS THAN TIMED(J) SO SET FUNCTION
C...        DELAY1 TO THE DEPENDENT VARIABLE CORRESPONDING TO TIMED(J)
            IF(I.EQ.1)THEN
               DELAY1=CA1D(J)
               RETURN
            ELSE IF(I.EQ.2)THEN
               DELAY1=CA2D(J)
               RETURN
C...        MORE DELAYED VARIABLES (I GT 2) CAN BE ADDED HERE
            ELSE
            END IF
2        CONTINUE
      END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(4,101), EP(4,101),    TP(101)
C...
C...  STORE THE CURRENT VALUES OF T, CA1 AND CA2 IN ARRAYS CA1D AND
C...  CA2D FOR USE IN FUNCTION DELAY1
      IS=IS+1
      TIMED(IS)=T
      CA1D(IS)=CA(1)
      CA2D(IS)=CA(2)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,11X,1HE,7X,5HERINT,6X,6HCA1(T),2X,10HCA1(T-TD1),
     1                                 6X,6HCA2(T),2X,10HCA2(T-TD2),
     2                                 6X,6HCA3(T),6X,6HCA0(T))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP) THEN
      CA1DEL=DELAY1(1,T-TD1)
      CA2DEL=DELAY1(2,T-TD2)
      WRITE(NO,2)T,E,ERINT,CA(1),CA1DEL,CA(2),CA2DEL,CA(3),CA0
2     FORMAT(F10.1,8F12.3)
      ELSE
      END IF
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(NORUN,IP)=CA(3)
       EP(NORUN,IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      IF(NORUN.LT.4)RETURN
      CALL TPLOTS(4,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,47H CA3(T) VS T FOR THE FOUR RUNS LISTED IN INITAL)
      CALL TPLOTS(4,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,47H E(T) VS T FOR THE FOUR RUNS LISTED IN INITAL  )
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
END OF RUNS
*APP PRC22
      SUBROUTINE INITAL
C...
C...  LIQUID LEVEL CONTROL OF TWO CASCADED TANKS
C...
C...  THIS PROBLEM INVOLVES THE PROPORTIONAL-INTEGRAL (PI) CONTROL
C...  OF THE LIQUID LEVELS IN TWO CASCADED TANKS.  THE LIQUID LEVEL
C...  IS MEASURED IN THE SECOND TANK, AND THE FLOW INTO THE FIRST
C...  TANK IS THEREBY REGULATED.  THE DESCRIPTIVE EQUATIONS ARE
C...
C...  TANK NO. 1
C...
C...     A1*DH1/DT = F0 - F1
C...
C...  TANK NO. 2
C...
C...     A2*DH2/DT = F1 - F2
C...
C...  VALVES INTO TANK 1, BETWEEN TANKS 1 AND 2, OUT OF TANK 2
C...
C...     F0 = CV0*X0*SQRT(H0)
C...
C...     F1 = CV1*X1*SQRT(H1)
C...
C...     F2 = CV2*X2*SQRT(H2)
C...
C...  CONTROLLER EQUATIONS
C...
C...     E = H2SET - H2
C...
C...     X0 = X0S + KC*(E + (1/TI)*INT(E))
C...
C...  WHERE
C...
C...     H1        HEIGHT OF THE LIQUID IN TANKS 1 AND 2, RESPECTIVELY,
C...     H2        (CM)
C...
C...     A1        CROSS SECTIONAL AREAS OF TANKS 1 AND 2, RESPECTIVELY,
C...     A2        (CM**2)
C...
C...     F0        FLOW INTO TANKS 1 AND 2, RESPECTIVELY, FLOW OUT OF
C...     F1        TANK 2 (CU CM/SEC)
C...     F2
C...
C...     H0        UPSTEAM HEAD AVAILABLE FOR FLOW INTO TANK 1 (CM)
C...
C...     CV0       VALVE CONSTANTS (CU CM/SEC-CM**0.5)
C...     CV1
C...     CV2
C...
C...     X0        VALVE STEM POSITIONS (DIMENSIONLESS AND LIMITED TO
C...     X1        THE INTERVAL 0 TO 1)
C...     X2
C...
C...     E         ERROR IN THE HEIGHT H2 (CM)
C...
C...     H2SET     SET POINT FOR H2 (CM)
C...
C...     X0S       STEADY STATE VALVE STEM POSITION (DIMENSIONLESS)
C...
C...     KC        CONTROLLER GAIN (1/CM), INTEGRAL TIME (SEC), RE-
C...     TI        SPECTIVELY
C...
C...  COMMON AREAS FOR DSS/2, MODEL CONSTANTS AND VARIABLES
      COMMON/T/     T,  NFIN,  NRUN
     1      /Y/    H1,    H2,    EI
     2      /F/ DH1DT, DH2DT,     E
     3      /C/    A1,    A2,   CV0,   CV1,   CV2,   X0S,    X1,
     4             X2,    TI,   AKC, H2SET,    H0,    F0,    F1,
     5             F2,    X0
C...
C...  SET THE MODEL PARAMETERS
      A1=10000.
      A2=10000.
      CV0=3000.
      CV1=3000.
      CV2=3000.
      X0S=0.5
      X1=1.
      X2=1.
      H0=400.
C...
C...  SEVERAL RUNS ARE PROGRAMMED TO INVESTIGATE THE CONTROLLER PERFOR-
C...  MANCE
      GO TO(1,2,3,4,5,6),NRUN
C...
C...  WITH NO CONTROL (AKC = 0), THE SYSTEM WILL REACH THE STEADY STATE
C...  H1 = H2 = 100.  TI AND H2SET ARE DEFINED SIMPLY TO AVOID UNDEFINED
C...  VARIABLES WHEN THE CONTROLLER EQUATION IS USED IN SUBROUTINE DERV.
C...  FOR H1 = H2 = 100, THE FLOWS THROUGH THE THREE VALVES ARE F0 = F1
C...  F2 = 30000.  SINCE ALL THREE FLOWS ARE EQUAL, FROM THE ORDINARY
C...  DIFFERENTIAL EQUATIONS (ODE*S), DH1/DT = DH2/DT = 0 CORRESPONDING
C...  TO THE STEADY STATE H1 = H2 = 100
1     AKC=0.
      TI=100.
      H2SET=100.
      GO TO 10
C...
C...  WITH CONTROL, THE SYSTEM WILL ALSO REACH THE STEADY STATE H1 = H2
C...  = 100 IF H2SET = 100.  NOTE THEREFORE THAT FOR CASES 1 AND 2 (NRUN
C...  = 1, 2), THE SYSTEM WILL REACH THE SAME STEADY STATE, WITH OR
C...  WITHOUT CONTROL.  IN THIS SENSE, THE SYSTEM SELF-REGULATES TO
C...  H1 = H2 = 100 REGARDLESS OF THE INITIAL CONITION (WHICH IN THIS
C...  CASE IS H1(0) = 100, H2(0) = 75)
2     AKC=0.03
      TI=100.
      H2SET=100.
      GO TO 10
C...
C...  PROPORTIONAL CONTROL ONLY WITH H2SET = 125 DEMONSTRATES OFFSET
C...  (THE ERROR AT STEADY STATE).  INTEGRAL CONTROL IS ESSENTIALLY
C...  REMOVED BY SETTING TI TO A LARGE VALUE (THE INTEGRAL ACTION IS
C...  PROPORTIONAL TO 1/TI IN THE CONTROLLER EQUATION), AND THE CORRES-
C...  PONDING OFFSET IS 1.80 CM
3     AKC=0.03
      TI=100000.
      H2SET=125.
      GO TO 10
C...
C...  PROPORTIONAL PLUS INTEGRAL (PI) CONTROL DEMONSTRATES THE ELIMI-
C...  NATION OF THE OFFSET OF THE THIRD CASE (I.E., NRUN = 3) BY THE
C...  INTEGRAL ACTION.  THE CONTROLLER PARAMETERS KC AND TI ARE SELECTED
C...  FOR AN UNDERDAMPED RESPONSE (SEE E VS T PLOTTED IN SUBROUTINE
C...  PRINT)
4     AKC=0.03
      TI=100.
      H2SET=125.
      GO TO 10
C...
C...  PROPORTIONAL PLUS INTEGRAL (PI) CONTROL DEMONSTRATES THE ELIMI-
C...  NATION OF THE OFFSET OF THE THIRD CASE (I.E., NRUN = 3) BY THE
C...  INTEGRAL ACTION.  THE CONTROLLER PARAMETERS KC AND TI ARE SELECTED
C...  FOR AN OVERDAMPED RESPONSE (SEE E VS T PLOTTED IN SUBROUTINE
C...  PRINT)
5     AKC=0.0003
      TI=100.
      H2SET=125.
      GO TO 10
C...
C...  PROPORTIONAL PLUS INTEGRAL (PI) CONTROL DEMONSTRATES THE ELIMI-
C...  NATION OF THE OFFSET OF THE THIRD CASE (I.E., NRUN = 3) BY THE
C...  INTEGRAL ACTION.  THE CONTROLLER PARAMETERS KC AND TI ARE SELECTED
C...  FOR A NEAR CRITICALLY DAMPED RESPONSE (SEE E VS T PLOTTED IN SUB-
C...  ROUTINE PRINT)
6     AKC=0.001
      TI=100.
      H2SET=125.
      GO TO 10
10    CONTINUE
C...
C...  SET THE MODEL INITIAL CONDITIONS
      H1=100.
      H2=75.
      EI=0.
C...
C...  INITIALIZE THE CALCULATIONS IN DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN,  NRUN
     1      /Y/    H1,    H2,    EI
     2      /F/ DH1DT, DH2DT,     E
     3      /C/    A1,    A2,   CV0,   CV1,   CV2,   X0S,    X1,
     4             X2,    TI,   AKC, H2SET,    H0,    F0,    F1,
     5             F2,    X0
C...
C...  MODEL ALGEBRA
C...
C...     CONTROLLER EQUATIONS
         E=H2SET-H2
         X0=X0S+AKC*(E+(1./TI)*EI)
         IF(X0.LT.0.)X0=0.
         IF(X0.GT.1.)X0=1.
C...
C...     VALVE EQUATIONS
         F0=CV0*X0*SQRT(H0)
         F1=CV1*X1*SQRT(H1)
         F2=CV2*X2*SQRT(H2)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DH1DT=(1./A1)*(F0-F1)
      DH2DT=(1./A2)*(F1-F2)
C...
C...  NOTE THAT E IS THE THIRD DERIVATIVE, AND IT IS ALREADY CALCULATED
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN,  NRUN
     1      /Y/    H1,    H2,    EI
     2      /F/ DH1DT, DH2DT,     E
     3      /C/    A1,    A2,   CV0,   CV1,   CV2,   X0S,    X1,
     4             X2,    TI,   AKC, H2SET,    H0,    F0,    F1,
     5             F2,    X0
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION H2P(51), EP(51), TP(51)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.0.5)WRITE(NO,1)
1     FORMAT(7X,1HT,6X,2HH1,6X,2HH2,6X,2HX0,6X,2HF0,6X,2HF1,6X,2HF2,
     1 7X,1HE,6X,2HEI)
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO SUBROUTINE
C...  PRINT
      IP=IP+1
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      WRITE(NO,2)T,H1,H2,X0,F0,F1,F2,E,EI
2     FORMAT(F8.1,2F8.2,F8.3,3F8.0,F8.2,F8.1)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
3     H2P(IP)=H2
       EP(IP)=E
       TP(IP)=T
C...
C...  AT THE END OF THE RUN, PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL TPLOTS(1,IP,TP,H2P)
      WRITE(NO,10)AKC,TI
10    FORMAT(1H ,//,26H H2 (CM) VS T (SEC), KC = ,F7.4,6H TI = ,F8.1)
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)AKC,TI
11    FORMAT(1H ,//,26H  E (CM) VS T (SEC), KC = ,F7.4,6H TI = ,F8.1)
C...
C...  INIIALIZE THE COUNTER FOR THE NEXT PLOT
      IP=0
      RETURN
      END
LIQUID LEVEL CONTROL OF TWO CASCADED TANKS - SELF REGULATED
0.        1000.     20.
    3 5000    1    1  REL 0.001
LIQUID LEVEL CONTROL OF TWO CASCASED TANKS
0.        1000.     20.
    3 5000    1    1  REL 0.001
LIQUID LEVEL CONTROL OF TWO CASCASED TANKS
0.        1000.     20.
    3 5000    1    1  REL 0.001
LIQUID LEVEL CONTROL OF TWO CASCASED TANKS
0.        1000.     20.
    3 5000    1    1  REL 0.001
LIQUID LEVEL CONTROL OF TWO CASCASED TANKS
0.        1000.     20.
    3 5000    1    1  REL 0.001
LIQUID LEVEL CONTROL OF TWO CASCASED TANKS
0.        1000.     20.
    3 5000    1    1  REL 0.001
END OF RUNS
*APP PRC23
      SUBROUTINE INITAL
C...
C...  ROOT LOCUS PLOTTING FOR AN NTH-ORDER SYSTEM
C...
C...  THE FOLLOWING CODING ILLUSTRATES THE PLOTTING OF A ROOT LOCUS
C...  DIAGRAM FOR A FOURTH-ORDER SYSTEM.  HOWEVER, THE METHOD CAN BE
C...  APPLIED TO A SYSTEM OF NTH-ORDER (WITH N ESSENTIALLY UNLIMITED)
C...  IF THE CHARACTERISTIC CLOSED LOOP POLYNOMIAL IS OBTAINED BY
C...  EIGENVALUE ANALYSIS VIA CALLS TO SUBROUTINES JMAP AND EIGEN,
C...  RATHER THAN ANALYTICALLY AS DONE HERE FOR THE FOURTH-ORDER SYSTEM.
C...
C...  CONSIDER THE FOLLOWING DIFFERENTIAL EQUATIONS FOR THREE CSTR*S
C...  (CONTINUOUS STIRRED TANK REACTORS) WITH PI CONTROL OF THE CON-
C...  CENTRATION FROM THE THIRD CSTR
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM =  AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION = -CA3
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE ENTIRELY LINEAR, SO A LINEARIZATION
C...  AND CONVERSION TO PERTURBATION VARIABLES IS NOT NECESSARY
C...  (ACTUALLY, EXPRESSION OF THE EQUATIONS IN TERMS OF PERTURBATIONS
C...  HAS ALREADY BEEN DONE AS INDICATED BY THE DEFINITION OF THE ERROR
C...  E = -CA3, FOR WHICH THE SET POINT IS ZERO, I.E., THE MORE GENERAL
C...  DEFINITION OF THE ERROR WOULD BE E = CA3SET - CA3).
C...
C...  THUS, BECAUSE PERTURBATION VARIABLES HAVE BEEN USED, THE INITIAL
C...  CONDITIONS FOR THE DEPENDENT VARIABLES, CA1(T), CA2(T) AND CA3(T),
C...  WILL BE TAKEN AS ZERO, I.E.,
C...
C...     CA1(0) = CA2(0) = CA3(0) = 0
C...
C...                                             ---    ---
C...  (A)  OBTAIN THE OVERALL TRANSFER FUNCTION, CA3(S)/CAD(S), FOR THIS
C...       SYSTEM (S IS THE LAPLACE TRANSFORM OPERATOR)
C...
C...  (B)  USE AN IMSL SUBROUTINE (E.G., ZPOLR, ZRPOLY) TO FACTOR THE
C...       CLOSED LOOP CHARACTERISTIC POLYNOMIAL OF THE SYSTEM FOR A
C...       SERIES OF VALUES OF KC WITH TAUI = 5.
C...
C...  (C)  PLOT THE ROOTS AS A ROOT LOCUS DIAGRAM (REAL PARTS OF THE
C...       ROOTS VS THE IMAGINARY PARTS OF THE ROOTS)
C...
C...  (D)  FROM THE ROOT LOCUS DIAGRAM, ESTIMATE THE ULTIMATE GAIN OF
C...       THE SYSTEM
C...
C...  (E)  CONFIRM THE ULTIMATE GAIN OF PART (4) WITH A SIMULATION OF
C...       THE SYSTEM.
C...
C...
C...  THE LAPLACE TRANSFORMS OF THE DIFFERENTIAL EQUATIONS AND INITIAL
C...  CONDITIONS ARE
C...
C...       ---            ---   ---      ---
C...     S*CA1 = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...       ---            ---   ---      ---
C...     S*CA2 = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...       ---            ---   ---      ---
C...     S*CA3 = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  OR
C...
C...     --- ---
C...     CA1/CA0 = (1/TAU)/(S + (1/TAU) + K)
C...
C...     --- ---
C...     CA2/CA1 = (1/TAU)/(S + (1/TAU) + K)
C...
C...     --- ---
C...     CA3/CA2 = (1/TAU)/(S + (1/TAU) + K)
C...
C...  THESE ALGEBRAIC EQUATIONS CAN EASILY BE COMBINED TO OBTAIN THE
C...  TRANSFER FUNCTION FOR THE PROCESS (THREE CSTR*S)
C...
C...     --- ---
C...     CA3/CA0 = (1/TAU)**3/(S + (1/TAU) + K)**3
C...
C...             = 1/(TAU*S + K*TAU + 1)**3 = GP(S)
C...
C...  THE LAPLACE TRANSFORM OF THE CONTROLLER EQUATION IS
C...
C...     ---                         ---            ---
C...     CAM = AK*(1 + 1/(TAUI*S))*(-CA3) = GC(S)*(-CA3)
C...
C...  AND FOR CA0,
C...
C...     ---   ---   ---
C...     CA0 = CAD + CAM
C...
C...  IF THESE EQUATIONS ARE COMBINED, AND THE OVER BARS FOR LAPLACE
C...  TRANSFORMS DROPPED
C...
C...     CA3/CA0 = CA3/(CAD + CAM) = CA3 /(CAD + GC(S)*(-CA3)) = GP(S)
C...
C...  SOLVING FOR CA3/CAD GIVES
C...
C...     CA3*(1 + GC(S)*GP(S)) = GP(S)*CAD
C...
C...     CA3/CAD = GP(S)/(1 + GC(S)*GP(S))
C...
C...  WHICH IS A STANDARD FORM FOR THE CLOSED LOOP TRANSFER FUNCTION
C...  RELATING THE CONTROLLED VARIABLE (E.G., CA3), THE DISTURBANCE
C...  VARIABLE (E.G., CAD), AND THE CONTROLLER AND PROCESS TRANSFER
C...  FUNCTIONS (E.G., GC(S) AND GP(S)).
C...
C...  THE CLOSED LOOP CHARACTERISTIC EQUATION (THE DENOMINATOR OF THE
C...  TRANSFER FUNCTION CA3/CAD SET TO ZERO) IS
C...
C...     1 + GC(S)*GP(S) = 0
C...
C...  FOR WHICH THE ROOTS R1, R2, R3 AND R4 ARE TO BE COMPUTED AS A
C...  FUNCTION OF KC.  IN THE PRESENT CASE,
C...
C...     1 + AK*(1 + 1/(TAUI*S))*(1/(TAU*S + K*TAU + 1)**3) = 0
C...
C...  OR AFTER REARRANGEMENT
C...
C...     (TAU*S)*(TAU*S + K*TAU + 1)**3 + AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...  IF THE CUBIC TERM IS MULTIPLIED OUT
C...
C...     (TAU*S)*((TAU*S)**2 + 2*(TAU*S)*(K*TAU + 1) + (K*TAU + 1)**2)*
C...
C...     (TAU*S + K*TAU + 1) + AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...
C...     (TAU*S)*((TAU*S)**3 + 3*((TAU*S)**2)*(K*TAU + 1) +
C...
C...     3*(TAU*S)*((K*TAU + 1)**2) + (K*TAU + 1)**3) +
C...
C...     AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...
C...     (TAU*S)**4 + 3*((TAU*S)**3)*(K*TAU + 1) +
C...
C...     3*((TAU*S)**2)*(K*TAU + 1)**2) + (TAU*S)*(K*TAU + 1)**3) +
C...
C...     AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...  WHICH CAN BE WRITTEN IN THE FINAL FORM
C...
C...     A4*S**4 + A3*S**3 + A2*S**2 + A1*S + A0 = 0
C...
C...  WHERE
C...
C...     A4 = TAU**4
C...
C...     A3 = 3*(TAU**3)*(K*TAU + 1)
C...
C...     A2 = 3*(TAU**2)*((K*TAU + 1)**2)
C...
C...     A1 = TAU*((K*TAU + 1)**3) + AK*TAU
C...
C...     A0 = AK*TAU/TAUI
C...
C...  OR IN FACTORED FORM
C...
C...     (TAU**4)*(S - R1)*(S - R2)*(S - R3)*(S - R4) = 0
C...
C...  R1, R2, R3 AND R4 ARE THEN TO BE PLOTTED AS A FUNCTION OF AK
C...  (WITH TAU = 2, K = 0.5, TAUI = 5).
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
      COMMON/IO/       NI,        NO
C...
C...  DIMENSION THE ARRAYS REQUIRED FOR COMPUTING THE ROOTS OF THE
C...  CHARACTERISTIC POLYNOMIAL
      REAL A(0:4), ZREAL(4), ZIMAG(4), ZR(303), ZI(303)
      COMPLEX Z(4)
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
      CAD=0.6
      AK=51.
      TAUI=5.
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
      CA(1)=0.4
      CA(2)=0.2
      CA(3)=0.1
      ERINT=0.
C...
C...  INITIALIZE THE REMAINDER OF THE MODEL
      CALL DERV
      IP=0
C...
C...  ******************************************************************
C...
C...  STEP THROUGH A SERIES OF OF VALUES OF AK AND COMPUTE THE CORRES-
C...  PONDING ROOTS OF THE CHARACTERISTIC EQUATION
C...
C...  ******************************************************************
C...
C...  SET THE COEFFICIENTS OF THE CHARACTERISTIC POLYNOMIAL WHICH DO
C...  NOT DEPEND ON AK (NOTE THE SOMEWHAT UNEXPECTED ORDER FOR STORING
C...  THE POLYNOMIAL COEFFICIENTS REQUIRED BY IMSL ROUTINE ZPOLR)
      A(0)=TAU**4
      A(1)=3.*(TAU**3)* (RK*TAU+1.)
      A(2)=3.*(TAU**2)*((RK*TAU+1.)**2)
C...
C...  SET THE INITIAL VALUE OF AK
      AKO=-1.0
C...
C...  SET THE DEGREE OF THE CHARACTERISTIC POLYNOMIAL
      NDEG=4
C...
C...  PRINT A HEADING FOR THE COMPUTED ROOTS
      WRITE(NO,4)
4     FORMAT(1H ,7X,2HAK,
     1           5X,7HREAL R1,5X,7HIMAG R1,5X,7HREAL R2,5X,7HIMAG R2,
     2           5X,7HREAL R3,5X,7HIMAG R3,5X,7HREAL R4,5X,7HIMAG R4)
C...
C...  STEP THROUGH A SERIES OF VALUES OF AK
      DO 1 I=1,101
C...
C...  INCREMENT THE VALUE OF AK AND COMPUTE THE COEFFICIENTS OF THE
C...  CHARACTERISTIC POLYNOMIAL THAT DEPEND ON AK
      AKO=AKO+1.0
      A(3)=TAU*((RK*TAU+1.)**3)+AKO*TAU
      A(4)=AKO*TAU/TAUI
C...
C...  COMPUTE AND PRINT THE ROOTS OF THE CHARACTERISTIC POLYNOMIAL.  THE
C...  FOLLOWING CALL TO SUBROUTINE ZPOLR REQUIRES THE AVAILABILITY OF
C...  THE IMSL LIBRARY.  THIS CALL MUST BE REPLACED BY A CALL TO ANOTHER
C...  POLYNOMIAL ROOT FINDING ROUTINE IF THE IMSL LIBRARY IS NOT AVAIL-
C...  ABLE
      CALL ZPOLR(A,NDEG,Z,IER)
      DO 3 IR=1,NDEG
      ZREAL(IR)= REAL(Z(IR))
      ZIMAG(IR)=AIMAG(Z(IR))
3     CONTINUE
      WRITE(NO,2)AKO,(ZREAL(IR),ZIMAG(IR),IR=1,NDEG)
2     FORMAT(F10.1,8E12.4)
C...
C...  STORE THE ROOTS FOR SUBSEQUENT PLOTTING (ONLY THE SECOND, THIRD
C...  AND FOURTH ROOTS ARE STORED FOR PLOTTING.  THE FIRST ROOT IS REAL,
C...  LARGE AND NEGATIVE, AND WOULD THEREFORE DISTORT THE PLOT IF IN-
C...  CLUDED
      ZR(    I)=ZREAL(2)
      ZI(    I)=ZIMAG(2)
      ZR(101+I)=ZREAL(3)
      ZI(101+I)=ZIMAG(3)
      ZR(202+I)=ZREAL(4)
      ZI(202+I)=ZIMAG(4)
C...
C...  GO ON TO THE NEXT VALUE OF AK
1     CONTINUE
C...
C...  PLOT THE ROOT LOCUS PLOT
      CALL TPLOTS(1,303,ZR,ZI)
      WRITE(NO,5)
5     FORMAT(1H ,//,
     1 54H ROOT LOCUS DIAGRAM (ONLY THREE ROOT LOCI ARE PLOTTED))
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALL TO A CONTINUOUS PLOTTER IS MACHINE DEPENDENT
C...  AND MUST EITHER BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO A
C...  COMMENT
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZR,ZI,303,6H*REAL*,6H*IMAG*,2H**,1)
C...
C...  ******************************************************************
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  MODEL ALGEBRA
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
      DCADT(1)=(CA0  -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA(1)-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA(2)-CA(3))/TAU-RK*CA(3)
C...
C...  NOTE THAT THE DIFFERENTIAL EQUATION D(ERINT)/DT = E IS ALREADY
C...  PROGRAMMED BY SETTING E WHICH APPEARS IN THE DERIVATIVE SECTION
C...  (COMMON/F/ ABOVE).  THE INTEGRATED RESULT, ERINT, IN COMMON/Y/
C...  CAN THEN BE USED IN THE CONTROLLER EQUATION FOR CAM
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(101), EP(101), TP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(1H1,8X,1HT,11X,1HE,7X,5HERINT,7X,5HCA(1),4X,8HDCADT(1),
     1                                     7X,5HCA(2),4X,8HDCADT(2),
     2                                     7X,5HCA(3),4X,8HDCADT(3))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP)
     1  WRITE(NO,2)T,E,ERINT,(CA(I),DCADT(I),I=1,3)
2     FORMAT(F10.1,8F12.3)
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(IP)=CA(3)
       EP(IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,46H CA3(T) VS T                                  )
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,46H   E(T) VS T                                  )
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
END OF RUNS
*APP PRC24
      SUBROUTINE INITAL
C...
C...  DYNAMIC RESPONSE OF A MANOMETER
C...
C...  THE DIFFERENTIAL HEIGHT OF LIQUID IN A U-TUBE MANOMETER, H, CAN
C...  BE CALCULATED AS A FUNCTION OF TIME, T, BY INTEGRATION OF THE
C...  SECOND-ORDER ORDINARY DIFFERENTIAL EQUATION (ODE)
C...
C...     (TAU**2)D2H/DT2 + 2*TAU*Z*DH/DT + H = F(T)              (1)
C...
C...  WHERE
C...
C...     TAU     CHACTERISTIC TIME (RECIPROCAL OF THE NATURAL
C...             FREQUENCY) OF THE MANOMETER (SEC)
C...
C...     Z       DAMPING COEFFICIENT (DIMENSIONLESS)
C...
C...     F(T)    FORCING FUNCTION CORRESPONDING TO THE PRESSURE APPLIED
C...             TO ONE LEG OF THE MANOMETER (M)
C...
C...  FOR A MANOMETER, TAU AND Z ARE DEFINED BY
C...
C...     TAU = (L/(2*G))**0.5, Z = (8*VIS/((D**2)*RHO))*(2*L/G)**0.5
C...
C...  WHERE FOR THE PARTICULAR MANOMETER CONSIDERED IN THE FOLLOWING
C...  ANALYSIS
C...
C...     L        TOTAL LENGTH OF THE LIQUID IN THE MAMOMETER = 0.9915 M
C...
C...     G        ACCELERATION OF GRAVITY = 9.8 M/SEC**2
C...
C...     VIS      LIQUID VISCOSITY = 2.5E-03 PA-SEC (1 PA = 1 PASCAL =
C...              NEWTON/M**2)
C...
C...     D        TUBE DIAMETER (M)
C...
C...     RHO      LIQUID DENSITY = 13600 KG/M**3
C...
C...  IN THE FOLLOWING PROGRAMMING, THE TUBE DIAMETER, D, IS SET TO
C...  THREE VALUES IN THREE RUNS CORRESPONDING TO Z GT 1 (OVERDAMPED),
C...  Z = 1 (CRITICALLY DAMPED) AND Z LT 1 (UNDERDAMPED)
C...
C...  INITIALLY, THE LIQUID IN THE MAMOMETER IS AT REST.  THEREFORE, THE
C...  INITIAL CONDITIONS FOR EQUATION (1) ARE
C...
C...     H(0) = 0, DH(O)/DT = 0                                  (2)(3)
C...
C...  AT T = 0, A PRESSURE, P1, OF 2.0E+04 PA IS APPLIED TO ONE OF THE
C...  LEGS OF THE MAMOMETER.  THE OTHER LEG HAS A VACUUM ABOVE IT.  THUS
C...  F(T) IN EQUATION (1) IS A CONSTANT WITH THE VALUE
C...
C...     F(T) = GC*P1/(RHO*G) = 1*2.0E+04/(13600*9.8) = 0.1501 M
C...
C...  WHERE
C...
C...     GC       CONVERSION FACTOR = 1 KG-M/N-SEC**2
C...
C...  EQUATIONS (1) TO (3) CAN BE SOLVED ANALYTICALLY, E.G., BY THE
C...  LAPLACE TRANSFORM.  THE ANALYTICAL SOLUTIONS FOR THE THREE CASES,
C...  Z GT 1, Z = 1, Z LT 1, ARE PROGRAMMED IN SUBROUTINE PRINT AND
C...  PRINTED ALONG WITH THE NUMERICAL SOLUTION
C...
C...  THE DERIVATION OF EQUATION (1), AND ITS LAPLACE TRANSFORM SOLUTION
C...  ARE OUTLINED BELOW
C...
C...  A CONTINUITY BALANCE ON LEG 1 OF THE MANOMETER GIVES
C...
C...     D(H1*S*RHO)/DT = -V*S*RHO
C...
C...  WHERE
C...
C...     H1       HEIGHT OF LIQUID IN LEG 1 (M)
C...
C...     S        CROSS SECTIONAL AREA OF THE TUBE (M**2)
C...
C...     V        FLUID VELOCITY (M/SEC)
C...
C...  SIMILARLY, FOR LEG 2
C...
C...     D(H2*S*RHO)/DT = V*S*RHO
C...
C...  A MOMENTUM BALANCE ON THE FLUID IN THE TUBE GIVES
C...
C...     (1/GC)*D(RHO*L*S*V)/DT = (G/GC)*RHO*H1*S - (G/GC)*RHO*H2*S
C...
C...             + P1*S - 0*S - (F*V*ABS(V)/(2*D*GC))*S
C...
C...                   F = 64*VIS/(D*ABS(V)*RHO)
C...
C...  THESE EQUATIONS CAN BE SIMPLIFIED (ASSUMING CONSTANT S AND RHO) TO
C...
C...     DH1/DT = -V
C...
C...     DH2/DT =  V
C...
C...     DV/DT = (G/L)*(H1 - H2) + P1*GC/(L*RHO) - 32*VIS*V/((D**2)*RHO)
C...
C...  THESE EQUATIONS CAN EASILY BE REARRANGED TO GIVE AN EQUATION IN
C...  H = H2 - H1
C...
C...     V = (1/2)*D(H2 - H1)/DT = (1/2)*DH/DT
C...
C...     (1/2)D2H/DT2 = -(G/L)*H + (P1*GC/(L*RHO))
C...
C...                    - (16*VIS/((D**2)*RHO))*DH/DT
C...
C...  WHICH CAN BE REARRANGED TO
C...
C...     (L/(2*G))*D2H/DT2 + (16*VIS*L/((D**2)*RHO*G))*DH/DT + H =
C...
C...                         (GC/(RHO*G))*P1
C...
C...  EQUATION (1) THEN FOLLOWS FROM THIS RESULT WITH TAU AND Z DEFINED
C...  PREVIOUSLY
C...
C...  EQUATION (1) CAN BE LAPLACE TRANSFORMED TO
C...
C...     ((TAU**2)*(S**2) + 2*TAU*Z*S + 1)*H(S) = (GC*P1/(RHO*G))*(1/S)
C...
C...  WHICH CAN THEN BE SOLVED FOR THE TRANSFORMED HEIGHT, H(S).  THE
C...  CHARACTERISTIC POLYNOMIAL CAN BE WRITTEN IN FACTORED FORM AS
C...
C...     (TAU**2)*(S**2) + 2*TAU*Z*S + 1 = (TAU**2)*(S - R1)*(S - R2)
C...
C...  WHERE R1 AND R2 ARE GIVEN BY THE QUADRATIC FORMULA
C...
C...    R1, R2 = (-2*TAU*Z + (OR -)((2*TAU*Z)**2 - 4*(TAU**2))**0.5)/
C...
C...                               (2*(TAU**2))
C...  OR
C...
C...     R1, R2 = (-Z + (OR -)(Z**2 - 1)**0.5)/TAU
C...
C...  R1 AND R2 WILL BE REAL AND DISTINCT, REAL AND REPEATED OR COMPLEX
C...  FOR Z GT 1, Z = 1 AND Z LT 1.  THE ANALYSIS WILL BE CONTINUED FOR
C...  VALUES OF TAU AND Z CORRESPONDING TO THREE TUBE DIAMETERS
C...
C...     CASE 1 - D = 4.50E-04 M
C...
C...              Z = 3.9691E-07/(4.50E-04)**2 = 1.9600 (OVERDAMPED)
C...
C...     CASE 2 - D = 6.30E-04 M
C...
C...              Z = 3.9691E-07/(6.30E-04)**2 = 1.0000 (CRITICALLY
C...                                                       DAMPED)
C...     CASE 3 - D = 1.80E-03 M
C...
C...              Z = 3.9691E-07/(1.80E-03)**2 = 0.1225 (UNDERDAMPED)
C...
C...  SUBSTITUTION OF THESE CONSTANTS IN THE LAPLACE TRANSFORM OF H
C...  GIVES
C...
C...     H(S) = (0.1501/S)/(0.05058*S**2 + 2*Z*(0.02249)*S + 1)
C...
C...          (0.1501/S)/(0.05085*(S - R1)*(S - R2))
C...
C...  WHERE FROM THE QUADRATIC FORMULA
C...
C...     CASE 1 - R1 = -1.2196, R2 = -16.210
C...
C...     CASE 2 - R1 = R2 = R = -4.4464
C...
C...     CASE 3 - R1 = -0.54468 + 4.41291I, R2 = -0.54468 - 4.41291I
C...
C...              (I = SQRT(-1) SO R1 AND R2 ARE COMPLEX CONJUGATES)
C...
C...  INVERSION OF H(S) CAN BE ACCOMPLISHED BY PARTIAL FRACTIONS
C...
C...     CASE 1
C...
C...        H(S) = A/S + B/(S - R1) + C/(S - R2)
C...
C...  WHERE A, B AND C ARE CONSTANTS TO BE DETERMINED (THE MULTIPLYING
C...  CONSTANT 0.1501/0.05058 WILL BE INCLUDED AFTER THE INVERSION).  IN
C...  THE USUAL WAY FOR PARTIAL FRACTION EXPANSIONS
C...
C...     A = 1/(R1*R2) = 1/((-1.12196)*(-16.120)) = 0.05058
C...
C...     B = 1/(R1*(R1 - R2)) = -0.05470
C...
C...     C = 1/(R2*(R2 - R1)) =  0.004115
C...
C...  SUBSTITUTION IN H(S) FOLLOWED BY INVERSION GIVES
C...
C...        H(T) = 0.1501*(1 - 1.0815*EXP(-1.2196*T)
C...
C...                         + 0.0815*EXP(-16.210*T)
C...
C...  NOTE BY INSPECTION THAT H(0) = 0 WHICH IS A GOOD CHECK OF THE
C...  CONSTANTS A, B AND C
C...
C...     CASE 2
C...
C...        H(S) = A/S + B/(S - R) + C/(S - R)**2
C...
C...  WHICH IS THE USUAL PARTIAL FRACTION EXPANSION FOR REPEATED ROOTS
C...
C...     A = 1/R**2 = 1/(-4.4464)**2 = 0.05058
C...
C...     B = D(1/S)/DS WITH S = R = -1/R**2 = -0.05058
C...
C...     C = 1/R = -0.2249
C...
C...  SUBSTITUTION IN H(S) FOLLOWED BY INVERSION GIVES
C...
C...        H(T) = 0.1501*(1 - EXP(-4.4464*T) - 4.4464*T*EXP(-4.4464*T))
C...
C...  AGAIN, BY INSPECTION H(0) = 0
C...
C...     CASE 3
C...
C...        H(S) = A/S + B/(S - R1) + C/(S - R2)
C...
C...  WHERE A, B AND C CAN BE EVALUATED AS BEFORE IN CASE 1.  THUS
C...
C...     A = 1/(R1*R2) = 1/((-0.54468 + 4.41291I)*(-0.55468 - 4.41291I))
C...
C...       = 0.05058
C...
C...     B = 1/(R1*(R1 - R2)) = 1/((-0.55468 + 4.41291I)*(2)*(4.41291I))
C...
C...       = 1/(-38.9475 - 4.80725I) = 0.02548*EXP(-I*PHI)
C...
C...  WITH PHI = ARCTAN(-4.80725/-38.9475) = 187.04 DEGREES
C...
C...     C = 1/(R2*(R2 - R1)) = 0.02548*EXP(I*PHI)
C...
C...  SUBSTITUTION IN H(S) FOLLOWED BY INVERSION GIVES
C...
C...        H(T) = 0.1501*(1 + 0.02548*EXP(-I*PHI)*EXP(R1*T)
C...
C...                         + 0.02548*EXP( I*PHI)*EXP(R2*T))
C...
C...  WHICH CAN BE WRITTEN IN A FORM MORE CONVENIENT FOR CALCULATION (OF
C...  COURSE, H(T) MUST BE REAL)
C...
C...        H(T) = 0.1501*(1
C...
C...             + 0.50376*EXP(-I*PHI)*EXP(RE(R1)*T)*EXP(I*IM(R1)*T))
C...
C...             + 0.50376*EXP( I*PHI)*EXP(RE(R2)*T)*EXP(I*IM(R2)*T))
C...
C...             = 0.1501*(1
C...
C...             + 0.50376*EXP(-0.54468*T)*(EXP( I*(IM(R1)*T - PHI)) +
C...
C...                                      * EXP(-I*(IM(R1)*T - PHI)))
C...
C...             = 0.1501*(1
C...
C...             + (2)*(0.50376)*EXP(-0.54468*T)*COS(4.41291*T - PHI))
C...
C...  WHICH FOLLOWS FROM THE IDENTITY
C...
C...     COS(X) = (EXP(I*X) + EXP(-I*X))/2
C...
C...  AGAIN, H(0) = 0
C...
C...  THE THREE ANALYTICAL SOLUTIONS, H(T) FOR THE THREE CASES, ARE PRO-
C...  GRAMMED IN SUBROUTINE PRINT
C...
      COMMON /T/      T,  NOSTOP,  NORUN
     1       /Y/     Y1,      Y2
     2       /F/  DY1DT,   DY2DT
     3       /C/    TAU,       Z,      F,     IP
C...
C...  SET THE MODEL PARAMETERS
C...
C...     TIME CONSTANT
C...     D(H2*S*RHO)/DT = V*S*RHO
         XL=0.9915
         G=9.8
         TAU=SQRT(XL/(2.*G))
C...
C...     DAMPING COEFFICIENT
         VIS=1.5E-03
         RHO=13600.
         IF(NORUN.EQ.1)DIA=4.50E-04
         IF(NORUN.EQ.2)DIA=6.30E-04
         IF(NORUN.EQ.3)DIA=1.80E-03
         Z=(8.*VIS/((DIA**2)*RHO))*SQRT(2.*XL/G)
C...
C...     FORCING FUNCTION
         GC=1.
         PA=2.0E+04
         F=GC*PA/(RHO*G)
C...
C...  INITIAL CONDITIONS
      Y1=0.
      Y2=0.
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
C...
C...  SET A COUNTER FOR THE PLOTTED SOLUTION
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON /T/      T,  NOSTOP,  NORUN
     1       /Y/     Y1,      Y2
     2       /F/  DY1DT,   DY2DT
     3       /C/    TAU,       Z,      F,     IP
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DY1DT=Y2
      DY2DT=(1./TAU**2)*(F-2.*TAU*Z*Y2-Y1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON /T/      T,  NOSTOP,  NORUN
     1       /Y/     Y1,      Y2
     2       /F/  DY1DT,   DY2DT
     3       /C/    TAU,       Z,      F,     IP
C...
C...  DIMENSION THE ARRAYS TO STORE THE NUMERICAL SOLUTION FOR PLOTTING
      DIMENSION TP(51),YP(3,51),YAP(3,51)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)TAU,Z,F
1     FORMAT(
     1  23H CHARACTERISTIC TIME = ,F7.3,/,
     2  23H DAMPING COEFFICIENT = ,F7.3,/,
     3  20H FORCING FUNCTION = ,  F10.3,//,
     4 9X,1HT,3X,7HH (NUM),2X,8HH (ANAL))
C...
C...  CALCULATE THE ANALYTICAL SOLUTION
      IF(NORUN.EQ.1)Y1A=F*(1.-1.0815*EXP(-1.2196*T)
     1                       +0.0815*EXP(-16.210*T))
      IF(NORUN.EQ.2)Y1A=F*(1.-EXP(-4.4464*T)-4.4464*T*EXP(-4.4464*T))
      IF(NORUN.EQ.3)Y1A=F*(1.+1.00751*EXP(-0.54468*T)
     1                       *COS(4.41291*T-187.04*3.1415927/180.))
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      WRITE(NO,2)T,Y1,Y1A
2     FORMAT(F10.1,2F10.4)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
       YP(NORUN,IP)=Y1
      YAP(NORUN,IP)=Y1A
C...
C...  PLOT THE NUMERICAL SOLUTION AT THE END OF THE THIRD RUN
      IF(IP.LT.  51)RETURN
      IF(NORUN.LT.3)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTIONS FOR THE THREE CASES
      CALL TPLOTS(NORUN,IP,TP,YP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,//,
     1       17H 1 - D = 4.50E-04,/,
     2       17H 2 - D = 6.30E-04,/,
     3       17H 3 - D = 1.80E-03)
C...
C...  PLOT THE ANALYTICAL SOLUTIONS FOR THE THREE CASES
      CALL TPLOTS(NORUN,IP,TP,YAP)
      WRITE(NO,3)
      RETURN
      END
DYNAMICS OF A MANOMETER, D = 4.50E-04
0.         10.       0.2
    2 1000    1    1  REL 0.001
DYNAMICS OF A MANOMETER, D = 6.30E-04
0.         10.       0.2
    2 1000    1    1  REL 0.001
DYNAMICS OF A MANOMETER, D = 1.80E-03
0.         10.       0.2
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC25
      SUBROUTINE INITAL
C...
C...  TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD ASSEMBLY
C...
C...  A CONTROL SYSTEM HAS BEEN PROPOSED FOR CONTROLLING THE TEMPERA-
C...  TURE OF THE NUCLEAR FUEL IN A REACTOR BY SENSING THE TEMPERATURE
C...  OF THE FUEL AT THE CENTERLINE OF A ROD AND ADJUSTING THE RATE
C...  OF THE NUCLEAR REACTION BASED ON DEPARTURES FROM THE DESIRED
C...  TEMPERATURE.  THE FOLLOWING EQUATIONS MODEL THE PROPOSED SYSTEM
C...
C...  TF  = (KF/(RHOF*CPF))*(TF   + (1/R)*TF ) - (HR/(RHOF*CPF))   (1)
C...    T                      RR           R
C...
C...  TF(R,0) = TF0                                                (2)
C...
C...  TF (0,T) = 0, KF*TF (RF,T) = H*(TC - TF(RF,T))            (3)(4)
C...    R                R
C...
C...                             T
C...  HR = HRS + KC*(E + (1/TI)*INT E DT))                         (5)
C...                             0
C...
C...  E = TFSET - TF(0,T)                                          (6)
C...
C...  WHERE
C...
C...  TF(R,T)  FUEL TEMPERATURE, 0 LE R LE RF
C...
C...  R        RADIAL POSITION IN THE ROD
C...
C...  T        TIME
C...
C...  RHOF,    DENSITY, HEAT CAPACITY AND THERMAL CONDUCTIVITY OF
C...  CPF,KF   THE FUEL
C...
C...  HR       VOLUMETRIC RATE OF HEAT RELEASE OF THE NUCLEAR REACTION
C...
C...  HRS      STEADY STATE VALUE OF HR
C...
C...  RF       RADIUS OF THE FUEL ROD
C...
C...  TFSET    SET POINT TEMPERATURE FOR THE FUEL TEMPERATURE AT THE
C...           CENTERLINE OF THE ROD
C...
C...  E        ERROR IN THE FUEL CENTERLINE TEMPERATURE
C...
C...  KC,TI    GAIN AND INTEGRAL TIME OF THE CONTROLLER
C...
C...  H        HEAT TRANSFER COEFFICIENT BETWEEN THE OUTSIDE OF THE
C...           FUEL ROD AND THE SURROUNDING COOLANT
C...
C...  TC       COOLANT TEMPERATURE
C...
C...  TF0      INITIAL FUEL TEMPERATURE
C...
C...  HR COULD BE CONTROLLED ACCORDING TO EQUATIONS (5) AND (6), FOR
C...  EXAMPLE, BY POSITIONING THE CONTROL RODS FOR THE REACTOR.
C...
C...  DEVELOP A COMPUTER SIMULATION OF THIS SYSTEM WHICH PRINTS AND
C...  AND PLOTS TF(0,T) AND TF(RF,T) VS T SO THAT THE HEATING OF THE
C...  FUEL CAN BE STUDIED AND THE EFFECTIVENESS OF THE PROPOSED CON-
C...  TROLLER ASSESSED.  THE FOLLOWING PARAMETERS APPLY
C...
C...  RHOF = 0.5, CPF = 0.8, KF = 1.0, HRS = 0.1, RF = 2.5, TC = 85,
C...
C...  TF0 = 25, H = 0.1
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  SET THE MODEL PARAMETERS
      RHOF=0.5
      CPF=0.8
      KF=1.0
      RF=2.5
      TC=85.
      TFSET=900.
      TF0=25.
      H=0.1
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=5.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.3)THEN
         KC=5.0
         TI=2.0
      END IF
      HRS=200.
      NR=11
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN SUBROUTINE DERV
      CF1=1./(RHOF*CPF)
      CF2=H/KF
C...
C...  INITIAL CONDITIONS AND RADIAL GRID FOR THE FUEL
      DO 1 I=1,NR
      TF(I)=TF0
      R(I)=RF*FLOAT(I-1)/FLOAT(NR-1)
1     CONTINUE
      EINT=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      IP=0
      IR=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  CONTROLLER
      E=TFSET-TF(1)
      HR=HRS+KC*(E+(1./TI)*EINT)
C...
C...  SPATIAL DERIVATIVE TF
C...                       R
      CALL DSS004(0.,RF,NR,TF ,TFR )
C...
C...  BOUNDARY CONDITION AT R = 0
      TFR(1)=0.
C...
C...  BOUNDARY CONDITION AT R = RF
      TFR(NR)=CF2*(TC-TF(NR))
C...
C...  SPATIAL DERIVATIVE TR
C...                       RR
      CALL DSS004(0.,RF,NR,TFR,TFRR)
C...
C...  PDE FOR TF
C...
C...  R = 0 (NOTE - 1./R(1)*TFR(1) = TFRR(1) AT R(1) FROM L*HOSPITAL*S
C...  RULE
      TFT(1)=KF*CF1*2.*TFRR(1)+CF1*HR
C...
C...  R NE 0
      DO 1 I=2,NR
      TFT(I)=KF*CF1*(TFRR(I)+1./R(I)*TFR(I))+CF1*HR
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION    TP(31), TFP(2,31),    EP(31),   HRP(31),TFPR(7,11)
C...
C...  PRINT THE NUMERICAL SOLUTION
      IP=IP+1
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      NS=2
      WRITE(NO,1)T,(  TF(I),I=1,NR,NS),( TFR(I),I=1,NR,NS),
     1             (TFRR(I),I=1,NR,NS),( TFT(I),I=1,NR,NS)
1     FORMAT(1H ,//,5H T = ,F9.1,//,
     1 10H   TF(R,T),6F12.0,/,10H  TFR(R,T),6E12.3,/,
     2 10H TFRR(R,T),6E12.3,/,10H  TFT(R,T),6E12.3,//)
C...
C...  STORE TF(R,T) AND TA(R,T) FOR PLOTTING OF THE TEMPERATURE
C...  PROFILES
      IR=IR+1
      DO 2 I=1,NR
      TFPR(IR,I)=TF(I)
2     CONTINUE
C...
C...  STORE TF(0,T) AND TA(RF,T) FOR PLOTTING
3     TP(IP)=T
      TFP(1,IP)=TF(1)
      TFP(2,IP)=TF(NR)
      EP(IP)=E
      HRP(IP)=HR
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.31)RETURN
C...
C...  TIME PLOTS
      CALL TPLOTS(2,IP,TP,TFP)
      WRITE(NO,10)
10    FORMAT(1H ,//,
     1 56H 1 - TF(0,T), 2 - TF(RF,T) VS T                         )
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)
11    FORMAT(1H ,//,
     1 56H E = TFSET - TF(0,T) VS T                               )
      CALL TPLOTS(1,IP,TP,HRP)
      WRITE(NO,12)
12    FORMAT(1H ,//,
     1 56H HR VS T                                                )
C...
C...  SPATIAL PLOTS
      CALL TPLOTS(IR,NR,R,TFPR)
      WRITE(NO,13)
13    FORMAT(1H ,//,
     1 56H TF(R,T) VS R, T = 0, 0.5, 1.0,..., 3.0                 )
      RETURN
      END
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
END OF RUNS
*APP PRC26
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TRIPLE-EFFECT EVAPORATOR
C...
C...  CONSIDER A TRIPLE-EFFECT EVAPORATOR, DIAGRAMMED BELOW
C
C                    WS1,T1             WS2,T2         WS3,T3
C                 ............       ............       .....+
C                 .          .       .          .       .
C                 .          .       .          .       .
C               .....        .     .....        .     .....
C              .     .       .    .     .       .    .     .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .........      .   .........      .   .........
C             . M1,T1 .      .   . M2,T2 .      .   . M3,T3 .
C       .....+.....   .      ...+.....   .      ...+.....   .
C        WS0  .  .   .....       .  .   .....       .  .   .....
C             .   .   .  .       .   .   .  .       .   .   .  .
C       .....+.  .    .  .       .  .    .  .       .  .    .  .
C       WF,CF .   .   .  .       .   .   .  .       .   .   .  .
C             .  .    .  .       .  .    .  .       .  .    .  .
C             .   .   .  .       .   .   .  .       .   .   .  .
C          .......    .  .    .......    .  .    .......    .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          +  .       .  .    +  .       .  .    +  .       .  .
C         TL0 .       .  .   TL1 .       .  .   TL2 .       .  .
C              .     .   .      .+.     .   .      .+.     .   .
C               .....    .      .  .....    .      .  .....    .
C                 .      .      .    .      .      .    .      .
C                 .    .....    .    .    .....    .    .    .....
C                 .    .LLC.    .    .    .LLC.    .    .    .LLC.
C                 .    .....    .    .    .....    .    .    .....
C                 .      .      .    .      .      .    .      .
C                 .      .      .    .      .      .    .      .
C                ...    ...     .   ...    ...     .   ...    ...
C                .P....+.V.......   .P....+.V.......   .P....+.V......+
C                ...    ... W1,C1   ...    ... W2,C2   ...    ... W3,C3
C
C    .....
C    .LLC. - LIQUID LEVEL CONTROLLER
C    .....
C
C     ...
C     .P.  - PUMP
C     ...
C
C     ...
C     .V.  - CONTROL VALVE
C     ...
C...
C...  FIVE FEEDBACK CONTROL SYSTEMS ARE INCLUDED, PRIMARILY TO MAINTAIN
C...  THE CONCENTRATION OF THE LIQUID IN THE THIRD EFFECT.  THE PURPOSE
C...  OF THE SIMULATION IS TO DETERMINE HOW WELL THE CONTROLS WORK IN
C...  REGULATING THIS PRODUCT COMPOSITION.
C
C...  THE EQUATIONS WHICH MODEL THIS SYSTEM ARE
C...
C...     (1)  TOTAL MASS BALANCE FOR EACH EVAPORATOR
C...
C...          DM1/DT = WF - W1 - WS1, M1(0) = M10
C...
C...          DM2/DT = W1 - W2 - WS2, M2(0) = M20
C...
C...          DM3/DT = W2 - W3 - WS3, M3(0) = M30
C...
C...     (2)  COMPONENT (SOLUTE) BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*C1)/DT = WF*CF - W1*C1, M1(0)*C1(0) = M10*C10
C...
C...          D(M2*C2)/DT = W1*C1 - W2*C2, M2(0)*C2(0) = M20*C20
C...
C...          D(M3*C3)/DT = W2*C2 - W3*C3, M3(0)*C3(0) = M30*C30
C...
C...     (3)  CONTROLLER FOR THE LIQUID LEVEL IN EACH EVAPORATOR
C...
C...          W1 = W1SS + KC1*(M1 - M1SET)
C...
C...          W2 = W2SS + KC2*(M2 - M2SET)
C...
C...          W3 = W3SS + KC3*(M3 - M3SET)
C...
C...     (4)  ENTHALPY BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*HL1)/DT = WF*HF  + WS0*(HVS0 -HLS0)
C...
C...                       - W1*HL1 - WS1*HVS1, M1(0)*HL1(0) = M10*HL10
C...
C...          D(M2*HL2)/DT = W1*HL1 + WS1*(HVS1 - HLS1)
C...
C...                       - W2*HL2 - WS2*HVS2, M2(0)*HL2(0) = M20*HL20
C...
C...          D(M3*HL3)/DT = W2*HL2 + WS2*(HVS2 - HLS2)
C...
C...                       - W3*HL3 - WS3*HVS3, M3(0)*HL3(0) = M30*HL30
C...
C...     (5)  ENERGY BALANCE FOR THE VAPOR (NEGLECTING VAPOR DYNAMICS)
C...
C...          WS1 = U2*A2*(TL1 - T2)/(HVS1 - HLS1)
C...
C...          WS2 = U3*A3*(TL2 - T3)/(HVS2 - HLS2)
C...
C...     (6)  ENTHALPY EQUATIONS
C...
C...          HLI = HL(TI,CI), I = 1, 2, 3
C...
C...          HVSI = HVS(TI),  I = 1, 2, 3
C...
C...     (7)  CONTROLLERS FOR WS3 AND WS0 (NOT SHOWN IN THE DIAGRAM)
C...
C...          WS3 = WS3SS + KCS3*((T3 - T3SET)
C...
C...                                 T
C...                      + (1/TI3)*INT (T3 - T3SET)*DT)
C...                                 0
C...
C...          WS0 = WS0SS + KCS0*((BPRSET - BPR3)
C...
C...                                 T
C...                      + (1/TI0)*INT (BPRSET - BPR3)*DT)
C...                                 0
C...  WHERE
C...
C...     M1,M2,M3        LIQUID HOLDUPS IN EVAPORATORS 1, 2, 3
C...
C...     T               TIME
C...
C...     W1,W2,W3        LIQUID FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     WS1,WS2,WS3     VAPOR FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     C1,C2,C2        LIQUID CONCENTRATIONS IN EVAPORATORS 1, 2, 3
C...
C...     W1SS,W2SS,W3SS  STEADY STATE VAPOR RATES FROM EVAPORATORS 1,
C...                     2, 3
C...
C...     KC1,KC2,KC3     GAINS OF THE LIQUID LEVEL CONTROLLERS ON
C...                     EVAPORATORS 1, 2, 3
C...
C...     M1SET,M2SET,    SET POINTS FOR THE LIQUID LEVEL CONTROLLERS
C...     M3SET           ON EVAPORATORS 1, 2, 3
C...
C...     HL1,HL2,HL3     ENTHALPIES OF THE LIQUIDS IN EVAPORATORS 1, 2,
C...                     3
C...
C...     WF,TF,HF,CF     FLOW RATE, TEMPARATURE, ENTHALPY, COMPOSITION
C...                     OF THE FEED TO EVAPORATOR 1
C...
C...     WS0,HVS0,HLS0   FLOW RATE, VAPOR AND LIQUID (CONDENSATE) ENTHA-
C...                     LPIES OF THE STEAM TO EVAPORATOR 1
C...
C...     HVS1,HVS2,HVS3  ENTHALPIES OF THE VAPOR FROM EVAPORATORS 1, 2,
C...                     3
C...
C...     HLS1,HLS2       ENTHALPIES OF THE LIQUID (CONDENSATE) IN EVAP-
C...                     ORATORS 2, 3
C...
C...     T1,T2,T3        TEMPERATURES OF THE LIQUID AND VAPOR IN EVAP-
C...                     ORATORS 1, 2, 3
C...
C...     TL0,TL1,TL2     TEMPERATURES OF THE LIQUID (CONDENSATE) IN
C...                     EVAPORATORS 1, 2, 3
C...
C...     TS0             TEMPERATURE OF THE STEAM TO EVAPORATOR 1
C...
C...     U1,U2,U3        HEAT TRANSFER COEFFICIENTS FOR EVAPORATORS 1,
C...                     2, 3
C...
C...     A1,A2,A3        HEAT TRANSFER AREAS FOR EVAPORATORS 1, 2, 3
C...
C...     WS3SS, WS0SS    STEADY STATE VAPOR RATE FROM EVAPORATOR 3,
C...                     STEADY STATE STEAM RATE TO EVAPORATOR 1
C...
C...     KCS3,KCS0       CONTROLLERS GAINS FOR WS3 AND WS0
C...
C...     TI3,TI0         CONTROLLER INTEGRAL TIMES FOR WS3 AND WS0
C...
C...     T3SET, BPRSET   SET POINTS FOR T3 AND BPR (BOILING POINT RISE)
C...
C...     BPR1,BPR2,BPR3  BOILING POINT RISES FOR EVAPORATORS 1, 2, 3,
C...                     I.E., BPR1 = T1 - TL1, ETC.
C...
C...  THE NUMERICAL PARAMETERS FOR THE SYSTEM (NAOH IN WATER) ARE
C...
C...     HLI = (TI - 32)*(1 - 1.2*CI + 2.4*CI**2) BTU/LB
C...
C...         0 LE CI LE 0.3, (CI IS THE WEIGHT FRACTION OF NAOH IN THE
C...                          LIQUID IN EVAPORATOR I, I = 1, 2, 3)
C...
C...     HLI = (TI - 32)*(2.83*CI - 0.56*CI**2)
C...
C...         CI GT 0.3
C...
C...     BPRI = 36*CI + 250*CI**2 (BPRI IS THE BOILING POINT RISE IN
C...                               EVAPORATOR I, I = 1, 2, 3)
C...
C...     TLI = TI - BPRI (I = 1, 2, 3)
C...
C...     HLSI = TLI - 32 (I = 1, 2, 3)
C...
C...     HVSI = 0.45*(TI  - 32) + 1075 (I = 1, 2, 3)
C...
C...     WF = 200000 LB/HR, CF = 0.05, TF = 102 F, T3SET = 182 F
C...
C...     BPRSET = 80.5 F, A1 = A2 = A3 = 2900 FT**2, TS0 = 350 F,
C...
C...     U1 = 800 BTU/HR-FT**2-F, U2 = 500 BTU/HR-FT**2-F, U3 = 300
C...
C...     BTU/HR-FT**2-F, WS0SS = 30000 LB/HR, WS3SS = 10000 LB/HR
C...
C...     W1SS = 100000 LB/HR, W2SS = 50000 LB/HR, W3SS = 25000 LB/HR
C...
C...     KC1 = 100, KC2 = 100, KC3 = 50, M1SET = M2SET = M3SET = 2000 LB
C...
C...     KCS0 = 500, KCS3 = 500, TI0 = 0.1, TI3 = 0.1
C...
C...     INITIAL CONDITIONS
C...
C...     M1 = M2 = M3 = 2000 LB, T1 = T2 = T3 = 102 F, C1 = C2 = C3 =
C...
C...     0.05
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
C...
C...  COMMON BLOCK FOR OTHER MODEL VARIABLES, MODEL PARAMETERS
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL PARAMETERS
C...
C...     STEADY STATE VAPOR RATES
         W1SS=100000.
         W2SS= 50000.
         W3SS= 25000.
C...
C...     LIQUID LEVEL CONTROLLER GAINS
         KC1=100.
         KC2=100.
         KC3=50.
C...
C...     LIQUID LEVEL CONTROLLER SET POINTS
         M1SET=2000.
         M2SET=2000.
         M3SET=2000.
C...
C...     FEED FLOW RATE, TEMPERATURE, COMPOSITION
         WF=200000.
         TF=102.
         CF=0.05
C...
C...     HEAT TRANSFER COEFFICIENTS
         U1=800.
         U2=500.
         U3=300.
C...
C...     HEAT TRANSFER AREAS
         A1=2900.
         A2=2900.
         A3=2900.
C...
C...     STEADY STATE VAPOR RATES OF PI CONTROLLERS
         WS0SS=30000.
         WS3SS=10000.
C...
C...     GAINS OF PI CONTROLLERS
         KCS0=500.
         KCS3=500.
C...
C...     INTEGRAL TIMES OF PI CONTROLLERS
         TI0=0.1
         TI3=0.1
C...
C...     SET POINTS FOR PI CONTROLLERS
         BPRSET=80.5
         T3SET=182.0
C...
C...     STEAM TEMPERATURE
         TS0=350.
C...
C...  INITIAL CONDITIONS
C...
C...     TOTAL MASS BALANCES
         M1=2000.
         M2=2000.
         M3=2000.
C...
C...     COMPONENT BALANCES
         M1C1=2000.*0.05
         M2C2=2000.*0.05
         M3C3=2000.*0.05
C...
C...     ENTHALPY BALANCES
         M1HL1=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M2HL2=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M3HL3=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
C...
C...     PI CONTROLLERS
         E1INT=0.
         E2INT=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL ALGEBRA
C...
C...     LIQUID COMPOSITIONS
         C1=M1C1/M1
         C2=M2C2/M2
         C3=M3C3/M3
C...
C...     LIQUID ENTHALPIES
         HL1=M1HL1/M1
         HL2=M2HL2/M2
         HL3=M3HL3/M3
C...
C...     VAPOR RATES IN THE EVAPORATORS
         W1=W1SS+KC1*(M1-M1SET)
         W2=W2SS+KC2*(M2-M2SET)
         W3=W3SS+KC3*(M3-M3SET)
C...
C...     LIQUID TEMPERATURES
C...
C...     T1
         IF(C1.LE.0.3)THEN
            T1=HL1/(1.0-1.2*C1+2.4*C1**2)+32.0
         ELSE IF(C1.GT.0.3)THEN
            T1=HL1/(2.83*C1-0.56*C1**2)+32.0
         END IF
C...
C...     T2
         IF(C2.LE.0.3)THEN
            T2=HL2/(1.0-1.2*C2+2.4*C2**2)+32.0
         ELSE IF(C2.GT.0.3)THEN
            T2=HL2/(2.83*C2-0.56*C2**2)+32.0
         END IF
C...
C...     T3
         IF(C3.LE.0.3)THEN
            T3=HL3/(1.0-1.2*C3+2.4*C3**2)+32.0
         ELSE IF(C3.GT.0.3)THEN
            T3=HL3/(2.83*C3-0.56*C3**2)+32.0
         END IF
C...
C...     BOILING POINT RISES
         BPR1=36.0*C1+250.0*C1**2
         BPR2=36.0*C2+250.0*C2**2
         BPR3=36.0*C3+250.0*C3**2
C...
C...     CONDENSATE TEMPERATURES
         TL1=T1-BPR1
         TL2=T2-BPR2
         TL3=T3-BPR3
C...
C...     CONDENSATE ENTHALPIES
         HLS0=TS0-32.0
         HLS1=TL1-32.0
         HLS2=TL2-32.0
         HLS3=TL3-32.0
C...
C...     VAPOR ENTHALPIES
         HVS0=0.45*(TS0-32.0)+1075.
         HVS1=0.45*(T1-32.0)+1075.
         HVS2=0.45*(T2-32.0)+1075.
         HVS3=0.45*(T3-32.0)+1075.
C...
C...     VAPOR RATES IN THE HEATING COILS
         WS1=U2*A2*(TL1-T2)/(HVS1-HLS1)
         WS2=U3*A3*(TL2-T3)/(HVS2-HLS2)
C...
C...     FEED ENTHALPY
         HF=(TF-32.0)*(1.0-1.2*CF+2.4*CF**2)
C...
C...     PI CONTROLLERS
         E1=BPRSET-BPR3
         WS0=WS0SS+KCS0*(E1+(1./TI0)*E1INT)
         E2=T3-T3SET
         WS3=WS3SS+KCS3*(E2+(1./TI3)*E2INT)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MASS BALANCES
         M1T=WF-W1-WS1
         M2T=W1-W2-WS2
         M3T=W2-W3-WS3
C...
C...     COMPONENT BALANCES
         M1C1T=WF*CF-W1*C1
         M2C2T=W1*C1-W2*C2
         M3C3T=W2*C2-W3*C3
C...
C...     ENTHALPY BALANCES
         M1HL1T=WF*HF +WS0*(HVS0-HLS0)
     1         -W1*HL1-WS1*HVS1
         M2HL2T=W1*HL1+WS1*(HVS1-HLS1)
     1         -W2*HL2-WS2*HVS2
         M3HL3T=W2*HL2+WS2*(HVS2-HLS2)
     1         -W3*HL3-WS3*HVS3
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), CP(3,101)
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,1)T,M1,M2,M3,C1,C2,C3,T1,T2,T3
1        FORMAT(' T = ',F6.3,/,
     1   10X,'M1',10X,'M2',10X,'M3',/,3F12.1,/,
     1   10X,'C1',10X,'C2',10X,'C3',/,3F12.4,/,
     1   10X,'T1',10X,'T2',10X,'T3',/,3F12.1,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      CP(1,IP)=C1
      CP(2,IP)=C2
      CP(3,IP)=C3
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(3,IP,TP,CP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' 1 - C1   2 - C2   3 - C3 VS T')
      RETURN
      END
CONTROL OF A TRIPLE-EFFECT EVAPORATOR
0.        1.        0.01
   11 1000    1    1  REL 0.001
END OF RUNS
*APP PRC27
      SUBROUTINE INITAL
C...
C...  ULTIMATE GAIN AND TUNING OF THE PI CONTROL OF A PLATE ABSORBER
C...
C...  THE FOLLOWING SIMULATION OF A PLATE ABSORBER WITH A PI CONTROLLER
C...  DEMONSTRATES (1) THE DETERMINATION OF THE ULTIMATE GAIN OF THE
C...  CONTROLLER (THE PROPORTIONAL GAIN AT WHICH THE SYSTEM UNDERGOES
C...  SUSTAINED OSCILLATION) AND (2) THE TUNING OF THE PI CONTROLLER
C...  USING THE ULTIMATE GAIN (BY TAKING ONE HALF OF THE ULTIMATE GAIN,
C...  THEN ADJUSTING THE INTGRAL TIME TO ACHIEVE A RESPONSIVE SYSTEM).
C...
C...  AN 8-TRAY TOWER IS BEING PLANNED TO REMOVE NH3 FROM AIR USING
C...  WATER AT A RATE OF 0.1 LB MOL/SEC.  THE ENTERING GAS CONTAINS
C...  4 O/O NH3 AND ITS FLOW RATE IS REGULATED WITH A PI CONTROLLER
C...  SO THAT THE NH3 CONCENTRATION IN THE EXITING GAS IS 0.1 O/O.
C...  INITIALLY, THERE ARE 2.5 LB MOLS OF WATER ON EACH TRAY.  THE
C...  MOLAR LIQUID FLOW RATE, LN, OUT OF EACH TRAY IS GIVEN BY
C...
C...               LN = 0.2*(HN - 2.5)**1.5
C...
C...  WHERE HN IS THE MOLAR LIQUID HOLDUP ON TRAY N.  THUS A MINIMUM
C...  OF 2.5 LB MOLS OF LIQUID IS NEEDED ON EACH TRAY BEFORE LIQUID
C...  STARTS FLOWING FROM EACH TRAY.  THE EQUILIBRIUM RELATIONSHIP
C...  AT THE CONDITIONS IN THE COLUMN IS
C...
C...                      Y = 0.78*X
C...
C...  THE MOLAR FLOW RATE OF THE ENTERING GAS IS GIVEN BY
C...
C...                      VO = 0.2*Z
C...
C...           Z = 0.5 + AKC*(E + (1/TI)*INT(E*DT))
C...
C...                     E = YSET - Y8
C...
C...  GRAMMED IN SUBROUTINE DERV IS BASED ON THE ASSUMPTIONS
C...
C...                    IDEAL TRAYS
C...
C...                    NEGLIGIBLE GAS HOLDUP
C...
C...                    ISOTHERMAL OPERATION
C...
C...  DISCUSSION OF OUTPUT
C...  --------------------
C...
C...  THE OUTPUT FROM THIS SIMULATION IS SOMEWHAT UNREALISTIC BECAUSE
C...  OF THE ASSUMPTION OF NEGLIGIBLE GAS HOLDUP.  AS THE CONTROLLER
C...  GAIN, AKC IS INCREASED TO REACH THE ULTIMATE GAIN, THE OUTLET
C...  GAS COMPOSITION, Y(8), APPROACHES THE SET POINT VALUE, YSET =
C...  0.001, VERY CLOSELY WITH ESSENTIALLY NO OVERSHOOT OR OSCILLATION
C...  I.E., THE CONTROLLER WORKS NEARLY PERFECTLY.  FINALLY, A VALUE
C...  OF AKC IS REACHED AT WHICH THE SIMULATION APPEARS TO GO UNSTABLE.
C...  IN OTHER WORDS, THERE IS NO OBVIOUS TRANSITION TO INSTABILTY
C...  AS MIGHT BE EXPECTED WITH AN INCREASING DEGREE OF OSCILLATION.
C...
C...  THIS CHARACTERISTIC OF THE OUTPUT APPEARS TO BE DUE TO THE IMME-
C...  DIATE CHANGE OF THE GAS FLOW RATE THROUGHOUT THE TOWER IN RESPONSE
C...  TO THE ERROR, ERROR = YSET - Y(8).  THUS, Y(8) IS ADJUSTED ALMOST
C...  INSTANTANEOUSLY IN RESPONSE TO THIS ERROR THROUGH THE DIFFERENTIAL
C...  EQUATION FOR TRAY 8.  THE TOWER APPEARS TO OPERATE AS A FIRST-
C...  ORDER SYSTEM GOVERNED BY ONE ODE, AND IS THEREFORE DIFFICULT TO
C...  FORCE TO BECOME UNSTABLE.  EVENTUALLY, IF THE GAIN IS HIGH ENOUGH,
C...  THE SIMULATION BECOMES UNSTABLE, BUT VIA A RATHER UNREALISTIC
C...  IMMEDIATE TRANSITION TO INSTABILITY.
C...
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  SET THE MODEL PARAMETERS
      FN=0.1
      HMIN=2.5
      YSET=0.001
      WEIR=0.2
C...
C...  SET THE CONTROLLER PARAMETERS FOR CASES (1) AND (2) DESCRIBED
C...  PREVIOUSLY
C...
C...     (1)  (NR = 1)
C...
              IF(NR.EQ.1)THEN
C...          THE ULTIMATE GAIN IS TAKEN AS 5.0E+05 SINCE INCREASING
C...          THE GAIN SLIGHTLY ABOVE THIS VALUE, E.G., TO 7.0E+05,
C...          CAUSES AN EXCESSIVE COMPUTER RUN TIME INDICATING THAT
C...          THE SIMULATION IS CLOSE TO INSTABILITY
              AKC=5.0E+05
              RTI=0.
C...
C...     (2)  (NR = 2)
C...
              ELSE IF(NR.EQ.2)THEN
              AKC=2.5E+05
              RTI=1.0
              END IF
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 K=1,8
C...
C...  SET THE INITIAL TOTAL LIQUID HOLDUPS ON THE TRAYS
      H(K)=2.5
C...
C...  SET THE INITIAL NH3 HOLDUPS ON THE TRAYS ((TOTAL HOLDUP)*
C...  NH3 MOL FRACTION IN THE LIQUID) = HX)
      HX(K)=0.
    1 CONTINUE
C...
C...  SET THE INITIAL INTEGRAL OF THE ERROR, INT(E*DT)
      EI=0.
C...
C...  SET THE ENTERING GAS AND LIQUID COMPOSITIONS
      YO=0.04
      XN=0.
C...
C...  INITIALIZE THE CALCULATIONS IN DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  MODEL ALGEBRA
      DO 2 K=1,8
C...
C...  LIQUID COMPOSITIONS, X(K), FROM THE PRODUCTS H(K)*X(K) (=
C...  HX(K)) AND THE LIQUID HOLDUPS, H(K)
      X(K)=HX(K)/H(K)
C...
C...  GAS COMPOSITIONS
      Y(K)=0.78*X(K)
C...
C...  LIQUID FLOW RATES
      FL(K)=0.
      IF(H(K).GT.HMIN)FL(K)=WEIR*(SQRT(H(K)-HMIN))**3
2     CONTINUE
C...
C...  CONTROLLER ERROR, DERIVATIVE OF THE INTEGRAL INT(E*DT)
      ERROR=YSET-Y(8)
      DEIDT=ERROR
C...
C...  GAS FLOW RATE ENTERING THE TOWER
      VO=0.2*(0.5+AKC*(ERROR+RTI*EI))
      IF(VO.LT.0.)VO=0.
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MATERIAL BALANCE
C...
C...        DH(N)/DT = L(N+1) - L(N)
C...
C...     COMPONENT (NH3) BALANCE
C...
C...        D(H(N)*X(N))/DT = L(N+1)*X(N+1) + VO*Y(N-1)
C...
C...                        - L(N)*X(N) - VO*Y(N)
C...
C...     WHERE N = 1, 2,..., 8 FOR THE EIGHT TRAYS
C...
C...  TRAY 1
      DHDT(1)=FL(2)-FL(1)
      DHXDT(1)=FL(2)*X(2)+VO*YO-FL(1)*X(1)-VO*Y(1)
C...
C...  TRAY 8
      DHDT(8)=FN-FL(8)
      DHXDT(8)=FN*XN+VO*Y(7)-FL(8)*X(8)-VO*Y(8)
C...
C...  TRAYS 2 TO 7
      DO 1 K=2,7
      DHDT(K)=FL(K+1)-FL(K)
      DHXDT(K)=FL(K+1)*X(K+1)+VO*Y(K-1)-FL(K)*X(K)-VO*Y(K)
    1 CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  DIMENSION THE ARRAYS FOR STORING THE PLOTTED SOLUTION
      DIMENSION EP(101), X1P(101), VP(101), Y8P(101), FL1P(101),
     1          TP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/10*10).NE.(IP-1))GO TO 2
      WRITE(NO,1)T,VO,(Y(I),I=1,8),(X(I),I=1,8),(H(I),I=1,8),
     1                (FL(I),I=1,8)
1     FORMAT(1H ,//,5H T = ,F5.0,5X,5HVO = ,F10.4,/,
     1              5H Y = ,8E11.3,/,
     2              5H X = ,8E11.3,/,
     3              5H H = ,8E11.3,/,
     4              5H L = ,8E11.3,/)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2      EP(IP)=DEIDT
      X1P(IP)=X(1)
       VP(IP)=VO
      Y8P(IP)=Y(8)
      FL1P(IP)=FL(1)
       TP(IP)=T
C...
C...  AT THE END OF THE RUN, PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
C...
C...  ERROR VS TIME
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,26H ERROR (MOL FR) VS T (SEC))
C...
C...  EXITING LIQUID COMPOSITION VS TIME
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,23H X1 (MOL FR) VS T (SEC))
C...
C...  GAS VOLUMETRIC FLOW RATE VS TIME
      CALL TPLOTS(1,IP,TP,VP)
      WRITE(NO,12)
12    FORMAT(1H ,//,24H V (MOLS/SEC) VS T (SEC))
C...
C...  EXITING GAS COMPOSITION VS TIME
      CALL TPLOTS(1,IP,TP,Y8P)
      WRITE(NO,13)
13    FORMAT(1H ,//,23H Y8 (MOL FR) VS T (SEC))
C...
C...  LIQUID FLOW RATE FROM TRAY 1 VS TIME
      CALL TPLOTS(1,IP,TP,FL1P)
      WRITE(NO,14)
14    FORMAT(1H ,//,28H FL(1) (MOLS/SEC) VS T (SEC))
C...
C...  PREPARE A FILE FOR PLOTTING THE SOLUTION ON A MICROCOMPUTER (PC)
C...  (SECOND RUN ONLY)
      IF(NR.EQ.2)THEN
C...
C...  OPEN THE PC PLOT FILE GRAF
      OPEN(1,FILE='GRAF')
C...
C...  SET AND PRINT THE NUMBER OF DEPENDENT VARIABLES
      NVAR=5
      WRITE(1,20)NVAR
20    FORMAT(I5)
C...
C...  PRINT THE INDEPENDENT VARIABLE AND FIVE DEPENDENT VARIABLES
      DO 21 I=1,IP
      WRITE(1,22)TP(I),EP(I),X1P(I),VP(I),Y8P(I),FL1P(I)
22    FORMAT(5X,E15.5,/,(4E15.5,/))
21    CONTINUE
      END IF
C...
C...  FILE GRAF IS COMPLETE
      IP=0
      RETURN
      END
PLATE ABSORBER
0.        200.      2.0
   1710000    1    1  REL 0.001
PLATE ABSORBER
0.        200.      2.0
   1710000    1    1  REL 0.001
END OF RUNS
*APP PRC28
      SUBROUTINE INITAL
C...
C...  COMPARISON OF THE ANALYTICAL AND NUMERICAL SOLUTIONS AND EIGEN-
C...  VALUES OF A SECOND-ORDER, NONOSCILLATORY ORDINARY DIFFERENTIAL
C...  EQUATION
C...
C...  CONSIDER THE SECOND-ORDER ORDINARY DIFFERENTIAL EQUATION (ODE)
C...
C...      2    2
C...     D X/DT  + 5*DX/DT + 4*X = 2                                 (1)
C...
C...     X(0) = 0, DX(0)/DT = 1                                   (2)(3)
C...
C...  AN ANALYTICAL SOLUTION TO EQUATIONS (1) TO (3) CAN BE OBTAINED BY
C...  CLASSICAL METHODS, E.G., THE LAPLACE TRANSFORM.  THE ANALYTICAL
C...  SOLUTION IS COMPARED WITH THE NUMERICAL SOLUTION IN THE FOLLOWING
C...  PROGRAM.
C...
C...  IF THE LAPLACE TRANSFORM OF X(T) IS DEFINED AS XL(S), EQUATIONS
C...  (1) TO (3) TRANSFORM TO
C...
C...     (S**2)*XL(S) - S*X(0) - DX(0)/DT + 5*S*XL(S) - 5*X(0) + 4*XL(S)
C...
C...                                = 2/S
C...
C...  WHICH REDUCES TO
C...
C...     ((S**2) + 5*S + 4)*XL = 1 + 2/S
C...
C...  OR
C...
C...     XL = (S + 2)/(S*(S + 4)*(S + 1)) = A/S + B/(S + 4) + C/(S + 1)
C...
C...  WHERE A, B AND C ARE CONSTANTS TO BE DETERMINED IN THE PARTIAL
C...  FRACTIONS EXPANSION OF XL.  INVERSION TO THE T DOMAIN GIVES
C...
C...     X(T) = A + B*EXP(-4*T) + C*EXP(-T)
C...
C...  WHERE
C...
C...     A = (S + 2)/((S + 4)*(S + 1))    = 1/2
C...                                  S=0
C...
C...     B = (S +2)/(S*(S+1))     = -1/6
C...                         S=-4
C...
C...     C = (S + 2)/((S*(S + 4))     = -1/3
C...                             S=-1
C...
C...  VERIFICATION OF THIS SOLUTION IS LEFT TO THE READER.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
C...
C...  INITIAL CONDITIONS
      X1=0.
      X2=1.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
      DX1DT=X2
      DX2DT=2.0-5.0*X2-4.0*X1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION    TP(51),   X1P(51)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINES JMAP, EIGEN
      DIMENSION        AJ(2,2),          WF(2),
     1                   SV(2),       SVOLD(2),
     2                   FV(2),       FVOLD(2)
      COMPLEX        EIGENV(2)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(2), TO THE DEPENDENT
C...  VARIABLES IN COMMON/Y/, AND THE DERIVATIVE VECTOR, FV(2), TO THE
C...  DERIVATIVES IN COMMON/F/
      EQUIVALENCE (X1,SV(1)), (DX1DT,FV(1))
C...
C...  PRINT A HEADING FOR THE NUMERICAL AND ANALYTICAL SOLUTIONS
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'X1',10X,'XA')
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS EVERY FIFTH CALL
C...  TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         A=1./2.
         B=-1./6.
         C=-1./3.
         XA=A+B*EXP(-4.*T)+C*EXP(-T)
         WRITE(NO,2)T,X1,XA
2        FORMAT(F10.1,2F12.5)
      END IF
C...
C...  MAP THE JACOBIAN MATRIX AT THE BEGINNING AND END OF THE SOLUTION
      IF((IP.EQ.1).OR.(IP.EQ.51))THEN
         NODE=2
         CALL JMAP(NODE,AJ,SV,SVOLD,FV,FVOLD)
C...
C...     COMPUTE THE TEMPORAL EIGENVALUES OF THE TWO ODES DEFINED IN
C...     COMMON /Y/ AND /F/
         CALL EIGEN(NODE,AJ,EIGENV,WF)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      X1P(IP)=X1
       TP(IP)=T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,3)
3     FORMAT(1H ,//,' X(T) VS T')
      RETURN
      END
NUMERICAL AND ANALYTICAL SOLUTIONS OF A NONOSCILLATORY ODE
0.        10.       0.2
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC29
      SUBROUTINE INITAL
C...
C...  COMPARISON OF THE ANALYTICAL AND NUMERICAL SOLUTIONS AND EIGEN-
C...  VALUES OF A SECOND-ORDER, OSCILLATORY ORDINARY DIFFERENTIAL
C...  EQUATION
C...
C...  CONSIDER THE SECOND-ORDER ORDINARY DIFFERENTIAL EQUATION (ODE)
C...
C...      2    2
C...     D X/DT  + 2*DX/DT + 2*X = 1                            (1)
C...
C...     X(0) = 2, DX(0)/DT = 0                              (2)(3)
C...
C...  AN ANALYTICAL SOLUTION TO EQUATIONS (1) TO (3) CAN BE OBTAINED BY
C...  CLASSICAL METHODS, E.G., THE LAPLACE TRANSFORM.  THE ANALYTICAL
C...  SOLUTION IS COMPARED WITH THE NUMERICAL SOLUTION IN THE FOLLOWING
C...  PROGRAM.
C...
C...  IF THE LAPLACE TRANSFORM OF X(T) IS DEFINED AS XL(S), EQUATIONS
C...  (1) TO (3) TRANSFORM TO
C...
C...     (S**2)*XL - S*X(0) - DX(0)/DT + 2*S*XL - 2*X(0) + 2*XL = 1/S
C...
C...  WHICH REDUCES TO
C...
C...     ((S**2) + 2*S + 2)*XL = 2*S + 4 + 1/S
C...
C...  OR
C...
C...     XL = (2*(S**2) + 4*S + 1)/(S*(S**2 + 2*S + 2))
C...
C..         = A/S + (B*S + C)/(S**2 + 2*S + 2)
C...
C...  WHERE A, B AND C ARE CONSTANTS TO BE DETERMINED IN THE PARTIAL
C...  FRACTIONS EXPANSION OF XL.
C...
C...  THE ROOTS OF S**2 + 2*S + 2 = 0 ARE S1 = -1 + I, S2 = -1 - I.
C...  HOWEVER, THE FORM OF THE PARTIAL FRACTIONS EXPANSION (THE TERM
C...  INVOLVING CONSTANTS B AND C) WAS SELECTED TO AVOID HAVING TO
C...  WORK WITH THESE COMPLEX ROOTS.  THUS,
C...
C...     XL = A/S + (B*(S + 1))/((S + 1)**2 + 1**2)
C...
C...              + (C - B)/((S + 1)**2 + 1**2)
C...
C...  WHICH CAN BE INVERTED DIRECTLY TO
C...
C...     X(T) = A + B*EXP(-T)*COS(T) + (C - B)*EXP(-T)*SIN(T)
C...
C...  THIS RESULT FOLLOWS DIRECTLY FROM THE TRANSFORM PAIRS
C...
C...     L(F(T)*EXP(A*T)) = FL(S - A)
C...
C...     L(SIN(W*T)) = W/(S**2 + W**2)
C...
C...     L(COS(W*T)) = S/(S**2 + W**2)
C...
C...  THE CONSTANT A CAN BE DETERMINED IN THE USUAL WAY
C...
C...     A = (2*(S**2) + 4*S + 1)/(S**2 + 2*S + 2)    = 1/2
C...                                              S=0
C...
C...  THE CONSTANTS B AND C CAN BE EVALUATED FROM THE EQUATION
C...
C...     (2*(S**2) + 4*S + 1)/(S*(S**2 + 2*S + 2)) =
C...
C...     A/S + (B*S + C)/(S**2 + 2*S + 2)
C...
C...  WHICH MUST BE TRUE FOR ANY VALUE OF S WITH A = 1/2.  WE THERE-
C...  FORE SELECT S = 1 AND S = -1.  THUS,
C...
C...     S = 1, 7/(1*5) = 1/2 + (B + C)/5
C...
C...  OR
C...
C...     B + C = 9/2
C...
C...     S = -1, -1/(-1*1) = 1/2 + (-B + C)/1
C...
C...  OR
C...
C...     -B + C = 3/2
C...
C...  SOLVING THESE TWO EQUATIONS FOR B AND C, WE OBTAIN
C...
C...     B = 3/2, C = 3, C - B = 3/2
C...
C...  THEREFORE, THE SOLUTION IS
C...
C...     X(T) = 1/2 + (3/2)*EXP(-T) + (3/2)*EXP(-T)*SIN(T)
C...
C...          = 1/2 + SQRT((3/2)**2 + (3/2)**2)*COS(T - ARCTAN(1))
C...
C...  VERIFICATION OF THIS SOLUTION IS LEFT TO THE READER.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
C...
C...  INITIAL CONDITIONS
      X1=2.
      X2=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
      DX1DT=X2
      DX2DT=1.0-2.0*X2-2.0*X1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        X1,        X2
     2      /F/     DX1DT,     DX2DT
     3      /C/        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION    TP(51),   X1P(51)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINES JMAP, EIGEN
      DIMENSION        AJ(2,2),          WF(2),
     1                   SV(2),       SVOLD(2),
     2                   FV(2),       FVOLD(2)
      COMPLEX        EIGENV(2)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(2), TO THE DEPENDENT
C...  VARIABLES IN COMMON/Y/, AND THE DERIVATIVE VECTOR, FV(2), TO THE
C...  DERIVATIVES IN COMMON/F/
      EQUIVALENCE (X1,SV(1)), (DX1DT,FV(1))
C...
C...  PRINT A HEADING FOR THE NUMERICAL AND ANALYTICAL SOLUTIONS
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'X1',10X,'XA')
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS EVERY FIFTH CALL
C...  TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         XA=(1./2)+(3./2.)*EXP(-T)*COS(T)+(3./2.)*EXP(-T)*SIN(T)
         WRITE(NO,2)T,X1,XA
2        FORMAT(F10.1,2F12.5)
      END IF
C...
C...  MAP THE JACOBIAN MATRIX AT THE BEGINNING AND END OF THE SOLUTION
      IF((IP.EQ.1).OR.(IP.EQ.51))THEN
         NODE=2
         CALL JMAP(NODE,AJ,SV,SVOLD,FV,FVOLD)
C...
C...     COMPUTE THE TEMPORAL EIGENVALUES OF THE TWO ODES DEFINED IN
C...     COMMON /Y/ AND /F/
         CALL EIGEN(NODE,AJ,EIGENV,WF)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      X1P(IP)=X1
       TP(IP)=T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,3)
3     FORMAT(1H ,//,' X(T) VS T')
      RETURN
      END
NUMERICAL AND ANALYTICAL SOLUTIONS OF A OSCILLATORY ODE
0.        10.       0.2
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC30
      SUBROUTINE INITAL
C...
C...  DIRECT FREQUENCY RESPONSE TESTING
C...
C...  CONSIDER THE DIRECT FREQUENCY RESPONSE TESTING OF A SYSTEM WITH
C...  A TRANSFER FUNCTION 1/(2*S + 1) AS INDICATED IN THE FOLLOWING
C...  DIAGRAM
C...
C...                      .............
C...                      .           .
C...                      .     1     .
C...      SIN(W*T) ......+.  -------  .......+ A*SIN(W*T + PHI)
C...                      .  2*S + 1  .
C...                      .           .
C...                      .............
C...
C...  A = A(W) AND PHI = PHI(W) ARE THE FREQUENCY RESPONSE CHARACTER-
C...  ISTICS OF THE SYSTEM, WHICH MAY BE CALCULATED IN EITHER OF TWO
C...  WAYS
C...
C...     (1)  THE TRANSFER FUNCTION CAN BE CONVERTED INTO THE DIFFER-
C...          ENTIAL EQUATION
C...
C...             2*DY/DT + Y = SIN(W*T)
C...
C...          WHICH CAN THEN BE INTEGRATED
C...
C...     (2)  THE SUBSTITUTION S = J*W CAN BE MADE DIRECTLY IN THE
C...          TRANSFER FUNCTION.
C...
C...  BOTH APPROACHES ARE USED BELOW.
C...
C...  (1)  THE LAPLACE TRANSFORM OF THE DIFFERENTIAL EQUATION, SUBJECT
C...       TO THE INITIAL CONDITION Y(0) = 0, IS
C...
C...       2*S*YL + YL = W/(S**2 + W**2)
C...
C...       OR SOLVING FOR THE LAPLACE TRANSFORM OF Y(T), YL(S)
C...
C...       YL(S) = W/((2*S + 1)*(S**2 + W**2))
C...
C...       YL(S) = W/((2*S + 1)*(S + J*W)*(S - J*W))
C...
C...       YL(S) = A/(2*S + 1) + B/(S + J*W) + C/(S - J*W)
C...
C...       WHERE A, B AND C ARE CONSTANTS IN THE PARTIAL FRACTIONS
C...       EXPANSION TO BE DETERMINED.
C...
C...       A = W/((-1/2 + J*W)*(-1/2 - J*W)) = W/(1/4 + W**2)
C...
C...       B = W/((2*(-J*W) + 1)*(-J*W - J*W)) =
C...
C...         = W/((-2*J*W)*(1 - 2*J*W))
C...
C...       C = W/(( 2*J*W) + 1)*( J*W + J*W)) =
C...
C...         = W/(( 2*J*W)*(1 + 2*J*W))
C...
C...       INVERSION THEN GIVES
C...
C...       Y(T) = (1/2)*A*EXP(-(1/2)*T) + B*EXP(-J*W*T) + C*EXP(J*W*T)
C...
C...            = (1/2)*A*EXP(-(1/2)*T) +
C...
C...  ABS(1/(1 + 2*J*W))*(EXP(J*W*T + J*PHI) - EXP(-(J*W*T + J*PHI))
C...                      ----------------------------------------
C...                                         2*J
C...
C...            = (1/2)*A*EXP(-(1/2)*T) +
C...
C...            + (1/(1 + (2*W)**2)**0.5)*SIN(W*T + PHI)
C...
C...
C...       WHERE PHI = ARCTAN(-2*W/1)
C...
C...       A CHECK ON THE INITIAL CONDITION GIVES
C...
C...       Y(0) = (1/2)*A + (1/(1 + 4*W**2)**0.5)*SIN(PHI)
C...
C...            = (1/2)*W/(1/4 + W**2) + (1/(1 + 4*W**2)**0.5)
C...
C...             *(-2*W)/(1 + 4*W**2)**0.5 = 0
C...
C...       THE STEADY STATE (LONG TIME) SOLUTION IS SIMPLY
C...
C...       Y(T) = (1/(1 + (2*W)**2))*SIN(W*T + PHI)
C...
C...            = A(W)*SIN(W*T + PHI(W))
C...
C...       WHERE
C...
C...       A(W) = 1/(1 + (2*W)**2), PHI(W) = ARCTAN(-2*W)
C...
C...       ARE THE FREQUENCY RESPONSE CHARACTERISTICS OF THE SYSTEM
C...       1/(2*S + 1) AS NOTED PREVIOUSLY.  THESE FREQUENCY RESPONSE
C...       CHARACTERISTICS CAN ALSO BE CALCULATED BY THE SECOND METHOD
C...       INDICATED BELOW.
C...
C...       A SECOND APPROACH TO THE LAPLACE TRANSFORM SOLUTION IS TO
C...       USE A PARTIAL FRACTIONS EXPANSION OF THE FORM
C...
C...       YL(S) = W/((2*S + 1)*(S**2 + W**2))
C...
C...             = A/(2*S + 1) + (B*S + C)/(S**2 + W**2)
C...
C...       THE CONSTANTS A, B AND C CAN BE DETERMINED BY PUTTING THE
C...       RIGHT HAND SIDE OF THE PARTIAL FRACTIONS OVER A COMMON
C...       DENOMINATOR
C...
C...                               W
C...       YL(S) = -------------------------------------
C...                     (2*S + 1)*(S**2 + W**2)
C...
C...               A*(S**2 + W**2) + (B*S + C)*(2*S + 1)
C...             = -------------------------------------
C...                     (2*S + 1)*(S**2 + W**2)
C...
C...        SINCE THE DENOMINATORS OF THE PRECEDING EQUATION ARE THE
C...        SAME, THE NUMERATORS MUST BE EQUAL, I.E.,
C...
C...        W = A*(S**2 + W**2) + (B*S + C)*(2*S + 1)
C...
C...        IF WE EQUATE THE COEFFIEICNTS OF LIKE POWERS OF S
C...
C...        S**2: 0 = A + 2*B
C...
C...        S**1: 0 = B + 2*C
C...
C...        S**0: W = A*W**2 + C
C...
C...        THESE THREE EQUATIONS CAN BE SOLVED FOR THE THREE UNKNOWNS,
C...        A, B AND C.  THUS
C...
C...        A = -2*B
C...
C...        W = -2*B*W**2 + C
C...
C...        W = -2*B*W**2 - (1/2)*B
C...
C...        OR
C...
C...        B = -2*W/(1 + 4*W**2)
C...
C...        A =  4*W/(1 + 4*W**2)
C...
C...        C =    W/(1 + 4*W**2)
C...
C...        THUS, THE INVERSE TRANSFORM IS
C...
C...        Y(T) = 2*W/(1 + 4*W**2)*EXP(-(1/2)*T)
C...
C...             -2*W/(1 + 4*W**2)*COS(W*T)
C...
C...             +  1/(1 + 4*W**2)*SIN(W*T)
C...
C...        THIS SOLUTION CLEARLY SATISFIES THE INITIAL CONDITION
C...
C...        Y(0) = 0.  ALSO, IT IS IDENTICAL TO THE PRECEDING SOLUTION
C...        IF THE TRIGONOMETRIC IDENTITY
C...
C...        SIN(W*T + PHI) = SIN(PHI)*COS(W*T) + COS(PHI)*SIN(W*T)
C...
C...                       = (-2*W/(1 + 4*W**2)**0.5)*COS(W*T)
C...
C...                       + (   1/(1 + 4*W**2)**0.5)*SIN(W*T)
C...
C...        IS USED TO REPLACE SIN(W*T + PHI) IN THE PRECEDING SOLUTION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/         Y
     2      /F/      DYDT
     3      /C/         W,        IP
C...
C...  SET THE FREQUENCY
      W=1.0
C...
C...  SET THE INITIAL CONDITION
      Y=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/         Y
     2      /F/      DYDT
     3      /C/         W,        IP
C...
C...  DIFFERENTIAL EQUATION
C...
C...     CASE 1 - LINEAR
         IF(NORUN.EQ.1)THEN
         DYDT=(SIN(W*T)-Y)/2.
C...
C...     CASE 2 - NONLINEAR
         ELSE IF(NORUN.EQ.2)THEN
         DYDT=(SIN(W*T)-Y*ABS(Y))/2.
         END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/         Y
     2      /F/      DYDT
     3      /C/         W,        IP
      DIMENSION TP(501), YP(2,501)
C...
C...  PRINT A HEADING
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',7X,'SIN(W*T)',12X,'NUM',11X,'ANAL')
C...
C...  COMPUTE THE RHS (SIN(W*T)) AND THE ANALYTICAL SOLUTION FOR
C...  PRINTING EVERY 20TH CALL TO PRINT
      IF(((IP-1)/20*20).EQ.(IP-1))THEN
      RHS=SIN(W*T)
      DENOM=(1.0+4.0*W**2)
      YA=2.0*W/DENOM*EXP(-(1./2.)*T)
     1  -2.0*W/DENOM*COS(W*T)
     2  +  1.0/DENOM*SIN(W*T)
C...
C...  PRINT THE RHS, NUMERICAL AND ANALYTICAL SOLUTIONS
      WRITE(NO,2)T,RHS,Y,YA
2     FORMAT(F10.2,3F15.5)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      YP(1,IP)=SIN(W*T)
      YP(2,IP)=Y
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.501)RETURN
C...
C...  *****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CHANGED FOR OTHER COMPUTERS OR CONVERTED TO COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YP,IP,3H*T*,15H*SIN(WT), Y(T)*,2H**,2)
C...
C...  *****************************************************************
C...
C...  FROM THE PRECEDING PLOT, THE AMPLITUDE AND PHASE OF THE OUTPUT
C...  SINE (I.E., A*SIN(W*T + PHI)) CAN BE OBSERVED, AND COMPARED WITH
C...  THE VALUES A = (1/(1 + 2)**0.5) = 0.4472, PHI = ARCTAN(-2*1/1) =
C...  -1.11 RADIANS = -63.43 DEGREES.
      RETURN
      END
DIRECT FREQUENCY RESPONSE TESTING - LINEAR CASE
0.        20.       0.04
    1 1000    1    1  REL 0.001
DIRECT FREQUENCY RESPONSE TESTING - NONLINEAR CASE
0.        20.       0.04
    1 1000    1    1  REL 0.001
END OF RUNS
*APP PRC31
      SUBROUTINE INITAL
C...
C...  ROOT LOCUS STABILITY ANALYSIS OF A FOURTH-ORDER SYSTEM
C...
C...  CONSIDER THE FOLLOWING FOURTH-ORDER ODE
C...
C...     (S**4 + 6*S**3 + 11*S**2 + (6 + KC)*S + KC/TI)*Y = 1
C...
C...  WHERE S = D /DT, I.E., S IS A FIRST-ORDER DIFFERENTIAL OPERATOR,
C...
C...             2    2
C...  SO S**2 = D  /DT , ETC.
C...
C...  COMPUTE A SOLUTION TO THIS ODE FOR HOMOGENEOUS (ZERO) INITIAL
C...  CONDITIONS FOR TI = 0.1, KC = 0, 0.4, 0.8, 1.2 TO ESTIMATE THE
C...  ULTIMATE GAIN (MAXIMUM VALUE OF KC FOR WHICH THE SOLUTION IS
C...  STABLE) AND COMPARE THE RESULTS WITH THE ROOT LOCUS DIAGRAM
C...  FOR THIS SYSTEM.  THE ROOT LOCUS DIAGRAM IS COMPUTED AND DRAWN
C...  BY A CALL TO SUBROUTINE ROOTS IN SUBROUTINE PRINT.
C...
C...  THE FOURTH-ORDER ODE CAN BE REDUCED TO FOUR FIRST-ORDER ODES BY
C...  THE CHANGE OF VARIABLES
C...
C...                               2    2        3    3
C...     Y1 = Y, Y2 = DY/DT, Y3 = D Y/DT , Y4 = D Y/DT
C...
C...  THUS, THE NEW SET OF FOUR ODES IS
C...
C...     DY4/DT + 6*Y4 + 11*Y3 + (6 + KC)*Y2 + (KC/TI)*Y1 = 1
C...
C...     DY1/DT = Y2, DY2/DT = Y3, DY3/DT = Y4
C...
C...  WITH THE INITIAL CONDITIONS
C...
C...     Y1(0) = Y2(0) = Y3(0) = Y4(0) = 0
C...
C...  NOTE THAT FOR THE CASE KC = 0, THE ODE REDUCES TO
C...
C...     (S**4 + 6*S**3 + 11*S**2 + 6*S)*Y = 1
C...
C...  OR
C...
C...     (S*(S + 1)*(S + 2)*(S + 3))*Y = 1
C...
C...  WHICH LAPLACE TRANSFORMS TO
C...
C...     Y = 1/((S**2)*(S + 1)*(S + 2)*(S + 3))
C...
C...  THE INVERSE TRANSFORM CAN BE OBTAINED BY PARTIAL FRACTIONS
C...
C...     = A/S**2 + B/(S + 1) + C/(S + 2) + D/(S + 3)
C...
C...  FOR WHICH THE INVERSE TRANSFORM IS
C...
C...     Y(T) = A*T**2 + B*EXP(-T) + C*EXP(-2*T) + D*EXP(-3*T)
C...
C...  NOTE THAT THE SYSTEM IS UNSTABLE DUE TO THE A*T**2 TERM.  ONCE
C...  KC GT 0, THIS RAMP FUNCTION TERM NO LONGER APPEARS IN THE SOLUTION
C...  AND THE SOLUTION IS STABLE UNTIL KC IS INCREASED TO THE ULTIMATE
C...  GAIN OF THE SYSTEM.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  SET THE EQUATION PARAMETERS
      TI=0.1
      IF(NORUN.EQ.1)KC=0.
      IF(NORUN.EQ.2)KC=0.4
      IF(NORUN.EQ.3)KC=0.8
      IF(NORUN.EQ.4)KC=1.2
C...
C...  INITIAL CONDITIONS
      Y1=0.
      Y2=0.
      Y3=0.
      Y4=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  FOUR FIRST-ORDER ODES
      DY1DT=Y2
      DY2DT=Y3
      DY3DT=Y4
      DY4DT=1.0-6.0*Y4-11.0*Y3-(6.0+KC)*Y2-(KC/TI)*Y1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(101), YP(3,101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)KC
1     FORMAT(1H ,//,' SOLUTION FOR KC = ',F5.2,//,
     1              11X,'T',11X,'Y')
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
      WRITE(NO,2)T,Y1
2     FORMAT(F12.3,F12.5)
      END IF
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING.  THE SOLUTION FOR
C...  KC = 0 IS NOT STORED SINCE THIS SOLUTION IS UNSTABLE
      IF(NORUN.GT.1)THEN
      TP(IP)=T
      YP(NORUN-1,IP)=Y1
      END IF
C...
C...  CHECK FOR THE END OF A RUN
      IF(IP.LT.101)RETURN
C...
C...  PLOT THE SOLUTION AT THE END OF THE FOURTH RUN
      IF(NORUN.NE.4)RETURN
      CALL TPLOTS(NORUN-1,IP,TP,YP)
      WRITE(NO,3)
3     FORMAT(1H ,/,' Y(T) VS T, KC = 0.4, 0.8, 1.2',/)
C...
C...  AT THE END OF THE FOUR RUNS, CALL SUBROUTINE ROOTS TO COMPUTE AND
C...  PLOT THE ROOT LOCUS DIAGRAM FOR 11 VALUES OF KC.  THE OUTPUT CAN
C...  BE COMPARED WITH THE NUMERICAL SOLUTION.  SPECIFICALLY, THE VALUE
C...  OF KC FOR WHICH THE SYSTEM BECOMES UNSTABLE (AT LEAST ONE OF THE
C...  ROOTS OF THE CHARACTERSTIC EQUATION ASSUMES A POSITIVE REAL PART)
C...  CAN BE COMPARED WITH THE VALUE OF KC FOR WHICH THE NUMERICAL SOLU-
C...  TION BECOMES UNSTABLE
      CALL ROOTS(NI,NO)
      RETURN
      END
      SUBROUTINE ROOTS(NI,NO)
C...
C...  ROOT LOCUS DIAGRAM OF A FOURTH-ORDER FEEDBACK SYSTEM
C...
C...  CONSIDER THE FOLLOWING FEEDBACK CONTROL SYSTEM
C...
C...                       ............
C...                 M     .          .    C
C...            ..........+.    GP    ..........
C...            .          .          .        .
C...            .          ............        .
C...            .                              .
C...            .                              .
C...            .          ............        +-
C...            .          .          .       ...+
C...            ............    GC    .+.......S.+..... C
C...                       .          .       ...        SET
C...                       ............
C...
C...  WHERE
C...
C...     M       MANIPULATED VARIABLE
C...
C...     C       CONTROLLED VARIABLE
C...
C...     C       CONTROLLED VARIABLE SET POINT
C...      SET
C...
C...     GP      PROCESS TRANSFER FUNCTION
C...
C...     GC      CONTROLLER TRANSFER FUNCTION
C...
C...     S       SUMMER
C...
C...  CONSIDER THE FOLLOWING SPECIFIC TRANSFER FUNCTIONS
C...
C...     GP = 1/((S + 1)*(S + 2)*(S + 3))
C...
C...     GC = KC*(1 + 1/(TI*S))
C...
C...  COMPUTE THE ROOTS OF THE CLOSED LOOP CHARACTERISTIC EQUATION FOR
C...  THIS SYSTEM,
C...
C...     1 + GP*GC = 0
C...
C...  AND PLOT THEM AS A ROOT LOCUS DIAGRAM.  TAKE TI = 0.1.  FROM THE
C...  ROOT LOCUS DIAGRAM, DETERMINE APPROXIMATELY THE ULTIMATE GAIN
C...  OF THE CLOSED LOOP SYSTEM.
C...
C...  DIMENSION THE ARRAYS REQUIRED BY SUBROUTINE ZPOLR
      REAL A(5), KC, PLOTRE(44), PLOTIM(44)
      COMPLEX Z(4)
C...
C...  THE CLOSED LOOP CHARACTERISTIC EQUATION TO BE PLOTTED IS
C...
C...                    1
C...     1 + -----------------------*KC(1 + 1/(TI*S)) = 0
C...         (S + 1)*(S + 2)*(S + 3)
C...
C...  WHICH CAN BE REARRANGED TO
C...
C...     S*(S + 1)*(S + 2)*(S + 3) + KC*(S + 1/TI) = 0
C...
C...  OR
C...
C...     S**4 + 6*S**3 + 11*S**2 + (6 + KC)*S + KC/TI = 0
C...
C...  THREE OF THE POLYNOMIAL COEFFICIENTS CAN BE DEFINED AT THIS POINT
      A(1)=1.
      A(2)=6.
      A(3)=11.
C...
C...  STEP THROUGH A SERIES OF VALUES OF KC TO CONSTRUCT THE ROOT LOCUS
C...  PLOT
      DO 1 I=1,11
      KC=0.2*FLOAT(I-1)
      A(4)=6.+KC
      TI=0.1
      A(5)=KC/TI
C...
C...  CALL IMSL SUBROUTINE ZPOLR TO CALCULATE THE ROOTS OF THE CLOSED
C...  LOOP CHARACERISTIC EQUATION FOR THE CURRENT VALUE OF KC
      NDEG=4
      CALL ZPOLR(A,NDEG,Z,IER)
C...
C...  PRINT THE ROOTS
      WRITE(NO,2)KC
2     FORMAT(1H ,//,' KC = ',F6.2,/,8X,'REAL',8X,'IMAG')
      DO 3 J=1,NDEG
      ZREAL= REAL(Z(J))
      ZIMAG=AIMAG(Z(J))
      WRITE(NO,4)ZREAL,ZIMAG
4     FORMAT(2F12.5)
C...
C...  STORE THE ROOTS FOR SUBSEQUENT PLOTTING
      ISUB=(I-1)*NDEG+J
      PLOTRE(ISUB)=ZREAL
      PLOTIM(ISUB)=ZIMAG
3     CONTINUE
C...
C...  GO ON TO THE NEXT VALUE OF KC
1     CONTINUE
C...
C...  ALL OF THE VALUES OF KC HAVE BEEN USED, SO PLOT THE ROOT LOCUS
      CALL TPLOTS(1,44,PLOTRE,PLOTIM)
      WRITE(NO,5)
5     FORMAT(1H ,/,' ROOT LOCUS OF S*(S+1)*(S+2)*(S+3)+KC*(S+1/TI)=0',
     1 ', 0 LE KC LE 2')
      RETURN
      END
FOURTH-ORDER ODE, KC = 0
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 0.4
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 0.8
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 1.2
0.        50.       0.5
    4 1000    1    1  REL 0.001
END OF RUNS
*APP PRC32
      SUBROUTINE INITAL
C...
C...  FREQUENCY RESPONSE STABILITY ANALYSIS OF A FOURTH-ORDER SYSTEM
C...
C...  CONSIDER THE FOLLOWING FOURTH-ORDER ODE
C...
C...     (S**4 + 6*S**3 + 11*S**2 + (6 + KC)*S + KC/TI)*Y = 1
C...
C...  WHERE S = D /DT, I.E., S IS A FIRST-ORDER DIFFERENTIAL OPERATOR,
C...
C...             2    2
C...  SO S**2 = D  /DT , ETC.
C...
C...  COMPUTE A SOLUTION TO THIS ODE FOR HOMOGENEOUS (ZERO) INITIAL
C...  CONDITIONS FOR TI = 0.1, KC = 0, 0.4, 0.8, 1.2 TO ESTIMATE THE
C...  ULTIMATE GAIN (MAXIMUM VALUE OF KC FOR WHICH THE SOLUTION IS
C...  STABLE) AND COMPARE THE RESULTS WITH THE FREQUENCY RESPONSE (BODE)
C...  DIAGRAMS FOR THIS SYSTEM.  THE BODE DIAGRAMS ARE COMPUTED AND
C...  PLOTTED BY A CALL TO SUBROUTINE BODE IN SUBROUTINE PRINT.
C...
C...  THE FOURTH-ORDER ODE CAN BE REDUCED TO FOUR FIRST-ORDER ODES BY
C...  THE CHANGE OF VARIABLES
C...
C...                               2    2        3    3
C...     Y1 = Y, Y2 = DY/DT, Y3 = D Y/DT , Y4 = D Y/DT
C...
C...  THUS, THE NEW SET OF FOUR ODES IS
C...
C...     DY4/DT + 6*Y4 + 11*Y3 + (6 + KC)*Y2 + (KC/TI)*Y1 = 1
C...
C...     DY1/DT = Y2, DY2/DT = Y3, DY3/DT = Y4
C...
C...  WITH THE INITIAL CONDITIONS
C...
C...     Y1(0) = Y2(0) = Y3(0) = Y4(0) = 0
C...
C...  NOTE THAT FOR THE CASE KC = 0, THE ODE REDUCES TO
C...
C...     (S**4 + 6*S**3 + 11*S**2 + 6*S)*Y = 1
C...
C...  OR
C...
C...     (S*(S + 1)*(S + 2)*(S + 3))*Y = 1
C...
C...  WHICH LAPLACE TRANSFORMS TO
C...
C...     Y = 1/((S**2)*(S + 1)*(S + 2)*(S + 3))
C...
C...  THE INVERSE TRANSFORM CAN BE OBTAINED BY PARTIAL FRACTIONS
C...
C...     = A/S**2 + B/(S + 1) + C/(S + 2) + D/(S + 3)
C...
C...  FOR WHICH THE INVERSE TRANSFORM IS
C...
C...     Y(T) = A*T**2 + B*EXP(-T) + C*EXP(-2*T) + D*EXP(-3*T)
C...
C...  NOTE THAT THE SYSTEM IS UNSTABLE DUE TO THE A*T**2 TERM.  ONCE
C...  KC GT 0, THIS RAMP FUNCTION TERM NO LONGER APPEARS IN THE SOLUTION
C...  AND THE SOLUTION IS STABLE UNTIL KC IS INCREASED TO THE ULTIMATE
C...  GAIN OF THE SYSTEM.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  SET THE EQUATION PARAMETERS
      TI=0.1
      IF(NORUN.EQ.1)KC=0.
      IF(NORUN.EQ.2)KC=0.4
      IF(NORUN.EQ.3)KC=0.8
      IF(NORUN.EQ.4)KC=1.2
C...
C...  INITIAL CONDITIONS
      Y1=0.
      Y2=0.
      Y3=0.
      Y4=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  FOUR FIRST-ORDER ODES
      DY1DT=Y2
      DY2DT=Y3
      DY3DT=Y4
      DY4DT=1.0-6.0*Y4-11.0*Y3-(6.0+KC)*Y2-(KC/TI)*Y1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2,        Y3,        Y4
     2      /F/     DY1DT,     DY2DT,     DY3DT,     DY4DT
     3      /C/        KC,        TI,        IP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(101), YP(3,101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)KC
1     FORMAT(1H ,//,' SOLUTION FOR KC = ',F5.2,//,
     1              11X,'T',11X,'Y')
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
      WRITE(NO,2)T,Y1
2     FORMAT(F12.3,F12.5)
      END IF
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING.  THE SOLUTION FOR
C...  KC = 0 IS NOT STORED SINCE THIS SOLUTION IS UNSTABLE
      IF(NORUN.GT.1)THEN
      TP(IP)=T
      YP(NORUN-1,IP)=Y1
      END IF
C...
C...  CHECK FOR THE END OF A RUN
      IF(IP.LT.101)RETURN
C...
C...  PLOT THE SOLUTION AT THE END OF THE FOURTH RUN
      IF(NORUN.NE.4)RETURN
      CALL TPLOTS(NORUN-1,IP,TP,YP)
      WRITE(NO,3)
3     FORMAT(1H ,/,' Y(T) VS T, KC = 0.4, 0.8, 1.2',/)
C...
C...  AT THE END OF THE FOUR RUNS, CALL SUBROUTINE BODE TO COMPUTE AND
C...  PLOT THE BODE DIAGRAM FOR THE FOURTH-ORDER SYSTEM.  THE OUTPUT CAN
C...  BE COMPARED WITH THE NUMERICAL SOLUTION.  SPECIFICALLY, THE VALUE
C...  OF KC FOR WHICH THE FREQUENCY RESPONSE STABILITY CRITERIA IS MET,
C...  I.E., LOG(GAIN) = 0, ANGLE = -180, CAN BE COMPARED WITH THE VALUE
C...  OF KC FOR WHICH THE NUMERICAL SOLUTION BECOMES UNSTABLE.
      CALL BODE(NI,NO)
      RETURN
      END
      SUBROUTINE BODE(NI,NO)
C...
C...  COMPUTE AND PLOT (AS BODE DIAGRAMS) THE FREQUENCY RESPONSE
C...  CHARACTERISTICS OF THE SYSTEM CONSISTING OF THE FOLLOWING
C...  PROCESS TRANSFER FUNCTION, GP(S), AND CONTROLLER TRANSFER
C...  FUNCTION, GC(S)
C...
C...                        1
C...     GP(S) = -----------------------
C...             (S + 1)*(S + 2)*(S + 3)
C...
C...     GC(S) = KC*(1 + 1/(TI*S))
C...
C...  WITH TI = 0.1.  DETERMINE THE ULTIMATE GAIN FOR THE SYSTEM FROM
C...  THE FREQUENCY RESPONSE CHARACTERISTICS.
C...
C...  DIMENSION THE ARRAYS FOR THE FREQUENCY RESPONSE CHARACTERISTICS
      DIMENSION WP(30), AMPP(30), PHASEP(30)
C...
C...  THE FREQUENCY SCALE WILL RANGE OVER THREE DECADES, 0.1 LE W LE
C...  100, WITH 10 POINTS PER DECADE
      WIN=10.0**0.1
      W=0.1/WIN
C...
C...  STEP THROUGH THE THREE DECADES, 10 POINTS PER DECADE
      DO 1 I=1,30
      W=WIN*W
C...
C...  FREQUENCY RESPONSE OF 1/(S + 1)
      CALL FR1(1.0/1.0,W,AMP1,PHASE1)
C...
C...  FREQUENCY RESPONSE OF 1/(S + 2)
      CALL FR1(1.0/2.0,W,AMP2,PHASE2)
C...
C...  FREQUENCY RESPONSE OF 1/(S + 3)
      CALL FR1(1.0/3.0,W,AMP3,PHASE3)
C...
C...  FREQUENCY RESPONSE OF (1 + 1/(TI*S))
      CALL FR2(0.1,W,AMP4,PHASE4)
C...
C...  COMPUTE THE OVERALL AMPLITUDE
      AMP=20.0*(ALOG10(1./2.)+ALOG10(1./3.))+AMP1+AMP2+AMP3+AMP4
C...
C...  COMPUTE THE OVERALL PHASE
      PHASE=PHASE1+PHASE2+PHASE3+PHASE4
C...
C...  PRINT THE FREQUENCY RESPONSE CHARACTERISTICS
      WRITE(NO,2)W,AMP1,PHASE1,
     1             AMP2,PHASE2,
     2             AMP3,PHASE3,
     3             AMP4,PHASE4,
     4             AMP ,PHASE
 2     FORMAT(1H ,/,' W = ',F6.3,4X,'AMP (DB)',5X,'PHASE',/,
     1             '    1/(S + 1)',F10.4,F10.3,/,
     2             '    1/(S + 2)',F10.4,F10.3,/,
     3             '    1/(S + 3)',F10.4,F10.3,/,
     4             ' 1 + 1/(TI*S)',F10.4,F10.3,/,
     5             '         G(S)',F10.4,F10.3,/)
C...
C...  STORE THE FREQUENCY RESPONSE CHARACTERISTICS FOR PLOTTING
      WP(I)=ALOG10(W)
      AMPP(I)=AMP
      PHASEP(I)=PHASE
1     CONTINUE
C...
C...  PLOT THE FREQUENCY RESPONSE CHARACTERISTICS
C...
C...     AMPLITUDE PLOT
         CALL TPLOTS(1,30,WP,AMPP)
         WRITE(NO,10)
10       FORMAT(1H ,/,' LOG(A) (DB) VS LOG(W)',/)
C...
C...     PHASE PLOT
         CALL TPLOTS(1,30,WP,PHASEP)
         WRITE(NO,11)
11       FORMAT(1H ,/,' PHASE (DEGREES) VS LOG(W)',/)
C...
C...  AT THIS POINT, THE BODE PLOTS CAN BE USED TO DETERMINE THE GAIN
C...  KC REQUIRED TO MOVE THE SYSTEM TO INCIPIENT INSTABILITY, I.E.,
C...  KC WILL BE THE VERTICAL SHIFT OF THE AMPLITUDE CURVE REQUIRED
C...  TO MEET THE CONDITION LOG(A) = 0 WHEN PHASE = -180.  THE PRECEDING
C...  NUMERICAL OUTPUT, AND THE BODE DIAGRAMS INDICATE THAT KC IS BET-
C...  WEEN 1.0 AND 1.20, WHICH AGREES WITH THE NUMERICAL SOLUTION COM-
C...  PUTED IN SUBROUTINES INITAL, DERV AND PRINT, AND PLOTTED IN SUB-
C...  ROUTINE PRINT
      RETURN
      END
      SUBROUTINE FR1(TC,W,AMP,PHASE)
C...
C...  SUBROUTINE FR1 COMPUTES THE FREQUENCY RESPONSE OF A FIRST-ORDER
C...  LAG WITH TRANSFER FUNCTION
C...
C...     G(S) = 1/(TC*S + 1)
C...
C...  THE FREQUENCY RESPONSE CHARACTERISTICS ARE COMPUTED AS THE MAGNI-
C...  TUDE (AMPLITUDE) AND ANGLE (PHASE) OF G(S) AFTER THE SUBSTITUTION
C...  S = J*W
C...
C...  AMPLITUDE
      AMP=1.0/SQRT((TC*W)**2+1.0)
C...
C...  CONVERT TO DECIBELS
      AMP=20.0*ALOG10(AMP)
C...
C...  PHASE
      PHASE=ATAN(TC*W)
C...
C...  CONVERT THE ANGLE TO DEGREES AND PUT IN THE FOURTH QUADRANT
      PI=3.1415927
      PHASE=-PHASE*180.0/PI
      RETURN
      END
      SUBROUTINE FR2(TI,W,AMP,PHASE)
C...
C...  SUBROUTINE FR2 COMPUTES THE FREQUENCY RESPONSE OF A PROPORTIONAL-
C...  INTEGRAL CONTROLLER WITH TRANSFER FUNCTION
C...
C...     G(S) = (1 + 1/(TI*S))
C...
C...  THE FREQUENCY RESPONSE CHARACTERISTICS ARE COMPUTED AS THE MAGNI-
C...  TUDE (AMPLITUDE) AND ANGLE (PHASE) OF G(S) AFTER THE SUBSTITUTION
C...  S = J*W
C...
C...  AMPLITUDE
      AMP=SQRT(1.0+1.0/(TI*W)**2)
C...
C...  CONVERT TO DECIBELS
      AMP=20.0*ALOG10(AMP)
C...
C...  PHASE
      PHASE=ATAN(1.0/(TI*W))
C...
C...  CONVERT THE ANGLE TO DEGREES AND PUT IN THE FOURTH QUADRANT
      PI=3.1415927
      PHASE=-PHASE*180.0/PI
      RETURN
      END
FOURTH-ORDER ODE, KC = 0
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 0.4
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 0.8
0.        50.       0.5
    4 1000    1    1  REL 0.001
FOURTH-ORDER ODE, KC = 1.2
0.        50.       0.5
    4 1000    1    1  REL 0.001
END OF RUNS
*APP PRC33
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TWO-STAGE HEAT EXCHANGER SYSTEM
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE OF PARTICULAR
C...  INTEREST IN THE SIMULATION.
C...
C...  THE SYSTEM PARAMETERS ARE:
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = 1, U = 25, AT = 10, T0 = 60,
C...
C...  TJ0 = 200, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  A PI CONTROLLER HAS BEEN PROPOSED TO MAINTAIN THE OUTLET TEMPERA-
C...  TURE, T2, AT 180.  THE CONTROLLER EQUATIONS ARE:
C...
C...     E = T2SET - T2; (T2SET = 180)
C...
C...                                 T
C...     FJ = FJSS + AKC*(E + (1/TI)INT E*DT); (INT DENOTES AN INTEGRAL)
C...                                 0
C...
C...     FJSS = 1, T1(0) = T2(0) = 180, TJ1(0) = TJ2(0) = 200
C...
C...  WHERE
C...
C...     FJSS        STEADY STATE VALUE OF FJ
C...
C...     AKC         CONTROLLER GAIN
C...
C...     TI          CONTROLLER INTEGRAL TIME
C...
C...  NOTE THAT T1(0) = 180 WHILE T0 = 60 SO THAT THE ENTERING STREAM
C...  WITH TEMPERATURE T0 BEGINS TO COOL THE LIQUID IN THE RIGHT TANK
C...  AND THEREBY CAUSES A CHANGE IN THE TEMPERATURE TO BE CONTROLLED,
C...  T2.
C...
C...  INVESTIGATE WHETHER THIS CONTROLLER WILL WORK, AND IF IT LOOKS
C...  PROMISING, TUNE THE CONTROLLER, I.E, FIND VALUES OF AKC AND TI
C...  TO GIVE A GOOD RESPONSE OF E VS T WITH NO OFFSET.  IN ADDITION TO
C...  PLOTTING E VS T, PLOT FJ VS T TO DEMONSTRATE HOW THE CONTROLLER
C...  CHANGES THE JACKET FLOW RATE.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
        U=25.
       AT=10.
       T0=60.
      TJ0=200.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
        R=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      T2SET=180.
      FJSS=1.
      IF(NORUN.EQ.1)AKC=0.
      IF(NORUN.GE.2)AKC=5.0
      TI=10.
C...
C...  INITIAL CONDITIONS
       T1=180.
       T2=180.
      TJ1=200.
      TJ2=200.
       EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  CONTROLLER EQUATIONS
      E=T2SET-T2
      FJ=FJSS+AKC*(E+(1./TI)*EI)
C...
C...  LIMIT THE JACKET FLOW TO POSITIVE VALUES IN THE THIRD RUN
      IF((NORUN.EQ.3).AND.(FJ.LT.0.))FJ=0.
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), EP(51), FJP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2',11X,'E',
     1       10X,'FJ')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/1*1).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2,E,FJ
2     FORMAT(F10.1,6F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      EP(IP)=E
      FJP(IP)=FJ
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.NE.51)RETURN
C...
C...  E(T) VS T
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' E(T) VS T')
C...
C...  FJ(T) VS T
      CALL TPLOTS(1,IP,TP,FJP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' FJ(T) VS T')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
END OF RUNS
*APP PRC34
      SUBROUTINE INITAL
C...
C...  OFFSET/STABILITY TRADEOFF IN THE PROPORTIONAL CONTROL OF
C...  DYNAMIC SYSTEMS
C...
C...  CONSIDER A DYNAMIC SYSTEM MODELED BY THE DIFFERENTIAL EQUATIONS
C...
C...     DY1/DT + Y1 = YL + YM, Y1(0) = 1
C...
C...     DY2/DT + Y2 = Y1, Y2(0) = 1
C...
C...     DY3/DT + Y3 = Y2, Y3(0) = 1
C...
C...     DY4/DT + Y4 = Y3, Y4(0) = 1
C...
C...     DY5/DT + Y5 = Y4, Y5(0) = 1
C...
C...  WHERE
C...
C...     YL = LOAD VARIABLE
C...
C...     YM = MANIPULATED VARIABLE = KC*E
C...
C...     E = ERROR = Y5SET - Y5
C...
C...  (1)  IF UNDER NORMAL (DISTURBANCE-FREE) OPERATING CONDITIONS, YL
C...       = 1, Y5SET = 1, WHAT ARE THE VALUES OF Y1, Y2, Y3, Y4, Y5
C...       AND E.
C...
C...  (2)  CONSIDER THE CASE WHERE YL CHANGES FROM 1 TO 2 AT T = 0.
C...       CAN YOU FIND A VALUE OF THE CONTROLLER GAIN, KC, FOR WHICH
C...       THE SYSTEM REMAINS STABLE AND THE OFFSET (E AT INFINITE T)
C...       DOES NOT EXCEED 0.05.
C...
C...  OBVIOUSLY THE DIFFERENTIAL EQUATIONS HAVE BEEN CHOSEN TO BE
C...  SIMPLE (E.G., LINEAR) AND EASY TO ANALYZE.  FOR CASE (1), A
C...  SOLUTION CAN BE DEVELOPED ESSENTIALLY BY INSPECTION.  IF YL
C...  = 1, YM = 0 (FROM E = 0), THEN IT FOLLOWS THAT AT STEADY STATE
C...  (DY1/DT = DY2/DT = DY3/DT = DY4/DT = DY5/DT = 0), Y1 = Y2 =
C...  Y3 = Y4 = Y5 = 1, AND THESE CONDITIONS WILL APPLY FOR ANY VALUE
C...  OF KC.  THUS THE SYSTEM DOES NOT DEPART FROM ITS INITIAL STEADY
C...  STATE CONDITION (NOTE THAT THE INITIAL CONDITIONS FOR THE FIVE
C...  DIFFERENTIAL EQUATIONS ARE ALL 1).  THE PROGRAMMING FOR CASE
C...  (1) (NORUN = 1) CONFIRMS THESE CONCLUSIONS.
C...
C...  FOR CASE (2), A DISTURBANCE IS INTRODUCED INTO THE SYSTEM BY
C...  YL = 2 (THE TERM ON THE RHS OF THE FIRST DIFFERENTIAL EQUATION
C...  DRIVES ALL OF THE DERIVATIVES AWAY FROM ZER0).  EVENTUALLY, THE
C...  SYSTEM WILL COME TO ANOTHER STEADY STATE (IF THE SYSTEM IS STABLE)
C...  CORRESPONDING TO YL = 2, YM = KC*E = KC*(Y5SET - Y5) = KC*(-0.05)
C...  (NOTE THE OFFSET OF -0.05 = Y5SET - Y5 = 1 - 1.05), Y1 = Y2 = Y3
C...  Y4 = Y5 = 1.05, DY1/DT = DY2/DT = DY3/DT = DY4/DT = DY5/DT = 0.
C...  KC CAN BE CALCULATED FOR THIS NEW STEADY STATE BY SUBSTUTITION
C...  IN THE FIRST DIFFERENTIAL EQUATION
C...
C...     DY1/DT + Y1 = YL + KC*E = 0 + 1.05 = 2 + KC*(-0.05)
C...
C...  OR KC = 19.  THE QUESTION THEN REMAINS WHETHER THE SYSTEM IS
C...  DYNAMICALLY STABLE FOR THIS VALUE OF KC.  THE FOLLOWING PROGRAM-
C...  MING PROVIDES AN ANSWER TO THIS QUESTION BY COMPUTING A SOLUTION
C...  TO THE DIFFERENTIAL EQUATIONS WITH KC = 19.
C...
C...  THE PRECEDING DIFFERENTIAL EQUATIONS CAN BE APPLIED TO PHYSICAL
C...  SYSTEMS.  FOR EXAMPLE, CONSIDER THE FOLLOWING SERIES OF FIVE
C...  PERFECTLY MIXED TANKS
C
C                                 ......                        E
C       ........................... KC ..........................
C       . YM                      ......                        .
C       +                                            Y5SET ...+SUM
C YL..+SUM...                                                   + -
C           .                                                   .
C          .+ .  .    .  .  .    .  .  .    .  .  .    .  .  .  .
C          .  .  .    .  .  .    .  .  .    .  .  .    .  .  .  .
C          .--.--.    .--.--.    .--.--.    .--.--.    .--.--.  .
C          .  .  .    .  .  .    .  .  .    .  .  .    .  .  .  .
C          .  .  .    .  .  .    .  .  .    .  .  .    .  .  .  .
C          . 0.0 .    . 0.0 .    . 0.0 .    . 0.0 .    . 0.0 .  .
C          .     .---+.     .---+.     .---+.     .---+.     .-----+ Y5
C          ....... Y1 ....... Y2 ....... Y3 ....... Y4 .......
C
C...  THUS, THE DIFFERENTIAL EQUATIONS, AND ASSOCIATED ALGEBRAIC EQUA-
C...  TIONS, MODEL A SERIES OF FIVE PERFECTLY MIXED TANKS WITH THE
C...  OUTLET FROM THE FIFTH TANK CONTROLLED BY A PROPORTIONAL FEEDBACK
C...  CONTROLLER.  FOR THE PRESENT CASE, THE RATIO OF THE TANK VOLUMES
C...  OVER THE VOLUMETRIC FLOW RATES (THE NOMINAL HOLDING TIME) IS
C...  UNITY.
C...
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/   Y(5)
     2      /F/DYDT(5)
     3      /C/     YL,     YM,      E,     KC,  Y5SET,      N
      REAL          KC
C...
C...  SET THE MODEL PARAMETERS
      Y5SET=1.
      IF(NORUN.EQ.1)THEN
        YL=1.
        KC=19.
      ELSE IF(NORUN.EQ.2)THEN
        YL=2.
        KC=19.
      ELSE IF(NORUN.EQ.3)THEN
        YL=2.
        KC=10.
      ELSE IF(NORUN.EQ.4)THEN
        YL=2.
        KC=1.
      ELSE IF(NORUN.EQ.5)THEN
         YL=2.
         KC=19.
      END IF
C...
C...  INITIAL CONDITIONS
      N=5
      IF(NORUN.LE.4)THEN
         DO 1 I=1,N
         Y(I)=1.
1        CONTINUE
      ELSE IF(NORUN.EQ.5)THEN
         DO 2 I=1,N
         Y(I)=1.05
2        CONTINUE
      END IF
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/   Y(5)
     2      /F/DYDT(5)
     3      /C/     YL,     YM,      E,     KC,  Y5SET,      N
      REAL          KC
C...
C...  MODEL ALGEBRA
      E=Y5SET-Y(5)
      YM=KC*E
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DYDT(1)=YL+YM-Y(1)
      DO 1 I=2,N
      DYDT(I)=Y(I-1)-Y(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/   Y(5)
     2      /F/DYDT(5)
     3      /C/     YL,     YM,      E,     KC,  Y5SET,      N
      REAL          KC
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,(Y(I),I=1,N),(DYDT(I),I=1,N)
1     FORMAT(1H ,/,5X,6H     T,F10.2
     1          ,/,5X,6H     Y,5F10.3
     2          ,/,5X,6H DY/DT,5F10.3)
      RETURN
      END
FIFTH-ORDER LINEAR SYSTEM, NO DISTURBANCE
0.        20.       1.0
    5 1000    1    1  REL 0.001
FIFTH-ORDER LINEAR SYSTEM, RESPONSE TO STEP DISTURBANCE
0.        20.       1.0
    5 1000    1    1  REL 0.001
FIFTH-ORDER LINEAR SYSTEM, RESPONSE TO STEP DISTURBANCE
0.        20.       1.0
    5 1000    1    1  REL 0.001
FIFTH-ORDER LINEAR SYSTEM, RESPONSE TO STEP DISTURBANCE
0.        20.       1.0
    5 1000    1    1  REL 0.001
FIFTH-ORDER LINEAR SYSTEM, NO DISTURBANCE
0.        20.       1.0
    5 1000    1    1  REL 0.001
END OF RUNS
*APP PRC35
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TWO-STAGE HEAT EXCHANGER SYSTEM
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE OF PARTICULAR
C...  INTEREST IN THE SIMULATION.
C...
C...  THE SYSTEM PARAMETERS ARE:
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = 1, U = 25, AT = 10, T0 = 60,
C...
C...  TJ0 = 200, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  A PI CONTROLLER HAS BEEN PROPOSED TO MAINTAIN THE OUTLET TEMPERA-
C...  TURE, T2, AT 180.  THE CONTROLLER EQUATIONS ARE:
C...
C...     E = T2SET - T2; (T2SET = 180)
C...
C...                                 T
C...     FJ = FJSS + AKC*(E + (1/TI)INT E*DT); (INT DENOTES AN INTEGRAL)
C...                                 0
C...
C...     FJSS = 1, T1(0) = T2(0) = 180, TJ1(0) = TJ2(0) = 200
C...
C...  WHERE
C...
C...     FJSS        STEADY STATE VALUE OF FJ
C...
C...     AKC         CONTROLLER GAIN
C...
C...     TI          CONTROLLER INTEGRAL TIME
C...
C...  NOTE THAT T1(0) = 180 WHILE T0 = 60 SO THAT THE ENTERING STREAM
C...  WITH TEMPERATURE T0 BEGINS TO COOL THE LIQUID IN THE RIGHT TANK
C...  AND THEREBY CAUSES A CHANGE IN THE TEMPERATURE TO BE CONTROLLED,
C...  T2.
C...
C...  INVESTIGATE WHETHER THIS CONTROLLER WILL WORK, AND IF IT LOOKS
C...  PROMISING, TUNE THE CONTROLLER, I.E, FIND VALUES OF AKC AND TI
C...  TO GIVE A GOOD RESPONSE OF E VS T WITH NO OFFSET.  IN ADDITION TO
C...  PLOTTING E VS T, PLOT FJ VS T TO DEMONSTRATE HOW THE CONTROLLER
C...  CHANGES THE JACKET FLOW RATE.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
        U=25.
       AT=10.
       T0=60.
      TJ0=200.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
        R=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      T2SET=180.
      FJSS=1.
      IF(NORUN.EQ.1)AKC=0.
      IF(NORUN.GE.2)AKC=5.0
      TI=10.
C...
C...  INITIAL CONDITIONS
       T1=180.
       T2=180.
      TJ1=200.
      TJ2=200.
       EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  CONTROLLER EQUATIONS
      E=T2SET-T2
      FJ=FJSS+AKC*(E+(1./TI)*EI)
C...
C...  LIMIT THE JACKET FLOW TO POSITIVE VALUES IN THE THIRD RUN
      IF((NORUN.EQ.3).AND.(FJ.LT.0.))FJ=0.
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), EP(51), FJP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2',11X,'E',
     1       10X,'FJ')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/1*1).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2,E,FJ
2     FORMAT(F10.1,6F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      EP(IP)=E
      FJP(IP)=FJ
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.NE.51)RETURN
C...
C...  E(T) VS T
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' E(T) VS T')
C...
C...  FJ(T) VS T
      CALL TPLOTS(1,IP,TP,FJP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' FJ(T) VS T')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
END OF RUNS
*APP PRC36
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER (CASE 2)
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + V*T1  = CT*(TS - T1)
C...     T       Z
C...
C...   T2  - V*T2  = CT*(TS - T2)
C...     T       Z
C...
C...   T3  + V*T3  = CT*(TS - T3)
C...     T       Z
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        Z
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   Z          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   V,VS       AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT         PI*D*U/(RHO*CP*A)
C...
C...   CS         PI*D*U/(RHOS*CPS*AS)
C...
C...   PI         3.1415927
C...
C...   D          TUBE DIAMETER
C...
C...   U          OVERALL HEAT TRANSFER COEFFICIENT
C...
C...   RHO,RHOS   DENSITIES OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CP,CPS     HEAT CAPACITIES OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   A,AS       CROSS SECTIONAL AREAS OF THE TUBE AND SHELL,
C...              RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(Z,0) = T2(Z,0) = T3(Z,0) = TS(Z,0) = 60
C...
C...   T1(0,T) = 60, T2(ZL,T) = T1(ZL,T), T3(0,T) = T2(0,T)
C...
C...   TS(ZL,T) = 200
C...
C...   A = 1, AS = 5, RHO = RHOS = 62.5, CP = CPS = 1, U = 100, V = 1,
C...
C...   D = 0.1, ZL = 10
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(ZL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, VS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     VS = VSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     VSS      SHELL SIDE FLUID VELOCITY AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
C...     E        T3SET - T3(ZL,T)
C...
C...     T3SET    SET POINT
C...
C...  THE CONSTANTS IN THE CONTROLLER EQUATION ARE
C...
C...   VSS = 0.5, T3SET = 170
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=60.
      ZL=10.
      V=1.0
      VSS=0.5
      PI=3.1415927
      D=0.1
      U=100.
      RHO=62.5
      RHOS=62.5
      CP=1.0
      CPS=1.0
      A=1.0
      AS=1.0
      CT=PI*D*U/(RHO*CP*A)
      CS=PI*D*U/(RHOS*CPS*AS)
      TS0=200.
      T3SET=170.
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=0.1
         TI=30.0
      ELSE
      END IF
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=60.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      ZP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      VS=VSS+KC*(E+(1./TI)*EI)
      IF(VS.LT.0.)VS=0.
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,T1,T1Z, 1.)
      CALL DSS020(0.,ZL,N,T2,T2Z,-1.)
      CALL DSS020(0.,ZL,N,T3,T3Z, 1.)
      CALL DSS020(0.,ZL,N,TS,TSZ,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)= -V*T1Z(I)+CT*(TS(I)-T1(I))
      T2T(I)=  V*T2Z(I)+CT*(TS(I)-T2(I))
      T3T(I)= -V*T3Z(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSZ(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  VSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(ZL,T),
     14X,8HT3(ZL,T),4X,8H TS(0,T),4X,8H   VS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),VS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      VSP(IP)=VS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(ZL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,VSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H VS VS T                       )
      CALL TPLOTS(7,N,ZP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(Z,T) VS Z, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(ZL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,VSP,IP,3H*T*,10H* VS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T1SP,N,3H*Z*,10H*T1(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T2SP,N,3H*Z*,10H*T2(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T3SP,N,3H*Z*,10H*T3(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,TSSP,N,3H*Z*,10H*TS(Z,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP PRC37
      SUBROUTINE INITAL
C...
C...  ROOT LOCUS STABILITY ANALYSIS
C...
C...  THE FOLLOWING PROGRAMMING ILLUSTRATES THE STABILITY ANALYSIS OF
C...  A DYNAMIC SYSTEM USING THE ROOT LOCUS PLOT OF THE SYSTEM.
C...
C...  (1)  PLOT THE ROOT LOCUS DIAGRAM FOR THE SYSTEM WITH A CLOSED LOOP
C...  CHARACTERISTIC EQUATION
C...
C...     1 + GP(S)*GC(S) = 0
C...
C...  FOR THE PROCESS TRANSFER FUNCTION
C...
C...  GP(S) = 1/((S + 1)*(0.5*S + 1))
C...
C...  AND CONTROLLER TRANSFER FUNCTION
C...
C...     GC(S) = KC*(1 + 1/(10*S))
C...
C...  USE IMSL SUBROUTINE ZPOLR TO COMPUTE THE ROOTS FOR THE ROOT LOCUS
C...  DIAGRAM.
C...
C...  DETERMINE THE ULTIMATE GAIN FROM THE ROOT LOCUS DIAGRAM, I.E., THE
C...  GAIN FOR WHICH THE SYSTEM BECOMES UNSTABLE (HINT - THE ULTIMATE
C...  GAIN MAY NOT BE FINITE).
C...
C...  (2)  SIMULATE THE SYSTEM OF (1) AND DETERMINE THE ULTIMATE GAIN
C...  (VIA THE SIMULATION) FOR COMPARISON WITH THE VALUE OBTAINED BY THE
C...  ROOT LOCUS PLOT.
C...
C...  THE SYSTEM CAN BE BLOCK DIAGRAMMED AS
C...
C               ...........
C               .         .   Y
C         .....+.  GP(S)  ..........
C         .     .         .      .
C         .     ...........      .
C         .                      .
C         .     ...........      .
C         .  M  .         .   E  + -
C         .......  GC(S)  .+.....S+..... YSET
C               .         .
C               ...........
C...
C...  THE CLOSED LOOP CHARACTERISTIC EQUATION TO BE FACTORED IS
C...
C...     1 + 1/((S + 1)*(0.5*S + 1))*KC*(1 + 1/(TI*S)) = 0
C...
C...  OR
C...
C...     S*(S + 1)*(0.5*S + 1) + KC*(S + 1/10) = 0    (TI = 10)
C...
C...     0.5*S**3 + 1.5*S**2 + (1 + KC)*S + KC/10 = 0
C...
C...  THE COEFFICIENTS OF THIS POLYNOMIAL CAN NOW BE ENTERED INTO IMSL
C...  ROUTINE ZPOLR.
C...
C...  FOR PART (2), THE INTEGRO-DIFFERENTIAL EQUATIONS ARE
C...
C...     (0.5*S**2 + 1.5*S + 1)*Y = M
C...
C...  OR (WITH S = D /DT)
C...
C...          2    2
C...     0.5*D Y/DT  + 1.5*DY/DT + Y = M
C...
C...     E = YSET - Y
C...                        T
C...     M = KC*(E + (1/10)INT E*DT)
C...                        0
C...
C...  THE SECOND-ORDER DIFFERENTIAL EQUATION CAN BE WRITTEN AS TWO
C...  FIRST-ORDER DIFFERENTIAL EQUATIONS.  IF Y1 = Y, Y2 = DY/DT, THEN
C...
C...     0.5*DY2/DT + 1.5*Y2 + Y1 = M
C...
C...     DY1/DT = Y2
C...
C...  THESE EQUATIONS ARE THEN PROGRAMMED FOR PART (2).
C...
C...  DSS/2 COMMON BLOCK
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2,     EI
     2      /F/  DY1DT,  DY2DT,      E
     3      /C/    AKC,   YSET,     IP
C...
C...  DSS/2 COMMON FOR INPUT-OUTPUT UNIT NUMBERS
      COMMON/IO/ NI, NO
C...
C...  DIMENSION THE ARRAYS REQUIRED BY ZPOLR
      REAL A(4)
      COMPLEX Z(3)
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE ROOT LOCUS DIAGRAM
      REAL ZREAL(3), ZIMAG(3), PZREAL(303), PZIMAG(303)
C...
C...  SET THE COEFFICICNTS NOT DEPENDING ON KC
      A(1)=0.5
      A(2)=1.5
C...
C...  PRINT A HEADING FOR THE COMPUTED ROOTS
      WRITE(NO,4)
4     FORMAT(8X,'KC',3X,'REAL Z1',3X,'IMAG Z1',
     1               3X,'REAL Z2',3X,'IMAG Z2',
     2               3X,'REAL Z3',3X,'IMAG Z3')
C...
C...  STEP THROUGH A SERIES OF VALUES OF KC
      AKC=-0.1
      DO 1 I=1,101
      AKC=AKC+0.1
C...
C...  SET THE COEFFICIENTS DEPENDING ON KC
      A(3)=1.0+AKC
      A(4)=AKC/10.0
C...
C...  ***************************************************************
C...
C...  FACTOR THE POLYNOMIAL.  THE FOLLOWING CALL REQUIRES IMSL ROUTINE
C...  ZPOLR.
      NDEG=3
      CALL ZPOLR(A,NDEG,Z,IER)
C...
C...  ***************************************************************
C...
C...  PRINT THE ROOTS
      DO 2 J=1,NDEG
      ZREAL(J)= REAL(Z(J))
      ZIMAG(J)=AIMAG(Z(J))
2     CONTINUE
      WRITE(NO,3)AKC,(ZREAL(J),ZIMAG(J),J=1,NDEG)
3     FORMAT(7F10.3)
C...
C...  STORE THE ROOTS FOR PLOTTING
      DO 5 J=1,NDEG
      NSUB=(I-1)*3+J
      PZREAL(NSUB)=ZREAL(J)
      PZIMAG(NSUB)=ZIMAG(J)
5     CONTINUE
C...
C...  GO ON TO THE NEXT VALUE OF KC
1     CONTINUE
C...
C...  PLOT THE ROOT LOCUS DIAGRAM
      CALL TPLOTS(1,303,PZREAL,PZIMAG)
      WRITE(NO,6)
6     FORMAT(1H ,/,' ROOTS LOCUS PLOT OF THE THIRD-ORDER SYSTEM',/)
C...
C...  CONTROLLER GAIN, SET POINT FOR THE SIMULATION
      AKC=10.0
      YSET=1.0
C...
C...  INITIAL CONDITIONS FOR THE SIMULATION
      Y1=0.
      Y2=0.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2,     EI
     2      /F/  DY1DT,  DY2DT,      E
     3      /C/    AKC,   YSET,     IP
C...
C...  CONTROLLER EQUATIONS
      E=YSET-Y1
      AM=AKC*(E+(1.0/10.0)*EI)
C...
C...  DIFFERENTIAL EQUATIONS
      DY1DT=Y2
      DY2DT=(1./0.5)*(AM-1.5*Y2-Y1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2,     EI
     2      /F/  DY1DT,  DY2DT,      E
     3      /C/    AKC,   YSET,     IP
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), Y1P(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',8X,'Y(T)',8X,'E(T)')
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
      WRITE(NO,2)T,Y1,E
2     FORMAT(F10.1,2F12.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      Y1P(IP)=Y1
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,Y1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,' Y1(T) VS T')
      RETURN
      END
ROOT LOCUS STABILITY ANALYSIS
0.        10.       0.1
    3 1000    1    1  REL 0.001
END OF RUNS
*APP PRC38
      SUBROUTINE INITAL
C...
C...  VALIDATION OF DYNAMIC MODELS THROUGH CONSERVATION PRINCIPLES
C...
C...  THE GENERAL QUESTION OF WHEN A DYNAMIC MODEL IS EXECUTING
C...  CORRECTLY IS ADDRESSED IN THE FOLLOWING ANALYSIS.  SPECIFICALLY,
C...  WHEN A DYNAMIC MODEL REACHES A STEADY STATE CONDITION, A
C...  STEADY STATE CONSERVATION PRINCIPLE CAN OFTEN BE USED TO CHECK
C...  THE MODEL OUTPUT.  THIS PROCEDURE IS ILLUSTRATED WITH THE
C...  EXAMPLE IN HEAT TRANSFER.
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE TO BE COMPUTED
C...  FOR THREE VALUES OF THE PARAMETER R TO DETERMINE ITS EFFECT ON
C...  THE HEAT TRANSFER.
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = FJ = 1, U = AT = 10, T0 = 200,
C...
C...  TJ0 = 60, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1, 0.75, 0.5
C...
C...  (THREE CASES).  THE INITIAL CONDITIONS (FOR ALL THREE CASES) ARE:
C...
C...     T1(0) = T2(0) = TJ1(0) = TJ2(0) = 60
C...
C...  PRODUCE ABBREVIATED NUMERICAL SOLUTIONS AND GRAPHICAL SOLUTIONS
C...  AS TWO PLOTS:
C...
C...     T2(T) VS T (THREE CASES)
C...
C...     TJ2(T) VS T (THREE CASES)
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  IF EQUATIONS (1) TO (4) ARE SUMMED,
C...
C...     D(V1*RHO*CP*T1 + V2*RHO*CP*T2 +
C...
C...       VJ1*RHOJ*CPJ*TJ1 + VJ2*RHOJ*CPJ*TJ2)/DT =
C...                                                                (5)
C...       F*RHO*CP*T0 + FJ*RHOJ*CPJ*TJ0 -
C...
C...       F*RHO*CP*T2 - FJ*RHOJ*CPJ*TJ2
C...
C...  NOTE THE CANCELLATION OF THE TERMS FOR THE INTERMEDIATE (INTERNAL)
C...  STREAMS AND FOR THE HEAT TRANSFER.  EQUATION (5) IS AN OVERALL
C...  DYNAMIC BALANCE FOR THE TWO-STAGE HEAT TRANSFER SYSTEM.
C...
C...  AT STEADY STATE, THE TIME DERIVATIVE ON THE LHS OF EQUATION (5)
C...  WILL BE ZERO, AND EQUATION (5) REDUCES TO THE USUAL OVERALL STEADY
C...  STATE ENERGY BALANCE
C...
C...     F*RHO*CP*T0 + FJ*RHOJ*CPJ*TJ0 =
C...                                                                 (6)
C...     F*RHO*CP*T2 + FJ*RHOJ*CPJ*TJ2
C...
C...  EQUATION (6) PROVIDES AN INDEPENDENT CHECK OF THE DYNAMIC SIMULA-
C...  TION OF THE HEAT EXCHANGE SYSTEM (AFTER THE DYNAMIC SIMULATION HAS
C...  REACHED STEADY STATE).
C...
C...  THIS IDEA OF CHECKING A DYNAMIC SIMULATION VIA A CONSERVATION
C...  PRINCIPLE, IN THIS CASE THE STEADY STATE ENERGY BALANCE, CAN BE
C...  VERY USEFUL IN FINDING ERRORS IN DYNAMIC SIMULATIONS.  AS ONE
C...  RECENT EXAMPLE, AN ERROR WAS FOUND IN THE HEAT TRANSFER TERMS
C...  OF A COMPLICATED HEAT EXCHANGER MODEL BY THIS PROCEDURE (NOTE
C...  THAT IF THE HEAT TRANSFER TERMS ARE CORRECTLY FORMULATED, THEY
C...  WILL CANCEL, AS IN THE PRECEDING EQUATION (5)).
C...
C...  IN GENERAL, THE PROCEDURE IS TO ADD THE DYNAMIC EQUATIONS, THEN
C...  SET THE TIME DERIVATIVES OF THE RESULTING EQUATION TO ZERO.  THIS
C...  PROCEDURE WORKS FOR SETS OF PARTIAL DIFFERENTIAL EQUATIONS AS
C...  WELL AS ORDINARY DIFFERENTIAL EQUATIONS.
C...
C...  SOME PROGRAMMING IS ADDED AT THE END OF SUBROUTINE PRINT TO DEMON-
C...  STRATE THE APPLICATION OF EQUATION (6).
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
       FJ=1.
        U=10.
       AT=10.
       T0=200.
      TJ0=60.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
C...
C...  CHANGE THE PARAMETER R FOR EACH OF THE THREE RUNS
      IF(NORUN.EQ.1)THEN
         R=1.
      ELSE IF(NORUN.EQ.2)THEN
         R=0.75
      ELSE IF(NORUN.EQ.3)THEN
         R=0.5
      END IF
C...
C...  INITIAL CONDITIONS
       T1=60.
       T2=60.
      TJ1=60.
      TJ2=60.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), T2P(3,51), TJ2P(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2
2     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
       T2P(NORUN,IP)=T2
      TJ2P(NORUN,IP)=TJ2
      TP(IP)=T
C...
C...  CHECK FOR THE END OF A RUN
      IF(IP.NE.51)RETURN
C...
C...  APPLY EQUATION (6) BY FIRST COMPUTING THE STEADY STATE HEAT RATES
C...  IN AND OUT
      QIN =F*RHO*CP*T0+FJ*RHOJ*CPJ*TJ0
      QOUT=F*RHO*CP*T2+FJ*RHOJ*CPJ*TJ2
C...
C...  COMPUTE THE PERCENT DIFFERENCE BETWEEN THE HEAT RATES IN AND OUT
      PD=(QIN-QOUT)/QIN*100.
C...
C...  PRINT THE RESULTS OF THE STEADY STATE CALCULATION (NOTE - QOUT WILL
C...  NOT EQUAL QIN IF THE SYSTEM HAS NOT REACHED STEADY STATE.  IN THE
C...  PRESENT CASE, STEADY STATE HAS NOT QUITE BEEN REACHED, AND THERE-
C...  FORE THE STEADY STATE BALANCE, EQUATION (6), CLOSES TO WITHIN ONLY
C...  1.7 PERCENT.  A LONGER RUN, E.G., TO T = 200 RATHER THAN 100, WILL
C...  GIVE BETTER CLOSURE OF EQUATION (6))
      WRITE(NO,21)QIN,QOUT,PD
21    FORMAT(1H ,//,'  QIN = ',E10.3,
     1              ' QOUT = ',E10.3,
     2              '  0/0 = ',F5.2)
C...
C...  AT THE END OF THE THIRD RUN, THE NUMERICAL SOLUTIONS FOR ALL
C...  THREE RUNS ARE PLOTTED TOGETHER.
      IF(NORUN.NE.3)RETURN
C...
C...  T2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,T2P)
      WRITE(NO,11)
11    FORMAT(1H, //,' T2(T) VS T, R = 1, 0.75, 0.5')
C...
C...  TJ2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,TJ2P)
      WRITE(NO,12)
12    FORMAT(1H ,//,' TJ2(T) VS T, R = 1, 0.75, 0.5')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER, R = 1
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.75
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.5
0.        100.      2.0
    4 1000    1    1  REL 0.001
END OF RUNS
*APP PRC39
      SUBROUTINE INITAL
C...
C...  LAPLACE TRANSFORM SOLUTION OF SIMULTANEOUS ODES
C...
C...  SOLVE THE FOLLOWING 2X2 SYSTEM OF ORDINARY DIFFERENTIAL EQUATIONS
C...  USING LAPLACE TRANSFORM.  COMPUTE A NUMERICAL SOLUTION FOR COM-
C...  PARISON WITH THE ANALYTICAL SOLUTION.
C...
C...     DY1/DT =  2*Y1 - 3*Y2, Y1(0) = 8
C...
C...     DY2/DT = -2*Y1 +   Y2, Y2(0) = 3
C...
C...  LAPLACE TRANSFORMATION OF THE TWO ODES, INCLUDING THE INITIAL
C...  CONDITIONS, GIVES
C...
C...     S*Y1 - 8 =  2*Y1 - 3*Y2
C...
C...     S*Y2 - 3 = -2*Y1 +   Y2
C...
C...  OR, AFTER REARRANGEMENT,
C...
C...     (S - 2)*Y1 +      3 *Y2 = 8
C...
C...          2 *Y1 + (S - 1)*Y2 = 3
C...
C...  MULTIPLICATION OF THE FIRST EQUATION BY 2, AND THE SECOND EQUATION
C...  BY (S - 2), FOLLOWED BY SUBTRACTION GIVES
C...
C...     ((S - 1)*(S - 2) - 6)*Y2 = 3*(S - 2) - 16
C...
C...     (S**2 - 3*S - 4)*Y2 = 3*S - 22
C...
C...     Y2 = (3*S - 22)/(S**2 - 3*S - 4)
C...
C...        = (3*S - 22)/((S - R1)*(S - R2)) = A/(S - R1) + B/(S - R2)
C...
C...  WHERE A AND B ARE CONSTANTS IN A PARTIAL FRACTIONS EXPANSION OF
C...  Y2.  R1 AND R2 ARE THE EIGENVALUES OF THE ORIGINAL ODE SYSTEM,
C...  I.E.,
C...
C...     R1, R2 = + 3 + (OR -)*((-3)**2 - 4*(1)*-4)**0.5
C...              --------------------------------------
C...                                 2
C...
C...            = -1, 4
C...
C...  A AND B CAN NOW BE EVALUATED,
C...
C...     A = (3*S - 22)/(S - R2)     = (-3 - 22)/(-1 - 4) =  5
C...                            S=R1
C...
C...     B = (3*S - 22)/(S - R1)     = (12 - 22)/( 4 + 1) = -2
C...                            S=R2
C...
C...  THE INVERSE TRANSFORM FOR Y2 IS THEREFORE
C...
C...     Y2 = 5*EXP(-T) - 2*EXP(4*T)
C...
C...  Y1 CAN BE OBTAINED FROM SUBSTITUTION OF Y2 IN THE SECOND ODE,
C...
C...     -5*EXP(-T) - 8*EXP(4*T) = -2*Y1 + (5*EXP(-T) - 2*EXP(4*T))
C...
C...     Y1 = 5*EXP(-T) + 3*EXP(4*T)
C...
C...  THIS SOLUTION CAN BE VERIFIED BY SUBSTITUTION IN THE TWO ODES
C...
C...     Y1(0) = 5 + 3 = 8, Y2(0) = 5 - 2 = 3
C...
C...  FOR THE FIRST ODE,
C...
C...     -5*EXP(-T) + 12*EXP(4*T) = 2*(5*EXP(-T) + 3*EXP(4*T))
C...
C...                              - 3*(5*EXP(-T) - 2*EXP(4*T))
C...
C...     (-5 - 10 + 15)*EXP(-T) + (12 - 6 - 6)*EXP(4*T) = 0
C...
C...  FOR THE SECOND ODE,
C...
C...     -5*EXP(-T) - 8*EXP(4*T) = -2*(5*EXP(-T) + 3*EXP(4*T))
C...
C...                              +   (5*EXP(-T) - 2*EXP(4*T))
C...
C...     (-5 + 10 - 5)*EXP(-T) + ( -8 + 6 + 2)*EXP(4*T) = 0
C...
C...  A NUMERICAL SOLUTION IS COMPUTED IN THE FOLLOWING CODING FOR COM-
C...  PARISON WITH THE PRECEDING ANALYTICAL SOLUTION.
C...
C...  DSS/2 COMMON
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2
     2      /F/  DY1DT,  DY2DT
C...
C...  INITIAL CONDITIONS
      Y1=8.
      Y2=3.
C...
C...  INITIAL CONDITIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2
     2      /F/  DY1DT,  DY2DT
C...
C...  TWO ODES
      DY1DT= 2.0*Y1-3.0*Y2
      DY2DT=-2.0*Y1+1.0*Y2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     Y1,     Y2
     2      /F/  DY1DT,  DY2DT
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(T.EQ.0.)WRITE(NO,1)
1     FORMAT(9X,'T',4X,'Y1 (NUM)',3X,'Y1 (ANAL)',
     1              4X,'Y2 (NUM)',3X,'Y2 (ANAL)',
     2              4X,'ERROR Y1',4X,'ERROR Y2')
C...
C...  COMPUTE THE ANALYTICAL SOLUTIONS
      Y1A=5.0*EXP(-T)+3.0*EXP(4.0*T)
      Y2A=5.0*EXP(-T)-2.0*EXP(4.0*T)
C...
C...  COMPUTE THE PERCENT DIFFERENCE BETWEEN THE NUMERICAL AND ANALYTI-
C...  CAL SOLUTIONS
      E1=(Y1-Y1A)/Y1A*100.
      E2=(Y2-Y2A)/Y2A*100.
C...
C...  PRINT THE ANALYTICAL AND NUMERICAL SOLUTIONS
      WRITE(NO,2)T,Y1,Y1A,Y2,Y2A,E1,E2
2     FORMAT(F10.1,6F12.4)
      RETURN
      END
LAPLACE TRANSFORM SOLUTION OF SIMULTANEOUS ODES
0.        1.0       0.1
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC40
      SUBROUTINE INITAL
C...
C...  FEEDBACK CONTROL WITH SENSOR DYNAMICS
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED BY DAVIS (1) FOR THE
C...  HEATING OF A CONTINUOUS STIRRED TANK WITH FEEDBACK CONTROL
C...
C...  LIQUID ENERGY BALANCE
C...
C...     M*CP*DT/DTIME = F*CP*(T0 - T) + FS*HV
C...
C...  THERMOWELL ENERGY BALANCE
C...
C...     C1*DTW/DTIME = U1*A1*(T - TW)
C...
C...  THERMOCOUPLE ENERGY BALANCE
C...
C...     C2*DTT/DTIME = U2*A2*(TW - TT)
C...
C...  PROPORTIONAL CONTROL
C...
C...     FS = KP*(TS - TT)
C...
C...  WHERE
C...
C...     T          TANK LIQUID TEMPERATURE
C...
C...     TW         THERMOWELL TEMPERATURE
C...
C...     TT         THERMOCOUPLE TEMPERATURE
C...
C...     FS         STEAM FLOW RATE
C...
C...     M          MASS OF LIQUID IN THE TANK
C...
C...     CP         SPECIFIC HEAT OF THE LIQUID IN THE TANK
C...
C...     F          FLOW RATE THROUGH THE TANK
C...
C...     T0         ENTERING LIQUID TEMPERATURE
C...
C...     C1         THERMOWELL THERMAL CAPACITANCE
C...
C...     U1,A1      LIQUID TO THERMOWELL HEAT TRANSFER COEFFICIENT
C...                AND AREA
C...
C...     U2,A2      THERMOWELL TO THERMOCOUPLE HEAT TRANSFER COEFFICIENT
C...                AND AREA
C...
C...     KP         PROPORTIONAL CONTROLLER GAIN
C...
C...     TS         CONTROLLER SET POINT
C...
C...  THE PRECEDING ORDINARY DIFFERENTIAL EQUATIONS (ODES) ARE TO BE
C...  INTEGRATED SUBJECT TO THE FOLLOWING INITIAL CONDITIONS
C...
C...     T(0) = TW(0) = TT(0) = 50
C...
C...  NUMERICAL VALUES FOR THE MODEL PARAMETERS ARE GIVEN BY DAVIS.
C...
C...  (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR CHEMICAL
C...       ENGINEERING, JOHN WILEY AND SONS, INC., NY, 1984, PROB. 5,
C...       PP 47-48
C...
C...  ALSO, TO IMPROVE THE CONTROLLER PERFORMANCE (ELIMINATE OFFSET),
C...  A PROPORTIONAL-INTEGRAL (PI) CONTROLLER HAS BEEN PROGRAMMED WITH
C...  INTEGRAL TIME TI.
C...
C...  THE FOLLOWING CASES ARE PROGRAMMED
C...
C...     (1)  TS = 50, KP = 2, TI = INF (NO DYNAMIC RESPONSE SINCE ALL
C...          TIME DERIVATIVES REMAIN AT ZERO)
C...
C...     (2)  TS = 60, KP = 2, TI = INF (+10 SET POINT CHANGE, NO
C...          INTEGRAL ACTION, I.E., TI = INF WHERE INF IS INFINITY)
C...
C...     (3)  TS = 60, KP = 1, TI = 10  (+10 SET POINT CHANGE WITH
C...          A WELL TUNED CONTROLLER WHICH EFFECTIVELY ELIMINATES
C...          THE OFFSET)
C...
C...  TWO ERRORS ARE OF INTEREST
C...
C...     (1)  THE ACTUAL ERROR OF THE TANK LIQUID TEMPERATURE
C...
C...          E1 = T - TS
C...
C...     (2)  THE ERROR ON WHICH THE CONTROLLER OPERATES
C...
C...          E2 = TS - TT
C...
C...  THE FOLLOWING SIMULATION DEMONSTRATES THAT THESE TWO ERRORS ARE
C...  SUBSTANTIALLY DIFFERENT AS A RESULT OF THE SENSOR (THERMOWELL AND
C...  THERMOCOUPLE) DYNAMICS.  OF COURSE, E1 IS OF PRIMARY INTEREST.
C...
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  SET THE MODEL PARAMETERS
      T0=50.
C...
C...  SET THE CONTROLLER PARAMETERS FOR THREE RUNS
      IF(NORUN.EQ.1)THEN
         TS=50.
         KP=2.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         TS=60.
         KP=2.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.3)THEN
         TS=60.
         KP=1.0
         TI=10.0
      END IF
C...
C...  INITIAL CONDITIONS
       T=50.
      TW=50.
      TT=50.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  MODEL ALGEBRA.  NOTE THE EQUATION FOR THE CONTROLLER INCLUDES
C...  INTEGRAL ACTION.  ALSO, THERE IS NO PROVISION IN THE CONTROLLER
C...  EQUATION AS PROGRAMMED TO PREVENT THE STEAM FLOW RATE, FS, FROM
C...  GOING NEGATIVE.  THIS COULD EASILY BE PREVENTED BY SETTING FS =
C...  0 IF FS LT 0
      E2=TS-TT
      FS=KP*(E2+1./TI*EI)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DTDT=T0-T+FS
      DTWDT=0.1*(T-TW)
      DTTDT=TW-TT
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(51), EP1(3,51), EP2(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(6X,'TIME',11X,'T',5X,'E1=T-TS',4X,'E2=TS-TT')
      IP=IP+1
      E1=T-TS
      E2=TS-TT
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)TIME,T,E1,E2
2        FORMAT(F10.1,3F12.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=TIME
      EP1(NORUN,IP)=E1
      EP2(NORUN,IP)=E2
C...
C...  PLOT THE SOLUTION AT THE END OF THE THIRD RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.3)RETURN
C...
C...  PLOT LIQUID TEMPERATURE ERROR VS TIME
      CALL SPLOTS(NORUN,IP,TP,EP1)
      WRITE(NO,11)
11    FORMAT(1H ,/,
     1 ' E1 = T - TS, (TS,KP), 1 - (50,2), 2 - (60,2), 3 - (60,6)')
C...
C...  PLOT SENSOR ERROR VS TIME
      CALL SPLOTS(NORUN,IP,TP,EP2)
      WRITE(NO,12)
12    FORMAT(1H ,/,
     1 ' E2 = TS - TT, (TS,KP), 1 - (50,2), 2 - (60,2), 3 - (60,6)')
      RETURN
      END
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
END OF RUNS
*APP PRC41
      SUBROUTINE INITAL
C...
C...  DAMPING IN A SECOND-ORDER LINEAR SYSTEM
C...
C...  CONSIDER THE FOLLOWING THREE CASES OF A SECOND-ORDER, LINEAR,
C...  CONSTANT COEFFICIENT ORDINARY DIFFERENTIAL EQUATION (ODE)
C...
C...          2    2
C...  (2.1)  D Y/DT  + 3*DY/DT + Y = 0, Y(0) = 0, DY(0)/DT = 1
C...
C...          2    2
C...  (2.2)  D Y/DT  +   DY/DT + Y = 0, Y(0) = 0, DY(0)/DT = 1
C...
C...          2    2
C...  (2.3)  D Y/DT  + 2*DY/DT + Y = 0, Y(0) = 0, DY(0)/DT = 1
C...
C...  IN ALL THREE CASES, THE LAPLACE TRANSFORM OF THE ODE, INCLUDING
C...  THE INITIAL CONDITIONS, IS
C...
C...     (S**2)*Y - 1 + C*S*Y + Y = 0, C = 1, 2, 3
C...
C...  OR, IN FACTORED FORM
C...
C...     (S - R1)*(S - R2)*Y = 1
C...
C...  A PARTIAL FRACTIONS EXPANSION THEN GIVES
C...
C...     Y = 1/((S - R1)*(S - R2)) = A/(S - R1) + B/(S - R2)
C...
C...  FOR WHICH THE INVERSE TRANSFORM IS
C...
C...     Y = A*EXP(R1*T) + B*EXP(R2*T)
C...
C...  WITH
C...
C...     A = 1/(R1 - R2), B = 1/(R2 - R1)
C...
C...  THE REMAINING REQUIREMENT, THEN, IS TO EVALUATE R1, R2, A AND B
C...  FOE THE PARTICULAR VALUES OF C.
C...
C...  FOR CASE (2.1),
C...
C...             -3 + (OR -) (3**2 - 4*1*1)**0.5
C...     R1,R2 = -------------------------------
C...                           2*1
C...
C...           = -0.382, -2.618
C...
C...     A = 1/(-0.382 - (-2.618)) =  0.4472
C...
C...     B = 1/(-2.618 - (-0.382)) = -0.4472
C...
C...  TO CHECK THE INITIAL CONDITIONS,
C...
C...     A + B = 0
C...
C...     A*R1 + B*R2 = (0.4472)*(-0.382) + (-0.4472)*(-2.618) = 0.9999
C...
C...  FOR CASE (2.2),
C...
C...             -1 + (OR -) (1**3 - 4*1*1)**0.5
C...     R1,R2 = -------------------------------
C...                            2*1
C...
C...           = -0.5 + 0.8660*I, -0.5 - 0.8860*I
C...
C...     A = 1/(-0.5 + 0.8660*I - (-0.5 - 0.8660*I)) =  1/1.732*I
C...
C...     B = 1/(-0.5 - 0.8660*I - (-0.5 + 0.8660*I)) = -1/1.732*I
C...
C...     Y = (1/1.732*I)*EXP((-0.5 + 0.8660*I)*T)
C...
C...       - (1/1.732*I)*EXP((-0.5 - 0.8660*I)*T)
C...
C...       = (2/1.732)*EXP(-0.5*T)*(EXP(0.8660*T) - EXP(-0.8660*T))
C...                               -------------------------------
C...                                              2*I
C...
C...       = 1.155*EXP(-0.5*T)*SIN(0.8660*T)
C...
C...  TO CHECK THE INITIAL CONDITIONS,
C...
C...     Y(0) = 0 (FROM SIN(0.8660*T) = 0)
C...
C...     DY(0)/DT = 1.155*(-0.5*0 + 0.8660*1*1) = 1.002
C...
C...  FOR CASE (2.3),
C...
C...             -2 + (OR -) (2**2 - 4*1*1)**0.5
C...     R1,R2 = -------------------------------
C...                           2*1
C...
C...           = -1 (REPEATED)
C...
C...  THE SOLUTION IN THE T DOMAIN IS INDETERMINATE SINCE
C...
C...     Y(T) = (1/(R1 - R2))*(EXP(R1*T) - EXP(R2*T))
C...
C...          = 0/0 WHEN R1 = R2 = -1
C...
C...  L*HOSPITAL*S RULE COULD BE APPLIED TO Y(T), OR WE CAN RETURN TO
C...  Y(S).
C...
C...  THUS, IN THE S DOMAIN,
C...
C...     Y = 1/(S - R)**2
C...
C...  FROM THE TRANSFORM PAIRS
C...
C...                 F(T)                         F(S)
C...
C...                  T                          1/S**2
C...
C...            F(T)*EXP(A*T)                   F(S - A)
C...
C...     Y(T) = T*EXP(-T)
C...
C...  TO CHECK THE INITIAL CONDITIONS,
C...
C...     Y(0) = 0
C...
C...     DY(0)/DT = EXP(-0) = 1
C...
C...  THE CHECKING OF THE SOLUTIONS FOR THE DIFFERENTIAL EQUATIONS IS
C...  LEFT TO THE READER.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         C,        IP
C...
C...  SET THE PARAMETER C
      IF(NORUN.EQ.1)C=1.0
      IF(NORUN.EQ.2)C=2.0
      IF(NORUN.EQ.3)C=3.0
C...
C...  SET THE INITIAL CONDITIONS
      Y1=0.
      Y2=1.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         C,        IP
C...
C...  ODES
      DY1DT=Y2
      DY2DT = 0.0-C*Y2-Y1
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         C,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), YP(3,101)
C...
C...  COMPUTE THE ANALYTICAL SOLUTION FOR PRINTING
C...
C...  UNDERDAMPED
      IF(NORUN.EQ.1)THEN
         YA=1.155*EXP(-0.5*T)*SIN(0.8660*T)
C...
C...  CRITICALLY DAMPED
      ELSE IF(NORUN.EQ.2)THEN
         YA=T*EXP(-T)
C...
C...  OVERDAMPED
      ELSE IF(NORUN.EQ.3)THEN
         A= 0.4472
         B=-0.4472
         R1=-0.382
         R2=-2.618
         YA=A*EXP(R1*T)+B*EXP(R2*T)
      END IF
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',11X,'Y',10X,'YA')
      END IF
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,2)T,Y1,YA
2        FORMAT(F10.2,2F12.4)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      YP(NORUN,IP)=Y1
C...
C...  PLOT THE SOLUTIONS FOR THE THREE RUNS
      IF((IP.LT.101).OR.(NORUN.LT.3))RETURN
      CALL SPLOTS(NORUN,IP,TP,YP)
      WRITE(NO,3)
3     FORMAT(1H ,/,' Y(T) VS T',
     1 '   1 - UNDERDAMPED   2 - CRITICALLY DAMPED   3 - OVERDAMPED')
C...
C...  ****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YP,IP,3H*T*,6H*Y(T)*,9H*DAMPING*,NORUN)
C...
C...  ****************************************************************
C...
      RETURN
      END
DAMPING IN A SECOND-ORDER LINEAR SYSTEM
0.        10.0      0.1
    2 1000    1    1  REL 0.001
DAMPING IN A SECOND-ORDER LINEAR SYSTEM
0.        10.0      0.1
    2 1000    1    1  REL 0.001
DAMPING IN A SECOND-ORDER LINEAR SYSTEM
0.        10.0      0.1
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC42
      SUBROUTINE INITAL
C...
C...  LINEAR STABILITY ANALYSIS OF A NONLINEAR SECOND-ORDER ORDINARY
C...  DIFFERENTIAL EQUATION
C...
C...  CONSIDER THE FOLLOWING NONLINEAR ORDINARY DIFFERENTIAL EQUATION
C...  (ODE)
C...
C...      2    2
C...     D Y/DT  + EXP(A*Y) + Y = 2, Y(0) = DY(0)/DT = 0
C...
C...  INTUITIVELY IT SEEMS THAT THE SOLUTION TO THE PROBLEM COULD BE
C...  UNSTABLE (Y(T) COULD BECOME UNBOUNDED).  FOR EXAMPLE, IF A GT 0
C...  AND Y GT 0 SO THAT THE PRODUCT A*Y IS POSITIVE, THE TERM EXP(A*Y)
C...  WILL INCREASE AS Y INCREASES, POSSIBLY LEADING TO AN UNSTABLE
C...  SOLUTION.
C...
C...  ALSO, IF A LT 0 AND Y LT 0, EXP(A*T) WILL AGAIN INCREASE IF
C...  Y DECREASES (BECOMES MORE NEGATIVE), BUT WILL DECREASE IF Y
C...  INCREASES (BECOMES MORE POSITIVE).  THUS THE SITUATION WITH
C...  REGARD TO STABILITY IS RATHER COMPLICATED, AND DEPENDS ON THE
C...  VALUES OF A AND Y.  THIS STABILITY IS INVESTIGATED IN THE
C...  FOLLOWING LINEAR ANALYSIS.
C...
C...  IF THE ODE IS LINEARIZED AROUND THE POINT YS,
C...
C...      2    2
C...     D Y/DT  + EXP(A*YS) + A*EXP(A*YS)*(Y - YS) + Y = 2
C...
C...  SUBTRACTION OF THE STEADY STATE EQUATION
C...
C...     EXP(A*YS) + YS = 2
C...
C...  GIVES
C...
C...      2    2
C...     D Y/DT  + A*EXP(A*YS)*(Y - YS) + (Y - YS) = 0
C...
C...  IF A PERTURBATION VARIABLE YP IS NOW DEFINED AS YP = Y - YS,
C...  THE LINEARIZED ODE CAN BE WRITTEN IN TERMS OF YP
C...
C...      2     2
C...     D YP/DT  + A*EXP(A*YS)*YP + YP = 0
C...
C...  WITH THE INITIAL CONDITIONS
C...
C...     YP(0) = -YS, DYP(0)/DT = 0
C...
C...  NOTE THAT THE LINEARIZED PROBLEM DEPENDS ON A AS EXPECTED, AND
C...  ON YS, I.E., THE SOLUTION TO A NONLINEAR PROBLEM, OR A LINEAR
C...  APPROXIMATION, DEPENDS ON THE ABSOLUTE VALUE OF THE DEPENDENT
C...  VARIABLE(S).
C...
C...  IF THIS LINEAR PROBLEM IS SOLVED BY THE LAPLACE TRANSFORM
C...
C...            --                            --
C...     (S**2)*YP + S*YS + (A*EXP(A*YS) + 1)*YP = 0
C...
C...  FROM WHICH THE TRANSFORMED VARIABLE IS
C...
C...     --
C...     YP = -S*YS/(S**2 + A*EXP(A*YS) + 1)
C...
C...  INVERSION GIVES
C...
C...     YP(T) = -YS*COS(W*T), W = (A*EXP(A*YS) + 1)**0.5
C...
C...  THIS RESULT AGAIN INDICATES THAT THE SOLUTION DEPENDS ON A AND
C...  YS.
C...
C...  CONSIDER NOW THE SPECIAL CASE YS = 0, FOR WHICH YP(T) = 0 AND
C...  IN PARTICULAR, YP(0) = 0.  THUS, THE INITIAL CONDITION FOR THE
C...  PERTURBATION EQUATION IS HOMOGENEOUS (ZERO) WHICH IS THE USUAL
C...  PROCEDURE IN DEVELOPING PERTURBATION EQUATIONS, I.E., THE INITIAL
C...  CONDITIONS ARE TAKEN AS HOMOGENEOUS TO SIMPLIFY THE ANALYSIS OF
C...  THE LINEARIZED EQUATION (NOTE ALSO THAT Y(T) = 0 IS A SOLUTION
C...  TO THE NONLINEAR ODE IF THE RIGHT HAND SIDE IS 1, SO THAT IN
C...  ORDER TO AVOID THIS TRIVIAL SOLUTION, THE RIGHT HAND SIDE WAS
C...  TAKEN AS 2).  THE EIGENVALUES OF THE LINEARIZED SYSTEM ARE THE
C...  ROOTS OF THE CHARACTERISTIC EQUATION
C...
C...     S**2 + (A + 1) = 0
C...
C...  OR S1 = (-(A + 1))**0.5 = I*(A + 1)**0.5 AND S2 = -S1. SEVERAL
C...  SPECIAL CASES CAN BE CONSIDERED
C...
C...     A   S1,S2            CHARACTERISTICS OF EIGENVALUES
C...
C...     0   +I,-I     PURE IMAGINARY (I = (-1)**0.5) SO THAT THE
C...                   SOLUTION IS A STABLE OSCILLATION
C...
C...    -1    0,0      ZERO SO THAT THE SOLUTION IS STABLE AND CONSTANT
C...
C...    -2   +1,-1     ONE POSITIVE EIGENVALUE SO THE SYSTEM IS UNSTABLE
C...
C...  IF A GT 0, THE EIGENVALUES ARE PURE IMAGINARY, SO THE SOLUTION IS
C...  A STABLE OSCILLATION, WHILE IF A LT -1, ONE EIGENVALUE IS REAL AND
C...  POSITIVE SO THE SOLUTION IS UNSTABLE.
C...
C...  THESE CONCLUSIONS ARE NOW COMPARED WITH THE NUMERICAL SOLUTION TO
C...  THE NONLINEAR PROBLEM TO SEE HOW WELL THE LINEAR STABILITY ANA-
C...  LYSIS APPLIES TO THE NONLINEAR SYSTEM.  ALSO, SOME ADDITIONAL
C...  COMMENTS CONCERNING STABILITY APPEAR IN SUBROUTINE PRINT.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         A,        YS,        IP
C...
C...  SET THE VALUES OF A, YS
      IF(NORUN.EQ.1)A=1.
      IF(NORUN.EQ.2)A=0.
      IF(NORUN.EQ.3)A=-1.
      IF(NORUN.EQ.4)A=-2.
      YS=0.
C...
C...  INITIAL CONDITIONS
      Y1=0.
      Y2=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         A,        YS,        IP
C...
C...  ODES
      DY1DT=Y2
      DY2DT=2.0-(EXP(A*Y1)+Y1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        Y1,        Y2
     2      /F/     DY1DT,     DY2DT
     3      /C/         A,        YS,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTING
      DIMENSION TP(101), YP(101), YP4(4,101), YTP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'Y1',10X,'Y2',6X,'DY1/DT',6X,'DY2/DT')
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,2)T,Y1,Y2,DY1DT,DY2DT
2        FORMAT(F10.2,4F12.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      YP(IP)=Y1
      YP4(NORUN,IP)=Y1
      YTP(IP)=Y2
C...
C...  PLOT Y(T) VS T AT THE END OF EACH RUN
      IF(IP.LT.101)RETURN
      CALL SPLOTS(1,IP,TP,YP)
      WRITE(NO,3)A
3     FORMAT(1H ,/,' Y(T) VS T FOR A = ',F5.1)
C...
C...  *****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YP,IP,3H*T*,6H*Y(T)*,
C... 1   23H*NONLINEAR OSCILLATION*,1)
C...
C...  *****************************************************************
C...
C...  PROFESSOR S. H. JOHNSON, DEPARTMENT OF MECHANICAL ENGINEERING AND
C...  MECHANICS, LEHIGH UNIVERSITY, INDICATED THAT FROM A THEOREM BY
C...  LYAPUNOV, IF A LINEARIZED SYSTEM HAS AN UNSTABLE EIGENVALUE (AN
C...  EIGENVALUE IN THE RIGHT HALF COMPLEX PLANE), THE NONLINEAR SYSTEM
C...  WILL BE EITHER UNSTABLE (THE SOLUTION WILL BE UNBOUNDED) OR THE
C...  THE NONLINEAR SYSTEM WILL MOVE TO A STABLE LIMIT CYCLE.  TO IN-
C...  VESTIGATE THESE POSSIBILITITES, THE PHASE PLANE FOR THE NONLINEAR
C...  ODE IS ALSO PLOTTED
      CALL SPLOTS(1,IP,YP,YTP)
      WRITE(NO,5)A
5     FORMAT(1H ,/,' PHASE PLANE PLOT, DY(T)/DT VS Y, A = ',F5.1)
C...
C...  *****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(YP,YTP,IP,6H*Y(T)*,10H*DY(T)/DT*,
C... 1   13H*LIMIT CYCLE*,1)
C...
C...  *****************************************************************
C...
C...  AT THE END OF THE FOURTH RUN, PLOT THE SOLUTIONS TOGETHER
      IF(NORUN.LT.4)RETURN
      CALL SPLOTS(NORUN,IP,TP,YP4)
      WRITE(NO,4)
4     FORMAT(1H ,/,' Y(T) VS T, A = 1, 0, -1, -2')
C...
C...  *****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YP4,IP,3H*T*,6H*Y(T)*,
C... 1   23H*NONLINEAR OSCILLATION*,NORUN)
C...
C...  *****************************************************************
C...
      RETURN
      END
LINEAR STABILITY ANALYSIS OF A NONLINEAR SECOND-ORDER ODE, A = 1
0.        20.0      0.2
    2 1000    1    1  REL 0.001
LINEAR STABILITY ANALYSIS OF A NONLINEAR SECOND-ORDER ODE, A = 0
0.        20.0      0.2
    2 1000    1    1  REL 0.001
LINEAR STABILITY ANALYSIS OF A NONLINEAR SECOND-ORDER ODE, A = -1
0.        20.0      0.2
    2 1000    1    1  REL 0.001
LINEAR STABILITY ANALYSIS OF A NONLINEAR SECOND-ORDER ODE, A = -2
0.        20.0      0.2
    2 1000    1    1  REL 0.001
END OF RUNS
*APP PRC43
      SUBROUTINE INITAL
C...
C...  BATCH DISTILLATION SEPARATION OF N-HEPTANE FROM N-OCTANE
C...  WITH AUTOMATIC CONTROL
C...
C...  THE FOLLOWING MODEL IS AN EXTENSION OF THE BATCH DISTILLATION
C...  MODEL REPORTED BY DAVIS (1).  ESSENTIALLY, FIVE TRAYS HAVE BEEN
C...  ADDED TO THE DAVIS MODEL TO IMPROVE THE PERFORMANCE OF THE BATCH
C...  COLUMN.  THUS, AN INTERESTING VARIANT OF THE PROBLEM WOULD BE
C...  TO RUN THE FOLLOWING PROGRAM WITH AND WITHOUT THE FIVE TRAYS
C...  TO DETERMINE THEIR EFFECT ON THE BATCH COLUMN PERFORMANCE.
C...
C...  (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR CHEMICAL
C...       ENGINEERING, JOHN WILEY AND SONS, INC., NY, 1984, PROB. 4,
C...       PP 46-47
C...
C...  MASS BALANCE ON THE POT
C...
C...     DS/DT = L - V
C...
C...  COMPONENT BALANCE ON THE POT
C...
C...     D(S*XH0)/DT = L*XH1 - V*YH0
C...
C...  COMPONENT BALANCE ON TRAY 1
C...
C...     HM*DXH1/DT = V*YH0 + L*XH2 - V*YH1 - L*XH1
C...
C...  COMPONENT BALANCE ON TRAY 2
C...
C...     HM*DXH2/DT = V*YH1 + L*XH3 - V*YH2 - L*XH2
C...
C...  COMPONENT BALANCE ON TRAY 3
C...
C...     HM*DXH3/DT = V*YH2 + L*XH4 - V*YH3 - L*XH3
C...
C...  COMPONENT BALANCE ON TRAY 4
C...
C...     HM*DXH4/DT = V*YH3 + L*XH4 - V*YH4 - L*XH4
C...
C...  COMPONENT BALANCE ON TRAY 5
C...
C...     HM*DXH5/DT = V*YH4 + L*XHC - V*YH5 - L*XH5
C...
C...  COMPONENT BALANCE ON THE CONDENSER
C...
C...     M*DXHC/DT = V*YH5 - L*XHC - D*XHC
C...
C...  ASSUME THAT V IS CONSTANT, AS SET BY THE HEAT INPUT RATE TO THE
C...  STILL (POT).  THEN DEFINE A REFLUX RATIO BY THE EQUATIONS
C...
C...     V = L + D
C...
C...     R = D/L
C...
C...  THUS
C...
C...     V = L + L*R = L*(1 + R)
C...
C...  OR
C...
C...     L = (1/(1 + R))*V
C...
C...     D = (R/(1 + R))*V
C...
C...  ALSO, THE VAPOR IS ASSUMED TO BE IN EQUILBRIUM WITH ITS ASSOCIATED
C...  LIQUID, SO THAT
C...
C...     YHI = 2.16*XHI/(1 + 1.16*XHI), I = 0, 1, 2, 3, 4, 5
C...
C...  THE DEPENDENT VARIABLES OF THE PROBLEMS (I.E., VARIABLES DEFINED
C...  BY DIFFERENTIAL EQUATIONS) ARE XH0, XH1, XH2, XH3, XH4, XH5, XHC
C...  AND S, EACH OF WHICH REQUIRES AN INITIAL CONDITION.
C...
C...  THE FOLLOWING CONSTANTS ARE USED IN THE PROGRAMMING
C...
C...     M = 10, HM = 1, V = 2
C...
C...     S(0) = 100, XHC(0) = 0.5
C...
C...     XH0(0) = XH1(0) = XH2(0) = XH3(0) = XH4(0) = XH5(0) = 0.5
C...
C...  THE SOLUTION IS PRINTED AND PLOTTED IN SUBROUTINE PRINT.
C...
C...  IN ADDITION TO THE PRECEDING BASIC MODEL, THE FOLLOWING EQUATIONS
C...  FOR AN AUTOMATIC CONTROL SYSTEM ARE ALSO TO BE INCLUDED.  A PI
C...  CONTROLLER HAS BEEN PROPOSED WHICH WILL GIVE A TIME-AVERAGE PRO-
C...  DUCT COMPOSITION OF 0.8 MOLE FRACTION N-HEPTANE IN THE DISTILLATE
C...  PRODUCT.  THE PROPOSED CONTROL SYSTEM HAS THE EQUATIONS
C...
C...                             T
C...     D = DS +KP*(E + (1/TI)*INT E*DT)
C...                             O
C...
C...     E = I1/I2 - 0.8
C...
C...  WHERE
C...
C...           T
C...     I1 = INT D*XC*DT
C...           0
C...
C...           T
C...     I2 = INT D*DT
C...           0
C...
C...  THE PROPOSED CONTROL SYSTEM IS SIMULATED TO DETERMINE IF IT IS
C...  FEASIBLE.  SPECIFICALLY, THE VALUES OF THE PARAMETERS DS, KP
C...  AND TI ARE DETERMINED SO THAT E IS MINIMIZED OVER TIME WHILE I1,
C...  THE TOTAL AMOUNT OF N-HEPTANE PRODUCED IN THE DISTILLATE, IS
C...  MAXIMIZED.
C...
C...  NOTE THAT V = 2 (THE VAPOR BOILUP RATE REMAINS CONSTANT), BUT
C...  THE DISTILLATE RATE, D, NOW VARIES WITH TIME DUE TO THE CON-
C...  TROLLER.  THUS R (THE REFLUX RATIO) AND L (THE LIQUID RATE DOWN
C...  THROUGH THE COLUMN) ALSO VARY WITH TIME.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  MODEL PARAMETERS
      M=10.
      HM=1.0
      V=2.0
      N=5
C...
C...  CONTROLLER PARAMETERS
C...
C...  NO CONTROL
      IF(NORUN.EQ.1)THEN
         R=0.3
         DS=R/(1.0+R)*V
         AKC=0.
         TI=1.0E+10
C...
C...  PROPORTIONAL CONTROL
      ELSE IF(NORUN.EQ.2)THEN
         DS=0.4
         AKC=1.0
         TI=1.0E+10
C...
C...  PI CONTROL
      ELSE IF(NORUN.EQ.3)THEN
         DS=0.4
         AKC=1.0
         TI=50.
      END IF
C...
C...  INITIAL CONDITIONS
      DO 1 I=0,N
      XH(I)=0.5
1     CONTINUE
      XC=0.5
      S=100.
      XH(0)=S*XH(0)
      I1=0.
      I2=0.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      IP=0
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  MODEL ALGEBRA
C...
C...     CONTROLLER EQUATIONS
         IF(I2.LT.1.0E-10)THEN
C...        FOR JUST PROPORTIONAL CONTROL, A LARGE INITIAL ERROR
C...        PRODUCES A REASONABLE INITIAL CONTROL ACTION
            IF(NORUN.LE.2)E=-0.8
C...
C...        FOR PI CONTROL, A SMALLER INITIAL ERROR IS USED SO THAT
C...        THE INTEGRAL OF THIS ERROR IS REASONABLE
            IF(NORUN.GT.2)E= 0.
            D=DS
         ELSE IF(I2.GT.1.0E-10)THEN
            RI1I2=I1/I2
            E=RI1I2-0.8
            D=DS+AKC*(E+(1.0/TI)*EI)
         END IF
         IF(D.LT.0.)D=0.
C...
C...     LIQUID FLOW RATE
         L=V-D
C...
C...     BOTTOMS COMPOSITION
         XH0=XH(0)/S
C...
C...     PLACE CONSTRAINS ON THE LIQUID COMPOSITIONS
         DO 3 I=1,N
         IF(XH(I).LT.0.)XH(I)=0.
         IF(XH(I).GT.1.)XH(I)=1.
3        CONTINUE
         IF(XH0.LT.0.)XH0=0.
         IF(XH0.GT.1.)XH0=1.
         IF(XC.LT.0.)XC=0.
         IF(XC.GT.1.)XC=1.
C...
C...     VAPOR COMPOSITIONS
         DO 1 I=1,N
         YH(I)=2.16*XH(I)/(1.0+1.16*XH(I))
1        CONTINUE
         YH(0)=2.16*XH0  /(1.0+1.16*XH0  )
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DO 2 I=0,N
      IF(I.EQ.0)DXHDT(0)=L*XH(1)-V*YH(0)
      IF(I.EQ.N)DXHDT(N)=(1.0/M)*( L*XC   +V*YH(N-1)
     1                            -L*XH(N)-V*YH(N  ))
      IF((I.NE.0).AND.(I.NE.N))
     1          DXHDT(I)=(1.0/HM)*(L*XH(I+1)+V*YH(I-1)
     2                           - L*XH(I  )-V*YH(I  ))
2     CONTINUE
      DXCDT=(1.0/M)*(V*YH(N)-L*XC-D*XC)
      DSDT=L-V
      DI1DT=D*XC
      DI2DT=D
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), XCP(3,51), EP(4,51), DP(3,51)
C...
C...  INCREMENT THE COUNTER FOR PLOTTING
      IP=IP+1
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.1)THEN
         WRITE(NO,4)
4        FORMAT(' T',/,' XH0, (XH(I),I=1,N), XC, S',/,
     1          ' DXHDT(0), (DXHDT(I),I=1,N), DXCDT, DSDT',/,
     2          ' I1, I2, I1/I2, E, D',/)
C...
C...  SET RI1I2 SO THAT IT CAN BE PRINTED AT T = 0
      RI1I2=0.
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,  XH0,( XH  (I),I=1,N),  XC  ,  S  ,
     1             DXHDT(0),(DXHDT(I),I=1,N), DXCDT, DSDT
2        FORMAT(F10.1,/,8F9.3,/,8F9.5)
         WRITE(NO,3)I1, I2, RI1I2, E, D
3        FORMAT(5F9.5,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING.  ZEROS ARE STORED IN EP(4,IP)
C...  TO PRODUCE A ZERO ERROR LINE ON THE PLOT OF E VS T
      EP(     4,IP)=0.
      TP(IP)=T
      XCP(NORUN,IP)=XC
       EP(NORUN,IP)=E
       DP(NORUN,IP)=D
C...
C...  PLOT THE SOLUTION AT THE END OF THE THIRD RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.NE.3)RETURN
C...
C...  XC VS T
      CALL SPLOTS(NORUN,IP,TP,XCP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' XC VS T')
C...
C...  E VS T
      CALL SPLOTS(NORUN+1,IP,TP,EP)
      WRITE(NO,12)
12    FORMAT(1H ,/,' E VS T')
C...
C...  D VS T
      CALL SPLOTS(NORUN,IP,TP,DP)
      WRITE(NO,13)
13    FORMAT(1H ,/,' D VS T')
      RETURN
      END
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
END OF RUNS
*APP PRC44
      SUBROUTINE INITAL
C...
C...  CONTROL OF THE WATER COOLING OF SULFURIC ACID
C...
C...  CONSIDER THE FOLLOWING SYSTEM OF TWO TANKS USED TO COOL SULFURIC
C...  ACID WITH A COUNTERCURRENT WATER STREAM REGULATED BY A FEEDBACK
C...  CONTROLLER (1)
C...
C                                                    CONTROL
C                                                     VALVE
C                                                      ...
C                                                   .....+... COLD H2O
C                                                   .  ...    IN, TW3
C                                                   .   .
C                  TW1              TW2             .   .
C                   +......  .....................  .   .
C                         .  .                   .  .  ...
C                         .  .                   .  .  . .+...TA2S = 45
C                         .  .                   .  .  ...   CONTROLLER
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     ...............        ...............
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .  ... .
C                     .   .  .      .        .   .  .  ... .
C HOT H2SO4 IN .......+   .  .      .........+   .  .SENSOR.......+
C 10,000 LB/HR   TA0  .   .  .      .  TA1   .   .  .      .     TA2
C                     .   .   .     .        .   .   .     .
C                     .   .COIL.    .        .   .COIL.    .
C                     .   .   .     .        .   .   .     .
C                     .   .  .      .        .   .  .      .
C                     .   ...       .        .   ...       .
C                     ...............        ...............
C...
C...  (1)  JENSON, V. G., AND G. V. JEFFREYS, MATHEMATICAL METHODS
C...       IN CHEMICAL ENGINEERING, ACADEMIC PRESS, NY, PP 68-72.
C...
C...  THE PARAMETERS AND VARIABLES FOR THE SYSTEM ARE
C...
C...     TA0         ACID FEED TEMPERATURE, C
C...
C...     TA1, TA2    ACID TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     TA2S        SET POINT FOR THE CONTROLLER, C
C...
C...     TW3         WATER FEED TEMPERATURE, C
C...
C...     TW1, TW2    WATER TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     T           TIME, HOURS
C...
C...     W           WATER FLOW RATE, LB/HR
C...
C...     CPW         WATER SPECIFC HEAT, CHU/LB-C
C...
C...     M           ACID FLOW RATE, LB/HR
C...
C...     CPA         ACID SPECIFIC HEAT, CHU/LB-C
C...
C...     V           WEIGHT OF ACID IN EACH TANK, LB
C...
C...     A1          COIL HEAT TRANSFER AREA IN THE HOT TANK, FT**2
C...
C...     A2          COIL HEAT TRANSFER AREA IN THE COLD TANK, FT**2
C...
C...     U1          HEAT TRANSFER COEFFICIENT FOR THE HOT TANK,
C...                 CHU/HR-FT**2-C
C...
C...     U2          HEAT TRANSFER COEFFICIENT FOR THE COLD TANK,
C...                 CHU/HR-FT**2-C
C...
C...     KC          CONTROLLER GAIN, LB/HR-C
C...
C...     TI          CONTROLLER INTEGRAL TIME, HR
C...
C...  DEVELOP A MATHEMATICAL MODEL TO COMPUTE TA1(T) AND TA2(T).
C...  ASSUME A LOG MEAN TEMPERATURE DIFFERENCE CAN BE USED FOR THE
C...  HEAT TRANSFER IN EACH COIL (CHU = CENTIGRADE HEAT UNIT IS THE
C...  HEAT REQUIRED TO RAISE ONE LB OF H2O ONE DEGREE CENTIGRADE =
C...  1.8 BTU).  A PROPORTIONAL-INTEGRAL FEEDBACK CONTROLLER
C...  REGULATES THE COOLING WATER FLOW RATE BY SENSING THE ACID
C...  TEMPERATURE IN THE SECOND TANK, I.E., TA2.
C...
C...  BY A HEAT BALANCE ON THE FIRST TANK
C...
C...     V*CPA*DTA1/DT = W*CPW*TW2 + M*CPA*TA0
C...                                                            (1)
C...                   - W*CPW*TW1 - M*CPA*TA1
C...
C...  WHICH HAS THE INITIAL CONDITION
C...
C...     TA1(0) = TA10                                          (2)
C...
C...  SIMILARLY, FOR THE SECOND TANK,
C...
C...     V*CPA*DTA2/DT = W*CPW*TW3 + M*CPA*TA1
C...                                                            (3)
C...                   - W*CPW*TW2 - M*CPA*TA2
C...
C...     TA2(0) = TA20                                          (4)
C...
C...  EQUATIONS (1) TO (4) INVOLVE FOUR DEPENDENT VARIABLES, TA1,
C...  TA2, TW1 AND TW2, SO THAT TWO ADDITIONAL EQUATIONS ARE RE-
C...  QUIRED.  IF THE HEAT TRANSFER IS MODELED THROUGH A LOG-MEAN
C...  DELTA T, WE HAVE FOR THE FIRST TANK
C...
C...                                (TA1 - TW1) - (TA1 - TW2)
C...     W*CPW*(TW1 - TW2) = U1*A1-----------------------------   (5)
C...                              LN(TA1 - TW1) - LN(TA1 - TW2)
C...
C...                                (TA2 - TW2) - (TA2 - TW3)
C...     W*CPW*(TW2 - TW3) = U2*A2-----------------------------   (6)
C...                              LN(TA2 - TW2) - LN(TA2 - TW3)
C...
C...  EQUATIONS (5) AND (6) CAN BE EASILY REARRANGED (NOTE THE CANCEL-
C...  LATION IN THE NUMERATOR OF THE RHS, FOLLOWED BY THE CALCELLATION
C...  OF THE REMAINING TEMPERATURE DIFFERENCE FROM THE LHS AND RHS)
C...
C...     W*CPW = -U1*A1/LN((TA1 - TW1)/(TA1 - TW2))
C...
C...  OR
C...
C...     (TA1 - TW1)/(TA1 - TW2) = EXP(-(U1*A1)/(W*CPW)) = C1   (7)
C...
C...  SIMILARLY, FOR EQUATION (6),
C...
C...     (TA2 - TW2)/(TA2 - TW3) = EXP(-(U2*A2)/(W*CPW)) = C2   (8)
C...
C...  WHERE C1 AND C2 ARE THE INDICATED CONSTANTS.
C...
C...  EQUATIONS (7) AND (8) CAN BE REARRANGED AS
C...
C...     (TA2 - TW2) = C2*(TA2 - TW3)
C...
C...  OR
C...
C...     TW2 = TA2 - C2*(TA2 - TW3)                             (9)
C...
C...  AND
C...
C...     (TA1 - TW1) = C1*(TA1 - TW2)
C...
C...  OR
C...
C...     TW1 = TA1 - C1*(TA1 - TW2)                            (10)
C...
C...  EQUATIONS (9) AND (10) CAN BE USED TO CALCULATE TW2 AND TW1,
C...  RESPECTIVELY, WHICH ARE THEN USED IN EQUATIONS (1) AND (3).
C...
C...  THE SYSTEM NORMALLY RUNS AT A WATER RATE OF 7740 LB/HR.  THERE-
C...  FORE, THE CONTROLLER EQUATION WILL BE TAKEN AS
C...
C...                                T
C...     W = 7740 + KC*(E + (1/TI) INT E*DT)                    (11)
C...                                0
C...
C...  WHERE E IS THE ERROR, I.E., E = TA2 - TA2S, TA2S = 45.  SELECT
C...  KC AND TI TO ACHIEVE ACCEPTABLE CONTROL WHEN THE INLET ACID
C...  TEMPERATURE, TA0, INCREASES FROM THE USUAL STEADY STATE VALUE
C...  OF 174 TO 275 C.
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  SET THE MODEL PARAMETERS
      A1=69.3
      A2=95.8
      U1=200.
      U2=130.
      M=10000.
      V=10000.
      CPW=1.0
      CPA=0.36
      TW3=20.
C...
C...  RUN NO. 1, STEADY STATE CONDITIONS (AND NO CONTROL)
      IF(NORUN.EQ.1)THEN
         TA0=174.
         TA2S=45.
         KC=0.
         TI=1.0E+10
C...
C...  RUN NO. 2, STEP DISTURBANCE IN TA0 AND NO CONTROL
      ELSE IF(NORUN.EQ.2)THEN
         TA0=275.
         TA2S=45.
         KC=0.
         TI=1.0E+10
C...
C...  RUN NO. 3, STEP DISTURBANCE IN TA0 AND PROPORTIONAL CONTROL
      ELSE IF(NORUN.EQ.3)THEN
         TA0=275.
         TA2S=45.
         KC=300.
         TI=1.0E+10
C...
C...  RUN NO. 4, STEP DISTURBANCE IN TA0 AND PI CONTROL
      ELSE IF(NORUN.EQ.4)THEN
         TA0=275.
         TA2S=45.
         KC=300.
         TI=0.05
      END IF
C...
C...  SET THE INITIAL CONDITIONS
      TA1=88.0
      TA2=45.0
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  CONTROLLER EQUATION
      E=TA2-TA2S
      W=7740+KC*(E+(1.0/TI)*EI)
C...
C...  CALCULATE SOME CONSTANTS
      C1=EXP(-(U1*A1)/(CPW*W))
      C2=EXP(-(U2*A2)/(CPW*W))
C...
C...  EQUATION (9)
      TW2=TA2-C2*(TA2-TW3)
C...
C...  EQUATION (10)
      TW1=TA1-C1*(TA1-TW2)
C...
C...  EQUATION (1)
      DTA1DT=(1.0/(V*CPA))*(W*CPW*TW2+M*CPA*TA0
     1                     -W*CPW*TW1-M*CPA*TA1)
C...
C...  EQUATION (3)
      DTA2DT=(1.0/(V*CPA))*(W*CPW*TW3+M*CPA*TA1
     1                     -W*CPW*TW2-M*CPA*TA2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      REAL TP(41), EP(4,41), WP(4,41)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',8X,'TA2',10X,'E',10X,'W')
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,TA2,E,W
2        FORMAT(F10.2,2F11.2,F11.1)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      EP(NORUN,IP)=E
      WP(NORUN,IP)=W
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.41).OR.(NORUN.LT.4))RETURN
      CALL SPLOTS(NORUN,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' E VS T')
      CALL SPLOTS(NORUN,IP,TP,WP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' W VS T')
C...
C...  PLOT THE SOLUTIONS ON A CONTINUOUS PLOTTER
C...
C...  ****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE
C...  DEPENDENT, AND MUST BE MODIFIED FOR OTHER PLOTTERS OR
C...  CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,EP,IP,3H*T*,6H*E(T)*,12H*ERROR VS T*,4)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,WP,IP,3H*T*,6H*W(T)*,17H*WATER RATE VS T*,4)
C...
C...  ****************************************************************
C...
      RETURN
      END
CONTROL OF SULFURIC ACID COOLING, STEADY STATE
0.        2.0       0.05
    3 1000    1    1  REL 0.001
CONTROL OF SULFURIC ACID COOLING, NO CONTROL
0.        2.0       0.05
    3 1000    1    1  REL 0.001
CONTROL OF SULFURIC ACID COOLING, PROPORTIONAL CONTROL
0.        2.0       0.05
    3 1000    1    1  REL 0.001
CONTROL OF SULFURIC ACID COOLING, PI CONTROL
0.        2.0       0.05
    3 1000    1    1  REL 0.001
END OF RUNS
*APP PRC45
      SUBROUTINE INITAL
C...
C...  COOLING OF SULFURIC ACID WITH LIMITED COOLING WATER
C...
C...  CONSIDER THE FOLLOWING SYSTEM OF TWO TANKS USED TO COOL SULFURIC
C...  ACID WITH A COUNTERCURRENT WATER STREAM REGULATED BY A FEEDBACK
C...  CONTROLLER (1)
C...
C                                                    CONTROL
C                                                     VALVE
C                                                      ...
C                                                   .....+... COLD H2O
C                                                   .  ...    IN, TW3
C                                                   .   .
C                  TW1              TW2             .   .
C                   +......  .....................  .   .
C                         .  .                   .  .  ...
C                         .  .                   .  .  . .+...TA2S = 45
C                         .  .                   .  .  ...   CONTROLLER
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     ...............        ...............
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .  ... .
C                     .   .  .      .        .   .  .  ... .
C HOT H2SO4 IN .......+   .  .      .........+   .  .SENSOR.......+
C 10,000 LB/HR   TA0  .   .  .      .  TA1   .   .  .      .     TA2
C                     .   .   .     .        .   .   .     .
C                     .   .COIL.    .        .   .COIL.    .
C                     .   .   .     .        .   .   .     .
C                     .   .  .      .        .   .  .      .
C                     .   ...       .        .   ...       .
C                     ...............        ...............
C...
C...  (1)  JENSON, V. G., AND G. V. JEFFREYS, MATHEMATICAL METHODS
C...       IN CHEMICAL ENGINEERING, ACADEMIC PRESS, NY, PP 68-72.
C...
C...  THE PARAMETERS AND VARIABLES FOR THE SYSTEM ARE
C...
C...     TA0         ACID FEED TEMPERATURE, C
C...
C...     TA1, TA2    ACID TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     TA2S        SET POINT FOR THE CONTROLLER, C
C...
C...     TW3         WATER FEED TEMPERATURE, C
C...
C...     TW1, TW2    WATER TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     T           TIME, HOURS
C...
C...     W           WATER FLOW RATE, LB/HR
C...
C...     CPW         WATER SPECIFC HEAT, CHU/LB-C
C...
C...     M           ACID FLOW RATE, LB/HR
C...
C...     CPA         ACID SPECIFIC HEAT, CHU/LB-C
C...
C...     V           WEIGHT OF ACID IN EACH TANK, LB
C...
C...     A1          COIL HEAT TRANSFER AREA IN THE HOT TANK, FT**2
C...
C...     A2          COIL HEAT TRANSFER AREA IN THE COLD TANK, FT**2
C...
C...     U1          HEAT TRANSFER COEFFICIENT FOR THE HOT TANK,
C...                 CHU/HR-FT**2-C
C...
C...     U2          HEAT TRANSFER COEFFICIENT FOR THE COLD TANK,
C...                 CHU/HR-FT**2-C
C...
C...     KC          CONTROLLER GAIN, LB/HR-C
C...
C...     TI          CONTROLLER INTEGRAL TIME, HR
C...
C...  DEVELOP A MATHEMATICAL MODEL TO COMPUTE TA1(T) AND TA2(T).
C...  ASSUME A LOG MEAN TEMPERATURE DIFFERENCE CAN BE USED FOR THE
C...  HEAT TRANSFER IN EACH COIL (CHU = CENTIGRADE HEAT UNIT IS THE
C...  HEAT REQUIRED TO RAISE ONE LB OF H2O ONE DEGREE CENTIGRADE =
C...  1.8 BTU).  A PROPORTIONAL-INTEGRAL FEEDBACK CONTROLLER
C...  REGULATES THE COOLING WATER FLOW RATE BY SENSING THE ACID
C...  TEMPERATURE IN THE SECOND TANK, I.E., TA2.
C...
C...  BY A HEAT BALANCE ON THE FIRST TANK
C...
C...     V*CPA*DTA1/DT = W*CPW*TW2 + M*CPA*TA0
C...                                                            (1)
C...                   - W*CPW*TW1 - M*CPA*TA1
C...
C...  WHICH HAS THE INITIAL CONDITION
C...
C...     TA1(0) = TA10                                          (2)
C...
C...  SIMILARLY, FOR THE SECOND TANK,
C...
C...     V*CPA*DTA2/DT = W*CPW*TW3 + M*CPA*TA1
C...                                                            (3)
C...                   - W*CPW*TW2 - M*CPA*TA2
C...
C...     TA2(0) = TA20                                          (4)
C...
C...  EQUATIONS (1) TO (4) INVOLVE FOUR DEPENDENT VARIABLES, TA1,
C...  TA2, TW1 AND TW2, SO THAT TWO ADDITIONAL EQUATIONS ARE RE-
C...  QUIRED.  IF THE HEAT TRANSFER IS MODELED THROUGH A LOG-MEAN
C...  DELTA T, WE HAVE FOR THE FIRST TANK
C...
C...                                (TA1 - TW1) - (TA1 - TW2)
C...     W*CPW*(TW1 - TW2) = U1*A1-----------------------------   (5)
C...                              LN(TA1 - TW1) - LN(TA1 - TW2)
C...
C...                                (TA2 - TW2) - (TA2 - TW3)
C...     W*CPW*(TW2 - TW3) = U2*A2-----------------------------   (6)
C...                              LN(TA2 - TW2) - LN(TA2 - TW3)
C...
C...  EQUATIONS (5) AND (6) CAN BE EASILY REARRANGED (NOTE THE CANCEL-
C...  LATION IN THE NUMERATOR OF THE RHS, FOLLOWED BY THE CALCELLATION
C...  OF THE REMAINING TEMPERATURE DIFFERENCE FROM THE LHS AND RHS)
C...
C...     W*CPW = -U1*A1/LN((TA1 - TW1)/(TA1 - TW2))
C...
C...  OR
C...
C...     (TA1 - TW1)/(TA1 - TW2) = EXP(-(U1*A1)/(W*CPW)) = C1   (7)
C...
C...  SIMILARLY, FOR EQUATION (6),
C...
C...     (TA2 - TW2)/(TA2 - TW3) = EXP(-(U2*A2)/(W*CPW)) = C2   (8)
C...
C...  WHERE C1 AND C2 ARE THE INDICATED CONSTANTS.
C...
C...  EQUATIONS (7) AND (8) CAN BE REARRANGED AS
C...
C...     (TA2 - TW2) = C2*(TA2 - TW3)
C...
C...  OR
C...
C...     TW2 = TA2 - C2*(TA2 - TW3)                             (9)
C...
C...  AND
C...
C...     (TA1 - TW1) = C1*(TA1 - TW2)
C...
C...  OR
C...
C...     TW1 = TA1 - C1*(TA1 - TW2)                            (10)
C...
C...  EQUATIONS (9) AND (10) CAN BE USED TO CALCULATE TW2 AND TW1,
C...  RESPECTIVELY, WHICH ARE THEN USED IN EQUATIONS (1) AND (3).
C...
C...  THE SYSTEM NORMALLY RUNS AT A WATER RATE OF 7740 LB/HR.  THERE-
C...  FORE, THE CONTROLLER EQUATION WILL BE TAKEN AS
C...
C...                                T
C...     W = 7740 + KC*(E + (1/TI) INT E*DT)                    (11)
C...                                0
C...
C...  WHERE E IS THE ERROR, I.E., E = TA2 - TA2S, TA2S = 45.  SELECT
C...  KC AND TI TO ACHIEVE ACCEPTABLE CONTROL WHEN THE INLET ACID
C...  TEMPERATURE, TA0, INCREASES FROM THE USUAL STEADY STATE VALUE
C...  OF 174 TO 275 C.
C...
C...  ALSO, THE POSSIBILITY OF INSUFFICIENT COOLING WATER IS TO
C...  BE STUDIED.  SPECIFICALLY, THE WATER RATE, W, GIVEN BY
C...  EQUATION (11) MAY NOT BE AVAILABLE.  TO INVESTIGATE THIS
C...  CONDITION, FOUR RUNS ARE PROGRAMMED IN WHICH W IS LIMITED
C...  ACCORDING TO THE FOLLOWING TABLE:
C...
C...     RUN NO.           W (MAXIMUM)
C...
C...       1               UNLIMITED
C...
C...       2               W LIMITED TO 16,000 LB/HR
C...
C...       3               W LIMITED TO 13,000 LB/HR
C...
C...       4               W LIMITED TO 10,000 LB/HR
C...
C...  THE EFFECT OF THESE LIMITS ON W CAN BE OBSERVED IN THE OUTPUT,
C...  IN WHICH THE ERROR, E, AND W ARE PLOTTED TOGETHER FOR THE FOUR
C...  CASES.
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...
C...  SET THE MODEL PARAMETERS
      A1=69.3
      A2=95.8
      U1=200.
      U2=130.
      M=10000.
      V=10000.
      CPW=1.0
      CPA=0.36
      TW3=20.
      TA0=275.
      TA2S=45.
      KC=300.
      TI=0.05
C...
C...  SET THE INITIAL CONDITIONS
      TA1=88.0
      TA2=45.0
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  CONTROLLER EQUATION
      E=TA2-TA2S
      W=7740+KC*(E+(1.0/TI)*EI)
C...
C...  INCLUDE THE EFFECT OF LIMITED WATER SUPPLY
      IF(NORUN.EQ.1)THEN
1        CONTINUE
      ELSE IF(NORUN.EQ.2)THEN
         IF(W.GT.16000.)W=16000.
      ELSE IF(NORUN.EQ.3)THEN
         IF(W.GT.13000.)W=13000.
      ELSE IF(NORUN.EQ.4)THEN
         IF(W.GT.10000.)W=10000.
      END IF
C...
C...  CALCULATE SOME CONSTANTS
      C1=EXP(-(U1*A1)/(CPW*W))
      C2=EXP(-(U2*A2)/(CPW*W))
C...
C...  EQUATION (9)
      TW2=TA2-C2*(TA2-TW3)
C...
C...  EQUATION (10)
      TW1=TA1-C1*(TA1-TW2)
C...
C...  EQUATION (1)
      DTA1DT=(1.0/(V*CPA))*(W*CPW*TW2+M*CPA*TA0
     1                     -W*CPW*TW1-M*CPA*TA1)
C...
C...  EQUATION (3)
      DTA2DT=(1.0/(V*CPA))*(W*CPW*TW3+M*CPA*TA1
     1                     -W*CPW*TW2-M*CPA*TA2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      REAL TP(41), EP(4,41), WP(4,41)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',8X,'TA2',10X,'E',10X,'W')
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,TA2,E,W
2        FORMAT(F10.2,2F11.2,F11.1)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      EP(NORUN,IP)=E
      WP(NORUN,IP)=W
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.41).OR.(NORUN.LT.4))RETURN
      CALL SPLOTS(NORUN,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' E VS T')
      CALL SPLOTS(NORUN,IP,TP,WP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' W VS T')
C...
C...  PLOT THE SOLUTIONS ON A CONTINUOUS PLOTTER
C...
C...  ****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE
C...  DEPENDENT, AND MUST BE MODIFIED FOR OTHER PLOTTERS OR
C...  CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,EP,IP,3H*T*,6H*E(T)*,12H*ERROR VS T*,4)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,WP,IP,3H*T*,6H*W(T)*,17H*WATER RATE VS T*,4)
C...
C...  ****************************************************************
C...
      RETURN
      END
COOLING OF SULFURIC ACID, NO LIMIT ON COOLING WATER
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 16000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 13000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 10000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
END OF RUNS
*APP PRC46
      SUBROUTINE INITAL
C...
C...  SIMULATION AND ROOT LOCUS ANALYSIS OF A THIRD-ORDER SYSTEM WITH
C...  PI CONTROL
C...
C     CONSIDER A SYSTEM OF THREE CASCADED TANKS IN SERIES WHICH ARE
C     MODELED BY THE LINEAR ORDINARY DIFFERENTIAL EQUATIONS (ODES)
C
C        DH1/DT = F0 + FM - F1
C
C        DH2/DT = F1 - F2
C
C        DH3/DT = F2 - F3
C
C     WHERE
C
C        H1,H2,H3    LIQUID HEIGHTS IN THE THREE TANKS
C
C        T           TIME
C
C        F0          EXTERNAL FLOW RATE TO THE FIRST TANK
C
C        FM          MANIPULATED FLOW RATE TO THE FIRST TANK
C
C        F1,F2,F3    EXITING FLOW RATES FROM THE THREE TANKS
C
C     THE EXITING FLOW RATES ARE LINEARLY RELATED TO THE HEIGHTS BY
C
C        F1 = C1*H1, F2 = C2*H2, F3 = C3*H3
C
C     THESE EQUATIONS COULD BE, FOR EXAMPLE, LINEARIZED VALVE (SQUARE
C     ROOT) EQUATIONS.
C
C     A PROPORTIONAL CONTROLLER IS ALSO PART OF THE SYSTEM IN WHICH THE
C     HEIGHT IN THE THIRD TANK, H3, IS SENSED, AND USED TO ADJUST THE
C     FLOW RATE FM TO THE FIRST TANK
C
C        FM = KC*(H3SET - H3)
C
C     CONSIDER THE VARIABLES IN THE PRECEDING EQUATIONS TO BE PERTURBA-
C     TION VARIABLES DEFINED RELATIVE TO STEADY STATE VALUES.  OF PARTI-
C     CULAR INTEREST IS THE RESPONSE OF H3 TO CHANGES IN F0 WITH THE
C     SET POINT HELD CONSTANT (SO THAT H3SET = 0 SINCE THIS IS ALSO A
C     PERTURBATION VARIABLE).
C
C   (1)
C
C     DRAW A BLOCK DIAGRAM FOR THE SYSTEM.
C
C   (2)
C
C     DERIVE THE OVERALL CLOSED-LOOP TRANSFER FUNCTION FOR THE SYSTEM
C     FOR THE RATIO H3(S)/F0(S) WHERE S IS THE LAPLACE TRANSFORM VARI-
C     ABLE (OR DIFFERENTIAL OPERATOR D /DT).
C
C   (3)
C
C     REPEAT (1) AND (2) FOR THE CASE OF A PROPORTIONAL-INTEGRAL CON-
C     TROLLER WITH TRANSFER FUNCTION
C
C          FM = KC*(1 + (1/TI*S))*(H3SET - H3)
C
C   (4)
C
C     COMPUTE THE ROOTS OF THE CHARACTERISTIC POLYNOMIAL FOR 0 LE KC
C     LE 20, FOR THE THREE CASES, TI=1.0E+10, 10 AND 1.  FOR EACH OF
C     THE THREE CASES, DETERMINE THE ULTIMATE GAIN OF THE SYSTEM, I.E.,
C     THE VALUE OF KC FOR WHICH AT LEAST ONE OF THE FOUR ROOTS ASSUMES
C     A POSITIVE REAL PART.  TAKE C1 = 0.5, C2 = 1.0, C3 = 1.5, F0 =
C     1.
C
C   (5)
C
C     PLOT THE ROOT LOCUS DIAGRAM OF THE SYSTEM FOR THE THREE CASES,
C     EITHER AS THREE SEPARATE PLOTS, OR AS ONE COMPOSITE PLOT FOR
C     THE THREE VALUES OF TI.
C
C   (6)
C
C     FOR THE CASE OF TI = 10 IN THE PRECEDING PROBLEM, SIMULATE THE
C     THE SYSTEM FOR ONE HALF AND TWICE THE ULTIMATE GAIN TO SEE IF
C     STABILITY OF THE SYSTEM IS AS PREDICTED FROM THE ROOT LOCUS
C     ANALYSIS.
C
C     WE PROCEED DIRECTLY TO THE PI CONTROLLER SINCE THE PROPORTIONAL
C     CONTROLLER WILL BE A SPECIAL CASE.  THE LAPLACE TRANSFORMS OF
C     THE PRECEDING EQUATIONS ARE
C
C     H1(S) = (1/(S + C1))*(F0 + FM)
C
C     H2(S) = C1/(S + C2), H3(S) = C2/(S + C3)
C
C     WITH
C
C     FM = KC*(1 + 1/(TI*S))*E, E = H3SET - H3, H3SET = 0
C
C     THESE EQUATIONS CAN BE BLOCK DIAGRAMMED AS
C
C                ..........       ..........       ..........
C  F0  .....     .   1    .  H1   .   C1   .  H2   .   C2   .  H3
C ....+.SUM.....+. ------ .......+. ------ .......+. ------ ........+
C      .....     . S + C1 .       . S + C2 .       . S + C3 .   .
C     FM +       ..........       ..........       ..........   .
C        .                                                      .
C        .                                            (MINUS) - +
C        .                                                    .....
C        .                                          H3SET....+.SUM.
C        .                                                    .....
C        .                                                      . E
C        .                     ...............                  .
C        .......................KC*(1+1/TI*S)+...................
C                              ...............
C
C     FROM BASIC BLOCK DIAGRAM ALGEBRA PERFORMED ON THE PRECEDING
C     BLOCK DIAGRAM, THE CLOSED LOOP TRANSFER FUNCTION IS
C
C     H3(S)/F0(S) = GP(S)/(1 + GP(S)*GC(S))
C
C     WITH
C
C     GP(S) = C1*C2/((S + C1)*(S + C2)*(S + C3))
C
C     GC(S) = KC*(1 + 1/(TI*S))
C
C     THE CLOSED LOOP CHARACTERISTIC POLYNOMIAL IS THEREFORE
C
C     1 + GP(S)*GC(S)
C
C     FOR WHICH WE NEED TO FIND THE ROOTS TO ESTABLISH STABILITY,
C     I.E.,
C
C     1 + GP(S)*GC(S) = 0
C
C     OR IN TERMS OF THE PRESENT THIRD SYSTEM WITH PI CONTROL,
C
C     1 + C1*C2/((S + C1)*(S + C2)*(S + C3))*KC*(1 + 1/(TI*S)) = 0
C
C     WHICH CAN BE REARRANGED TO
C
C     S*(S + C1)*(S + C2)*(S + C3)+(C1*C2*KC*(S + 1/TI)) = 0
C
C     OR
C
C     S**4 + (C1 + C2 + C3)*(S**3) + (C1*C2 + C1*C3 + C2*C3)*(S**2)
C
C     + (C1*C2*C3 + C1*C2*KC)*S + C1*C2*KC/TI = 0
C
C
C     THE THIRD ORDER SYSTEM WITH PI CONTROL IS SIMULATED IN THE
C     FOLLOWING PROGRAMMING.  ALSO, THE ROOTS OF THE CHARACTERISTIC
C     POLYNOMIAL ARE COMPUTED BY AN IMSL ROUTINE AND PLOTTED AS A
C     ROOT LOCUS DIAGRAM IN SUBROUTINE LOCUS, CALLED FROM SUBROUTINE
C     PRINT.
C
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     H1,     H2,     H3,     EI
     2      /F/  DH1DT,  DH2DT,  DH3DT,      E
     3      /C/     KC,     TI,     C1,     C2,     C3,     F0,     IP
      REAL KC
C...
C...  SET THE MODEL PARAMETERS
      C1=0.5
      C2=1.0
      C3=1.5
      F0=1.0
      TI=10.0
C...
C...  THE ULTIMATE GAIN IS CALCULATED IN SUBROUTINE LOCUS, WITH
C...  THE FOLLOWING OUTPUT
C...
C...     ULTIMATE GAIN =     3.10000 WITH TI =    .100E+01
C...     ULTIMATE GAIN =    13.40000 WITH TI =    .100E+02
C...     ULTIMATE GAIN =    15.00000 WITH TI =    .100E+11
C...
C...  THUS, FOR TI = 10, THE ULTIMATE GAIN IS KC = 13.40.  TWO RUNS
C...  ARE SUBSEQUENTLY PROGRAMMED WITH KC =13.40/2 (HALF THE ULTIMATE
C...  GAIN) AND KC = 2*13.40 (TWICE THE ULTIMATE GAIN)
         IF(NORUN.EQ.1)KC=13.40/2.0
         IF(NORUN.EQ.2)KC=2.0*13.40
C...
C...  MODEL INITIAL CONDITIONS
      H1=0.
      H2=0.
      H3=0.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     H1,     H2,     H3,     EI
     2      /F/  DH1DT,  DH2DT,  DH3DT,      E
     3      /C/     KC,     TI,     C1,     C2,     C3,     F0,     IP
      REAL KC
C...
C...  CONTROLLER (WITH H3SET = 0 FOR NO CHANGE IN THE CNTROLLER SET
C...  POINT)
      E=-H3
      FM=KC*(E+(1.0/TI)*EI)
C...
C...  PROCESS DIFFERENTIAL EQUATIONS
C...
C...  FIRST TANK
         F1=C1*H1
         DH1DT=F0+FM-F1
C...
C...  SECOND TANK
         F2=C2*H2
         DH2DT=F1-F2
C...
C...  THIRD TANK
         F3=C3*H3
         DH3DT=F2-F3
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     H1,     H2,     H3,     EI
     2      /F/  DH1DT,  DH2DT,  DH3DT,      E
     3      /C/     KC,     TI,     C1,     C2,     C3,     F0,     IP
      REAL KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL TP(101), H3P(101)
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,2)T,H3,DH3DT
2        FORMAT(' T = ',F6.2,5X,'H3 = ',E12.4,5X,'DH3/DT = ',E12.4)
      END IF
C...
C...  STORE THE SOLUTIONS FOR PLOTTING
      TP(IP)=T
      H3P(IP)=H3
C...
C...  PLOT THE SOLUTIONS
      IF(IP.LT.101)RETURN
      CALL SPLOTS(1,IP,TP,H3P)
      WRITE(NO,1)
1     FORMAT(1H ,//,' H3(T) VS T')
C...
C...  ****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE
C...  DEPENDENT, AND WILL HAVE TO BE CONVERTED FOR OTHER PLOTTERS
C...  OR CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,H3P,IP,3H*T*,7H*H3(T)*,2H**,1)
C...
C...  AT THE END OF THE SECOND RUN, CALL SUBROUTINE LOCUS TO (1)
C...  COMPUTE THE ROOTS OF THE CLOSED LOOP CHARACTERISTIC EQUATION,
C...  (2) DETERMINE THE ULTIMATE GAIN AND (3) PLOT THE ROOTS AS A
C...  FUNCTION OF THE CONTROLLER GAIN, KC.  SUBROUTINE LOCUS CONTAINS
C...  CALLS TO A CONTINUOUS PLOTTER WHICH ARE MACHINE DEPENDENT, AND
C...  WILL HAVE TO BE CONVERTED FOR OTHER PLOTTERS OR CHANGED TO
C...  COMMENTS
C...
      IF(NORUN.LT.2)RETURN
C...  CALL LOCUS
C...
C...  ****************************************************************
C...
      RETURN
      END
      SUBROUTINE LOCUS
C...
C...  SUBROUTINE LOCUS COMPUTES THE ROOTS OF THE FOURTH-ORDER
C...  CHARACTERISTIC POLYNOMIAL AS A FUNCTION OF CONTROLLER GAIN,
C...  AND PLOTS THE ROOTS AS A ROOT LOCUS DIAGRAM.  THIS IS DONE
C...  FOR THREE DIFFERENT VALUES OF THE INTEGRAL TIME, TI, AND
C...  ALL THREE ROOT LOCI ARE PLOTTED TOGETHER.
C...
C...  DEFINE THE INTEGER VARIABLES WHICH DIMENSION THE PROBLEM
      PARAMETER (NDEG=4,NKCTOT=201,NTITOT=3)
C...
C...  DEFINE THE ARRAYS
      REAL COEFF(NDEG+1),A(NDEG*NKCTOT),B(NDEG*NKCTOT),KC
      COMPLEX ZERO(NDEG)
C...
C...  EXTERNAL THE IMSL ROUTINE USED TO CALCULATE THE ROOTS
      EXTERNAL ZPLRC
C...
C...  COMMON /IO/ CONTAINS THE INPUT/OUTPUT UNIT NUMBERS
      COMMON/IO/ NI, NO
C...
C...  DEFINE THE CONSTANTS FOR THE THREE STAGED TANKS
      C1=0.5
      C2=1.0
      C3=1.5
C...
C...  STEP THROUGH NTITOT VALUES OF THE INTEGRAL TIME
      DO 4 NTI=1,NTITOT
C...
C...  INITIALIZE THE INTEGER VARIABLE WHICH IS CHANGED TO A NONZERO
C...  VALUE WHEN THE ULTIMATE GAIN IS REACHED (I.E., WHEN AT LEAST
C...  ONE OF THE ROOTS HAS A POSITIVE REAL PART SO THAT THE CLOSED
C...  SYSTEM BECOMES UNSTABLE)
      NTEST=0
C...
C...  SET THE INTEGRAL TIME
      IF(NTI.EQ.1)TI=1.0
      IF(NTI.EQ.2)TI=10.0
      IF(NTI.EQ.3)TI=1.0E+10
C...
C...  STEP THROUGH NKCTOT VALUES OF THE CONTROLLER TIME FOR EACH
C...  VALUE OF THE INTEGRAL TIME
      DO 1 NKC=1,NKCTOT
C...
C...  SET THE CONTROLLER GAIN (0 LE KC LE 20)
      KC=0.1*FLOAT(NKC-1)
C...
C...  SET THE FIVE COEFFICIENTS IN THE FOURTH-ORDER POLYNOMIAL
      COEFF(1)=(C1*C2*KC/TI)
      COEFF(2)=(C1*C2*C3+C1*C2*KC)
      COEFF(3)=(C1*C2+C1*C3+C2*C3)
      COEFF(4)=(C1+C2+C3)
      COEFF(5)=1.0
C...
C...  CALL IMSL SUBROUTINE ZPLRC TO COMPUTE THE ROOTS OF THE
C...  FOURTH-ORDER CHARACTERISTIC POLYNOMIAL
      CALL ZPLRC(NDEG,COEFF,ZERO)
C...
C...  STORE THE ROOTS IN ARRAYS A (REAL PART) AND B (IMAGINARY PART)
C...  FOR SUBSEQUENT PLOTTING
      DO 2 NROOT=1,NDEG
      NPT=(NKC-1)*NDEG+NROOT
      A(NPT)= REAL(ZERO(NROOT))
      B(NPT)=AIMAG(ZERO(NROOT))
C...
C...  IF THE REAL PART OF THE CURRENT ROOT HAS A POSITIVE VALUE, THE
C...  VALUE OF KC IS THE ULTIMATE GAIN (THE SYSTEM HAS BECOME UNSTABLE).
      IF((A(NPT).GT.0.).AND.(NTEST.EQ.0))THEN
C...
C...  PRINT THE ULTIMATE GAIN
         WRITE(NO,5)KC,TI
5        FORMAT(' ULTIMATE GAIN = ',F10.5,' WITH TI = ',E10.3)
         NTEST=1
      END IF
C...
C...  OPTIONALLY, PRINT IN DETAIL THE GAIN, INTEGRAL TIME, NUMBER
C...  OF THE ROOT AND ITS REAL AND IMAGINARY PARTS (THIS WRITE
C...  STATEMENT IS A COMMENT, AND CAN BE ACTIVATED)
      IF(((NKC-1)/20*20).EQ.(NKC-1))THEN
C...     WRITE(NO,3)NPT,KC,TI,NROOT,A(NPT),B(NPT)
3        FORMAT(  ' NPT = ',I5,' KC = ',F10.3,' TI = ',E10.3,
     1          ' NROOT = ',I5, ' A = ',F10.4, ' B = ',F10.4)
      END IF
C...
C...  THE FOUR ROOTS HAVE BEEN COMPUTED FOR THE CURRENT VALUES OF KC AND
C...  TI
2     CONTINUE
C...
C...  THE CALCULATIONS FOR ALL NKCTOT VALUES OF KC HAVE BEEN COMPLETED
1     CONTINUE
C...
C...  PLOT THE ROOT LOCUS FOR THE FIRST VALUE OF TI
      IF(NTI.EQ.1)THEN
         CALL QIKSAX(3,3)
         CALL QIKPLT(A,B,-NDEG*NKCTOT,
     1   11H*REAL PART*,11H*IMAG PART*,20H*ROOT LOCUS DIAGRAM*,1)
C...
C...  IF THE ROOT LOCI ARE TO BE PLOTTED SEPARATELY, THE FOLLOWING
C...  TWO CALLS TO QLINE CAN BE REPLACED BY TWO CALLS TWO QIKLT.  ALSO,
C...  THE FOLLOWING CALL TO PLOT SHOULD BE MOVED TO JUST BEFORE THE
C...  FINAL (THIRD) CALL TO QLINE
         CALL PLOT(-7.0,1.0,-3)
C...
C...  PLOT THE ROOT LOCUS FOR THE SECOND VALUE OF TI
      ELSE IF(NTI.EQ.2)THEN
         CALL QLINE(A,B,-NDEG*NKCTOT,4)
C...
C...  PLOT THE ROOT LOCUS FOR THE THIRD VALUE OF TI
      ELSE IF(NTI.EQ.3)THEN
         CALL QLINE(A,B,-NDEG*NKCTOT,5)
      END IF
C...
C...  PLOT THE LINE WITH A REAL PART OF ZERO AND AN IMAGINARY PART
C...  OF -2 AND 2 (JUST TWO POINTS ARE REQUIRED).  THIS LINE WILL
C...  DEMONSTRATE IF THE ROOT LOCUS PASSES INTO THE RIGHT HALF OF
C...  THE COMPLEX PLANE
      A(1)=0.
      B(1)= 2.0
      A(2)=0.
      B(2)=-2.0
      CALL QLINE(A,B,2,6)
C...
C...  THE CALCULATIONS AND PLOTTING FOR ALL THREE VALUES OF TI ARE
C...  COMPLETE
4     CONTINUE
      RETURN
      END
HALF THE ULTIMATE GAIN
0.        50.0      0.5
    4 1000    1    1  ABS 0.001
TWICE THE ULTIMATE GAIN
0.        50.0      0.5
    4 1000    1    1  ABS 0.001
END OF RUNS
*APP PRC47
      SUBROUTINE DOC
C
C *********************************************************************
C
C     DYNAMIC SIMULATION OF A CHEMICAL PLANT - TUTORIAL NO. 1
C
C     THE DISTRIBUTED SYSTEM IS MODELED AS A SERIES OF DISCRETE (ODE)
C     SYSTEMS
C
C *********************************************************************
C
C     CONSIDER THE FOLLOWING SMALL PLANT CONSISTING OF A CSTR AND
C     COOLER WITH CONTROLLERS
C
C      F0,CA0,T0
C     ...........
C               .
C               .
C       .       .       .
C       .       .       .
C       .       +       .
C       .               .
C       .................
C       .               .                RECYCLE
C       .     V,CA,T    .+......................................
C       .               .  FR,CA,TR                            .
C       .    REACTOR    .                               FC,TC  .
C  ..C...     (CSTR)    .                                 .    .
C  .    .               .                                 .    .
C  .    .................                             TCV +    .
C  C            .    .         ....                   .  ...   .
C  .            .    ..C..C..C..TC...C..C..C..C..C..C.... .    .
C  .            .              ....                   .  ...   .
C  C            .                                         .    .
C  .            .                                         +    .
C  .            .                         ..................   .
C  C            .   FP,C,T     ......     .                .   .
C  .            ..............+.PUMP.....+.     COOLER     .....
C  .                           ......  .  .                .
C  C                                   .  ..................
C  .                                   .   .
C  . ....                              .   .
C  ...LC...C                           .   +
C    ....  .                           . FC,TC1
C         ...                          .
C          .                           .
C          . LCV                       .
C  F,CA,T ...                          .
C     +... . ...........................
C         ...
C
C     TC  - TEMPERATURE CONTROLLER
C
C     TCV - TEMPERATURE CONTROL VALVE
C
C     LC  - LIQUID LEVEL CONTROOLER
C
C     LCV - LIQUID LEVEL CONTROL VALVE
C
C     THE VARIABLES INDICATED ABOVE ARE DEFINED IN THE FOLLOWING
C     CODING.  THE OBJECTIVE OF THE CONTROLLERS IS TO MAINTAIN THE
C     REACTOR TEMPERATURE, T, AND VOLUME, V, AT PRESCRIBED VALUES
C     (SET POINTS).
C
C     ..C..  DENOTES A LINE FOR CONTROL SIGNALS (TYPICALLY, AN
C            ELECTRONIC OR PNEUMATIC LINE).
C
C     THE CSTR IS PERFECTLY MIXED, WHILE THE COOLER IS DISTRIBUTED.
C     THE COOLER IS MODELED IN THE FOLLOWING CODING AS TWO PERFECTLY
C     MIXED SECTIONS, AS DIAGRAMMED BELOW:
C
C                TC1,VC/2                     TC2,VC/2
C        .......................       ......................
C FC,TC1 .                     .       .                    . FC,TC
C   +..... (U*A/2)*(TH1 - TC1) .+....... (U*A/2)*(TR - TC2) .+......
C        .          +          .       .          +         .
C        .......................       ......................
C                   .                             .
C        .......................       ......................
C   FR,T .          .          .       .          .         . FR,TR
C  .....+.          .          .......+.          .         ........+
C        .                     .       .                    .
C        .......................       ......................
C                TH1,VH/2                      TR,VH/2
C
C     THE EQUATIONS FOR THE REACTOR ARE:
C
C     TOTAL MATERIAL BALANCE
C
C     D(V*RHO)/DT = F0*RHO + FR*RHO - FP*RHO
C
C     OR
C
C     DV/DT = F0 - F, V(0) = V0
C
C     COMPONENT (REACTANT) BALANCE
C
C     D(V*CA)/DT = F0*CA0 + FR*CA - FP*CA - V*K0*EXP(-E/(R*T))*CA
C
C     OR
C
C     D(V*CA)/DT = F0*CA0 - F*CA - V*K0*EXP(-E/(R*T))*CA, V(0)*CA(0)
C
C     ENERGY BALANCE
C
C     D(V*RHO*CP*T)/DT = F0*RHO*CP*T0 + FR*RHO*CP*TR
C
C         -FP*RHO*CP*T - DH*V*K0*EXP(-E/(R*T))*CA, V(0)*T(0)
C
C     THE EQUATIONS FOR THE COOLER ARE:
C
C     ENERGY BALANCE ON THE LEFT COLD SECTION
C
C     (VC/2)*RHOC*CPC*DTC1/DT = FC*RHOC*CPC*TC2 - FC*RHOC*CPC*TC1
C
C               + (U*A/2)*(TH1 - TC1), TC1(0)
C
C     ENERGY BALANCE ON THE RIGHT COLD SECTION
C
C     (VC/2)*RHOC*CPC*DTC2/DT = FC*RHOC*CPC*TC - FC*RHOC*CPC*TC2
C
C               + (U*A/2)*(TR - TC2), TC2(0)
C
C     ENERGY BALANCE ON THE LEFT HOT SECTION
C
C     (VH/2)*RHO*CP*DTH1/DT = FR*RHO*CP*T - FR*RHO*CP*TH1
C
C               - (U*A/2)*(TH1 - TC1), TH1(0)
C
C     ENERGY BALANCE ON THE RIGHT HOT SECTION
C
C     (VH/2)*RHO*CP*DTR/DT = FR*RHO*CP*TH1 - FR*RHO*CP*TR
C
C               - (U*A/2)*(TR - TC2), TR(0)
C
C     THE THREE DIFFERENTIAL EQUATIONS FOR THE REACTOR ARE PROGRAMMED
C     IN SUBROUTINE CSTR, AND THE FOUR DIFFERENTIAL EQUATIONS FOR THE
C     COOLER ARE PROGRAMMED IN SUBROUTINE COOLER.  THE INITIAL CONDI-
C     TIONS ARE ALSO INCLUDED IN THESE SUBROUTINES.
C
      RETURN
      END
      SUBROUTINE INITAL
      COMMON/C/     NC,      T,     FP,      F
C...
C...  INITIALIZE THE MODEL
         NC=0
C...
C...     REACTOR
         CALL CSTR
C...
C...     COOLER
         CALL COOLER
      RETURN
      END
      SUBROUTINE DERV
      COMMON/C/     NC,      T,     FP,      F
C...
C...  COMPUTE THE MODEL DERIVATIVES
         NC=1
C...
C...     REACTOR
         CALL CSTR
C...
C...     COOLER
         CALL COOLER
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/C/     NC,      T,     FP,      F
C...
C...  PRINT THE SOLUTION
         NC=2
C...
C...     REACTOR
         CALL CSTR
C...
C...     COOLER
         CALL COOLER
      RETURN
      END
      SUBROUTINE CSTR
C...
C...  USUAL DSS/2 COMMON AREA FOR THE DIFFERENTIAL EQUATIONS
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,    VCA,     VT,    TC1,    TC2,    TH1,     TR
     2      /F/   DVDT, DVCADT,  DVTDT, DTC1DT, DTC2DT, DTH1DT,  DTRDT
C...
C...  COMMON/C/ HAS THE VARIABLES WHICH CONNECT THE REACTOR AND COOLER
      COMMON/C/     NC,      T,     FP,      F
C...
C...  COMMON/IO/ HAS THE INPUT/OUTPUT UNIT NUMBERS (SET IN THE MAIN
C...  DDS/2 PROGRAM)
      COMMON/IO/    NI,     NO
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      REAL VP(101), TP(101), CAP(101), TIMEP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  SET THE REACTOR PARAMETERS AND INITIAL CONDITIONS
      IF(NC.EQ.0)THEN
C...
C...  PARAMETERS
C...
C...     LIQUID SPECIFIC HEAT
         CP=1.0
C...
C...     LIQUID DENSITY
         RHO=1.0
C...
C...     PUMP FLOW RATE (FP = F + FR)
         FP=200.
C...
C...     ENTERING FLOW
         F0=100.
C...
C...     ENTERING LIQUID TEMPERATURE
         T0=25.
C...
C...     PREEXPONENTIAL FACTOR
         RK=1.0E+02
C...
C...     ACTIVATION ENERGY
         EA=5000.
C...
C...     GAS CONSTANT
         R=1.987
C...
C...     ENTERING CONCENTRATION
         CA0=0.01
C...
C...     HEAT OF REACTION
         HR=-10000.
C...
C...     LIQUID LEVEL CONTROLLER SET POINT
         VSET=20000.
C...
C...     STEADY STATE OUTLET FLOW RATE
         FS=100.0
C...
C...     LIQUID LEVEL CONTROLLER GAIN
         AKC=0.
C...
C...  INITIAL CONDITIONS
C...
C...     REACTOR (LIQUID) VOLUME
         V=20000.
C...
C...     REACTOR CONCENTRATION
         CA=0.01
         VCA=V*CA
C...
C...     REACTOR TEMPERATURE
         T=25.
         VT=V*T
      END IF
C...
C...  MODEL EQUATIONS
      IF(NC.EQ.1)THEN
C...
C...  LIQUID LEVEL CONTROLLER
         E=V-VSET
         F=FS+AKC*E
C...
C...  MODEL ALGEBRA
C...
C...     RECYCLE FLOW
         FR=FP-F
C...
C...     REACTOR CONCENTRATION
         CA=VCA/V
C...
C...     REACTOR TEMPERATURE
         T=VT/V
C...
C...  DIFFERENTIAL EQUATIONS FOR THE REACTOR
C...
C...     TOTAL MATERIAL BALANCE
         DVDT=F0-F
C...
C...     COMPONENT MATERIAL BALANCE
         EXPT=EXP(-EA/(R*(T+273.14)))
         DVCADT=F0*CA0-F*CA-V*RK*CA*EXPT
C...
C...     ENERGY BALANCE
         DVTDT=F0*T0+FR*TR-FP*T-(HR*V)/(RHO*CP)*RK*CA*EXPT
      END IF
C...
C...  PRINT AND PLOT THE SOLUTION
      IF(NC.EQ.2)THEN
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE CSTR
         IF((IP/10*10).EQ.IP)THEN
C...           WRITE(NO,1)TIME,V,CA,T
1              FORMAT(' REACTOR',/,
     1            ' TIME = ',F7.1,'    V = ',F7.0,
     2            '   CA = ',F7.5,'    T = ',F7.1)
         END IF
C...
C...     STORE THE SOLUTION FOR PLOTTING
         IP=IP+1
         VP(IP)=V
         TP(IP)=T
         CAP(IP)=CA
         TIMEP(IP)=TIME
C...
C...     PLOT THE SOLUTION AT THE END OF THE RUN
         IF(IP.LT.101)RETURN
C...
C...     VOLUME VS TIME
         CALL SPLOTS(1,IP,TIMEP,VP)
         WRITE(NO,11)
11       FORMAT(1H ,//,' VOLUME, V, VS TIME')
C...
C...     TEMPERATURE VS TIME
         CALL SPLOTS(1,IP,TIMEP,TP)
         WRITE(NO,12)
12       FORMAT(1H ,//,' TEMPERATURE, T, VS TIME')
C...
C...     CONCENTRATION VS TIME
         CALL SPLOTS(1,IP,TIMEP,CAP)
         WRITE(NO,13)
13       FORMAT(1H ,//,' CONCENTRATION, CA, VS TIME')
         IP=0
      END IF
      RETURN
      END
      SUBROUTINE COOLER
C...
C...  USUAL DSS/2 COMMON AREA FOR THE DIFFERENTIAL EQUATIONS
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,    VCA,     VT,    TC1,    TC2,    TH1,     TR
     2      /F/   DVDT, DVCADT,  DVTDT, DTC1DT, DTC2DT, DTH1DT,  DTRDT
C...
C...  COMMON/C/ HAS THE VARIABLES WHICH CONNECT THE REACTOR AND COOLER
      COMMON/C/     NC,      T,     FP,      F
C...
C...  COMMON/IO/ HAS THE INPUT/OUTPUT UNIT NUMBERS (SET IN THE MAIN
C...  DDS/2 PROGRAM)
      COMMON/IO/    NI,     NO
C...
C.. . DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      REAL TRP(101), TC1P(101), FRP(101), TIMEP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  SET THE COOLER PARAMETERS AND INITIAL CONDITIONS
      IF(NC.EQ.0)THEN
C...
C...  PARAMETERS
C...
C...     HOT LIQUID DENSITY
         RHO=1.0
C...
C...     HOT LIQUID HEAT CAPACITY
         CP=1.0
C...
C...     COLD LIQUID DENSITY
         RHOC=1.0
C...
C...     COLD LIQUID HEAT CAPACITY
         CPC=1.0
C...
C...     LENGTH
         ZL=100.
C...
C...     OVERALL HEAT TRANSFER COEFFICIENT
         U=2.
C...
C...     HEAT TRANSFER AREA
         A=100000.
C...
C...     ENTERING COOLANT TEMPERATURE
         TC=25.
C...
C...     SHELL SIDE FLOW CROSS SECTIONAL AREA
         AS=100.
C...
C...     TUBE SIDE FLOW CROSS SECTIONAL AREA
         AT=200.
C...
C...     TEMPERATURE CONTROLLER SET POINT
         TSET=25.
C...
C...     STEADY STATE COOLANT FLOW RATE
         FCS=100.0
C...
C...     TEMPERATURE CONTROLLER GAIN
         AKC=0.
C...
C...     VOLUME OF SHELL SECTIONS
         VC=AS*ZL/2.
C...
C...     VOLUME OF TUBE SECTIONS
         VH=AT*ZL/2.
C...
C...  INITIAL CONDITIONS
C...
C...     SHELL SIDE TEMPERATURES
         TC1=25.
         TC2=25.
C...
C...     TUBE SIDE TEMPERATURES
         TH1=25.
         TR =25.
      END IF
C...
C...  MODEL EQUATIONS
      IF(NC.EQ.1)THEN
C...
C...  FLOW CONTROLLER
         E=TSET-T
         FC=FCS+AKC*E
C...
C...  MODEL ALGEBRA
C...
C...     RECYCLE FLOW
         FR=FP-F
C...
C...  COOLER DIFFERENTIAL EQUATIONS
C...
C...     LEFT SHELL SIDE SECTION
         DTC1DT=(2.0/(VC*RHOC*CPC))*(FC*RHOC*CPC*TC2-FC*RHOC*CPC*TC1
     1         +(U*A/2.0)*(TH1-TC1))
C...
C...     RIGHT SHELL SIDE SECTION
         DTC2DT=(2.0/(VC*RHOC*CPC))*(FC*RHOC*CPC*TC -FC*RHOC*CPC*TC2
     1         +(U*A/2.0)*(TR -TC2))
C...
C...     LEFT TUBE SIDE SECTION
         DTH1DT=(2.0/(VH*RHO*CP))*(FR*RHO*CP*T  -FR*RHO*CP*TH1
     1         -(U*A/2.0)*(TH1-TC1))
C...
C...     RIGHT TUBE SIDE SECTION
         DTRDT =(2.0/(VH*RHO*CP))*(FR*RHO*CP*TH1- FR*RHO*CP*TR
     1         -(U*A/2.0)*(TR -TC2))
      END IF
C...
C...  PRINT AND PLOT THE SOLUTION
      IF(NC.EQ.2)THEN
C...
C...     PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE COOLER
         IF((IP/10*10).EQ.IP)THEN
C...        WRITE(NO,1)TIME,T,TR,TC1
1           FORMAT(' COOLER',/,
     1         ' TIME = ',F7.1,'    T = ',F7.1,
     2         '   TR = ',F7.1,'  TC1 = ',F7.1)
         END IF
C...
C...     STORE THE SOLUTION FOR PLOTTING
         IP=IP+1
         TRP(IP)=TR
         TC1P(IP)=TC1
         FRP(IP)=FR
         TIMEP(IP)=TIME
C...
C...     PLOT THE SOLUTION AT THE END OF THE RUN
         IF(IP.LT.101)RETURN
C...
C...     RECYCLE TEMPERATURE VS TIME
         CALL SPLOTS(1,IP,TIMEP,TRP)
         WRITE(NO,11)
11       FORMAT(1H ,//,' RECYCLE TEMPERATURE, TR, VS TIME')
C...
C...     COOLER SHELL SIDE OUTLET TEMPERATURE VS TIME
         CALL SPLOTS(1,IP,TIMEP,TC1P)
         WRITE(NO,12)
12       FORMAT(1H ,//,
     1      ' COOLER SHELL SIDE OUTLET TEMPERATURE, TC1, VS TIME')
C...
C...     RECYCLE FLOW VS TIME
         FRP(1)=FRP(2)
         CALL SPLOTS(1,IP,TIMEP,FRP)
         WRITE(NO,13)
13       FORMAT(1H ,//,' RECYCLE FLOW, FR, VS TIME')
         IP=0
      END IF
      RETURN
      END
DYNAMIC SIMULATION OF A SMALL CHEMICAL PLANT
0.        100.      1.0
    7 1000    1    1  REL 0.001
END OF RUNS
*APP PRC48
      SUBROUTINE INITAL
C...
C...  TEMPERATURE CONTROL OF HEXAMETHYLENETETRAMINE PRODUCTION
C...
C...  HEXAMETHYLENETETRAMINE (HMT) IS TO BE PRODUCED IN A SEMIBATCH
C...  REACTOR BY ADDING AN AQUEOUS AMMONIA SOLUTION (25 WT% NH3) AT THE
C...  RATE OF 2 GPM TO AN INITIAL CHARGE OF 238 GAL (AT 25 C) OF FORMA-
C...  LIN SOLUTION CONTAINING 42% BY WEIGHT FORMALDEHYDE.  THE ORIGINAL
C...  TEMPERATURE OF THE FORMALIN SOLUTION IS RAISED TO 50 C IN ORDER
C...  TO START THE REACTION.  THE TEMPERATURE OF THE NH4OH SOLUTION IS
C...  25 C.  THE HEAT OF REACTION IN THE LIQUID PHASE MAY BE ASSUMED
C...  INDEPENDENT OF TEMPERATURE AND CONCENTRATION AND TAKEN AS -960
C...  BTU/LB OF HMT.  THE REACTION IS IRREVERSIBLE AND THE RATE OF
C...  REACTION IS FIRST ORDER IN EACH OF THE REACTANTS.  THE MAXIMUM
C...  REACTOR TEMPERATURE IS TO BE CONTROLLED AT 80 C BY USING AN
C...  IMMERSION COOLER, POSITIONED BY A PI CONTROLLER.
C...
C...  THE IMMERSION COOLER CONSISTS OF A MOVABLE COIL THROUGH WHICH WATER
C...  FLOWS.  THE OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE STIRRED
C...  REACTION MIXTURE AND THE COOLING WATER WILL BE 85 BTU/HR-FT**2-F.
C...  THE WATER FLOW RATE THROUGH THE COILS IS SUCH THAT ITS TEMPERATURE
C...  VARIES LITTLE, AND AN AVERAGE VALUE OF 25 C MAY BE USED.  GIVEN THE
C..   FOLLOWING DATA, DEVELOP A MATHEMATICAL MODEL AND SIMULATION TO
C...  EVALUATE THE PERFORMANCE OF THE PROPOSED CONTROL SYSTEM.
C...
C...     DENSITY OF AMMONIA SOLUTION = 0.91 GM/CM**3
C...
C...     DENSITY OF FORMALIN (42%) AT 25 C = 1.10 GM/CM**3
C...
C...     SPECIFIC HEAT OF REACTION MIXTURE (ASSUME CONSTANT), CP = 1.0
C...     BTU/LB-F
C...
C...     SPECIFIC HEAT OF 25 WT% NH3 SOLUTION, CP = 1.0 BTU/LB-F
C...
C...     REACTION RATE CONSTANT = 4.48E+05*EXP(-8000/(R*T)) CM**3/SEC-
C...     GM-MOL
C...
C...  THE MATHEMATICAL MODEL FOLLOWS.  THE REACTION IS
C...
C...     6HCH0 + 4NH OH ----+ (CH ) N  + 10 H 0
C...                4            2 6 4       2
C...
C...  ENERGY BALANCE
C...
C...     D(M*CP*TC)/DT = W0*CP0*T0 - U*A*(TC - TW) - DH*V*K*CA*CF   (1)
C...
C...     M(0)*TC(0), V = M/RHO
C...
C...  TOTAL MASS BALANCE
C...
C...     DM/DT = W0, M(0)                                           (2)
C...
C...  AMMONIA BALANCE
C...
C...     D(V*CA)/DT = W0*WA0/MA - 4*V*K*CA*CF, V(0)*CA(0)           (3)
C...
C...  FORMALDEHYDE BALANCE
C...
C...     D(V*CF)/DT = -6*V*K*CA*CF, V(0)*CF(0)                      (4)
C...
C...  IMMERSION COOLER
C...
C...                              T
C...     A = AS + KC*(E + (1/TI) INT E*DT), E = TC - TCSET          (5)
C...                              0
C...
C...  WHERE
C...
C...     TC      TEMPERATURE (C)
C...
C...     M       MASS OF LIQUID IN THE REACTOR (GM)
C...
C...     CA      CONCENTRATION OF AMMONIA (GM MOL/CM**3)
C...
C...     CF      CONCENTRAION OF FORMALDEHYDE (GM MOL/CM**3)
C...
C...     T       TIME (SEC)
C...
C...     V       VOLUME OF LIQUID IN THE REACTOR (CM**3)
C...
C...     CP      SPECIFIC HEAT OF LIQUID IN THE REACTOR (CAL/GM-C)
C...
C...     WA0     FEED MASS CONCENTRATION OF AMMONIA (GM/GM)
C...
C...     W0      FEED MASS FLOW RATE (GM/SEC)
C...
C...     MA      MOLECULAR WEIGHT OF AMMONIA (GM/GM MOL)
C...
C...     CP0     FEED SPECIFIC HEAT (CM/GM-C)
C...
C...     TO      FEED TEMPERATURE (C)
C...
C...     U       COIL HEAT TRANSFER COEFFICIENT (CAL/SEC-CM**2-C)
C...
C...     A       HEAT TRANSFER AREA (CM**2)
C...
C...     AS      STEADY STATE HEAT TRANSFER AREA (CM**2)
C...
C...     TW      COOLANT TEMPERATURE (C)
C...
C...     K       SPECIFIC REACTION RATE CONSTANT (CM**3/SEC-GM MOL)
C...             (THIS IS GIVEN BY AN ARRHENIUS TEMPERATURE DEPENDENCY
C...             AND THE TEMPERATURE MUST BE ABSOLUTE, I.E., KELVIN)
C...
C...     DH      HEAT OF REACTION (CAL/GM MOL HMT PRODUCED)
C...
C...     TCSET   SET POINT FOR THE CONTROLLER (C)
C...
C...     KC      CONTROLLER GAIN (CM**2/C)
C...
C...     TI      CONTROLLER INTEGRAL TIME (1/SEC)
C...
C...  OF THE CONTROL SYSTEM.
C...
C...  THE FOLLOWING CONVERSION FACTORS CAN BE USED TO CONVERT THE MODEL
C...  CONSTANTS TO HAVE A CONSISTENT SET OF UNITS
C...
C...     1 GAL = 3.785 LITERS
C...
C...     1 BTU = 252 GM-CAL
C...
C...     1 LB = 454 GM
C...
C...     1 IN = 2.54 CM
C...
C...     1 BTU/LB-F = 1 CAL/GM-C
C...
C...     1 C = 1.8 F
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF,     EI
     2      /F/   DMTC,     DM,   DVCA,   DVCF,  DEIDT
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,  TCSET,     AS,
     6              KC,     TI,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K,
     1              KC
C...
C...  CONVERT THE MODEL CONSTANTS
C...
C...     ENTERING MASS FLOW RATE (GPM TO GM/SEC)
         W0=2.0*3.785*1000.0*0.91/60.0
C...
C...     INITIAL MASS (GAL TO GM)
         M0=238.0*3.785*1000.0*1.10
C...
C...     HEAT TRANSFER COEFFICIENT (BTU/HR-FT**2-F TO CAL/SEC-CM**2-SEC)
         U=85.0*252.0/3600.0*(1.0/(2.54*12.0)**2)*1.8
C...
C...     HEAT OF REACTION (BTU/LB TO GM/GM MOL HMT PRODUCED)
         MWHMT=(12.0+2.0)*6.0+14.0*4.0
         DH=-960.0*252.0/454.0*MWHMT
C...
C...  CONTROLLER PARAMETERS
      AS=0.
      TCSET=80.
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=50000.
         TI=500.
      END IF
C...
C...  SET OTHER MODEL CONSTANTS
      CP=1.0
      CP0=1.0
      T0=25.0
      TW=25.0
      RHO=1.10
      WA0=0.25
      MWA=17.0
      MWF=30.0
C...
C...  INITIAL CONDITIONS
      MTC=M0*50.0
      M=M0
      V=M0/RHO
      VCA=V*0.
      VCF=V*0.42*1.10/MWF
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF,     EI
     2      /F/   DMTC,     DM,   DVCA,   DVCF,  DEIDT
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,  TCSET,     AS,
     6              KC,     TI,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K,
     1              KC
C...
C...  MODEL ALGEBRA
      TC=MTC/M
      V=M/RHO
      CA=VCA/V
      CF=VCF/V
      K=4.48E+05*EXP(-8000.0/(1.987*(TC+273.16)))
C...
C...  CONTROLLER EQUATIONS
      E=TC-TCSET
      A=AS+KC*(E+(1.0/TI)*EI)
      IF(A.LT.0.)A=0.
C...
C...  MODEL ODES
C...
C...     ENERGY BALANCE
         DMTC=W0*CP0*T0-U*A*(TC-TW)-DH*V*K*CA*CF
C...
C...     TOTAL MASS BALANCE
         DM=W0
C...
C...     AMMONIA BALANCE
         DVCA=W0*WA0/MWA-4.0*V*K*CA*CF
C...
C...     FORMALDEHYDE BALANCE
         DVCF=-6.0*V*K*CA*CF
C...
C...     CONTROLLER DIFFERENTIAL EQUATION (ONLY THE POSITIVE ERROR IS
C...     INTEGRATED SO THAT THE HEAT TRANSFER AREA DOES NOT TEND TO
C...     NEGATIVE VALUES)
         IF(E.GT.0.)THEN
            DEIDT=E
         ELSE
            DEIDT=0.
         END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF,     EI
     2      /F/   DMTC,     DM,   DVCA,   DVCF,  DEIDT
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,  TCSET,     AS,
     6              KC,     TI,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K,
     1              KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL      TP(51),      TCP(2,51),      CAP(2,51),      CFP(2,51),
     1        AP(2,51),       EP(2,51)
C...
C...  COMPUTE THE INDIVIDUAL TERMS IN THE ODES FOR PRINTING
C...
C...     ENERGY BALANCE
         E1=W0*CP0*T0
         E2=-U*A*(TC-TW)
         E3=-DH*V*K*CA*CF
         DMTC=E1+E2+E3
C...
C...     AMMONIA BALANCE
         A1=W0*WA0/MWA
         A2=-4.0*V*K*CA*CF
         DVCA=A1+A2
C...
C...     FORMALDEHYDE BALANCE
         F1=-6.0*V*K*CA*CF
C...
C...  PRINT THE DETAILED NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,1)      T,    MTC,      M,    VCA,    VCF,     TC,
     1                    V,     CA,     CF,      K,     E1,     E2,
     2                   E3,   DMTC,     A1,     A2,   DVCA,     F1,
     3                 DVCF
1        FORMAT(1H ,//,' T = ',F7.1,/,
     1   '                 MTC',E10.3,5X,'                   M',E10.3,/,
     2   '                 VCA',E10.3,5X,'                 VCF',E10.3,/,
     3   '                  TC',E10.3,5X,'                   V',E10.3,/,
     4   '                  CA',E10.3,5X,'                  CF',E10.3,/,
     5   '                   K',E10.3,5X,'           W0*CP0*T0',E10.3,/,
     6   '        -U*A*(TC-TW)',E10.3,5X,'       -DH*V*K*CA*CF',E10.3,/,
     7   '                DMTC',E10.3,5X,'           W0*WA0/MA',E10.3,/,
     8   '      -4.0*V*K*CA*CF',E10.3,5X,'                DVCA',E10.3,/,
     9   '      -6.0*V*K*CA*CF',E10.3,5X,'                DVCF',E10.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      TCP(NORUN,IP)=TC
      CAP(NORUN,IP)=CA
      CFP(NORUN,IP)=CF
       AP(NORUN,IP)=A
       EP(NORUN,IP)=TC-TCSET
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.51).OR.(NORUN.LT.2))RETURN
C...
C...     TC VS T
         CALL SPLOTS(NORUN,IP,TP,TCP)
         WRITE(NO,11)
11       FORMAT(1H ,/,' TC(T) VS T, 1 - NO CONTROL, 2 - PI CONTROL')
C...
C...     CA VS T
         CALL SPLOTS(NORUN,IP,TP,CAP)
         WRITE(NO,12)
12       FORMAT(1H ,/,' CA(T) VS T, 1 - NO CONTROL, 2 - PI CONTROL')
C...
C...     CF VS T
         CALL SPLOTS(NORUN,IP,TP,CFP)
         WRITE(NO,13)
13       FORMAT(1H ,/,' CF(T) VS T, 1 - NO CONTROL, 2 - PI CONTROL')
C...
C...     A VS T
         CALL SPLOTS(NORUN,IP,TP,AP)
         WRITE(NO,14)
14       FORMAT(1H ,/,' A(T) VS T, 1 - NO CONTROL, 2 - PI CONTROL')
C...
C...     E VS T
         CALL SPLOTS(NORUN,IP,TP,EP)
         WRITE(NO,15)
15       FORMAT(1H ,/,' E(T) VS T, 1 - NO CONTROL, 2 - PI CONTROL')
      RETURN
      END
SEMI-BATCH PRODUCTION OF HMT, NO CONTROL
0.        1800.0    36.0
    5 1000    1    1  REL 0.001
SEMI-BATCH PRODUCTION OF HMT, PI CONTROL
0.        1800.0    36.0
    5 1000    1    1  REL 0.001
END OF RUNS
