CFPRIME INGV21                                                          INGV21      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 INGV21                                                 INGV21      3
CD                                                                      INGV21      4
CD    TO PERFORM INITIALIZATION AND DATA CHECK FOR GOVERNOR TYPE 21.    INGV21      5
CD                                                                      INGV21      6
CD    THE DATA STRUCTURE AFTER THE INITIALIZATION IS GIVEN BELOW.       INGV21      7
CD                                                                      INGV21      8
CD   9.8 Hydraulic turbine-governor type 21                             INGV21      9
CD                                                                      INGV21     10
CD     Governor data                                                    INGV21     11
CD                                                                      INGV21     12
CD     DDAT(JGG+ 1)   = PMAX                                            INGV21     13
CD     DDAT(JGG+ 2)   = R                                               INGV21     14
CD     DDAT(JGG+ 3)   = TG                                              INGV21     15
CD     DDAT(JGG+ 4)   = TP                                              INGV21     16
CD     DDAT(JGG+ 5)   = TD                                              INGV21     17
CD     DDAT(JGG+ 6)   = DD                                              INGV21     18
CD     DDAT(JGG+ 7)   = GMAX                                            INGV21     19
CD     DDAT(JGG+ 8)   = GMIN                                            INGV21     20
CD     DDAT(JGG+ 9)   = TW                                              INGV21     21
CD     DDAT(JGG+10)   = VELO                                            INGV21     22
CD     DDAT(JGG+11)   = VELC                                            INGV21     23
CD                                                                      INGV21     24
CD     Governor states                                                  INGV21     25
CD                                                                      INGV21     26
CD     XSTATE(JPS+1)  = TP block                    : compulsory        INGV21     27
CD     XSTATE(JPS+2)  = integrator block            : compulsory        INGV21     28
CD     XSTATE(JPS+3)  = TD block                    : compulsory        INGV21     29
CD     XSTATE(JPS+4)  = TW block                    : compulsory        INGV21     30
CD                                                                      INGV21     31
CD     Governor Y-variables                                             INGV21     32
CD                                                                      INGV21     33
CD     XLDREF(JYP+1)  = load reference signal                           INGV21     34
CD                                                                      INGV21     35
      INCLUDE 'PARX.INS'                                                INGV21     36
      INCLUDE 'CNB1.INS'                                                INGV21     37
      INCLUDE 'CNB3.INS'                                                INGV21     38
      INCLUDE 'CNB4.INS'                                                INGV21     39
      INCLUDE 'CNB19.INS'                                               INGV21     40
      INCLUDE 'CNXSTA.INS'                                              INGV21     41
      INCLUDE 'CNMDAT.INS'                                              INGV21     42
      INCLUDE 'CNMSTA.INS'                                              INGV21     43
      INCLUDE 'CNEXC.INS'                                               INGV21     44
      INCLUDE 'CNSTN.INS'                                               INGV21     45
      INCLUDE 'CNMYVA.INS'                                              INGV21     46
      INCLUDE 'CNYVAR.INS'                                              INGV21     47
      INCLUDE 'CNPRGV.INS'                                              INGV21     48
      INCLUDE 'CNUNIT.INS'                                              INGV21     49
      INCLUDE 'CNMSG.INS'                                               INGV21     50
C                                                                       INGV21     51
C  INPUT TIME CONSTANTS CHECK AND RESET                                 INGV21     52
C                                                                       INGV21     53
      IF(DDAT(JGG+4).LT.TMIN.AND.IDDAT(JGG+4).NE.0)THEN                 INGV21     54
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21     55
     *    INAME(KN),NDGC(N)                                             INGV21     56
         WRITE(MSG(2),9020) 'TP',DDAT(JGG+4)                            INGV21     57
         IF(MTFLAG.EQ.0) THEN                                           INGV21     58
            WRITE(MSG(3),9030) TMIN                                     INGV21     59
         ELSE                                                           INGV21     60
            WRITE(MSG(3),9030) TMIN,'TP',0.0                            INGV21     61
            DDAT(JGG+4)=0.0                                             INGV21     62
         ENDIF                                                          INGV21     63
         CALL PRTMSG(3)                                                 INGV21     64
      ENDIF                                                             INGV21     65
