CFPRIME GXDOT                                                           GXDOT       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 GXDOT                                                  GXDOT       3
CD                                                                      GXDOT       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF DETAILED AND        GXDOT       5
CD    CLASSICAL MACHINE FOR USE IN THE TRAPEZOIDAL METHOD. THIS         GXDOT       6
CD    SUBROUTINE IS SIMILAR TO SUBROUTINE DGEN. THE DIFFERENCES ARE     GXDOT       7
CD                                                                      GXDOT       8
CD    1. THE PARTS RELATED TO THE RUNGE-KUTTA METHOD ARE DELETED        GXDOT       9
CD                                                                      GXDOT      10
CD    2. THE JACOBIAN CLACULATION PATH IS ADDED                         GXDOT      11
CD                                                                      GXDOT      12
CD    3. THE STATE DERIVATIVE ARRAY, XDOT, IS HERE A GLOBAL ARRAY       GXDOT      13
CD                                                                      GXDOT      14
      INCLUDE 'PARX.INS'                                                GXDOT      15
      INCLUDE 'CNPT.INS'                                                GXDOT      16
      INCLUDE 'CNB1.INS'                                                GXDOT      17
      INCLUDE 'CNB3.INS'                                                GXDOT      18
      INCLUDE 'CNB4.INS'                                                GXDOT      19
      INCLUDE 'CNB5.INS'                                                GXDOT      20
      INCLUDE 'CNB8.INS'                                                GXDOT      21
      INCLUDE 'CNB9.INS'                                                GXDOT      22
      INCLUDE 'CNB91.INS'                                               GXDOT      23
      INCLUDE 'CNB10.INS'                                               GXDOT      24
      INCLUDE 'CNB19.INS'                                               GXDOT      25
      INCLUDE 'CNEXC.INS'                                               GXDOT      26
      INCLUDE 'CNSTN.INS'                                               GXDOT      27
      INCLUDE 'CNMSG.INS'                                               GXDOT      28
      INCLUDE 'CNUDM.INS'                                               GXDOT      29
      INCLUDE 'CNUDMA.INS'                                              GXDOT      30
      INCLUDE 'CNUDMB.INS'                                              GXDOT      31
      INCLUDE 'CNUDMK.INS'                                              GXDOT      32
      INCLUDE 'CNIPTR.INS'                                              GXDOT      33
      INCLUDE 'CNMSTA.INS'                                              GXDOT      34
      INCLUDE 'CNXSTA.INS'                                              GXDOT      35
      INCLUDE 'CNQSTA.INS'                                              GXDOT      36
      INCLUDE 'CNZSTA.INS'                                              GXDOT      37
      INCLUDE 'CNMDAT.INS'                                              GXDOT      38
      INCLUDE 'CNPRGV.INS'                                              GXDOT      39
      INCLUDE 'CNUVAR.INS'                                              GXDOT      40
      INCLUDE 'CNVOLT.INS'                                              GXDOT      41
      INCLUDE 'CNFLAG.INS'                                              GXDOT      42
      INCLUDE 'CNMYVA.INS'                                              GXDOT      43
      INCLUDE 'CNYVAR.INS'                                              GXDOT      44
      INCLUDE 'CNUNIT.INS'                                              GXDOT      45
      INCLUDE 'CNXDOT.INS'                                              GXDOT      46
      INCLUDE 'CNJCOB.INS'                                              GXDOT      47
      INCLUDE 'CNIMPR.INS'                                              GXDOT      48
      INCLUDE 'CNSTAB.INS'                                              GXDOT      49
      INCLUDE 'CNGEAR.INS'                                              GXDOT      50
      INCLUDE 'CNABAK.INS'                                              GXDOT      51
      INCLUDE 'CNVMAX.INS'                                              GXDOT      52
C                                                                       GXDOT      53
      COMPLEX VOLTK,VOLTK1                                              GXDOT      54
      DIMENSION EVOLT(2),EVOLT1(2)                                      GXDOT      55
      EQUIVALENCE (VOLTK,EVOLT(1),VR),(EVOLT(2),VIM)                    GXDOT      56
      EQUIVALENCE (VOLTK1,EVOLT1(1),VR1),(EVOLT1(2),VIM1)               GXDOT      57
C                                                                       GXDOT      58
      CHARACTER*4 CKID                                                  GXDOT      59
      CHARACTER*2 CID                                                   GXDOT      60

C --------------- PARALLEL CODE ADDITIONS ---------------------------- C

      integer kam, begin, last , step
      integer numtask, taskid, src, msglen, allgrp
      integer concN, concXSTATE, concJSTATE, concPDGN, concPQGN

C      open(unit=8, file='iter', status='new')

C -------------------------------------------------------------------- C

*IF DEBUG                                                               GXDOT      61
      LDEB=(JDEB(81).NE.0)                                              GXDOT      62
*ENDIF                                                                  GXDOT      63
C                                                                       GXDOT      64
      CKD=0.0                                                           GXDOT      65
      CKD2=0.0                                                          GXDOT      66
      XKQ1=0.0                                                          GXDOT      67
      XKQ2=0.0                                                          GXDOT      68
      XKQ3=0.0                                                          GXDOT      69
      CKQ=0.0                                                           GXDOT      70
      CKQ1=0.0                                                          GXDOT      71
      CKQ2=0.0                                                          GXDOT      72
      ASATQ=0.0                                                         GXDOT      73
      BSATQ=0.0                                                         GXDOT      74
      JJ=0                                                              GXDOT      75
C                                                                       GXDOT      76
      N=0                                                               GXDOT      77
      IFC=0                                                             GXDOT      78
C                                                                       GXDOT      79
      ITMACH=0                                                          GXDOT      80
      IAIDEX=0                                                          GXDOT      81
      IBIDEX=0                                                          GXDOT      82
      ICIDEX=0                                                          GXDOT      83
      NALUFT=0                                                          GXDOT      84

C --------------- PARALLEL CODE ADDITIONS ---------------------------- C

      call MP_ENVIRON(numtask, taskid)

C                                                                       GXDOT      85
c      DO 850 K=1,IPNODE                                                GXDOT      86
c       begin = (taskid*IPNODE/numtask)+1
     
c       last = (taskid+1)*IPNODE/numtask

c      if( (taskid+1) .eq. numtask) then
c        last = IPNODE
c      end if 

      step = IPNODE/numtask
      begin = taskid + 1

      do 850 k = begin, IPNODE, step

C -------------------------------------------------------------------- C

C                                                                       GXDOT      87
      KN=3*K                                                            GXDOT      88
      NLF=NOLD(K)                                                       GXDOT      89
      VOLTK=VOLT(K)                                                     GXDOT      90
      GTV=CABS(VOLTK)                                                   GXDOT      91
      AT=ATAN2(VIM,VR)                                                  GXDOT      92
C                                                                       GXDOT      93

C --------------- PARALLEL CODE ADDITIONS ---------------------------- C

C      write(8,*) 'K= ', k
C      write(8,*) 'kthge = ', kthge(k)
 
100   DO 101 L = 1 , kthge(k)

      n=n+1                                                            

C      write(8,*) 'L= ', L  , '& ', 'N= ', N

C      L=0                                                               GXDOT      94
C 100  L=L+1                                                             GXDOT      95
C      N=N+1                                                             GXDOT      96

C -------------------------------------------------------------------- C

      JG=JCONTA(1,N)                                                    GXDOT      97
      JYG=MYVAR(1,N)                                                    GXDOT      98
      JSTATE=MSTATE(1,N)                                                GXDOT      99
      ISTATE=MSTATE(1,N+1)-JSTATE                                       GXDOT     100
      IDOMG=JSTATE+1                                                    GXDOT     101
      IOFSET=JSTATE                                                     GXDOT     102
      LSTATE=0                                                          GXDOT     103
C                                                                       GXDOT     104
      IGENS=ICONTA(1,N)                                                 GXDOT     105
      IGVN=ICONTA(2,N)                                                  GXDOT     106
      ISATN=ICONTA(3,N)                                                 GXDOT     107
      IEXN=ICONTA(4,N)                                                  GXDOT     108
      ISTABN=ICONTA(5,N)                                                GXDOT     109
      IFLTRN=ICONTA(6,N)                                                GXDOT     110
      IUALN=ICONTA(7,N)                                                 GXDOT     111
      ICBRN=ICONTA(9,N)                                                 GXDOT     112
      IGSTAN=ICONTA(10,N)                                               GXDOT     113
      ITEBN=ICONTA(11,N)                                                GXDOT     114
      IMXLN=ICONTA(12,N)                                                GXDOT     115
C                                                                       GXDOT     116
      CKID=NDGC(N)                                                      GXDOT     117
      CID=CKID(3:4)                                                     GXDOT     118
C                                                                       GXDOT     119
      HM=DDAT(JG+1)                                                     GXDOT     120
C                                                                       GXDOT     121
      IF (IGENS.EQ.4) THEN                                              GXDOT     122
C                                                                       GXDOT     123
C     MACHINES REPRESENTED BY CLASSICAL MODEL                           GXDOT     124
C                                                                       GXDOT     125
      IF (HM.LT.1.0E-5) GOTO 840                                        GXDOT     126
      LSTATE=2                                                          GXDOT     127
      TELEC=VR*CDG(1,N)+VIM*CDG(2,N)                                    GXDOT     128
      TGAPG(N)=TELEC                                                    GXDOT     129
C                                                                       GXDOT     130
C     FREQUENCY CONVERTER                                               GXDOT     131
C                                                                       GXDOT     132
      IF (IFC.NE.0) THEN                                                GXDOT     133
         TELEC=TELEC+TGAPG(N-1)                                         GXDOT     134
         IFC=0                                                          GXDOT     135
      ELSE                                                              GXDOT     136
         IF (N.NE.NT) THEN                                              GXDOT     137
            JGP1=JCONTA(1,N+1)                                          GXDOT     138
            IF ((IDDAT(JG+5)-IDDAT(JGP1+5)).NE.0) THEN                  GXDOT     139
               TELEC=TELEC+VR*CDG(1,N+1)+VIM*CDG(2,N+1)                 GXDOT     140
               IFC=1                                                    GXDOT     141
            END IF                                                      GXDOT     142
         END IF                                                         GXDOT     143
      END IF                                                            GXDOT     144
C                                                                       GXDOT     145
C     EQUATIONS OF MOTION                                               GXDOT     146
C                                                                       GXDOT     147
      TINN=TIN(JYG+1)                                                   GXDOT     148
      DAMP=DDAT(JG+2)                                                   GXDOT     149
C                                                                       GXDOT     150
      PACCL=(TINN-DAMP*XSTATE(IDOMG)-TELEC)                             GXDOT     151
      DSTATE(1)=PACCL*HM                                                GXDOT     152
      DSTATE(2)=XSTATE(IDOMG)                                           GXDOT     153
      ACCP(JYG+5)=PACCL                                                 GXDOT     154
C                                                                       GXDOT     155
C     LSDAMP = .TRUE.  ==>  UNIFIED DAMPING TERM SHOULD BE ADDED        GXDOT     156
C                           TO THE SWING EQUATION                       GXDOT     157
C                                                                       GXDOT     158
      SDAMP=0.0                                                         GXDOT     159
      WSYS=0.0                                                          GXDOT     160
      IF (LSDAMP) DSTATE(1)=DSTATE(1)-SDAMP*(XSTATE(IDOMG+1)-WSYS)      GXDOT     161
