CFPRIME IEGOV                                                           IEGOV       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 IEGOV(IREC,IU,DA,NCARD,NTHGEN,NEXTG,MGEN,MGOV,NB,NM,   IEGOV       3
     1                 UNITID,ERR)                                      IEGOV       4
CD                                                                      IEGOV       5
CD    TO READ GOVERNOR CARDS FROM IEEE FORMAT DYNAMIC DATA.             IEGOV       6
CD                                                                      IEGOV       7
      INCLUDE 'CNUNIT.INS'                                              IEGOV       8
      INCLUDE 'CNMSG.INS'                                               IEGOV       9
*IF -MI2                                                                IEGOV      10
      INTEGER*2 NTHGEN,NEXTG,MGEN,MGOV                                  IEGOV      11
*ENDIF                                                                  IEGOV      12
      DIMENSION NTHGEN(NB),NEXTG(NM),MGEN(NM),MGOV(NM)                  IEGOV      13
                                                                        IEGOV      14
      CHARACTER*(*) DA(NCARD)                                           IEGOV      15
      CHARACTER*(*) UNITID(NM)                                          IEGOV      16
      CHARACTER*4 UID,ULP                                               IEGOV      17
      CHARACTER*80 LINE                                                 IEGOV      18
      CHARACTER*12 BUSNAM,BUSLP                                         IEGOV      19
C                                                                       IEGOV      20
      LOGICAL ERR                                                       IEGOV      21
C                                                                       IEGOV      22
      IBUSNO=0                                                          IEGOV      23
      IBUSLP=0                                                          IEGOV      24
      ERR=.FALSE.                                                       IEGOV      25
      ICMT=0                                                            IEGOV      26
      ISANTY=0                                                          IEGOV      27
C                                                                       IEGOV      28
      CALL GETLIN(IU,LINE)                                              IEGOV      29
      IF (LINE(2:20).NE.'SPEED GOVERNOR DATA') THEN                     IEGOV      30
        WRITE(MSG(1),1000)                                              IEGOV      31
        WRITE(MSG(3),1010) LINE(2:16)                                   IEGOV      32
        WRITE(MSG(2),3000)                                              IEGOV      33
        CALL PRTMSG(3)                                                  IEGOV      34
        ERR=.TRUE.                                                      IEGOV      35
        GOTO 9999                                                       IEGOV      36
      ENDIF                                                             IEGOV      37
C                                                                       IEGOV      38
   1  CONTINUE                                                          IEGOV      39
      IGVTYP=1                                                          IEGOV      40
      DO 110 I=1,NCARD                                                  IEGOV      41
        IF((I.EQ.4).AND.(IGVTYP.EQ.3)) THEN                             IEGOV      42
C          : GOVERNOR TYPE 3 ONLY NEEDS 3 CARDS:                        IEGOV      43
           ICMT=ICMT+1                                                  IEGOV      44
           DA(ICMT)=' '                                                 IEGOV      45
           GOTO 115                                                     IEGOV      46
        ENDIF                                                           IEGOV      47
        CALL GETLIN(IU,LINE)                                            IEGOV      48
        IF(LINE(2:5).EQ.'-999') GOTO 9999                               IEGOV      49
        IF(I.EQ.1) THEN                                                 IEGOV      50
            READ(LINE(1:5),'(I5)',IOSTAT=IOS)IBUSNO                     IEGOV      51
            IF(IBUSNO.LE.0.OR.IOS.NE.0) GOTO 9990                       IEGOV      52
            READ(LINE(7:18),'(A12)',IOSTAT=IOS)BUSNAM                   IEGOV      53
            IF(IOS.NE.0) GOTO 9995                                      IEGOV      54
            READ(LINE(20:23),'(A4)',IOSTAT=IOS)UID                      IEGOV      55
            IF(IOS.NE.0) GOTO 9995                                      IEGOV      56
            READ(LINE(25:26),'(I2)',IOSTAT=IOS)IGVTYP                   IEGOV      57
            IF(IOS.NE.0) GOTO 9995                                      IEGOV      58
            READ(LINE(27:31),'(I5)',IOSTAT=IOS)IBUSLP                   IEGOV      59
            IF(IOS.NE.0) GOTO 9990                                      IEGOV      60
            READ(LINE(33:44),'(A12)',IOSTAT=IOS)BUSLP                   IEGOV      61
            IF(IOS.NE.0) GOTO 9995                                      IEGOV      62
            READ(LINE(46:49),'(A4)',IOSTAT=IOS)ULP                      IEGOV      63
            IF(IOS.NE.0) GOTO 9995                                      IEGOV      64
        ENDIF                                                           IEGOV      65
        IF (LINE(2:10) .EQ. 'LOAD DATA') THEN                           IEGOV      66
            WRITE(MSG(3),1010) LINE(2:16)                               IEGOV      67
            WRITE(MSG(1),1000)                                          IEGOV      68
            WRITE(MSG(2),3020)                                          IEGOV      69
            CALL PRTMSG(3)                                              IEGOV      70
            ERR=.TRUE.                                                  IEGOV      71
            GOTO 9997                                                   IEGOV      72
        ENDIF                                                           IEGOV      73
        ICMT=ICMT+1                                                     IEGOV      74
        DA(ICMT)=LINE                                                   IEGOV      75
 110  CONTINUE                                                          IEGOV      76
