CFPRIME INGV04                                                          INGV04      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE INGV04(TIN5)                                           INGV04      3
CD                                                                      INGV04      4
CD    TO PERFORM INITIALIZATION AND DATA CHECK FOR GOVERNOR TYPES 4     INGV04      5
CD    AND 5.                                                            INGV04      6
CD                                                                      INGV04      7
CD    THE DATA STRUCTURE AFTER THE INITIALIZATION IS GIVEN BELOW.       INGV04      8
CD                                                                      INGV04      9
CD   9.3 Prime-mover turbine-governor model types 4 and 5               INGV04     10
CD                                                                      INGV04     11
CD     Governor data                                                    INGV04     12
CD                                                                      INGV04     13
CD     DDAT(JGG+ 1)   = K1                                              INGV04     14
CD     DDAT(JGG+ 2)   = T1                                              INGV04     15
CD     DDAT(JGG+ 3)   = T2                                              INGV04     16
CD     DDAT(JGG+ 4)   = T3                                              INGV04     17
CD     DDAT(JGG+ 5)   = RMAX                                            INGV04     18
CD     DDAT(JGG+ 6)   = RMIN                                            INGV04     19
CD     DDAT(JGG+ 7)   = PMAX                                            INGV04     20
CD     DDAT(JGG+ 8)   = (reserved for future use)                       INGV04     21
CD     DDAT(JGG+ 9)   = T4                                              INGV04     22
CD     DDAT(JGG+10)   = T5                                              INGV04     23
CD     DDAT(JGG+11)   = T6                                              INGV04     24
CD     DDAT(JGG+12)   = T7                                              INGV04     25
CD     DDAT(JGG+13)   = K2                                              INGV04     26
CD     DDAT(JGG+14)   = K3                                              INGV04     27
CD     DDAT(JGG+15)   = K4                                              INGV04     28
CD     DDAT(JGG+16)   = K5                                              INGV04     29
CD     DDAT(JGGP1+ 1) = K6                                              INGV04     30
CD     DDAT(JGGP1+ 2) = K7                                              INGV04     31
CD     DDAT(JGGP1+ 3) = K8                                              INGV04     32
CD                                                                      INGV04     33
CD     Governor states                                                  INGV04     34
CD                                                                      INGV04     35
CD     XSTATE(JPS+ 1) = T1 block                    : compulsory        INGV04     36
CD     XSTATE(JPS+ 2) = integrator block            : compulsory        INGV04     37
CD     XSTATE(JPS+ 3) = T4 block                    : compulsory        INGV04     38
CD     XSTATE(JPS+ 4) = T5 block                    : compulsory        INGV04     39
CD     XSTATE(JPS+ 5) = T6 block                    : compulsory        INGV04     40
CD     XSTATE(JPS+ 6) = T7 block                    : compulsory        INGV04     41
CD     XSTATE(JPS+ 7) = (reserved for future use)                       INGV04     42
CD                                                                      INGV04     43
CD     Governor Y-variables                                             INGV04     44
CD                                                                      INGV04     45
CD     XLDREF(JYP+ 1) = load reference signal                           INGV04     46
CD     CVP(JYP+2)     = governor output for turbine control             INGV04     47
CD     BLRPR(JYP+3)   = boiler pressure output                          INGV04     48
CD     PDEM(JYP+4)    = power demand from AGC control                   INGV04     49
CD     PSET(JYP+5)    = set point for boiler pressure control           INGV04     50
CD                                                                      INGV04     51
      INCLUDE 'PARX.INS'                                                INGV04     52
      INCLUDE 'CNB1.INS'                                                INGV04     53
      INCLUDE 'CNB3.INS'                                                INGV04     54
      INCLUDE 'CNB4.INS'                                                INGV04     55
      INCLUDE 'CNB8.INS'                                                INGV04     56
      INCLUDE 'CNB10.INS'                                               INGV04     57
      INCLUDE 'CNB19.INS'                                               INGV04     58
      INCLUDE 'CNPARX.INS'                                              INGV04     59
      INCLUDE 'CNXSTA.INS'                                              INGV04     60
      INCLUDE 'CNMDAT.INS'                                              INGV04     61
      INCLUDE 'CNMSTA.INS'                                              INGV04     62
      INCLUDE 'CNEXC.INS'                                               INGV04     63
      INCLUDE 'CNSTN.INS'                                               INGV04     64
      INCLUDE 'CNMYVA.INS'                                              INGV04     65
      INCLUDE 'CNYVAR.INS'                                              INGV04     66
      INCLUDE 'CNUNIT.INS'                                              INGV04     67
      INCLUDE 'CNPRGV.INS'                                              INGV04     68
      INCLUDE 'CNMSG.INS'                                               INGV04     69