C                                                                       GXDOT     162
      GOTO 631                                                          GXDOT     163
C                                                                       GXDOT     164
C     END OF CLASSICAL MACHINE                                          GXDOT     165
C                                                                       GXDOT     166
      END IF                                                            GXDOT     167
C                                                                       GXDOT     168
C     MACHINES REPRESENTED BY DETAILED MODEL                            GXDOT     169
C                                                                       GXDOT     170
      MD=IDDAT(JG+34)                                                   GXDOT     171
      MQ=IDDAT(JG+35)                                                   GXDOT     172
      IF (HM.LT.1.0E-5) THEN                                            GXDOT     173
         MQ=MQ-1                                                        GXDOT     174
         GOTO 840                                                       GXDOT     175
      END IF                                                            GXDOT     176
C                                                                       GXDOT     177
      DAMP=DDAT(JG+2)                                                   GXDOT     178
      XAD=DDAT(JG+6)                                                    GXDOT     179
      XAQ=DDAT(JG+7)                                                    GXDOT     180
      XAL=DDAT(JG+8)                                                    GXDOT     181
      XF=DDAT(JG+36)                                                    GXDOT     182
      RF=DDAT(JG+11)                                                    GXDOT     183
      AXD=DDAT(JG+22)                                                   GXDOT     184
      AXQ=DDAT(JG+23)                                                   GXDOT     185
      WXBASE=DDAT(JG+5)                                                 GXDOT     186
C                                                                       GXDOT     187
      SD=DDAT(JG+32)                                                    GXDOT     188
      SQ=DDAT(JG+33)                                                    GXDOT     189
      EFDN=EFD(JYG+4)                                                   GXDOT     190
      CDGN=CDG(1,N)                                                     GXDOT     191
      CQGN=CDG(2,N)                                                     GXDOT     192
      IREP=0                                                            GXDOT     193
 120  CONTINUE                                                          GXDOT     194
      DELTA=XSTATE(JSTATE+2)                                            GXDOT     195
      CSX=COS(DELTA)                                                    GXDOT     196
      SNX=SIN(DELTA)                                                    GXDOT     197
      CD1=CSX*CDGN+SNX*CQGN                                             GXDOT     198
      CQ1=CSX*CQGN-SNX*CDGN                                             GXDOT     199
C                                                                       GXDOT     200
      XADS=SD*XAD                                                       GXDOT     201
      XAQS=SQ*XAQ                                                       GXDOT     202
C                                                                       GXDOT     203
      FLXL=XSTATE(JSTATE+3)*DDAT(JG+36)                                 GXDOT     204
      IF(MD.EQ.2)THEN                                                   GXDOT     205
      FLXL=FLXL+XSTATE(JSTATE+4)*DDAT(JG+37)                            GXDOT     206
      ELSEIF(MD.EQ.3)THEN                                               GXDOT     207
      FLXL=FLXL+XSTATE(JSTATE+4)*DDAT(JG+37)                            GXDOT     208
     &+XSTATE(JSTATE+5)*DDAT(JG+38)                                     GXDOT     209
      ENDIF                                                             GXDOT     210
C                                                                       GXDOT     211
      C3=1./(AXD+1./XADS)                                               GXDOT     212
C                                                                       GXDOT     213
      SIAD=C3*(FLXL-CD1)                                                GXDOT     214
C                                                                       GXDOT     215
      SIAQ=0.0                                                          GXDOT     216
      IF(MQ.GT.1)THEN                                                   GXDOT     217
      JJ=JSTATE+MD                                                      GXDOT     218
      XKQ1=DDAT(JG+12)                                                  GXDOT     219
      SIAQ=XSTATE(JJ+3)/XKQ1                                            GXDOT     220
      IF(MQ.EQ.3)THEN                                                   GXDOT     221
      XKQ2=DDAT(JG+16)                                                  GXDOT     222
      SIAQ=SIAQ+XSTATE(JJ+4)/XKQ2                                       GXDOT     223
      ELSEIF(MQ.EQ.4)THEN                                               GXDOT     224
      XKQ2=DDAT(JG+16)                                                  GXDOT     225
      XKQ3=DDAT(JG+20)                                                  GXDOT     226
      SIAQ=SIAQ+XSTATE(JJ+4)/XKQ2+XSTATE(JJ+5)/XKQ3                     GXDOT     227
      ENDIF                                                             GXDOT     228
      ENDIF                                                             GXDOT     229
C                                                                       GXDOT     230
      C4=1./(AXQ+1./XAQS)                                               GXDOT     231
      SIAQ=C4*(SIAQ-CQ1)                                                GXDOT     232
C                                                                       GXDOT     233
C                                                                       GXDOT     234
      IF (ABS(SIAD).GT.5.0.OR.ABS(SIAQ).GT.5.0) THEN                    GXDOT     235
C                                                                       GXDOT     236
C     MACHINE FLUX EXCEEDS 5.0 PU. CHECK SYSTEM VOLTAGES TO DETERMINE   GXDOT     237
C     THE POSSIBLE CAUSE.                                               GXDOT     238
C                                                                       GXDOT     239
         MAXBUS=0                                                       GXDOT     240
         MINBUS=0                                                       GXDOT     241
         DO 130 KK=1,IVLAST                                             GXDOT     242
            IVMAXK=IVMAX(KK)                                            GXDOT     243
            IF (IVMAXK.EQ.0.OR.IVMTI(IVMAXK+1).EQ.0) GOTO 135           GXDOT     244
            MAXBUS=MAXBUS+1                                             GXDOT     245
 135        IF (IVMAXK.EQ.0.OR.IVMTI(IVMAXK+3).EQ.0) GOTO 130           GXDOT     246
            MINBUS=MINBUS+1                                             GXDOT     247
 130     CONTINUE                                                       GXDOT     248