C                                                                       IEGOV      77
 115  ISANTY=ISANTY+ICMT                                                IEGOV      78
      IREC=IREC+1                                                       IEGOV      79
      ISTREC=IREC                                                       IEGOV      80
      WRITE(IU31,REC=IREC)DA(1), DA(2)                                  IEGOV      81
      IREC=IREC+1                                                       IEGOV      82
      WRITE(IU31,REC=IREC)DA(3), DA(4)                                  IEGOV      83
C    ...............................................................    IEGOV      84
C    :SET UP MGOV() POINTERS                                       :    IEGOV      85
C    :                                                             :    IEGOV      86
      ITHGEN=NTHGEN(IBUSNO)                                             IEGOV      87
      IF(ITHGEN.NE.0) THEN                                              IEGOV      88
C        :YES there is a generator at this bus:                         IEGOV      89
 140     CONTINUE                                                       IEGOV      90
         IF(UID.EQ.UNITID(ITHGEN)) THEN                                 IEGOV      91
C           :id matched :                                               IEGOV      92
            MGOV(ITHGEN)=ISTREC                                         IEGOV      93
         ELSE                                                           IEGOV      94
C           :generator id not match, see if there is another:           IEGOV      95
C           :generator on the same bus                      :           IEGOV      96
            ITHGEN=NEXTG(ITHGEN)                                        IEGOV      97
            IF(ITHGEN.NE.0) GOTO 140                                    IEGOV      98
            WRITE(MSG(1),5115) IBUSNO                                   IEGOV      99
            CALL PRTMSG(1)                                              IEGOV     100
         ENDIF                                                          IEGOV     101
      ELSE                                                              IEGOV     102
         WRITE(MSG(1),5100) IBUSNO                                      IEGOV     103
         CALL PRTMSG(1)                                                 IEGOV     104
      ENDIF                                                             IEGOV     105
C                                                                       IEGOV     106
C    FOR CROSS COMPOUND STORE POINTER FOR LP STAGE                      IEGOV     107
C                                                                       IEGOV     108
      IF(IGVTYP.EQ.1 .AND. IBUSLP.NE.0) THEN                            IEGOV     109
      MTHGEN=NTHGEN(IBUSLP)                                             IEGOV     110
      IF(MTHGEN.NE.0) THEN                                              IEGOV     111
C        :YES there is a generator at this bus:                         IEGOV     112
 150     CONTINUE                                                       IEGOV     113
         IF(ULP.EQ.UNITID(MTHGEN)) THEN                                 IEGOV     114
C           :id matched :                                               IEGOV     115
            MGOV(MTHGEN)=ISTREC                                         IEGOV     116
         ELSE                                                           IEGOV     117
C           :generator id not match, see if there is another:           IEGOV     118
C           :generator on the same bus                      :           IEGOV     119
            MTHGEN=NEXTG(MTHGEN)                                        IEGOV     120
            IF(MTHGEN.NE.0) GOTO 150                                    IEGOV     121
            MGOV(ITHGEN)=0                                              IEGOV     122
            WRITE(MSG(1),5215) IBUSLP                                   IEGOV     123
            WRITE(MSG(2),5220)                                          IEGOV     124
            CALL PRTMSG(2)                                              IEGOV     125
         ENDIF                                                          IEGOV     126
      ELSE                                                              IEGOV     127