C                                                                       INGV04     70
      DATA ZERO/0.0/,BIG/99.0/                                          INGV04     71
C                                                                       INGV04     72
*IF LTSP                                                                INGV04     73
*ENDIF                                                                  INGV04     79
C                                                                       INGV04     80
C                                                                       INGV04     81
C   TYPE 4 AND 5                                                        INGV04     82
C                                                                       INGV04     83
      IF(IGVN.EQ.4)THEN                                                 INGV04     84
C                                                                       INGV04     85
C  INPUT TIME CONSTANTS CHECK AND RESET                                 INGV04     86
C                                                                       INGV04     87
         IF(DDAT(JGG+2).LT.TMIN.AND.IDDAT(JGG+2).NE.0)THEN              INGV04     88
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04     89
     *                        ,NDGC(N)                                  INGV04     90
            WRITE(MSG(2),9030) 'T1',DDAT(JGG+2)                         INGV04     91
            IF(MTFLAG.EQ.0) THEN                                        INGV04     92
               WRITE(MSG(3),9040) TMIN                                  INGV04     93
            ELSE                                                        INGV04     94
               WRITE(MSG(3),9040) TMIN,'T1',0.0                         INGV04     95
               DDAT(JGG+2)=0.0                                          INGV04     96
            ENDIF                                                       INGV04     97
            CALL PRTMSG(3)                                              INGV04     98
         ENDIF                                                          INGV04     99
C                                                                       INGV04    100
         IF(DDAT(JGG+4).LT.TMIN)THEN                                    INGV04    101
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04    102
     *                        ,NDGC(N)                                  INGV04    103
            WRITE(MSG(2),9030) 'T3',DDAT(JGG+4)                         INGV04    104
            IF(MTFLAG.EQ.0) THEN                                        INGV04    105
               WRITE(MSG(3),9040) TMIN                                  INGV04    106
            ELSE                                                        INGV04    107
               WRITE(MSG(3),9040) TMIN,'T3',TMIN                        INGV04    108
               DDAT(JGG+3)=TMIN                                         INGV04    109
            ENDIF                                                       INGV04    110
            CALL PRTMSG(3)                                              INGV04    111
         ENDIF                                                          INGV04    112
C                                                                       INGV04    113
         IF(DDAT(JGG+9).LT.TMIN.AND.IDDAT(JGG+9).NE.0)THEN              INGV04    114
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04    115
     *                        ,NDGC(N)                                  INGV04    116
            WRITE(MSG(2),9030) 'T4',DDAT(JGG+9)                         INGV04    117
            IF(MTFLAG.EQ.0) THEN                                        INGV04    118
               WRITE(MSG(3),9040) TMIN                                  INGV04    119
            ELSE                                                        INGV04    120
               WRITE(MSG(3),9040) TMIN,'T4',0.0                         INGV04    121
               DDAT(JGG+9)=0.0                                          INGV04    122
            ENDIF                                                       INGV04    123
            CALL PRTMSG(3)                                              INGV04    124
         ENDIF                                                          INGV04    125