C                                                                       GXDOT     249
         IF (MAXBUS.EQ.1.AND.MINBUS.EQ.0) THEN                          GXDOT     250
         WRITE(MSG(1),5000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   GXDOT     251
         WRITE(MSG(2),5010)                                             GXDOT     252
         WRITE(MSG(3),5020)                                             GXDOT     253
         CALL PRTMSG(3)                                                 GXDOT     254
         ELSE                                                           GXDOT     255
         WRITE(MSG(1),5000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   GXDOT     256
         WRITE(MSG(2),5030)                                             GXDOT     257
         WRITE(MSG(3),5040) MAXBUS+MINBUS                               GXDOT     258
         WRITE(MSG(4),5050)                                             GXDOT     259
         CALL PRTMSG(4)                                                 GXDOT     260
         END IF                                                         GXDOT     261
         CALL ASTOP('GXDOT: FATAL ERROR',18)                            GXDOT     262
C                                                                       GXDOT     263
      END IF                                                            GXDOT     264
C                                                                       GXDOT     265
      IF (NITER.GT.1) GOTO 140                                          GXDOT     266
C                                                                       GXDOT     267
      AJCOB(IAIDEX+1)=1.0                                               GXDOT     268
      AJCOB(IAIDEX+2)=1.0                                               GXDOT     269
C                                                                       GXDOT     270
      IF (ISATN.EQ.0) GOTO 140                                          GXDOT     271
C                                                                       GXDOT     272
C     NEW SATURATION FACTOR (D-AXIS)                                    GXDOT     273
C                                                                       GXDOT     274
C     DDAT(JG+32)      ==> SD                                           GXDOT     275
C     AJCOB(IAIDEX+1)  ==> SDI                                          GXDOT     276
C                                                                       GXDOT     277
      BAT=SQRT(SIAD**2+SIAQ**2)                                         GXDOT     278
      BATL=DDAT(JG+28)                                                  GXDOT     279
      BATM=DDAT(JG+29)                                                  GXDOT     280
      IF (BAT.GT.BATL) THEN                                             GXDOT     281
         IF (BAT.LT.BATM) THEN                                          GXDOT     282
C                                                                       GXDOT     283
C     REGION 2                                                          GXDOT     284
C                                                                       GXDOT     285
            XSAT=BAT-BATL                                               GXDOT     286
            DBAT=DDAT(JG+26)*EXP(DDAT(JG+27)*XSAT)                      GXDOT     287
            BATA=BAT+DBAT                                               GXDOT     288
            DDAT(JG+32)=BAT/BATA                                        GXDOT     289
            AJCOB(IAIDEX+1)=1.0/(1.0+DBAT*DDAT(JG+27))                  GXDOT     290
C                                                                       GXDOT     291
         ELSE                                                           GXDOT     292
C                                                                       GXDOT     293
C     REGION 3                                                          GXDOT     294
C                                                                       GXDOT     295
            DBAT=DDAT(JG+26)*EXP(DDAT(JG+27)*(BATM-BATL))               GXDOT     296
            DBAT=DBAT+(DDAT(JG+30)*(BAT-BATM))                          GXDOT     297
            BATA=BATM+DBAT                                              GXDOT     298
            DDAT(JG+32)=BAT/BATA                                        GXDOT     299
            AJCOB(IAIDEX+1)=DDAT(JG+32)                                 GXDOT     300
C                                                                       GXDOT     301
C     ENDIF BAT.LT.BATM                                                 GXDOT     302
C                                                                       GXDOT     303
         ENDIF                                                          GXDOT     304
C                                                                       GXDOT     305
      ELSE                                                              GXDOT     306
C                                                                       GXDOT     307
C     REGION 1                                                          GXDOT     308
C                                                                       GXDOT     309
         DDAT(JG+32)=1.0                                                GXDOT     310
         AJCOB(IAIDEX+1)=1.0                                            GXDOT     311
C                                                                       GXDOT     312
      ENDIF                                                             GXDOT     313
C                                                                       GXDOT     314
C     Q-AXIS                                                            GXDOT     315
C                                                                       GXDOT     316
C     DDAT(JG+33)     ==> SQ                                            GXDOT     317
C     AJCOB(IAIDEX+2) ==> SQI                                           GXDOT     318
C                                                                       GXDOT     319
      DDAT(JG+33)=1.0                                                   GXDOT     320
      AJCOB(IAIDEX+2)=1.0                                               GXDOT     321
C                                                                       GXDOT     322
      IF (ISATN.EQ.2) THEN                                              GXDOT     323
      DDAT(JG+33)=DDAT(JG+32)                                           GXDOT     324
      AJCOB(IAIDEX+2)=AJCOB(IAIDEX+1)                                   GXDOT     325
      ELSE IF (ISATN.EQ.3)THEN                                          GXDOT     326
      BATLQ=DDAT(JG+47)                                                 GXDOT     327
      BATMQ=DDAT(JG+48)                                                 GXDOT     328
      IF (BAT.GT.BATLQ) THEN                                            GXDOT     329
         IF (BAT.LT.BATMQ) THEN                                         GXDOT     330
C                                                                       GXDOT     331
C     REGION 2                                                          GXDOT     332
C                                                                       GXDOT     333
            XSAT=BAT-BATLQ                                              GXDOT     334
            ASATQ=DDAT(JG+45)                                           GXDOT     335
            BSATQ=DDAT(JG+46)                                           GXDOT     336
            DBAT=ASATQ*EXP(BSATQ*XSAT)                                  GXDOT     337
            BATA=BAT+DBAT                                               GXDOT     338
            DDAT(JG+33)=BAT/BATA                                        GXDOT     339
            AJCOB(IAIDEX+2)=1.0/(1.0+DBAT*BSATQ)                        GXDOT     340
C                                                                       GXDOT     341
         ELSE                                                           GXDOT     342
C                                                                       GXDOT     343
C     REGION 3                                                          GXDOT     344
C                                                                       GXDOT     345
            DBAT=ASATQ*EXP(BSATQ*(BATMQ-BATLQ))                         GXDOT     346
            DBAT=DBAT+(DDAT(JG+49)*(BAT-BATMQ))                         GXDOT     347
            BATA=BATMQ+DBAT                                             GXDOT     348
            DDAT(JG+33)=BAT/BATA                                        GXDOT     349
            AJCOB(IAIDEX+2)=DDAT(JG+33)                                 GXDOT     350
C                                                                       GXDOT     351
C     ENDIF BAT.LT.BATMQ                                                GXDOT     352
C                                                                       GXDOT     353
         END IF                                                         GXDOT     354
C                                                                       GXDOT     355
C     ENDIF BAT.GT.BATLQ                                                GXDOT     356
C                                                                       GXDOT     357
      END IF                                                            GXDOT     358
C                                                                       GXDOT     359
C     ENDIF ISATN.EQ.2                                                  GXDOT     360
C                                                                       GXDOT     361
      ENDIF                                                             GXDOT     362
C                                                                       GXDOT     363
 140  CONTINUE                                                          GXDOT     364
C                                                                       GXDOT     365
C   D-AXIS ROTOR CURRENTS                                               GXDOT     366
C   FIELD CURRENT IN RECIPROCAL P.U. SYSTEM                             GXDOT     367
C                                                                       GXDOT     368
      IF (IDDAT(JG+24).EQ.0.AND.IDDAT(JG+25).EQ.0) THEN                 GXDOT     369
C                                                                       GXDOT     370
C     XC1, XC2 ARE NOT PRESENTED                                        GXDOT     371
C                                                                       GXDOT     372
      CFDR=(XSTATE(JSTATE+3)-SIAD)*XF                                   GXDOT     373
      IF(MD.EQ.2)THEN                                                   GXDOT     374
      XKD1=DDAT(JG+37)                                                  GXDOT     375
      CKD=(XSTATE(JSTATE+4)-SIAD)*XKD1                                  GXDOT     376
      ELSEIF(MD.EQ.3)THEN                                               GXDOT     377
      XKD1=DDAT(JG+37)                                                  GXDOT     378
      XKD2=DDAT(JG+38)                                                  GXDOT     379
      CKD=(XSTATE(JSTATE+4)-SIAD)*XKD1                                  GXDOT     380
      CKD2=(XSTATE(JSTATE+5)-SIAD)*XKD2                                 GXDOT     381
      ENDIF                                                             GXDOT     382
C                                                                       GXDOT     383
      ELSE                                                              GXDOT     384
C                                                                       GXDOT     385
C     XC1, XC2 ARE PRESENTED                                            GXDOT     386
C                                                                       GXDOT     387
      CFDR=(XSTATE(JSTATE+3)-SIAD)                                      GXDOT     388
      CKD=(XSTATE(JSTATE+4)-SIAD)                                       GXDOT     389
C                                                                       GXDOT     390
      IF(MD.EQ.2)THEN                                                   GXDOT     391
C                                                                       GXDOT     392
      X11=DDAT(JG+39)                                                   GXDOT     393
      X12=DDAT(JG+40)                                                   GXDOT     394
      X22=DDAT(JG+41)                                                   GXDOT     395
      CFDRM=X11*CFDR+X12*CKD                                            GXDOT     396
      CKD=X12*CFDR+X22*CKD                                              GXDOT     397
      CFDR=CFDRM                                                        GXDOT     398
C                                                                       GXDOT     399
      ELSEIF(MD.EQ.3)THEN                                               GXDOT     400
C                                                                       GXDOT     401
      CKD2=(XSTATE(JSTATE+5)-SIAD)                                      GXDOT     402
C                                                                       GXDOT     403
      X11=DDAT(JG+39)                                                   GXDOT     404
      X12=DDAT(JG+40)                                                   GXDOT     405
      X13=DDAT(JG+41)                                                   GXDOT     406
      X22=DDAT(JG+42)                                                   GXDOT     407
      X23=DDAT(JG+43)                                                   GXDOT     408
      X33=DDAT(JG+44)                                                   GXDOT     409
C                                                                       GXDOT     410
      CFDRM=X11*CFDR+X12*CKD+X13*CKD2                                   GXDOT     411
      CKDM=X12*CFDR+X22*CKD+X23*CKD2                                    GXDOT     412
      CKD2=X13*CFDR+X23*CKD+X33*CKD2                                    GXDOT     413
      CFDR=CFDRM                                                        GXDOT     414
      CKD=CKDM                                                          GXDOT     415
C                                                                       GXDOT     416
      ENDIF                                                             GXDOT     417
      ENDIF                                                             GXDOT     418
C                                                                       GXDOT     419
      IF(MQ.GT.1)THEN                                                   GXDOT     420
      CKQ=(XSTATE(JJ+3)-SIAQ)/XKQ1                                      GXDOT     421
      IF(MQ.EQ.3)THEN                                                   GXDOT     422
      CKQ1=(XSTATE(JJ+4)-SIAQ)/XKQ2                                     GXDOT     423
      ELSEIF(MQ.EQ.4)THEN                                               GXDOT     424
      CKQ1=(XSTATE(JJ+4)-SIAQ)/XKQ2                                     GXDOT     425
      CKQ2=(XSTATE(JJ+5)-SIAQ)/XKQ3                                     GXDOT     426
      ENDIF                                                             GXDOT     427
      ENDIF                                                             GXDOT     428
C                                                                       GXDOT     429
C     SPECIAL PATH FOR NEGATIVE FIELD CURRENT                           GXDOT     430
C                                                                       GXDOT     431
      IF (CFDR.LT.0.0) THEN                                             GXDOT     432
         IF (ICBRN.NE.0) THEN                                           GXDOT     433
            IF (ICBRN.EQ.1) THEN                                        GXDOT     434
               IF (IREP.EQ.0) THEN                                      GXDOT     435
                  IREP=1                                                GXDOT     436
                  XF=999999.0                                           GXDOT     437
                  AXD=999999.0                                          GXDOT     438
                  GOTO 120                                              GXDOT     439
               ELSE                                                     GXDOT     440
                  CFDR=0.0                                              GXDOT     441
                  GOTO 200                                              GXDOT     442
               END IF                                                   GXDOT     443
            ELSE IF (ICBRN.EQ.2) THEN                                   GXDOT     444
               EFDN=0.0                                                 GXDOT     445
               JCB=JCONTA(8,N)                                          GXDOT     446
               RF=RF+DDAT(JCB+2)                                        GXDOT     447
            ELSE                                                        GXDOT     448
               EFDN=0.0                                                 GXDOT     449
               JCB=JCONTA(8,N)                                          GXDOT     450
               RF=RF+DDAT(JCB+2)*(ABS(CFDR)**DDAT(JCB+4))               GXDOT     451
            END IF                                                      GXDOT     452
         ELSE                                                           GXDOT     453
            IF (NITER.EQ.1.AND.ICONTA(13,N).EQ.1) THEN                  GXDOT     454
               WRITE(MSG(1),5060) NLF,INAME(KN-2),INAME(KN-1)           GXDOT     455
     *                           ,INAME(KN),CID                         GXDOT     456
               WRITE(MSG(2),5070) TS+H,CFDR*XAD                         GXDOT     457
               CALL PRTMSG(2)                                           GXDOT     458
               ICONTA(13,N)=-1                                          GXDOT     459
            END IF                                                      GXDOT     460
         END IF                                                         GXDOT     461
      ELSE IF (NITER.EQ.1.AND.ICONTA(13,N).EQ.-1) THEN                  GXDOT     462
         WRITE(MSG(1),5060) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   GXDOT     463
         WRITE(MSG(2),5080) TS+H,CFDR*XAD                               GXDOT     464
         CALL PRTMSG(2)                                                 GXDOT     465
         ICONTA(13,N)=1                                                 GXDOT     466
      END IF                                                            GXDOT     467
C                                                                       GXDOT     468
 200  CFDN=CFDR*XAD                                                     GXDOT     469
      CFD(JYG+5)=CFDN                                                   GXDOT     470
C                                                                       GXDOT     471
      ND=3                                                              GXDOT     472
      DSTATE(ND)=(EFDN/XAD-CFDR)*RF*WXBASE                              GXDOT     473
      IF(MD.EQ.2)THEN                                                   GXDOT     474
      DSTATE(4)=-DDAT(JG+15)*CKD                                        GXDOT     475
      ND=4                                                              GXDOT     476
      ELSEIF(MD.EQ.3)THEN                                               GXDOT     477
      DSTATE(4)=-DDAT(JG+15)*CKD                                        GXDOT     478
      DSTATE(5)=-DDAT(JG+19)*CKD2                                       GXDOT     479
      ND=5                                                              GXDOT     480
      ENDIF                                                             GXDOT     481
      IF(MQ.GT.1)THEN                                                   GXDOT     482
      DSTATE(ND+1)=-DDAT(JG+13)*CKQ                                     GXDOT     483
      IF(MQ.EQ.3)THEN                                                   GXDOT     484
      DSTATE(ND+2)=-DDAT(JG+17)*CKQ1                                    GXDOT     485
      ELSEIF(MQ.EQ.4)THEN                                               GXDOT     486
      DSTATE(ND+2)=-DDAT(JG+17)*CKQ1                                    GXDOT     487
      DSTATE(ND+3)=-DDAT(JG+21)*CKQ2                                    GXDOT     488
      ENDIF                                                             GXDOT     489
      ND=ND+MQ-1                                                        GXDOT     490
      ENDIF                                                             GXDOT     491
C                                                                       GXDOT     492
      TELEC=VR*CDGN+VIM*CQGN                                            GXDOT     493
      PDGN=TELEC                                                        GXDOT     494
      PDG(JYG+2)=PDGN                                                   GXDOT     495
      PQGN=VIM*CDGN-VR*CQGN                                             GXDOT     496
      PQG(JYG+3)=PQGN                                                   GXDOT     497
      TELEC=TELEC+(CDGN**2+CQGN**2)*DDAT(JG+9)                          GXDOT     498
      TGAPG(N)=TELEC                                                    GXDOT     499
C                                                                       GXDOT     500
      IF(IFC.NE.0)THEN                                                  GXDOT     501
      TELEC=TELEC+TGAPG(N-1)                                            GXDOT     502
C                                                                       GXDOT     503
      IFC=0                                                             GXDOT     504
      GOTO 300                                                          GXDOT     505
      ELSE                                                              GXDOT     506
        IF(N.GE.NT) GOTO 300                                            GXDOT     507
        JGP1=JCONTA(1,N+1)+5                                            GXDOT     508
        RAP1=DDAT(JGP1+4)                                               GXDOT     509
C                                                                       GXDOT     510
         IF((IDDAT(JG+5)-IDDAT(JGP1)).NE.0)THEN                         GXDOT     511
         CDGN1=CDG(1,N+1)                                               GXDOT     512
         CQGN1=CDG(2,N+1)                                               GXDOT     513
         CMAG2=CDGN1**2+CQGN1**2                                        GXDOT     514
         VOLTK1=VOLT(K+1)                                               GXDOT     515
         TELEC=TELEC+VR1*CDGN1+VIM1*CQGN1+CMAG2*RAP1                    GXDOT     516
C                                                                       GXDOT     517
         IFC=1                                                          GXDOT     518
         ENDIF                                                          GXDOT     519
      ENDIF                                                             GXDOT     520
C                                                                       GXDOT     521
 300  CONTINUE                                                          GXDOT     522
C                                                                       GXDOT     523
C  EQUATIONS OF MOTION                                                  GXDOT     524
C                                                                       GXDOT     525
      TINN=TIN(JYG+1)                                                   GXDOT     526
      IF (IDDAT(JG+31).NE.0)THEN                                        GXDOT     527
      XFREQ=1.0+XSTATE(IDOMG+1)/WXBASE                                  GXDOT     528
      TINN=TINN*XFREQ**DDAT(JG+31)                                      GXDOT     529
      ENDIF                                                             GXDOT     530
C                                                                       GXDOT     531
      IF (H.EQ.0.0) THEN                                                GXDOT     532
         IF (ITMACH.EQ.0) THEN                                          GXDOT     533
            IF (TINN.GT.0.01) THEN                                      GXDOT     534
               ACCEL=PACCL/TINN                                         GXDOT     535
               DV=VBUS(N)-GTV                                           GXDOT     536
               IF (ACCEL.GT.0.2.AND.DV.GT.0.2) THEN                     GXDOT     537
                  IFAUTO=0                                              GXDOT     538
                  ITMACH=1                                              GXDOT     539
               ELSE                                                     GXDOT     540
                  IFAUTO=1                                              GXDOT     541
               END IF                                                   GXDOT     542
            END IF                                                      GXDOT     543
         END IF                                                         GXDOT     544
      END IF                                                            GXDOT     545
C                                                                       GXDOT     546
      PACCL=TINN-DAMP*XSTATE(IDOMG)-TELEC                               GXDOT     547
      ACCP(JYG+6)=PACCL                                                 GXDOT     548
      DSTATE(1)=PACCL*HM                                                GXDOT     549
      DSTATE(2)=XSTATE(IDOMG)                                           GXDOT     550
C                                                                       GXDOT     551
C     LSDAMP = .TRUE.  ==>  UNIFIED DAMPING TERM SHOULD BE ADDED        GXDOT     552
C                           TO THE SWING EQUATION                       GXDOT     553
C                                                                       GXDOT     554
      SDAMP=0.0                                                         GXDOT     555
      WSYS=0.0                                                          GXDOT     556
      IF (LSDAMP) DSTATE(1)=DSTATE(1)-SDAMP*(XSTATE(IDOMG)-WSYS)        GXDOT     557
C                                                                       GXDOT     558
      LSTATE=ND                                                         GXDOT     559
      KSTATE=JSTATE+ND                                                  GXDOT     560
      JSTATE=JSTATE+ND                                                  GXDOT     561
C                                                                       GXDOT     562
      MBUSR(1)=K                                                        GXDOT     563
C                                                                       GXDOT     564
      MSUDM(1,1)=LSTATE                                                 GXDOT     565
      IF (IEXN.NE.0) THEN                                               GXDOT     566
C                                                                       GXDOT     567
      JE=JCONTA(3,N)                                                    GXDOT     568
      JYE=MYVAR(2,N)                                                    GXDOT     569
      IF (ISTABN.GT.0) JYS=MYVAR(3,N)                                   GXDOT     570
      IF (IUALN.NE.0) JYU=MYVAR(4,N)                                    GXDOT     571
      IF (IMXLN.NE.0) JYMX=MYVAR(8,N)                                   GXDOT     572
C                                                                       GXDOT     573
      IF (IEXN.EQ.50) THEN                                              GXDOT     574
C                                                                       GXDOT     575
C     USER DEFINED EXCITER                                              GXDOT     576
C                                                                       GXDOT     577
C     GET THE INPUT VALUES                                              GXDOT     578
C                                                                       GXDOT     579
         JE0=JE                                                         GXDOT     580
         JE1=JE0+9                                                      GXDOT     581
         CALL RINUDM                                                    GXDOT     582
C                                                                       GXDOT     583
         IF (NRBUS.EQ.0) THEN                                           GXDOT     584
            VCR=VR                                                      GXDOT     585
            VCI=VIM                                                     GXDOT     586
         ELSE                                                           GXDOT     587
            IBUSR=IDDAT(JE1+1)                                          GXDOT     588
            VCR=REAL(VOLT(IBUSR))                                       GXDOT     589
            VCI=AIMAG(VOLT(IBUSR))                                      GXDOT     590
         END IF                                                         GXDOT     591
         RC=DDAT(JE0+1)                                                 GXDOT     592
         XC=DDAT(JE0+2)                                                 GXDOT     593
         VCD=VCR+(RC*CDGN-XC*CQGN)                                      GXDOT     594
         VCQ=VCI+(RC*CQGN+XC*CDGN)                                      GXDOT     595
         VCM=SQRT(VCD*VCD+VCQ*VCQ)                                      GXDOT     596
         VALIN(1)=VCM                                                   GXDOT     597
         IF (VCM.GT.0.05) THEN                                          GXDOT     598
            VAG=ATAN2(VCQ,VCD)                                          GXDOT     599
            VAGD=DDAT(JE0+5)-VAG                                        GXDOT     600
            DDAT(JE0+5)=VAG                                             GXDOT     601
            IF (VAGD.GT.3.15) THEN                                      GXDOT     602
               IDDAT(JE0+4)=IDDAT(JE0+4)+1                              GXDOT     603
            ELSE IF (VAGD.LT.-3.15) THEN                                GXDOT     604
               IDDAT(JE0+4)=IDDAT(JE0+4)-1                              GXDOT     605
            END IF                                                      GXDOT     606
            VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                         GXDOT     607
         ELSE                                                           GXDOT     608
            VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)                 GXDOT     609
         END IF                                                         GXDOT     610
         IF (GTV.GT.0.05) THEN                                          GXDOT     611
            VAGD=DDAT(JE0+7)-AT                                         GXDOT     612
            DDAT(JE0+7)=AT                                              GXDOT     613
            IF (VAGD.GT.3.15) THEN                                      GXDOT     614
               IDDAT(JE0+6)=IDDAT(JE0+6)+1                              GXDOT     615
            ELSE IF (VAGD.LT.-3.15) THEN                                GXDOT     616
               IDDAT(JE0+6)=IDDAT(JE0+6)-1                              GXDOT     617
            END IF                                                      GXDOT     618
            VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                          GXDOT     619
         ELSE                                                           GXDOT     620
            VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)                 GXDOT     621
         END IF                                                         GXDOT     622
         VALIN(3)=ACCP(JYG+6)                                           GXDOT     623
         VALIN(4)=GTV                                                   GXDOT     624
         VALIN(6)=VR                                                    GXDOT     625
         VALIN(7)=VIM                                                   GXDOT     626
         VALIN(8)=CDGN                                                  GXDOT     627
         VALIN(9)=CQGN                                                  GXDOT     628
         VALIN(10)=PDGN                                                 GXDOT     629
         VALIN(11)=PQGN                                                 GXDOT     630
         VALIN(12)=XSTATE(IDOMG)                                        GXDOT     631
         VALIN(16)=CFDN                                                 GXDOT     632
         IF (ISTABN.GT.0) THEN                                          GXDOT     633
            VALIN(17)=VSS(JYS+1)                                        GXDOT     634
         ELSE                                                           GXDOT     635
            VALIN(17)=0.0                                               GXDOT     636
         END IF                                                         GXDOT     637
         IF (IUALN.NE.0) THEN                                           GXDOT     638
            VALIN(18)=VUAL(JYU+1)                                       GXDOT     639
         ELSE                                                           GXDOT     640
            VALIN(18)=0.0                                               GXDOT     641
         END IF                                                         GXDOT     642
         VALIN(20)=VREF(JYE+2)                                          GXDOT     643