C                                                                       INGV21     66
      IF(IDDAT(JGG+5).EQ.0)THEN                                         INGV21     67
         WRITE(MSG(1),9010) NLF,INAME(KN-2),INAME(KN-1),                INGV21     68
     *    INAME(KN),NDGC(N)                                             INGV21     69
         WRITE(MSG(2),9021) 'TD',DDAT(JGG+5)                            INGV21     70
         CALL PRTMSG(2)                                                 INGV21     71
         MSG(1)='GOVERNOR DATA ERROR'                                   INGV21     72
         CALL ASTOP(MSG(1),19)                                          INGV21     73
      ELSEIF(DDAT(JGG+5).LT.TMIN)THEN                                   INGV21     74
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21     75
     *    INAME(KN),NDGC(N)                                             INGV21     76
         WRITE(MSG(2),9020) 'TD',DDAT(JGG+5)                            INGV21     77
         IF(MTFLAG.EQ.0) THEN                                           INGV21     78
            WRITE(MSG(3),9030) TMIN                                     INGV21     79
         ELSE                                                           INGV21     80
            WRITE(MSG(3),9030) TMIN,'TD',TMIN,DDAT(JGG+6)               INGV21     81
     *                     ,DDAT(JGG+6)*DDAT(JGG+5)/TMIN                INGV21     82
            DDAT(JGG+6)=DDAT(JGG+6)*DDAT(JGG+5)/TMIN                    INGV21     83
            DDAT(JGG+5)=TMIN                                            INGV21     84
         ENDIF                                                          INGV21     85
         CALL PRTMSG(3)                                                 INGV21     86
      ENDIF                                                             INGV21     87
C                                                                       INGV21     88
      IF(DDAT(JGG+9)/2.0.LT.TMIN.AND.IDDAT(JGG+9).NE.0)THEN             INGV21     89
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21     90
     *    INAME(KN),NDGC(N)                                             INGV21     91
         WRITE(MSG(2),9020) 'TW/2',DDAT(JGG+9)/2.0                      INGV21     92
         IF(MTFLAG.EQ.0) THEN                                           INGV21     93
            WRITE(MSG(3),9030) TMIN                                     INGV21     94
         ELSE                                                           INGV21     95
            WRITE(MSG(3),9030) TMIN,'TW',2.0*TMIN                       INGV21     96
            DDAT(JGG+9)=2.0*TMIN                                        INGV21     97
         ENDIF                                                          INGV21     98
         CALL PRTMSG(3)                                                 INGV21     99
      ENDIF                                                             INGV21    100
C                                                                       INGV21    101
C     WSCC - EPRI TYPE "H" HYDRO GOVERNOR                               INGV21    102
C                                                                       INGV21    103
      IF (IDDAT(JGG+7).EQ.0) DDAT(JGG+7)=1.0                            INGV21    104
      BASPRN=DDAT(JG+3)/BASPC                                           INGV21    105
      DDAT(JGG+1)=DDAT(JGG+1)*BASPRN                                    INGV21    106
      KSTATE=4                                                          INGV21    107
C                                                                       INGV21    108
C     INITIALIZE THE STATE VARIABLES                                    INGV21    109
C                                                                       INGV21    110
      XSTATE(JSTATE+4)=TIN(JYG+1)/DDAT(JGG+1)                           INGV21    111
      XSTATE(JSTATE+2)=XSTATE(JSTATE+4)                                 INGV21    112
      XSTATE(JSTATE+3)=XSTATE(JSTATE+2)*DDAT(JGG+5)                     INGV21    113
      XSTATE(JSTATE+1)=0.0                                              INGV21    114
C                                                                       INGV21    115
C     DERIVE THE REFERENCE SIGNAL                                       INGV21    116
C                                                                       INGV21    117
      XLDREF(JYP+1)=DDAT(JGG+2)*XSTATE(JSTATE+2)                        INGV21    118
C                                                                       INGV21    119
C     PRINT INITIAL CONDITIONS                                          INGV21    120
C                                                                       INGV21    121
C     CHANGE THE SIGNS OF "VEL.CLOSE" TO IMPROVE EXECUTION SPEED        INGV21    122
C                                                                       INGV21    123
      DDAT(JGG+11)=-ABS(DDAT(JGG+11))                                   INGV21    124