C                                                                       INGV04    126
         IF(DDAT(JGG+10).LT.TMIN.AND.IDDAT(JGG+10).NE.0)THEN            INGV04    127
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04    128
     *                        ,NDGC(N)                                  INGV04    129
            WRITE(MSG(2),9030) 'T5',DDAT(JGG+10)                        INGV04    130
            IF(MTFLAG.EQ.0) THEN                                        INGV04    131
               WRITE(MSG(3),9040) TMIN                                  INGV04    132
            ELSE                                                        INGV04    133
               WRITE(MSG(3),9040) TMIN,'T5',0.0                         INGV04    134
               DDAT(JGG+10)=0.0                                         INGV04    135
            ENDIF                                                       INGV04    136
            CALL PRTMSG(3)                                              INGV04    137
         ENDIF                                                          INGV04    138
C                                                                       INGV04    139
         IF(DDAT(JGG+11).LT.TMIN.AND.IDDAT(JGG+11).NE.0)THEN            INGV04    140
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04    141
     *                        ,NDGC(N)                                  INGV04    142
            WRITE(MSG(2),9030) 'T6',DDAT(JGG+11)                        INGV04    143
            IF(MTFLAG.EQ.0) THEN                                        INGV04    144
               WRITE(MSG(3),9040) TMIN                                  INGV04    145
            ELSE                                                        INGV04    146
               WRITE(MSG(3),9040) TMIN,'T6',0.0                         INGV04    147
               DDAT(JGG+11)=0.0                                         INGV04    148
            ENDIF                                                       INGV04    149
            CALL PRTMSG(3)                                              INGV04    150
         ENDIF                                                          INGV04    151
C                                                                       INGV04    152
         IF(DDAT(JGG+12).LT.TMIN.AND.IDDAT(JGG+12).NE.0)THEN            INGV04    153
            WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)    INGV04    154
     *                        ,NDGC(N)                                  INGV04    155
            WRITE(MSG(2),9030) 'T7',DDAT(JGG+12)                        INGV04    156
            IF(MTFLAG.EQ.0) THEN                                        INGV04    157
               WRITE(MSG(3),9040) TMIN                                  INGV04    158
            ELSE                                                        INGV04    159
               WRITE(MSG(3),9040) TMIN,'T7',0.0                         INGV04    160
               DDAT(JGG+12)=0.0                                         INGV04    161
            ENDIF                                                       INGV04    162
            CALL PRTMSG(3)                                              INGV04    163
         ENDIF                                                          INGV04    164
C                                                                       INGV04    165
       DDAT(JGG+8)=0.0                                                  INGV04    166
       IF(DDAT(JGG+5).GT.9.0)DDAT(JGG+5)=9.0                            INGV04    167
       IF(DDAT(JGG+6).LT.-9.0)DDAT(JGG+6)=-9.0                          INGV04    168
       IF (IDDAT(JGG+5).EQ.0) DDAT(JGG+5)=9.0                           INGV04    169
       IF (IDDAT(JGG+6).EQ.0) DDAT(JGG+6)=-9.0                          INGV04    170
       DO 10 K=1,16                                                     INGV04    171
          IF(DDAT(JGG+K).GT.999.0) DDAT(JGG+K)=999.0                    INGV04    172
  10   CONTINUE                                                         INGV04    173
       KSTATE=7                                                         INGV04    174
C                                                                       INGV04    175
       NP1=N+1                                                          INGV04    176
       IGVNP1=ICONTA(2,NP1)                                             INGV04    177