C                                                                       IEGOV     128
C SET HP GOV TO ZERO                                                    IEGOV     129
C                                                                       IEGOV     130
         MGOV(ITHGEN)=0                                                 IEGOV     131
         WRITE(MSG(1),5200) IBUSLP                                      IEGOV     132
         CALL PRTMSG(1)                                                 IEGOV     133
      ENDIF                                                             IEGOV     134
      ENDIF                                                             IEGOV     135
C    :.............................................................:    IEGOV     136
      GOTO 1                                                            IEGOV     137
C                                                                       IEGOV     138
 9990 CONTINUE                                                          IEGOV     139
      WRITE(MSG(1),3050)                                                IEGOV     140
      MSG(2)=LINE                                                       IEGOV     141
      CALL PRTMSG(2)                                                    IEGOV     142
      ERR=.TRUE.                                                        IEGOV     143
      GOTO 9999                                                         IEGOV     144
 9995 CONTINUE                                                          IEGOV     145
      WRITE(MSG(1),3060)                                                IEGOV     146
      MSG(2)=LINE                                                       IEGOV     147
      CALL PRTMSG(2)                                                    IEGOV     148
      ERR=.TRUE.                                                        IEGOV     149
      GOTO 9999                                                         IEGOV     150
 9997 CONTINUE                                                          IEGOV     151
      WRITE(MSG(1),3080)                                                IEGOV     152
      CALL PRTMSG(1)                                                    IEGOV     153
      ERR=.TRUE.                                                        IEGOV     154
      GOTO 9999                                                         IEGOV     155
                                                                        IEGOV     156
 9999 CONTINUE                                                          IEGOV     157
C      ICHECK=MOD(ISANTY,NCARD)                                         IEGOV     158
C      IF(ICHECK.NE.0) WRITE(IU16,3070) ISANTY                          IEGOV     159
      RETURN                                                            IEGOV     160
C                                                                       IEGOV     161
 1000 FORMAT(' *** ERROR READING IEEE FORMAT GOVERNOR DATA CARDS.')     IEGOV     162
 1010 FORMAT(11X,'DATA READ IN IS: ',A)                                 IEGOV     163
 3000 FORMAT(11X                                                        IEGOV     164
     *,'EXPECTING  "SPEED GOVERBNOR DATA" IN COLUMNS 2 TO 20.')         IEGOV     165
 3020 FORMAT(11X,'EXPECTING  "-999" TO END GOVERNORS')                  IEGOV     166
 3050 FORMAT(' *** ERROR READING BUS NUMBER OF THIS DATA LINE:')        IEGOV     167
 3060 FORMAT(' *** ERROR READING BUS NAME OF THIS DATA LINE:')          IEGOV     168
 3070 FORMAT(' *** ERROR READ IN',I7,' GOVERNOR CARDS.')                IEGOV     169
 3080 FORMAT(' *** ERROR "-999" CARD MISSING FOR GOV DATA BLOCK')       IEGOV     170
 5115 FORMAT(                                                           IEGOV     171
     *' *** WARNING CAN NOT MATCH GOVERNOR WITH GENERATOR AT BUS:',I6)  IEGOV     172
 5215 FORMAT(' *** WARNING CAN NOT MATCH LP STAGE GOVERNOR ',           IEGOV     173
     +       'WITH GENERATOR AT BUS:',I6)                               IEGOV     174
 5220 FORMAT('     THE GOVERNOR IS IGNORED')                            IEGOV     175
 5100 FORMAT(' *** WARNING NO GENERATOR AT BUS:',I6                     IEGOV     176
     *,' THE GOVERNOR IS IGNORED.')                                     IEGOV     177
 5200 FORMAT(' *** WARNING NO GENERATOR AT LP STAGE BUS:',I6            IEGOV     178
     *,' THE GOVERNOR IS IGNORED.')                                     IEGOV     179
      END                                                               IEGOV     180
