CFPRIME IEGEN                                                           IEGEN       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 IEGEN(IREC,IU,DATA,NCARD,NTHGEN,NEXTG,MGEN,            IEGEN       3
     1                  NB,NM,NGENS,UNITID,BNAME,NBUSN,ERR)             IEGEN       4
CD                                                                      IEGEN       5
CD    TO READ GENERATOR CARDS FROM IEEE FORMAT DYNAMIC DATA.            IEGEN       6
CD                                                                      IEGEN       7
      INCLUDE 'CNUNIT.INS'                                              IEGEN       8
      INCLUDE 'CNMSG.INS'                                               IEGEN       9
*IF -MI2                                                                IEGEN      10
      INTEGER*2 NTHGEN,NEXTG,MGEN,NBUSN                                 IEGEN      11
*ENDIF                                                                  IEGEN      12
      DIMENSION NTHGEN(NB),NEXTG(NM),MGEN(NM),NBUSN(NM)                 IEGEN      13
                                                                        IEGEN      14
      CHARACTER*(*) UNITID(NM)                                          IEGEN      15
      CHARACTER*(*) BNAME(NM)                                           IEGEN      16
      CHARACTER*4 UID                                                   IEGEN      17
                                                                        IEGEN      18
C                                                                       IEGEN      19
      CHARACTER*(*) DATA(NCARD)                                         IEGEN      20
      CHARACTER*12 BUSNAM                                               IEGEN      21
      CHARACTER*80 LINE                                                 IEGEN      22
      LOGICAL ERR                                                       IEGEN      23
                                                                        IEGEN      24
C!   ......................................                             IEGEN      25
C!   : Remove this when connected to SSIMU:                             IEGEN      26
C    : Bus name based low flow flag       :                             IEGEN      27
      KLFO=0                                                            IEGEN      28
C!   :....................................:                             IEGEN      29
C                                                                       IEGEN      30
      IBUSNO=0                                                          IEGEN      31
      ERR=.FALSE.                                                       IEGEN      32
      ISANTY=0                                                          IEGEN      33
      ICMT=0                                                            IEGEN      34
C                                                                       IEGEN      35
C                                                                       IEGEN      36
      CALL GETLIN(IU,LINE)                                              IEGEN      37
      IF (LINE(2:15).NE.'GENERATOR DATA') THEN                          IEGEN      38
        WRITE(MSG(2),3000)                                              IEGEN      39
        WRITE(MSG(1),1000)                                              IEGEN      40
        WRITE(MSG(3),1010) LINE(2:21)                                   IEGEN      41
        CALL PRTMSG(3)                                                  IEGEN      42
        ERR=.TRUE.                                                      IEGEN      43
        GOTO 9999                                                       IEGEN      44
      ENDIF                                                             IEGEN      45
C                                                                       IEGEN      46
   1  CONTINUE                                                          IEGEN      47
      DO 110 I=1,NCARD                                                  IEGEN      48
         CALL GETLIN(IU,LINE)                                           IEGEN      49
         IF (LINE(2:5).EQ.'-999') GOTO 9999                             IEGEN      50
         IF(I.EQ.1) THEN                                                IEGEN      51
C          ....................................................         IEGEN      52
C          :Note: IEEE format uses columns 2 to 4 to store    :         IEGEN      53
C          :      Bus number in an I4 format. However, to     :         IEGEN      54
C          :      support a 5 digit bus numbering system such :         IEGEN      55
C          :      as PTI, the extra digit is expected to be   :         IEGEN      56
C          :      stored in column 1. This is still OK since  :         IEGEN      57
C          :      column 1 is reserved for printer control.   :         IEGEN      58
C          :      Be careful when printing such a file !!!    :         IEGEN      59
c          :                                                  :         IEGEN      60
            READ(LINE(1:5),'(I5)',IOSTAT=IOS)IBUSNO                     IEGEN      61
            IF(IBUSNO.LT.0.OR.IOS.NE.0) GOTO 9990                       IEGEN      62