C                                                                       INGV04    178
       IF (IGVNP1.NE.5 .AND. IGVNP1.NE.35) THEN                         INGV04    179
          BASPRN=DDAT(JG+3)/BASPC                                       INGV04    180
          DDAT(JGG+7)=DDAT(JGG+7)*BASPRN                                INGV04    181
          XINIT=TIN(JYG+1)/DDAT(JGG+7)                                  INGV04    182
          DDAT(JGG+16)=1.0-(DDAT(JGG+13)+DDAT(JGG+14)+DDAT(JGG+15))     INGV04    183
       ELSE                                                             INGV04    184
          JGV5=JCONTA(2,NP1)                                            INGV04    185
          JG5=JCONTA(1,NP1)                                             INGV04    186
          RATIO2=DDAT(JGV5+1)+DDAT(JGV5+2)+DDAT(JGV5+3)                 INGV04    187
          RATIO1=1.0-RATIO2                                             INGV04    188
          DDAT(JGG+16)=RATIO1-(DDAT(JGG+13)+DDAT(JGG+14)+DDAT(JGG+15))  INGV04    189
          DDAT(JGG+7)=DDAT(JGG+7)*BASPRN                                INGV04    190
          XINIT=TIN(JYG+1)/DDAT(JGG+7)                                  INGV04    191
          XINIT=XINIT/RATIO1                                            INGV04    192
          YINIT=XINIT*RATIO2                                            INGV04    193
          DDAT(JGV5+4)=TIN5/YINIT                                       INGV04    194
       ENDIF                                                            INGV04    195
C                                                                       INGV04    196
       DO 300 I=2,6                                                     INGV04    197
 300   XSTATE(JSTATE+I)=XINIT                                           INGV04    198
       XSTATE(JSTATE+1)=0.0                                             INGV04    199
       XSTATE(JSTATE+7)=XINIT                                           INGV04    200
C                                                                       INGV04    201
       IF(XSTATE(JSTATE+2).GT.1.0.OR.XSTATE(JSTATE+2).LT.0.0)THEN       INGV04    202
          WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)      INGV04    203
     *                    ,NDGC(N)                                      INGV04    204
          WRITE(MSG(2),9010) XSTATE(JSTATE+2)                           INGV04    205
          WRITE(MSG(3),9020)                                            INGV04    206
          CALL PRTMSG(3)                                                INGV04    207
       ENDIF                                                            INGV04    208
C                                                                       INGV04    209
       XLDREF(JYP+1)=XSTATE(JSTATE+6)                                   INGV04    210
       CVP(JYP+2)=XSTATE(JSTATE+2)                                      INGV04    211
C       IF (N.LE.NXDG) CVP(JYP+2)=XSTATE(JSTATE+2)                      INGV04    212
      IF(DDAT(JGG+16).LT.-0.0001) THEN                                  INGV04    213
         WRITE(MSG(1),9100) NLF,INAME(KN-2),INAME(KN-1),INAME(KN)       INGV04    214
     *                     ,NDGC(N)                                     INGV04    215
         WRITE(MSG(2),9110) DDAT(JGG+16)                                INGV04    216
         WRITE(MSG(3),9120)                                             INGV04    217
         CALL PRTMSG(3)                                                 INGV04    218
         MSG(1)=                                                        INGV04    219
     *   'INGV04: TYPE 4 GOVERNOR STEAM DISTRIBUTION FACTORS ERROR'     INGV04    220
         CALL ASTOP(MSG(1),56)                                          INGV04    221
      ENDIF                                                             INGV04    222
       JY=JY+2                                                          INGV04    223
*IF LTSP                                                                INGV04    224
*ENDIF                                                                  INGV04    249
C                                                                       INGV04    250
       MSTATE(6,N)=JSTATE+KSTATE                                        INGV04    251
C                                                                       INGV04    252
       IF (IGSTAN.EQ.0) GO TO 360                                       INGV04    253
       MYVAR(6,N)=JY                                                    INGV04    254
       JYPS=JY                                                          INGV04    255
       DDAT(JGS+1)=DDAT(JGS+1)/BASPRN                                   INGV04    256
       IF (DDAT(JGS+5).GT.ZERO.AND.ABS(DDAT(JGS+6)).GT.ZERO)            INGV04    257
     +   GO TO 350                                                      INGV04    258
       DDAT(JGS+5)=BIG                                                  INGV04    259
       DDAT(JGS+6)=-BIG                                                 INGV04    260
 350   CONTINUE                                                         INGV04    261
       PDGN=PDG(JYG+2)                                                  INGV04    262
       JYGNP1=MYVAR(1,N+1)                                              INGV04    263
       IGVN5= ICONTA(2,N+1)                                             INGV04    264
       IF(IGVN.EQ.4.AND.(IGVN5.EQ.5.OR.IGVN5.EQ.35))                    INGV04    265
     *                           PDGN=PDGN+PDG(JYGNP1+2)                INGV04    266