C                                                                       GXDOT     644
         KORD=0                                                         GXDOT     645
         VALIN(15)=EFD(JYG+4)                                           GXDOT     646
         VALIN(19)=VRFIN(JYE+3)                                         GXDOT     647
         CALL DEUDM(H,KORD,NLF,KN,CID)                                  GXDOT     648
         IDDAT(JE0+8)=KORD                                              GXDOT     649
C                                                                       GXDOT     650
         IOUT=IDDAT(JE7+1)                                              GXDOT     651
         VREG(JYE+1)=VALIN(1)                                           GXDOT     652
         EFD(JYG+4)=VALOUT(IOUT)                                        GXDOT     653
         VRFIN(JYE+3)=VALIN(19)                                         GXDOT     654
C                                                                       GXDOT     655
         JYUDM=JYE+4                                                    GXDOT     656
         DO 151 J=1,NUDB                                                GXDOT     657
            YVAR(JYUDM+J)=VALOUT(J)                                     GXDOT     658
  151    CONTINUE                                                       GXDOT     659
C                                                                       GXDOT     660
C     OBTAIN LINEARIZED EQUATIONS FOR USER DEFINED EXCITER              GXDOT     661
C     IF NECESSARY. CONNECTION WITH GENERATOR EQUATIONS WILL            GXDOT     662
C     BE MADE IN DGENLN                                                 GXDOT     663
C                                                                       GXDOT     664
         IF (JMUPDT) THEN                                               GXDOT     665
C                                                                       GXDOT     666
            BASPRN=DDAT(JG+3)/BASPC                                     GXDOT     667
            WXBASE=DDAT(JG+5)                                           GXDOT     668
            JEU=JE7-JE1+2                                               GXDOT     669
            DO 240 I=1,JEU                                              GXDOT     670
               UDAT(I)=DDAT(I+JE1-1)                                    GXDOT     671
  240       CONTINUE                                                    GXDOT     672
            IWS1=JE+8                                                   GXDOT     673
            JE1=JE1-IWS1                                                GXDOT     674
            JE2=JE2-IWS1                                                GXDOT     675
            JE3=JE3-IWS1                                                GXDOT     676
            JE4=JE4-IWS1                                                GXDOT     677
            JE5=JE5-IWS1                                                GXDOT     678
            JE6=JE6-IWS1                                                GXDOT     679
            JE7=JE7-IWS1                                                GXDOT     680
C                                                                       GXDOT     681
            CALL AEXC                                                   GXDOT     682
C                                                                       GXDOT     683
         END IF                                                         GXDOT     684
         LSTATE=LSTATE+KORD                                             GXDOT     685
         GO TO 440                                                      GXDOT     686
      END IF                                                            GXDOT     687