C          :..................................................:         IEGEN      63
            READ(LINE(7:18),'(A12)',IOSTAT=IOS)BUSNAM                   IEGEN      64
            IF(IOS.NE.0) GOTO 9995                                      IEGEN      65
            READ(LINE(20:23),'(A4)',IOSTAT=IOS)UID                      IEGEN      66
            IF(IOS.NE.0) GOTO 9995                                      IEGEN      67
C          .....................................................        IEGEN      68
C          :BUS NAME BASED LOWFLOW. GET INTERNAL BUS NUMBER    :        IEGEN      69
            IF((KLFO.EQ.4).AND.(BUSNAM.NE.' ')) THEN                    IEGEN      70
               CALL CHKBUS(BUSNAM,IBUSNO)                               IEGEN      71
               IF(IBUSNO.LT.0) THEN                                     IEGEN      72
                  WRITE(MSG(1),3090) BUSNAM                             IEGEN      73
                  CALL PRTMSG(1)                                        IEGEN      74
                  ERR=.TRUE.                                            IEGEN      75
                  GOTO 9999                                             IEGEN      76
               ENDIF                                                    IEGEN      77
            ENDIF                                                       IEGEN      78
C          :....................................................:       IEGEN      79
         ENDIF                                                          IEGEN      80
         IF (LINE(2:16) .EQ. 'EXCITATION DATA') THEN                    IEGEN      81
            WRITE(MSG(2),3020)                                          IEGEN      82
            WRITE(MSG(1),1000)                                          IEGEN      83
            WRITE(MSG(3),1010) LINE(2:16)                               IEGEN      84
            CALL PRTMSG(3)                                              IEGEN      85
            ERR=.TRUE.                                                  IEGEN      86
            GOTO 9997                                                   IEGEN      87
         ENDIF                                                          IEGEN      88
         ICMT=ICMT+1                                                    IEGEN      89
         DATA(ICMT)=LINE                                                IEGEN      90
 110  CONTINUE                                                          IEGEN      91
C                                                                       IEGEN      92
      ISANTY=ISANTY+ICMT                                                IEGEN      93
      IREC=IREC+1                                                       IEGEN      94
      ISTREC=IREC                                                       IEGEN      95
      WRITE(IU31,REC=IREC) DATA(1), DATA(2)                             IEGEN      96
      IREC=IREC+1                                                       IEGEN      97
      WRITE(IU31,REC=IREC) DATA(3), DATA(4)                             IEGEN      98
      IREC=IREC+1                                                       IEGEN      99
      WRITE(IU31,REC=IREC) DATA(5)                                      IEGEN     100
C    ....................................                               IEGEN     101
C    :SET UP NTHGEN/NEXTG/MGEN ARRAY    :                               IEGEN     102
C    :                                  :                               IEGEN     103
      ITHGEN=NTHGEN(IBUSNO)                                             IEGEN     104
      IF(ITHGEN.EQ.0) THEN                                              IEGEN     105
         NGENS=NGENS+1                                                  IEGEN     106
         IF(NGENS.GT.NM)THEN                                            IEGEN     107
           WRITE(MSG(1),3100)                                           IEGEN     108
           WRITE(MSG(2),3200)IBUSNO,BUSNAM,UID                          IEGEN     109
           CALL PRTMSG(2)                                               IEGEN     110
           MSG(1)='IEGEN: TOO MANY GENERATORS'                          IEGEN     111
           CALL ASTOP (MSG(1),26)                                       IEGEN     112
         ENDIF                                                          IEGEN     113
         NTHGEN(IBUSNO)=NGENS                                           IEGEN     114
         MGEN(NGENS)=ISTREC                                             IEGEN     115
         UNITID(NGENS)=UID                                              IEGEN     116
         BNAME(NGENS)=BUSNAM                                            IEGEN     117
         NBUSN(NGENS)=(IBUSNO)                                          IEGEN     118
      ELSE                                                              IEGEN     119
 120     CONTINUE                                                       IEGEN     120
         KTHGEN=NEXTG(ITHGEN)                                           IEGEN     121
         IF(KTHGEN.EQ.0) THEN                                           IEGEN     122
            NGENS=NGENS+1                                               IEGEN     123
            IF(NGENS.GT.NM)THEN                                         IEGEN     124
              WRITE(MSG(1),3100)                                        IEGEN     125
              WRITE(MSG(2),3200)IBUSNO,BUSNAM,UID                       IEGEN     126
              CALL PRTMSG(2)                                            IEGEN     127
              MSG(1)='IEGEN: TOO MANY GENERATORS'                       IEGEN     128
              CALL ASTOP (MSG(1),26)                                    IEGEN     129
            ENDIF                                                       IEGEN     130
            NEXTG(ITHGEN)=NGENS                                         IEGEN     131
            MGEN(NGENS)=ISTREC                                          IEGEN     132
            UNITID(NGENS)=UID                                           IEGEN     133
            BNAME(NGENS)=BUSNAM                                         IEGEN     134
            NBUSN(NGENS)=(IBUSNO)                                       IEGEN     135
         ELSE                                                           IEGEN     136
            ITHGEN=NEXTG(ITHGEN)                                        IEGEN     137
            GOTO 120                                                    IEGEN     138
         ENDIF                                                          IEGEN     139
      ENDIF                                                             IEGEN     140