C                                                                       INGV21    125
C     INITIAL CONDITION CHECK                                           INGV21    126
C                                                                       INGV21    127
      IF (XSTATE(JSTATE+1).GT.DDAT(JGG+10)) THEN                        INGV21    128
         KX=1                                                           INGV21    129
         XMAX=DDAT(JGG+10)                                              INGV21    130
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21    131
     *    INAME(KN),NDGC(N)                                             INGV21    132
         WRITE(MSG(2),9100)                                             INGV21    133
         WRITE(MSG(3),9110) KX,XSTATE(JSTATE+KX),XMAX                   INGV21    134
         CALL PRTMSG(3)                                                 INGV21    135
      ENDIF                                                             INGV21    136
      IF (XSTATE(JSTATE+1).LT.DDAT(JGG+11)) THEN                        INGV21    137
         KX=1                                                           INGV21    138
         XMIN=DDAT(JGG+11)                                              INGV21    139
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21    140
     *    INAME(KN),NDGC(N)                                             INGV21    141
         WRITE(MSG(2),9200)                                             INGV21    142
         WRITE(MSG(3),9110) KX,XSTATE(JSTATE+KX),XMIN                   INGV21    143
         CALL PRTMSG(3)                                                 INGV21    144
      ENDIF                                                             INGV21    145
C                                                                       INGV21    146
      IF (XSTATE(JSTATE+2).GT.DDAT(JGG+7)) THEN                         INGV21    147
         KX=2                                                           INGV21    148
         XMAX=DDAT(JGG+7)                                               INGV21    149
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21    150
     *    INAME(KN),NDGC(N)                                             INGV21    151
         WRITE(MSG(2),9100)                                             INGV21    152
         WRITE(MSG(3),9110) KX,XSTATE(JSTATE+KX),XMAX                   INGV21    153
         CALL PRTMSG(3)                                                 INGV21    154
      ENDIF                                                             INGV21    155
      IF (XSTATE(JSTATE+2).LT.DDAT(JGG+8)) THEN                         INGV21    156
         KX=2                                                           INGV21    157
         XMIN=DDAT(JGG+8)                                               INGV21    158
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),                INGV21    159
     *    INAME(KN),NDGC(N)                                             INGV21    160
         WRITE(MSG(2),9200)                                             INGV21    161
         WRITE(MSG(3),9110) KX,XSTATE(JSTATE+KX),XMIN                   INGV21    162
         CALL PRTMSG(3)                                                 INGV21    163
      ENDIF                                                             INGV21    164
C                                                                       INGV21    165
C     SET STATE POINTER                                                 INGV21    166
C                                                                       INGV21    167
      JSTATE=JSTATE+KSTATE                                              INGV21    168
      MSTATE(6,N)=JSTATE                                                INGV21    169
C                                                                       INGV21    170
      JY=JY+1                                                           INGV21    171
      RETURN                                                            INGV21    172
C                                                                       INGV21    173
 9000 FORMAT(' *** WARNING GENERATOR AT BUS: ',I5,' STATION: ',3A4      INGV21    174
     *,' GID:',A4)                                                      INGV21    175
 9010 FORMAT(' *** ERROR GENERATOR AT BUS: ',I5,' STATION: ',3A4        INGV21    176
     *,' GID:',A4)                                                      INGV21    177
 9020 FORMAT(5X,'TYPE 21 (WSCC TYPE GH) GOVERNOR ',A,'=',F8.6           INGV21    178
     *,' IS BELOW THE LIMIT VALUE')                                     INGV21    179
 9021 FORMAT(5X,'TYPE 21 (WSCC TYPE GH) GOVERNOR ',A,'=',F8.6)          INGV21    180
 9030 FORMAT(5X,'OF',F5.2,'. ',:,A,' HAS BEEN SET TO ',F4.2,:           INGV21    181
     *,' AND DD =',F8.3,' SET TO ',F8.3)                                INGV21    182
 9100 FORMAT(5X,'TYPE 21 (WSCC TYPE GH) GOVERNOR INITIAL CONDITION'     INGV21    183
     *,' VIOLATES UPPER LIMIT:')                                        INGV21    184
 9110 FORMAT(5X,'STATE NO =',I3,' STATE =',G12.5,' LIMIT =',G12.5)      INGV21    185
 9200 FORMAT(5X,'TYPE 21 (WSCC TYPE GH) GOVERNOR INITIAL CONDITION'     INGV21    186
     *,' VIOLATES LOWER LIMIT:')                                        INGV21    187
C                                                                       INGV21    188
      END                                                               INGV21    189