C                                                                       GXDOT     688
C     ALL STANDARD EXCITERS                                             GXDOT     689
C                                                                       GXDOT     690
      IVTN=IDDAT(JE+1)                                                  GXDOT     691
      IF(IVTN.EQ.0)THEN                                                 GXDOT     692
      ET=GTV                                                            GXDOT     693
      VR1=VR                                                            GXDOT     694
      VIM1=VIM                                                          GXDOT     695
      ELSE                                                              GXDOT     696
      VOLTK1=VOLT(IVTN)                                                 GXDOT     697
      ET=CABS(VOLTK1)                                                   GXDOT     698
      ENDIF                                                             GXDOT     699
C                                                                       GXDOT     700
C   COMPENSATOR                                                         GXDOT     701
C                                                                       GXDOT     702
      IF (IDDAT(JE+19).NE.0.OR.IDDAT(JE+20).NE.0)THEN                   GXDOT     703
      VRR=VR1+CDGN*DDAT(JE+19)-CQGN*DDAT(JE+20)                         GXDOT     704
      VRI=VIM1+CDGN*DDAT(JE+20)+CQGN*DDAT(JE+19)                        GXDOT     705
      VREG(JYE+1)=SQRT(VRR**2+VRI**2)                                   GXDOT     706
      ELSE                                                              GXDOT     707
      VREG(JYE+1)=ET                                                    GXDOT     708
      ENDIF                                                             GXDOT     709
C                                                                       GXDOT     710
C  SENSING CIRCUIT                                                      GXDOT     711
C                                                                       GXDOT     712
      IF (IDDAT(JE+18).NE.0)THEN                                        GXDOT     713
      DSTATE(LSTATE+1)=(VREG(JYE+1)-XSTATE(JSTATE+1))/DDAT(JE+18)       GXDOT     714
      ELSE                                                              GXDOT     715
      DSTATE(LSTATE+1)=0.                                               GXDOT     716
      XSTATE(JSTATE+1)=VREG(JYE+1)                                      GXDOT     717
      ENDIF                                                             GXDOT     718
C                                                                       GXDOT     719
      V1=XSTATE(JSTATE+1)                                               GXDOT     720
C                                                                       GXDOT     721
C                1   2   3   4   5   6   7   8   9  10  11  12          GXDOT     722
         GOTO (310,310,320,330,320,340,350,350,360,370,440,440,         GXDOT     723
C                                                                       GXDOT     724
C              X13  14  15 X16 X17 X18 X19 X20 X21 X22 X23 X24          GXDOT     725
     +         440,380,390,630,630,630,630,630,630,630,630,630,         GXDOT     726
C                                                                       GXDOT     727
C              X25 X26 X27 X28 X29  30  31  32  33  34                  GXDOT     728
     +         630,630,630,630,630,400,410,420,440,430),IEXN            GXDOT     729
C                                                                       GXDOT     730
 310  CONTINUE                                                          GXDOT     731
      LVUEL=ICONTA(14,N)                                                GXDOT     732
      CALL DEI1N2(H)                                                    GXDOT     733
      GOTO 440                                                          GXDOT     734
 320  CONTINUE                                                          GXDOT     735
      XSPU=1.0+XSTATE(IDOMG)/WXBASE                                     GXDOT     736
      LVUEL=ICONTA(14,N)                                                GXDOT     737
      LVOEL=ICONTA(15,N)                                                GXDOT     738
      CALL DEI3N5(H)                                                    GXDOT     739
      GOTO 440                                                          GXDOT     740
 330  CONTINUE                                                          GXDOT     741
      LVUEL=ICONTA(14,N)                                                GXDOT     742
      CALL DEI4(H)                                                      GXDOT     743
      GOTO 440                                                          GXDOT     744
 340  CONTINUE                                                          GXDOT     745
      LVUEL=ICONTA(14,N)                                                GXDOT     746
      LVOEL=ICONTA(15,N)                                                GXDOT     747
      CALL DEI6(H)                                                      GXDOT     748
      GOTO 440                                                          GXDOT     749
 350  CONTINUE                                                          GXDOT     750
      LVUEL=ICONTA(14,N)                                                GXDOT     751
      CALL DE7N8(VR1,VIM1)                                              GXDOT     752
      GOTO 440                                                          GXDOT     753
 360  CONTINUE                                                          GXDOT     754
      CALL DE9                                                          GXDOT     755
      GOTO 440                                                          GXDOT     756
 370  CONTINUE                                                          GXDOT     757
      CALL DEI10(H)                                                     GXDOT     758
      GOTO 440                                                          GXDOT     759
 380  CONTINUE                                                          GXDOT     760
      CALL DE14                                                         GXDOT     761
      GOTO 440                                                          GXDOT     762
 390  CONTINUE                                                          GXDOT     763
      CALL DEI15(H)                                                     GXDOT     764
      GOTO 440                                                          GXDOT     765
 400  CONTINUE                                                          GXDOT     766
      LVUEL=ICONTA(14,N)                                                GXDOT     767
      CALL DEI30(H)                                                     GXDOT     768
      GOTO 440                                                          GXDOT     769
 410  CONTINUE                                                          GXDOT     770
      CALL DE31                                                         GXDOT     771
      GOTO 440                                                          GXDOT     772
 420  CONTINUE                                                          GXDOT     773
      CALL DEI32(H)                                                     GXDOT     774
      GOTO 440                                                          GXDOT     775
 430  CONTINUE                                                          GXDOT     776
      LVUEL=ICONTA(14,N)                                                GXDOT     777
      LVOEL=ICONTA(15,N)                                                GXDOT     778
      LVS=ICONTA(16,N)                                                  GXDOT     779
      CALL DEI34(H)                                                     GXDOT     780
C                                                                       GXDOT     781
 440  CONTINUE                                                          GXDOT     782
      MSUDM(1,1)=LSTATE-MSUDM(1,1)                                      GXDOT     783
C                                                                       GXDOT     784
C   STABILIZERS                                                         GXDOT     785
C                                                                       GXDOT     786
      MSUDM(1,2)=LSTATE                                                 GXDOT     787
      IF(ISTABN.GT.0)THEN                                               GXDOT     788
C                                                                       GXDOT     789
      JSTATE=MSTATE(3,N)                                                GXDOT     790
      JS=JCONTA(4,N)                                                    GXDOT     791
      KSTATE=0                                                          GXDOT     792
      SPDPU=DSTATE(2)/WXBASE                                            GXDOT     793
C                                                                       GXDOT     794
      IF(ISTABN.EQ.50) THEN                                             GXDOT     795
C                                                                       GXDOT     796
C     USER DEFINED STABILIZER                                           GXDOT     797
C                                                                       GXDOT     798
C     GET THE INPUT VALUES                                              GXDOT     799
C                                                                       GXDOT     800
         JE0=JS                                                         GXDOT     801
         JE1=JE0+9                                                      GXDOT     802
         CALL RINUDM                                                    GXDOT     803
C                                                                       GXDOT     804
         IF(NRBUS.EQ.0) THEN                                            GXDOT     805
            VCR=VR                                                      GXDOT     806
            VCI=VIM                                                     GXDOT     807
         ELSE                                                           GXDOT     808
            IBUSR=IDDAT(JE1+1)                                          GXDOT     809
            VCR=REAL(VOLT(IBUSR))                                       GXDOT     810
            VCI=AIMAG(VOLT(IBUSR))                                      GXDOT     811
         ENDIF                                                          GXDOT     812
         RC=DDAT(JE0+1)                                                 GXDOT     813
         XC=DDAT(JE0+2)                                                 GXDOT     814
         VCD=VCR+(RC*CDGN-XC*CQGN)                                      GXDOT     815
         VCQ=VCI+(RC*CQGN+XC*CDGN)                                      GXDOT     816
         VCM=SQRT(VCD*VCD+VCQ*VCQ)                                      GXDOT     817
         VALIN(1)=VCM                                                   GXDOT     818
         IF(VCM.GT.0.05) THEN                                           GXDOT     819
            VAG=ATAN2(VCQ,VCD)                                          GXDOT     820
            VAGD=DDAT(JE0+5)-VAG                                        GXDOT     821
            DDAT(JE0+5)=VAG                                             GXDOT     822
            IF(VAGD.GT.3.15) THEN                                       GXDOT     823
               IDDAT(JE0+4)=IDDAT(JE0+4)+1                              GXDOT     824
            ELSEIF(VAGD.LT.-3.15) THEN                                  GXDOT     825
               IDDAT(JE0+4)=IDDAT(JE0+4)-1                              GXDOT     826
            ENDIF                                                       GXDOT     827
            VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                         GXDOT     828
         ELSE                                                           GXDOT     829
            VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)                 GXDOT     830
         ENDIF                                                          GXDOT     831
         IF(GTV.GT.0.05) THEN                                           GXDOT     832
            VAGD=DDAT(JE0+7)-AT                                         GXDOT     833
            DDAT(JE0+7)=AT                                              GXDOT     834
            IF(VAGD.GT.3.15) THEN                                       GXDOT     835
               IDDAT(JE0+6)=IDDAT(JE0+6)+1                              GXDOT     836
            ELSEIF(VAGD.LT.-3.15) THEN                                  GXDOT     837
               IDDAT(JE0+6)=IDDAT(JE0+6)-1                              GXDOT     838
            ENDIF                                                       GXDOT     839
            VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                          GXDOT     840
         ELSE                                                           GXDOT     841
            VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)                 GXDOT     842
         ENDIF                                                          GXDOT     843
         VALIN(3)=ACCP(JYG+6)                                           GXDOT     844
         VALIN(4)=GTV                                                   GXDOT     845
         VALIN(6)=VR                                                    GXDOT     846
         VALIN(7)=VIM                                                   GXDOT     847
         VALIN(8)=CDGN                                                  GXDOT     848
         VALIN(9)=CQGN                                                  GXDOT     849
         VALIN(10)=PDGN                                                 GXDOT     850
         VALIN(11)=PQGN                                                 GXDOT     851
         VALIN(12)=XSTATE(IDOMG)                                        GXDOT     852
         VALIN(15)=EFDN                                                 GXDOT     853
         VALIN(16)=CFDN                                                 GXDOT     854
C                                                                       GXDOT     855
         KORD=0                                                         GXDOT     856
         VALIN(17)=VSS(JYS+1)                                           GXDOT     857
         IF(IUALN.EQ.50)THEN                                            GXDOT     858
            VALIN(18)=VUAL(JYS+3)                                       GXDOT     859
         ELSE                                                           GXDOT     860
            VALIN(18)=VUAL(JYU+1)                                       GXDOT     861
         ENDIF                                                          GXDOT     862
C                                                                       GXDOT     863
         CALL DEUDM(H,KORD,NLF,KN,CID)                                  GXDOT     864
C                                                                       GXDOT     865
         IDDAT(JE0+8)=KORD                                              GXDOT     866
         IOUT1=IDDAT(JE7+1)                                             GXDOT     867
         IOUT2=IDDAT(JE7+2)                                             GXDOT     868
         VSS(JYS+1)=VALOUT(IOUT1)                                       GXDOT     869
         IF(IOUT2.EQ.0) THEN                                            GXDOT     870
            VUAL(JYS+3)=0.0                                             GXDOT     871
         ELSE                                                           GXDOT     872
            VUAL(JYS+3)=VALOUT(IOUT2)                                   GXDOT     873
         ENDIF                                                          GXDOT     874
