CFPRIME AMEL1                                                           AMEL1       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 AMEL1(ISTATE,MD,XAD)                                   AMEL1       3
CD                                                                      AMEL1       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 1 MAXIMUM EXCITATION   AMEL1       5
CD    CURRENT LIMITER.                                                  AMEL1       6
CD                                                                      AMEL1       7
      INCLUDE 'PARX.INS'                                                AMEL1       8
      INCLUDE 'CNB8.INS'                                                AMEL1       9
      INCLUDE 'CNEXC.INS'                                               AMEL1      10
      INCLUDE 'CNPARX.INS'                                              AMEL1      11
      INCLUDE 'CNMDAT.INS'                                              AMEL1      12
      INCLUDE 'CNXSTA.INS'                                              AMEL1      13
      INCLUDE 'CNMSTA.INS'                                              AMEL1      14
      INCLUDE 'CNUDMB.INS'                                              AMEL1      15
      INCLUDE 'CNABAK.INS'                                              AMEL1      16
C                                                                       AMEL1      17
      ISUB1=ISTATE+1                                                    AMEL1      18
C                                                                       AMEL1      19
C     TA, TB BLOCK                                                      AMEL1      20
C                                                                       AMEL1      21
      IF (IDDAT(JMX+3).EQ.0) THEN                                       AMEL1      22
         TATB=1.0                                                       AMEL1      23
         COFLD1=0.0                                                     AMEL1      24
      ELSE                                                              AMEL1      25
         TBI=1.0/DDAT(JMX+3)                                            AMEL1      26
         TATB=DDAT(JMX+2)*TBI                                           AMEL1      27
         A(ISUB1,ISUB1)=-TBI                                            AMEL1      28
         COFLD1=DDAT(JMX+1)*TBI                                         AMEL1      29
      END IF                                                            AMEL1      30
      COFLD2=DDAT(JMX+1)*TATB                                           AMEL1      31
C                                                                       AMEL1      32
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AMEL1      33
C                                                                       AMEL1      34
      IF (IDDAT(JMX+3).EQ.0) GOTO 10                                    AMEL1      35
      WS1=XAD*COFLD1                                                    AMEL1      36
      DO 20 J=1,MD+1                                                    AMEL1      37
         A(ISUB1,J+1)=WS1*FCTM(J)                                       AMEL1      38
  20  CONTINUE                                                          AMEL1      39
      BC(ISUB1,1)=BC(ISUB1,1)+WS1*FCTM(5)                               AMEL1      40
      BC(ISUB1,2)=BC(ISUB1,2)+WS1*FCTM(6)                               AMEL1      41
C                                                                       AMEL1      42
  10  CONTINUE                                                          AMEL1      43
C                                                                       AMEL1      44
C     INTERCONNECTION WITH EXCITER (OUTPUT EQUATION)                    AMEL1      45
C                                                                       AMEL1      46
      GAIN1=(1.0-TATB)                                                  AMEL1      47
      IF (IEXN.NE.50) THEN                                              AMEL1      48
C                                                                       AMEL1      49
      DO 30 I=1,4                                                       AMEL1      50
         IF (IUST(I).EQ.0) GOTO 40                                      AMEL1      51
         IWS1=IUST(I)                                                   AMEL1      52
         WS1=GUST(I)                                                    AMEL1      53
         WS2=COFLD2*WS1                                                 AMEL1      54
         A(IWS1,ISUB1)=-GAIN1*WS1                                       AMEL1      55
         DO 50 J=1,MD+1                                                 AMEL1      56
            A(IWS1,J+1)=A(IWS1,J+1)-WS2*FCTM(J)                         AMEL1      57
  50     CONTINUE                                                       AMEL1      58
         BC(IWS1,1)=BC(IWS1,1)-WS2*FCTM(5)                              AMEL1      59
         BC(IWS1,2)=BC(IWS1,2)-WS2*FCTM(6)                              AMEL1      60
  30  CONTINUE                                                          AMEL1      61
C                                                                       AMEL1      62
      ELSE                                                              AMEL1      63
C                                                                       AMEL1      64
C     CONNECTION WITH A USER DEFIEND EXCITER                            AMEL1      65
C                                                                       AMEL1      66
      MSEXC=MSUDM(1,1)                                                  AMEL1      67
      IWS1=ISTATE-MSEXC                                                 AMEL1      68
      DO 60 I=1,MSEXC+1                                                 AMEL1      69
         IWS2=IWS1+I                                                    AMEL1      70
         WS2=COFLD2*BXVS(I)                                             AMEL1      71
         IF (I.GT.MSEXC) IWS2=3                                         AMEL1      72
         A(IWS2,ISUB1)=-GAIN1*BXVS(I)                                   AMEL1      73
         DO 70 J=1,MD+1                                                 AMEL1      74
            A(IWS2,J+1)=A(IWS2,J+1)-WS2*FCTM(J)                         AMEL1      75
  70     CONTINUE                                                       AMEL1      76
         BC(IWS2,1)=BC(IWS2,1)-WS2*FCTM(5)                              AMEL1      77
         BC(IWS2,2)=BC(IWS2,2)-WS2*FCTM(6)                              AMEL1      78
  60  CONTINUE                                                          AMEL1      79
C                                                                       AMEL1      80
      END IF                                                            AMEL1      81
C                                                                       AMEL1      82
  40  ISTATE=ISTATE+1                                                   AMEL1      83
C                                                                       AMEL1      84
      RETURN                                                            AMEL1      85
      END                                                               AMEL1      86