C    :...................................:                              IEGEN     141
      GOTO 1                                                            IEGEN     142
C                                                                       IEGEN     143
 9990 CONTINUE                                                          IEGEN     144
      WRITE(MSG(1),3050)                                                IEGEN     145
      MSG(2)=LINE                                                       IEGEN     146
      CALL PRTMSG(2)                                                    IEGEN     147
      ERR=.TRUE.                                                        IEGEN     148
      GOTO 9999                                                         IEGEN     149
 9995 CONTINUE                                                          IEGEN     150
      WRITE(MSG(1),3060)                                                IEGEN     151
      MSG(2)=LINE                                                       IEGEN     152
      CALL PRTMSG(2)                                                    IEGEN     153
      ERR=.TRUE.                                                        IEGEN     154
      GOTO 9999                                                         IEGEN     155
 9997 CONTINUE                                                          IEGEN     156
      WRITE(MSG(1),3080)                                                IEGEN     157
      CALL PRTMSG(1)                                                    IEGEN     158
      ERR=.TRUE.                                                        IEGEN     159
 9999 CONTINUE                                                          IEGEN     160
      ICHECK=MOD(ISANTY,NCARD)                                          IEGEN     161
      IF(ICHECK.NE.0)THEN                                               IEGEN     162
         WRITE(MSG(1),3070) ISANTY                                      IEGEN     163
         CALL PRTMSG(1)                                                 IEGEN     164
      ENDIF                                                             IEGEN     165
      RETURN                                                            IEGEN     166
C                                                                       IEGEN     167
 1000 FORMAT(' *** ERROR READING IEEE FORMAT GENNERATOR DATA CARDS.')   IEGEN     168
 1010 FORMAT(11X,'DATA READ IN IS: ',A)                                 IEGEN     169
 3000 FORMAT(11X,'EXPECTING  "GENERATOR DATA" IN COLUMNS 2 TO 15.')     IEGEN     170
 3020 FORMAT(11X,'EXPECTING  "-999" TO END COMMENTS')                   IEGEN     171
 3050 FORMAT(' *** ERROR READING BUS NUMBER OF THIS DATA LINE:')        IEGEN     172
 3060 FORMAT(                                                           IEGEN     173
     *' *** ERROR READING BUS NAME OR UNIT ID OF THIS DATA LINE:')      IEGEN     174
 3070 FORMAT(' *** ERROR MACHINE DATA CARD ERROR. READ IN ',I6          IEGEN     175
     *,' CARDS.')                                                       IEGEN     176
 3080 FORMAT(' *** WARNING "-999" CARD MISSING FOR MACHINE DATA BLOCK') IEGEN     177
 3090 FORMAT(' *** PROBLEM WITH THIS BUS NAME : ',A12)                  IEGEN     178
 3100 FORMAT(' *** ERROR - NUMBER OF GENERATORS EXCEEDS THE MAXIMUM ')  IEGEN     179
 3200 FORMAT('     AT GENERATOR ON BUS ',I6, ' STATION: ',A12,          IEGEN     180
     +       ' GID: ',A4)                                               IEGEN     181
      END                                                               IEGEN     182
                                                                        IEGEN     183
