CFPRIME ADFGEN                                                          ADFGEN      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 ADFGEN(IFIND,J,NOENTY,NLF,IMAC,LFNBUS,CCT,INTNUM)      ADFGEN      3
C                                                                       ADFGEN      4
CD     THIS SUBROUTINE CAN                                              ADFGEN      5
CD       1. ADD A GENERATOR TO THE LIST OF GENERATORS                   ADFGEN      6
CD       2. FIND A GENERATOR IN THE LIST OF GENERATORS                  ADFGEN      7
C                                                                       ADFGEN      8
C     IF IFIND = 1  FIND THE SPECIFIED BUS                              ADFGEN      9
C              = 0   ADD THE SPECIFIED BUS                              ADFGEN     10
C                                                                       ADFGEN     11
      INCLUDE 'PARX.INS'                                                ADFGEN     12
      INCLUDE 'CNMSG.INS'                                               ADFGEN     13
C                                                                       ADFGEN     14
      CHARACTER*2 IMAC                                                  ADFGEN     15
      CHARACTER*2 CCT(*)                                                ADFGEN     16
      DIMENSION   LFNBUS(*),INTNUM(*)                                   ADFGEN     17
C                                                                       ADFGEN     18
      ILARGE=NOENTY+1                                                   ADFGEN     19
      ISMALL=0                                                          ADFGEN     20
C                                                                       ADFGEN     21
  50  CONTINUE                                                          ADFGEN     22
      J=(ILARGE+ISMALL)/2                                               ADFGEN     23
      IF(J.EQ.ISMALL)GOTO 90                                            ADFGEN     24
C                                                                       ADFGEN     25
      K=INTNUM(J)                                                       ADFGEN     26
      IF(LFNBUS(K).LT.NLF) GOTO 70                                      ADFGEN     27
      IF(LFNBUS(K).EQ.NLF)THEN                                          ADFGEN     28
         IF(CCT(K).LT.IMAC) GOTO 70                                     ADFGEN     29
         IF(CCT(K).EQ.IMAC)THEN                                         ADFGEN     30
            IF(IFIND.EQ.1)RETURN                                        ADFGEN     31
C            J=-J                                                       ADFGEN     32
            RETURN                                                      ADFGEN     33
         ENDIF                                                          ADFGEN     34
      ENDIF                                                             ADFGEN     35
  60  ILARGE=J                                                          ADFGEN     36
      GOTO 50                                                           ADFGEN     37
  70  ISMALL=J                                                          ADFGEN     38
      GOTO 50                                                           ADFGEN     39
C                                                                       ADFGEN     40
  90  CONTINUE                                                          ADFGEN     41
      J=-ILARGE                                                         ADFGEN     42
      IF(IFIND.EQ.1) RETURN                                             ADFGEN     43
      DO 100 I=NOENTY,ILARGE,-1                                         ADFGEN     44
      INTNUM(I+1)=INTNUM(I)                                             ADFGEN     45
 100  CONTINUE                                                          ADFGEN     46
C                                                                       ADFGEN     47
      IF(NOENTY.GE.NB/3)THEN                                            ADFGEN     48
        WRITE(MSG(1),1000) NB/3                                         ADFGEN     49
        WRITE(MSG(2),1100) NLF,IMAC                                     ADFGEN     50
        CALL PRTMSG(2)                                                  ADFGEN     51
        MSG(1)='ADFGEN: TOO MANY GENERATORS IN LOADFLOW.'               ADFGEN     52
        CALL ASTOP (MSG(1),40)                                          ADFGEN     53
      ENDIF                                                             ADFGEN     54
C                                                                       ADFGEN     55
      NOENTY=NOENTY+1                                                   ADFGEN     56
      INTNUM(ILARGE)=NOENTY                                             ADFGEN     57
      LFNBUS(NOENTY)=NLF                                                ADFGEN     58
      CCT(NOENTY)=IMAC                                                  ADFGEN     59
C                                                                       ADFGEN     60
 1000 FORMAT (' *** ERROR - NUMBER OF GENERATORS EXCEEDS ',I5)          ADFGEN     61
 1100 FORMAT ('     AT GENERATOR ON BUS ',I6, 'GID: ',A2)               ADFGEN     62
C                                                                       ADFGEN     63
      RETURN                                                            ADFGEN     64
      END                                                               ADFGEN     65