C                                                                       GXDOT     875
         JYUDM=JYS+3                                                    GXDOT     876
         DO 152 J=1,NUDB                                                GXDOT     877
            YVAR(JYUDM+J)=VALOUT(J)                                     GXDOT     878
  152    CONTINUE                                                       GXDOT     879
C                                                                       GXDOT     880
C     OBTAIN LINEARIZED EQUATIONS FOR USER DEFINED STABILIZER           GXDOT     881
C     IF NECESSARY. CONNECTION WITH EXCITER EQUATIONS WILL              GXDOT     882
C     BE MADE IN DGENLN                                                 GXDOT     883
C                                                                       GXDOT     884
         IF (JMUPDT) THEN                                               GXDOT     885
C                                                                       GXDOT     886
            BASPRN=DDAT(JG+3)/BASPC                                     GXDOT     887
            WXBASE=DDAT(JG+5)                                           GXDOT     888
            JEU=JE7-JE1+2                                               GXDOT     889
            DO 242 I=1,JEU                                              GXDOT     890
               UDAT(I)=DDAT(I+JE1-1)                                    GXDOT     891
  242       CONTINUE                                                    GXDOT     892
            IWS1=JS+8                                                   GXDOT     893
            JE1=JE1-IWS1                                                GXDOT     894
            JE2=JE2-IWS1                                                GXDOT     895
            JE3=JE3-IWS1                                                GXDOT     896
            JE4=JE4-IWS1                                                GXDOT     897
            JE5=JE5-IWS1                                                GXDOT     898
            JE6=JE6-IWS1                                                GXDOT     899
            JE7=JE7-IWS1                                                GXDOT     900
C                                                                       GXDOT     901
            CALL ASTAB                                                  GXDOT     902
C                                                                       GXDOT     903
         END IF                                                         GXDOT     904
         LSTATE=LSTATE+KORD                                             GXDOT     905
         GO TO 600                                                      GXDOT     906
      END IF                                                            GXDOT     907
C                                                                       GXDOT     908
C     ALL STANARD STABILIZERS                                           GXDOT     909
C                                                                       GXDOT     910
      ET=GTV                                                            GXDOT     911
C                                                                       GXDOT     912
C     TYPE   1   2   3   4   5   6   7   8   9  10  11 12               GXDOT     913
C                                                                       GXDOT     914
      GOTO(510,510,510,520,520,520,525,590,530,540,540,550),ISTABN      GXDOT     915
C                                                                       GXDOT     916
C       TYPE 1,2,3 STABILIZER                                           GXDOT     917
C                                                                       GXDOT     918
 510  CALL DSGNAL(K,H)                                                  GXDOT     919
      CALL DSTAB1(NXS,NWSS)                                             GXDOT     920
      GOTO 590                                                          GXDOT     921
C                                                                       GXDOT     922
C      TYPE 4,5,6,7 STABILIZER                                          GXDOT     923
C                                                                       GXDOT     924
 520  CALL DSGNAL(K,H)                                                  GXDOT     925
 525  CALL DSTAB4(NXS,NWSS)                                             GXDOT     926
      GOTO 590                                                          GXDOT     927
C                                                                       GXDOT     928
C       TYPE 9 STABILIZER                                               GXDOT     929
C                                                                       GXDOT     930
 530  CALL DSGNAL(K,H)                                                  GXDOT     931
      CALL DSTAB9(KBUSNO,NXS)                                           GXDOT     932
      GOTO 590                                                          GXDOT     933
C                                                                       GXDOT     934
C       TYPE 10,11 STABILIZER                                           GXDOT     935
C                                                                       GXDOT     936
 540  CALL DSGNAL(K,H)                                                  GXDOT     937
      CALL DSTA10(NXS)                                                  GXDOT     938
      GOTO 590                                                          GXDOT     939
C                                                                       GXDOT     940
C       TYPE 12 STABILIZER                                              GXDOT     941
C                                                                       GXDOT     942
 550  CALL DSGNAL(K,H)                                                  GXDOT     943
      CALL DSTA12(NXS)                                                  GXDOT     944
C                                                                       GXDOT     945
 590  IF (IFLTRN.NE.0) CALL DFLTER(NXS)                                 GXDOT     946
C                                                                       GXDOT     947
      ENDIF                                                             GXDOT     948
C                                                                       GXDOT     949
  600 CONTINUE                                                          GXDOT     950
      MSUDM(1,2)=LSTATE-MSUDM(1,2)                                      GXDOT     951
C                                                                       GXDOT     952
C   UNDER EXCITED LIMITERS                                              GXDOT     953
C                                                                       GXDOT     954
      MSUDM(1,3)=LSTATE                                                 GXDOT     955
      IF (IUALN.NE.0) THEN                                              GXDOT     956
         JSTATE=MSTATE(4,N)                                             GXDOT     957
         JU=JCONTA(6,N)                                                 GXDOT     958
         IF (ISTABN.NE.50) THEN                                         GXDOT     959
            IF (IUALN.EQ.50) THEN                                       GXDOT     960
C                                                                       GXDOT     961
C     GET THE INPUT VALUES                                              GXDOT     962
C                                                                       GXDOT     963
               JE0=JU                                                   GXDOT     964
               JE1=JE0+9                                                GXDOT     965
               CALL RINUDM                                              GXDOT     966
C                                                                       GXDOT     967
               IF (NRBUS.EQ.0) THEN                                     GXDOT     968
                  VCR=VR                                                GXDOT     969
                  VCI=VIM                                               GXDOT     970
               ELSE                                                     GXDOT     971
                  IBUSR=IDDAT(JE1+1)                                    GXDOT     972
                  VCR=REAL(VOLT(IBUSR))                                 GXDOT     973
                  VCI=AIMAG(VOLT(IBUSR))                                GXDOT     974
               END IF                                                   GXDOT     975
               RC=DDAT(JE0+1)                                           GXDOT     976
               XC=DDAT(JE0+2)                                           GXDOT     977
               VCD=VCR+(RC*CDGN-XC*CQGN)                                GXDOT     978
               VCQ=VCI+(RC*CQGN+XC*CDGN)                                GXDOT     979
               VCM=SQRT(VCD*VCD+VCQ*VCQ)                                GXDOT     980
               VALIN(1)=VCM                                             GXDOT     981
               IF (VCM.GT.0.05) THEN                                    GXDOT     982
                  VAG=ATAN2(VCQ,VCD)                                    GXDOT     983
                  VAGD=DDAT(JE0+5)-VAG                                  GXDOT     984
                  DDAT(JE0+5)=VAG                                       GXDOT     985
                  IF (VAGD.GT.3.15) THEN                                GXDOT     986
                     IDDAT(JE0+4)=IDDAT(JE0+4)+1                        GXDOT     987
                  ELSE IF (VAGD.LT.-3.15) THEN                          GXDOT     988
                     IDDAT(JE0+4)=IDDAT(JE0+4)-1                        GXDOT     989
                  END IF                                                GXDOT     990
                  VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                   GXDOT     991
               ELSE                                                     GXDOT     992
                  VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)           GXDOT     993
               END IF                                                   GXDOT     994
               IF (GTV.GT.0.05) THEN                                    GXDOT     995
                  VAGD=DDAT(JE0+7)-AT                                   GXDOT     996
                  DDAT(JE0+7)=AT                                        GXDOT     997
                  IF (VAGD.GT.3.15) THEN                                GXDOT     998
                     IDDAT(JE0+6)=IDDAT(JE0+6)+1                        GXDOT     999
                  ELSE IF (VAGD.LT.-3.15) THEN                          GXDOT    1000
                     IDDAT(JE0+6)=IDDAT(JE0+6)-1                        GXDOT    1001
                  END IF                                                GXDOT    1002
                  VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                    GXDOT    1003
               ELSE                                                     GXDOT    1004
                  VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)           GXDOT    1005
               END IF                                                   GXDOT    1006
               VALIN(3)=ACCP(JYG+6)                                     GXDOT    1007
               VALIN(4)=GTV                                             GXDOT    1008
               VALIN(6)=VR                                              GXDOT    1009
               VALIN(7)=VIM                                             GXDOT    1010
               VALIN(8)=CDGN                                            GXDOT    1011
               VALIN(9)=CQGN                                            GXDOT    1012
               VALIN(10)=PDGN                                           GXDOT    1013
               VALIN(11)=PQGN                                           GXDOT    1014
               VALIN(12)=XSTATE(IDOMG)                                  GXDOT    1015
               VALIN(15)=EFDN                                           GXDOT    1016
               VALIN(16)=CFDN                                           GXDOT    1017
               IF (ISTABN.GT.0) THEN                                    GXDOT    1018
                  VALIN(17)=VSS(JYS+1)                                  GXDOT    1019
               ELSE                                                     GXDOT    1020
                  VALIN(17)=0.0                                         GXDOT    1021
               END IF                                                   GXDOT    1022
C                                                                       GXDOT    1023
               KORD=0                                                   GXDOT    1024
               VALIN(18)=VUAL(JYU+1)                                    GXDOT    1025
               CALL DEUDM(H,KORD,NLF,KN,CID)                            GXDOT    1026
               IDDAT(JE0+8)=KORD                                        GXDOT    1027
C                                                                       GXDOT    1028
               IOUT=IDDAT(JE7+1)                                        GXDOT    1029
               VUAL(JYU+1)=VALOUT(IOUT)                                 GXDOT    1030
C                                                                       GXDOT    1031
               JYUDM=JYU+2                                              GXDOT    1032
               DO 153 J=1,NUDB                                          GXDOT    1033
                  YVAR(JYUDM+J)=VALOUT(J)                               GXDOT    1034
  153          CONTINUE                                                 GXDOT    1035
C                                                                       GXDOT    1036
C     OBTAIN LINEARIZED EQUATIONS FOR USER DEFINED UNDER EXCITED        GXDOT    1037
C     CURRENT LIMITER IF NECESSARY. CONNECTION WITH GENERATOR           GXDOT    1038
C     EQUATIONS WILL BE MADE IN DGENLN                                  GXDOT    1039
C                                                                       GXDOT    1040
               IF (JMUPDT) THEN                                         GXDOT    1041
C                                                                       GXDOT    1042
                  JEU=JE7-JE1+2                                         GXDOT    1043
                  DO 244 I=1,JEU                                        GXDOT    1044
                     UDAT(I)=DDAT(I+JE1-1)                              GXDOT    1045
  244             CONTINUE                                              GXDOT    1046
                  IWS1=JU+8                                             GXDOT    1047
                  JE1=JE1-IWS1                                          GXDOT    1048
                  JE2=JE2-IWS1                                          GXDOT    1049
                  JE3=JE3-IWS1                                          GXDOT    1050
                  JE4=JE4-IWS1                                          GXDOT    1051
                  JE5=JE5-IWS1                                          GXDOT    1052
                  JE6=JE6-IWS1                                          GXDOT    1053
                  JE7=JE7-IWS1                                          GXDOT    1054
C                                                                       GXDOT    1055
                  CALL AUAL                                             GXDOT    1056