C                                                                       INGV04    267
       KSTATE=KSTATE+1                                                  INGV04    268
       XSTATE(JSTATE+KSTATE)=(PDGN*DDAT(JGS+2)+CVP(JYP+2)*DDAT(JGS+3))* INGV04    269
     +   DDAT(JGS+4)                                                    INGV04    270
       IGNXSN=IDDAT(JS+1)                                               INGV04    271
       XSTATE(IGNXSN)=(PDGN*DDAT(JS+2)+CVP(JYP+2)*DDAT(JS+3))*DDAT(JS+4)INGV04    272
       DDAT(JS+4)=1.0/DDAT(JS+4)                                        INGV04    273
       DDAT(JGS+4)=1.0/DDAT(JGS+4)                                      INGV04    274
       WXBASE=DDAT(JG+5)                                                INGV04    275
       DDAT(JGS+1)=DDAT(JGS+1)/WXBASE                                   INGV04    276
C                                                                       INGV04    277
       GSS(JYPS+1)=0.0                                                  INGV04    278
       JY=JY+1                                                          INGV04    279
 360   CONTINUE                                                         INGV04    280
      ENDIF                                                             INGV04    281
C                                                                       INGV04    282
      IF(IGVN.EQ.5)KSTATE=0                                             INGV04    283
C                                                                       INGV04    284
      JSTATE=JSTATE+KSTATE                                              INGV04    285
C                                                                       INGV04    286
C  UPDATE THE INITIAL VALUE OF THE STATE IN STAB TYPE 7, IF HAPPENED.   INGV04    287
C                                                                       INGV04    288
      IF(ISTABN.EQ.7)THEN                                               INGV04    289
         JSTB7=MSTATE(3,N)+1                                            INGV04    290
         XSTATE(JSTB7)=XSTATE(JSTB7)+DDAT(JS+4)*CVP(JYP+2)              INGV04    291
      ENDIF                                                             INGV04    292
C                                                                       INGV04    293
      RETURN                                                            INGV04    294
C                                                                       INGV04    295
 9000 FORMAT(' *** WARNING GENERATOR AT BUS: ',I5,' STATION: ',3A4      INGV04    296
     *,' GID:',A4)                                                      INGV04    297
 9010 FORMAT(5X,'TYPE 4 (WSCC TYPE GS) GOVERNOR  STATE 2 = ',G12.5      INGV04    298
     *,' EXCEEDS')                                                      INGV04    299
 9020 FORMAT(5X,'ITS LIMITS OF 0.0 AND 1.0')                            INGV04    300
 9030 FORMAT(5X,'TYPE 4 (WSCC TYPE GS) GOVERNOR ',A,'=',F8.6            INGV04    301
     *,' IS BELOW THE LIMIT VALUE')                                     INGV04    302
 9040 FORMAT(5X,'OF',F5.2,:,A,' HAS BEEN SET TO ',F4.2)                 INGV04    303
 9100 FORMAT(' *** DATA ERROR GENERATOR AT BUS: ',I5,' STATION: ',3A4   INGV04    304
     *,' GID:',A4)                                                      INGV04    305
 9110 FORMAT(5X,'TYPE 4 (WSCC TYPE GS) GOVERNOR K5 HAS TURNED OUT'      INGV04    306
     *,' NEGATIVE OF',G13.5)                                            INGV04    307
 9120 FORMAT(5X,'REENTER OTHER K VALUES.')                              INGV04    308
C                                                                       INGV04    309
      END                                                               INGV04    310