C                                                                       GXDOT    1057
               END IF                                                   GXDOT    1058
               LSTATE=LSTATE+KORD                                       GXDOT    1059
               GO TO 609                                                GXDOT    1060
            END IF                                                      GXDOT    1061
         END IF                                                         GXDOT    1062
         IF (ISTABN.EQ.50) THEN                                         GXDOT    1063
            IF (IUALN.EQ.50) THEN                                       GXDOT    1064
               VUAL(JYU+1)=VUAL(JYS+3)                                  GXDOT    1065
               GO TO 609                                                GXDOT    1066
            END IF                                                      GXDOT    1067
         END IF                                                         GXDOT    1068
         CALL DUAL                                                      GXDOT    1069
      END IF                                                            GXDOT    1070
C                                                                       GXDOT    1071
C   ENDIF KGSTAT.EQ.0                                                   GXDOT    1072
C                                                                       GXDOT    1073
C      ENDIF                                                            GXDOT    1074
  609 CONTINUE                                                          GXDOT    1075
      MSUDM(1,3)=LSTATE-MSUDM(1,3)                                      GXDOT    1076
C                                                                       GXDOT    1077
C  MAXIMUM EXCITATION CURRENT LIMITER                                   GXDOT    1078
C                                                                       GXDOT    1079
      IF (IMXLN.NE.0) THEN                                              GXDOT    1080
         JMX=JCONTA(11,N)                                               GXDOT    1081
         JSTATE=MSTATE(7,N)                                             GXDOT    1082
         IF(IMXLN.EQ.50) THEN                                           GXDOT    1083
C                                                                       GXDOT    1084
C     GET THE INPUT VALUES                                              GXDOT    1085
C                                                                       GXDOT    1086
               JE0=JMX                                                  GXDOT    1087
               JE1=JE0+9                                                GXDOT    1088
               CALL RINUDM                                              GXDOT    1089
C                                                                       GXDOT    1090
               IF (NRBUS.EQ.0) THEN                                     GXDOT    1091
                  VCR=VR                                                GXDOT    1092
                  VCI=VIM                                               GXDOT    1093
               ELSE                                                     GXDOT    1094
                  IBUSR=IDDAT(JE1+1)                                    GXDOT    1095
                  VCR=REAL(VOLT(IBUSR))                                 GXDOT    1096
                  VCI=AIMAG(VOLT(IBUSR))                                GXDOT    1097
               END IF                                                   GXDOT    1098
               RC=DDAT(JE0+1)                                           GXDOT    1099
               XC=DDAT(JE0+2)                                           GXDOT    1100
               VCD=VCR+(RC*CDGN-XC*CQGN)                                GXDOT    1101
               VCQ=VCI+(RC*CQGN+XC*CDGN)                                GXDOT    1102
               VCM=SQRT(VCD*VCD+VCQ*VCQ)                                GXDOT    1103
               VALIN(1)=VCM                                             GXDOT    1104
               IF (VCM.GT.0.05) THEN                                    GXDOT    1105
                  VAG=ATAN2(VCQ,VCD)                                    GXDOT    1106
                  VAGD=DDAT(JE0+5)-VAG                                  GXDOT    1107
                  DDAT(JE0+5)=VAG                                       GXDOT    1108
                  IF (VAGD.GT.3.15) THEN                                GXDOT    1109
                     IDDAT(JE0+4)=IDDAT(JE0+4)+1                        GXDOT    1110
                  ELSE IF (VAGD.LT.-3.15) THEN                          GXDOT    1111
                     IDDAT(JE0+4)=IDDAT(JE0+4)-1                        GXDOT    1112
                  END IF                                                GXDOT    1113
                  VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                   GXDOT    1114
               ELSE                                                     GXDOT    1115
                  VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)           GXDOT    1116
               END IF                                                   GXDOT    1117
               IF (GTV.GT.0.05) THEN                                    GXDOT    1118
                  VAGD=DDAT(JE0+7)-AT                                   GXDOT    1119
                  DDAT(JE0+7)=AT                                        GXDOT    1120
                  IF (VAGD.GT.3.15) THEN                                GXDOT    1121
                     IDDAT(JE0+6)=IDDAT(JE0+6)+1                        GXDOT    1122
                  ELSE IF (VAGD.LT.-3.15) THEN                          GXDOT    1123
                     IDDAT(JE0+6)=IDDAT(JE0+6)-1                        GXDOT    1124
                  END IF                                                GXDOT    1125
                  VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                    GXDOT    1126
               ELSE                                                     GXDOT    1127
                  VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)           GXDOT    1128
               END IF                                                   GXDOT    1129
               VALIN(3)=ACCP(JYG+6)                                     GXDOT    1130
               VALIN(4)=GTV                                             GXDOT    1131
               VALIN(6)=VR                                              GXDOT    1132
               VALIN(7)=VIM                                             GXDOT    1133
               VALIN(8)=CDGN                                            GXDOT    1134
               VALIN(9)=CQGN                                            GXDOT    1135
               VALIN(10)=PDGN                                           GXDOT    1136
               VALIN(11)=PQGN                                           GXDOT    1137
               VALIN(12)=XSTATE(IDOMG)                                  GXDOT    1138
               VALIN(15)=EFDN                                           GXDOT    1139
               VALIN(16)=CFDN                                           GXDOT    1140
C                                                                       GXDOT    1141
               KORD=0                                                   GXDOT    1142
               CALL DEUDM(H,KORD,NLF,KN,CID)                            GXDOT    1143
               IDDAT(JE0+8)=KORD                                        GXDOT    1144
C                                                                       GXDOT    1145
               IOUT=IDDAT(JE7+1)                                        GXDOT    1146
               VMXL(JYMX+1)=VALOUT(IOUT)                                GXDOT    1147
C                                                                       GXDOT    1148
               JYUDM=JYMX+2                                             GXDOT    1149
               DO 154 J=1,NUDB                                          GXDOT    1150
                  YVAR(JYUDM+J)=VALOUT(J)                               GXDOT    1151
  154          CONTINUE                                                 GXDOT    1152
C                                                                       GXDOT    1153
C     OBTAIN LINEARIZED EQUATIONS FOR USER DEFINED UNDER EXCITED        GXDOT    1154
C     CURRENT LIMITER IF NECESSARY. CONNECTION WITH GENERATOR           GXDOT    1155
C     EQUATIONS WILL BE MADE IN DGENLN                                  GXDOT    1156
C                                                                       GXDOT    1157
               IF (JMUPDT) THEN                                         GXDOT    1158
C                                                                       GXDOT    1159
                  JEU=JE7-JE1+2                                         GXDOT    1160
                  DO 245 I=1,JEU                                        GXDOT    1161
                     UDAT(I)=DDAT(I+JE1-1)                              GXDOT    1162
  245             CONTINUE                                              GXDOT    1163
                  IWS1=JMX+8                                            GXDOT    1164
                  JE1=JE1-IWS1                                          GXDOT    1165
                  JE2=JE2-IWS1                                          GXDOT    1166
                  JE3=JE3-IWS1                                          GXDOT    1167
                  JE4=JE4-IWS1                                          GXDOT    1168
                  JE5=JE5-IWS1                                          GXDOT    1169
                  JE6=JE6-IWS1                                          GXDOT    1170
                  JE7=JE7-IWS1                                          GXDOT    1171
C                                                                       GXDOT    1172
                  CALL AOEL                                             GXDOT    1173
C                                                                       GXDOT    1174
               END IF                                                   GXDOT    1175
               LSTATE=LSTATE+KORD                                       GXDOT    1176
               MSUDM(1,3)=KORD                                          GXDOT    1177
               GO TO 620                                                GXDOT    1178
         ELSE                                                           GXDOT    1179
            CALL DEMXLI(H)                                              GXDOT    1180
         ENDIF                                                          GXDOT    1181
      ENDIF                                                             GXDOT    1182
  620 CONTINUE                                                          GXDOT    1183
C                                                                       GXDOT    1184
C  TRANSIENT EXCITATION BOOSTER                                         GXDOT    1185
C                                                                       GXDOT    1186
      IF (ITEBN.NE.0) THEN                                              GXDOT    1187
            JTB=JCONTA(10,N)                                            GXDOT    1188
            JYTB=MYVAR(7,N)                                             GXDOT    1189
            CALL DTEB(H)                                                GXDOT    1190
      END IF                                                            GXDOT    1191
C                                                                       GXDOT    1192
  630 CONTINUE                                                          GXDOT    1193
C                                                                       GXDOT    1194
C     ENDIF IEXN.EQ.0                                                   GXDOT    1195
C                                                                       GXDOT    1196
      ENDIF                                                             GXDOT    1197
C                                                                       GXDOT    1198
C  PRIME MOVER (GOVERNOR)                                               GXDOT    1199
C                                                                       GXDOT    1200
 631  IF(IGVN.NE.0)THEN                                                 GXDOT    1201
C                                                                       GXDOT    1202
C  STORE THE FOLLOWS USED LATER IN ROUTINES "DEGV04/10" AND "UPDATE"    GXDOT    1203
C                                                                       GXDOT    1204
      XSPU=XSTATE(IOFSET+1)/WXBASE                                      GXDOT    1205
      XACPU=DSTATE(1)/WXBASE                                            GXDOT    1206
C                                                                       GXDOT    1207
      JGG=JCONTA(2,N)                                                   GXDOT    1208
      JSTATE=MSTATE(5,N)                                                GXDOT    1209
      JYP=MYVAR(5,N)                                                    GXDOT    1210
*IF LTSP                                                                GXDOT    1211
*ENDIF                                                                  GXDOT    1226
C                                                                       GXDOT    1227
      IF(IGVN.EQ.50) THEN                                               GXDOT    1228
C                                                                       GXDOT    1229
C     GET THE INPUT VALUES                                              GXDOT    1230
C                                                                       GXDOT    1231
         JE0=JGG                                                        GXDOT    1232
         JE1=JE0+3                                                      GXDOT    1233
         CALL RINUDM                                                    GXDOT    1234
C                                                                       GXDOT    1235
         VALIN(1)=VGOV(JYP+2)                                           GXDOT    1236
         VALIN(2)=VGOV(JYP+4)                                           GXDOT    1237
         VALIN(3)=ACCP(JYG+6)                                           GXDOT    1238
         VALIN(4)=GTV                                                   GXDOT    1239
         IF(GTV.GT.0.05) THEN                                           GXDOT    1240
            VAGD=DDAT(JE0+2)-AT                                         GXDOT    1241
            DDAT(JE0+2)=AT                                              GXDOT    1242
            IF(VAGD.GT.3.15) THEN                                       GXDOT    1243
               IDDAT(JE0+1)=IDDAT(JE0+1)+1                              GXDOT    1244
            ELSEIF(VAGD.LT.-3.15) THEN                                  GXDOT    1245
               IDDAT(JE0+1)=IDDAT(JE0+1)-1                              GXDOT    1246
            ENDIF                                                       GXDOT    1247
            VALIN(5)=AT+6.2831853*IDDAT(JE0+1)                          GXDOT    1248
         ELSE                                                           GXDOT    1249
            VALIN(5)=DDAT(JE0+2)+6.2831853*IDDAT(JE0+1)                 GXDOT    1250
         ENDIF                                                          GXDOT    1251
         VALIN(6)=VR                                                    GXDOT    1252
         VALIN(7)=VIM                                                   GXDOT    1253
         VALIN(8)=CDGN                                                  GXDOT    1254
         VALIN(9)=CQGN                                                  GXDOT    1255
         VALIN(10)=PDGN                                                 GXDOT    1256
         VALIN(11)=PQGN                                                 GXDOT    1257
         VALIN(12)=XSTATE(IDOMG)                                        GXDOT    1258
         VALIN(15)=EFDN                                                 GXDOT    1259
         VALIN(16)=CFDN                                                 GXDOT    1260
         VALIN(20)=VREF(JYP+1)                                          GXDOT    1261
C                                                                       GXDOT    1262
         KORD=0                                                         GXDOT    1263
         CALL DEUDM(H,KORD,NLF,KN,CID)                                  GXDOT    1264
         LSTATE=LSTATE+KORD                                             GXDOT    1265
C                                                                       GXDOT    1266
         IOUT=IDDAT(JE7+1)                                              GXDOT    1267
         TIN(JYG+1)=VALOUT(IOUT)*BASER(JYP+3)                           GXDOT    1268
         VGOV(JYP+2)=VALIN(1)                                           GXDOT    1269
         VGOV(JYP+4)=VALIN(2)                                           GXDOT    1270
C                                                                       GXDOT    1271
         JYUDM=JYP+4                                                    GXDOT    1272
         DO 451 J=1,NUDB                                                GXDOT    1273
            YVAR(JYUDM+J)=VALOUT(J)                                     GXDOT    1274
  451    CONTINUE                                                       GXDOT    1275
         GO TO 750                                                      GXDOT    1276
      END IF                                                            GXDOT    1277
C                                                                       GXDOT    1278
C TYPE        1   2   3   4   5   6   7   8                             GXDOT    1279
      GOTO (640,640,640,650,650,660,670,680,750,750,750,750,750,750,    GXDOT    1280
C TYPE                           20  21  22                             GXDOT    1281
     +      750,750,750,750,750,700,710,720), IGVN                      GXDOT    1282
C                                                                       GXDOT    1283
C   TYPE 1,2 & 3                                                        GXDOT    1284
C                                                                       GXDOT    1285
  640 CALL DEGV01(JSGV)                                                 GXDOT    1286
*IF LTSP                                                                GXDOT    1287
*ENDIF                                                                  GXDOT    1296
      GOTO 750                                                          GXDOT    1297
C                                                                       GXDOT    1298
C     TYPE 4 OR TYPE 5                                                  GXDOT    1299
C                                                                       GXDOT    1300
  650 CALL DEGV04(JSGV)                                                 GXDOT    1301
*IF LTSP                                                                GXDOT    1302
*ENDIF                                                                  GXDOT    1311
      GOTO 750                                                          GXDOT    1312
C                                                                       GXDOT    1313
C     TYPE 6                                                            GXDOT    1314
C                                                                       GXDOT    1315
  660 CALL DEGV06(JSGV)                                                 GXDOT    1316
      GOTO 750                                                          GXDOT    1317
C                                                                       GXDOT    1318
C     TYPE 7                                                            GXDOT    1319
C                                                                       GXDOT    1320
  670 CALL DEGV07(JSGV)                                                 GXDOT    1321
      GOTO 750                                                          GXDOT    1322
C                                                                       GXDOT    1323
C     TYPE 8                                                            GXDOT    1324
C                                                                       GXDOT    1325
  680 CALL DEGV08(JSGV)                                                 GXDOT    1326
      GOTO 750                                                          GXDOT    1327
C                                                                       GXDOT    1328
C     HYDRO GOVERNOR TYPE 20 / 21 / 22                                  GXDOT    1329
C                                                                       GXDOT    1330
  700 CALL DEGV20(JSGV)                                                 GXDOT    1331
      GOTO 750                                                          GXDOT    1332
  710 CALL DEGV21(JSGV)                                                 GXDOT    1333
      GOTO 750                                                          GXDOT    1334
  720 CALL DEGV22(JSGV)                                                 GXDOT    1335
  750 CONTINUE                                                          GXDOT    1336
C                                                                       GXDOT    1337
C     ENDIF IGVN.NE.0                                                   GXDOT    1338
C                                                                       GXDOT    1339
      ENDIF                                                             GXDOT    1340
C                                                                       GXDOT    1341
      IF(IGVN.NE.50)CALL UPDATE(JSGV)                                   GXDOT    1342
C                                                                       GXDOT    1343
C   STORE CVP FOR TYPE 1,2 AND 4 GOVERNOR                               GXDOT    1344
C                                                                       GXDOT    1345
      IF(IGVN.NE.0)THEN                                                 GXDOT    1346
         IF(IGVN.LT.4.OR.IGVN.EQ.31.OR.IGVN.EQ.32)                      GXDOT    1347
     &                     CVP(JYP+2)=XSTATE(JSTATE+5)                  GXDOT    1348
         IF(IGVN.EQ.4.OR.IGVN.EQ.34.OR.IGVN.EQ.35)                      GXDOT    1349
     &                     CVP(JYP+2)=XSTATE(JSTATE+2)                  GXDOT    1350
      ENDIF                                                             GXDOT    1351
C                                                                       GXDOT    1352
C     STORE DSTATE IN XDOT ARRAY                                        GXDOT    1353
C                                                                       GXDOT    1354
      DO 830 LDTX=1,LSTATE                                              GXDOT    1355
         XDOT(IOFSET+LDTX)=DSTATE(LDTX)                                 GXDOT    1356
 830  CONTINUE                                                          GXDOT    1357
C                                                                       GXDOT    1358
C     UPDATE JACOBIAN MATRICES OF THE MACHINE IF NECESSARY              GXDOT    1359
C                                                                       GXDOT    1360
      MQ=MQ-1                                                           GXDOT    1361
      IF (JMUPDT) THEN                                                  GXDOT    1362
         IF (IGENS.NE.4) THEN                                           GXDOT    1363
            JY=JYG                                                      GXDOT    1364
            IWS1=MSTATE(1,N)                                            GXDOT    1365
            DELOMG=XSTATE(IWS1+2)                                       GXDOT    1366
            ICBUSN=K                                                    GXDOT    1367
            CALL DGENLN(1,VR,VIM,MD,MQ,ISTATE)                          GXDOT    1368
         ELSE                                                           GXDOT    1369
            XPDN=XPD(N)                                                 GXDOT    1370
            CPD=CDG(1,N)-VIM*XPDN                                       GXDOT    1371
            CPQ=CDG(2,N)+VR*XPDN                                        GXDOT    1372
            CALL CGENLN(1,VR,VIM,CPD,CPQ,XPDN,ISTATE)                   GXDOT    1373
         END IF                                                         GXDOT    1374
      END IF                                                            GXDOT    1375
C                                                                       GXDOT    1376
 840  CONTINUE                                                          GXDOT    1377
C                                                                       GXDOT    1378
C     UPDATE COUNTERS                                                   GXDOT    1379
C                                                                       GXDOT    1380
      IF (IGENS.NE.4) THEN                                              GXDOT    1381
         IAIDEX=IAIDEX+ISTATE+2                                         GXDOT    1382
         ICIDEX=ICIDEX+2*(MD+MQ+1)                                      GXDOT    1383
C                                                                       GXDOT    1384
 860     IBIDEX=IBIDEX+1                                                GXDOT    1385
         KS=IBJCOB(IBIDEX)                                              GXDOT    1386
         IF (KS.EQ.0) GOTO 865                                          GXDOT    1387
         IBIDEX=IBIDEX+2*ISTATE                                         GXDOT    1388
         GOTO 860                                                       GXDOT    1389
 865     CONTINUE                                                       GXDOT    1390
      ELSE                                                              GXDOT    1391
         IF (IGVN.EQ.0) THEN                                            GXDOT    1392
            IAIDEX=IAIDEX+4                                             GXDOT    1393
            IBIDEX=IBIDEX+2                                             GXDOT    1394
            ICIDEX=ICIDEX+2                                             GXDOT    1395
         ELSE                                                           GXDOT    1396
            IAIDEX=IAIDEX+ISTATE*ISTATE                                 GXDOT    1397
            IBIDEX=IBIDEX+2*ISTATE                                      GXDOT    1398
            ICIDEX=ICIDEX+2*ISTATE                                      GXDOT    1399
         END IF                                                         GXDOT    1400
      END IF                                                            GXDOT    1401
C                                                                       GXDOT    1402

C --------------- PARALLEL CODE ADDITIONS ---------------------------- C

C      IF (L.LT.KTHGE(K)) GO TO 100                                      GXDOT    1403

101   continue
 
C      write(8,*) 'One machine iteration complete', 'final n = ', N

 850  CONTINUE                                                          GXDOT    1404

c      call MP_CONCAT( N, concN, 4*IPNODE, allgrp)
c      call MP_CONCAT( XSTATE, concXSTATE, 4*IPNODE, allgrp)
c      call MP_CONCAT( JSTATE, concJSTATE, 4*IPNODE, allgrp)
c      call MP_CONCAT( PDGN, concPDGN, 4*IPNODE, allgrp)
c      call MP_CONCAT( PQGN, concPQGN, 4*IPNODE, allgrp)

C -------------------------------------------------------------------- C
       
      IF (JMUPDT.AND.KORDJB.EQ.0) KORDJB=1                              GXDOT    1405
C                                                                       GXDOT    1406
      RETURN                                                            GXDOT    1407
C                                                                       GXDOT    1408
 5000 FORMAT(' *** ERROR GENERATOR AT BUS ',I5,' STATION: ',3A4         GXDOT    1409
     1,' GID ',A2)                                                      GXDOT    1410
 5010 FORMAT('     THE GENERATOR FLUXES EXCEED 5.0 P.U. THE DATA OF ',  GXDOT    1411
     1'THIS GENERATOR')                                                 GXDOT    1412
 5020 FORMAT('     MAY BE ERRONEOUS.')                                  GXDOT    1413
 5030 FORMAT('     THE GENERATOR FLUXES EXCEED 5.0 P.U. IN ADDITION, ', GXDOT    1414
     1'THE VOLTAGES OF')                                                GXDOT    1415
 5040 FORMAT(5X,I5,' BUSES IN THE SYSTEM ARE OUTSIDE THE STABILITY ',   GXDOT    1416
     1'CHECKING LIMITS.')                                               GXDOT    1417
 5050 FORMAT('     THE SYSTEM MAY BE UNSTABLE OR SOME SYSTEM DATA MAY ',GXDOT    1418
     1'BE ERRONEOUS.')                                                  GXDOT    1419
 5060 FORMAT(' *** WARNING GENERATOR AT BUS ',I5,' STATION: ',3A4       GXDOT    1420
     1,' GID ',A2)                                                      GXDOT    1421
 5070 FORMAT('     AT TIME =',F8.3,', THE FIELD CURRENT BECOMES '       GXDOT    1422
     1,'NEGATIVE. IFD =',F9.4)                                          GXDOT    1423
 5080 FORMAT('     AT TIME =',F8.3,', THE FIELD CURRENT RETURNS TO '    GXDOT    1424
     1,'POSITIVE. IFD =',F9.4)                                          GXDOT    1425
C                                                                       GXDOT    1426
      END                                                               GXDOT    1427
