CFPRIME DGEN                                                            DGEN        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 DGEN (STEP)                                            DGEN        3
CD                                                                      DGEN        4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF DETAILED AND        DGEN        5
CD    CLASSICAL MACHINE FOR USE IN THE RUNGE-KUTTA AND TRAPEZOIDAL      DGEN        6
CD    METHOD. FOR EACH OF THE DETAILED GENERATOR IT CALLS OTHER ROUTINESDGEN        7
CD    TO CALCULATE THE DERIVATIVES OF THE CONTROLLER.                   DGEN        8
CD                                                                      DGEN        9
CD    IT CALLS ROUTINE RKG TO UPDATE THE STATES FOR THE CURRENT TIME    DGEN       10
CD    STEP BY THE RUNGE-KUTTA FORMULA.                                  DGEN       11
CD                                                                      DGEN       12
      INCLUDE 'PARX.INS'                                                DGEN       13
      INCLUDE 'CNPT.INS'                                                DGEN       14
      INCLUDE 'CNIPTR.INS'                                              DGEN       15
      INCLUDE 'CNB1.INS'                                                DGEN       16
      INCLUDE 'CNB3.INS'                                                DGEN       17
      INCLUDE 'CNB4.INS'                                                DGEN       18
      INCLUDE 'CNB5.INS'                                                DGEN       19
      INCLUDE 'CNMSTA.INS'                                              DGEN       20
      INCLUDE 'CNXSTA.INS'                                              DGEN       21
      INCLUDE 'CNQSTA.INS'                                              DGEN       22
      INCLUDE 'CNZSTA.INS'                                              DGEN       23
      INCLUDE 'CNB8.INS'                                                DGEN       24
      INCLUDE 'CNB9.INS'                                                DGEN       25
      INCLUDE 'CNB91.INS'                                               DGEN       26
      INCLUDE 'CNB10.INS'                                               DGEN       27
      INCLUDE 'CNB19.INS'                                               DGEN       28
      INCLUDE 'CNMDAT.INS'                                              DGEN       29
      INCLUDE 'CNMSG.INS'                                               DGEN       30
      INCLUDE 'CNSTN.INS'                                               DGEN       31
      INCLUDE 'CNEXC.INS'                                               DGEN       32
      INCLUDE 'CNUDM.INS'                                               DGEN       33
      INCLUDE 'CNPRGV.INS'                                              DGEN       34
      INCLUDE 'CNUVAR.INS'                                              DGEN       35
      INCLUDE 'CNVOLT.INS'                                              DGEN       36
      INCLUDE 'CNFLAG.INS'                                              DGEN       37
      INCLUDE 'CNMYVA.INS'                                              DGEN       38
      INCLUDE 'CNYVAR.INS'                                              DGEN       39
      INCLUDE 'CNPREV.INS'                                              DGEN       40
      INCLUDE 'CNUNIT.INS'                                              DGEN       41
      INCLUDE 'CNVMAX.INS'                                              DGEN       42
      INCLUDE 'BWRALL.INS'                                              DGEN       43
C                                                                       DGEN       44
      INTEGER ICABWR                                                    DGEN       45
      COMPLEX VOLTK,VOLTK1                                              DGEN       46
      DIMENSION EVOLT(2),EVOLT1(2)                                      DGEN       47
      EQUIVALENCE (VOLTK,EVOLT(1),VR),(EVOLT(2),VIM)                    DGEN       48
      EQUIVALENCE (VOLTK1,EVOLT1(1),VR1),(EVOLT1(2),VIM1)               DGEN       49
C                                                                       DGEN       50
      CHARACTER*2 CID                                                   DGEN       51
*IF DEBUG                                                               DGEN       52
      LDEB=(JDEB(81).NE.0)                                              DGEN       53
*ENDIF                                                                  DGEN       54
C                                                                       DGEN       55
      CKD=0.0                                                           DGEN       56
      CKD2=0.0                                                          DGEN       57
      XKQ1=0.0                                                          DGEN       58
      XKQ2=0.0                                                          DGEN       59
      XKQ3=0.0                                                          DGEN       60
      CKQ=0.0                                                           DGEN       61
      CKQ1=0.0                                                          DGEN       62
      CKQ2=0.0                                                          DGEN       63
      ASATQ=0.0                                                         DGEN       64
      BSATQ=0.0                                                         DGEN       65
C                                                                       DGEN       66
      ISR=6                                                             DGEN       67
      IFC=0                                                             DGEN       68
C                                                                       DGEN       69
      ITMACH=0                                                          DGEN       70
      ICABWR=0                                                          DGEN       71
C                                                                       DGEN       72
      DO 4150 K=1,IPNODE                                                DGEN       73
      KN=K*3                                                            DGEN       74
      NLF=NOLD(K)                                                       DGEN       75
      VOLTK=VOLT(K)                                                     DGEN       76
      GTV=CABS(VOLTK)                                                   DGEN       77
      AT=ATAN2(VIM,VR)                                                  DGEN       78
      N=NTHG(K)-1                                                       DGEN       79
      NEND=NTHG(K+1)-1                                                  DGEN       80
  100 N=N+1                                                             DGEN       81
C                                                                       DGEN       82
      JG=JCONTA(1,N)                                                    DGEN       83
      HM=DDAT(JG+1)                                                     DGEN       84
      IF(HM.LT. 1.0E-5)GOTO 4100                                        DGEN       85
C                                                                       DGEN       86
      IGENS=ICONTA(1,N)                                                 DGEN       87
      IGVN=ICONTA(2,N)                                                  DGEN       88
      ISATN=ICONTA(3,N)                                                 DGEN       89
      IEXN=ICONTA(4,N)                                                  DGEN       90
      ISTABN=ICONTA(5,N)                                                DGEN       91
      IFLTRN=ICONTA(6,N)                                                DGEN       92
      IUALN=ICONTA(7,N)                                                 DGEN       93
      ICBRN=ICONTA(9,N)                                                 DGEN       94
      IGSTAN=ICONTA(10,N)                                               DGEN       95
      ITEBN=ICONTA(11,N)                                                DGEN       96
      IMXLN=ICONTA(12,N)                                                DGEN       97
C                                                                       DGEN       98
      CID(1:2)=NDGC(N)(3:4)                                             DGEN       99
C                                                                       DGEN      100
      IF(IGENS.EQ.4)THEN                                                DGEN      101
C                                                                       DGEN      102
C   MACHINES REPRESENTED BY CLASSICAL MODEL                             DGEN      103
C                                                                       DGEN      104
      IOFSET=MSTATE(1,N)                                                DGEN      105
      LSTATE=0                                                          DGEN      106
      JG=JCONTA(1,N)                                                    DGEN      107
      JYG=MYVAR(1,N)                                                    DGEN      108
C                                                                       DGEN      109
      TELEC=REAL(VOLT(K))*CDG(1,N)+AIMAG(VOLT(K))*CDG(2,N)              DGEN      110
      TGAPG(N)=TELEC                                                    DGEN      111
      IF(IFC.NE.0)THEN                                                  DGEN      112
        TELEC=TELEC+TGAPG(N-1)                                          DGEN      113
        IFC=0                                                           DGEN      114
      ELSE                                                              DGEN      115
        IF(N.NE.NT)THEN                                                 DGEN      116
          JGP1=JCONTA(1,N+1)                                            DGEN      117
          IF((IDDAT(JG+5)-IDDAT(JGP1+5)).NE.0)THEN                      DGEN      118
            TELEC=TELEC+REAL(VOLT(K+1))*CDG(1,N+1)                      DGEN      119
     *                 +AIMAG(VOLT(K+1))*CDG(2,N+1)                     DGEN      120
            IFC=1                                                       DGEN      121
          ENDIF                                                         DGEN      122
        ENDIF                                                           DGEN      123
      ENDIF                                                             DGEN      124
C                                                                       DGEN      125
      IF(LIR1)XPREV(1,IOFSET+2)=XSTATE(IOFSET+2)                        DGEN      126
C                                                                       DGEN      127
C        EQUATIONS OF MOTION                                            DGEN      128
C                                                                       DGEN      129
      TINN=TIN(JYG+1)                                                   DGEN      130
      HM=DDAT(JG+1)                                                     DGEN      131
      DAMP=DDAT(JG+2)                                                   DGEN      132
C                                                                       DGEN      133
      PACCL=(TINN-DAMP*XSTATE(IOFSET+1)-TELEC)                          DGEN      134
      DSTATE(LSTATE+1)=PACCL*HM                                         DGEN      135
      DSTATE(LSTATE+2)=XSTATE(IOFSET+1)                                 DGEN      136
      ACCP(JYG+5)=PACCL                                                 DGEN      137
      JSTATE=IOFSET+2                                                   DGEN      138
      LSTATE=2                                                          DGEN      139
C                                                                       DGEN      140
C                                                                       DGEN      141
*IF DEBUG                                                               DGEN      142
      IF(LDEB)WRITE(IUD6,8800)LSTATE,IOFSET,(J,XSTATE(IOFSET+J)         DGEN      143
     *,DSTATE(J),J=1,LSTATE)                                            DGEN      144
*ENDIF                                                                  DGEN      145
C                                                                       DGEN      146
      GOTO 3550                                                         DGEN      147
C                                                                       DGEN      148
      ENDIF                                                             DGEN      149
C                                                                       DGEN      150
      JYG=MYVAR(1,N)                                                    DGEN      151
      JSTATE=MSTATE(1,N)                                                DGEN      152
      IOFSET=JSTATE                                                     DGEN      153
      IDOMG=JSTATE+1                                                    DGEN      154
      LSTATE=0                                                          DGEN      155
      IF (LIR1) XPREV(1,JSTATE+2)=XSTATE(JSTATE+2)                      DGEN      156
      MD=IDDAT(JG+34)                                                   DGEN      157
      MQ=IDDAT(JG+35)                                                   DGEN      158
      DAMP=DDAT(JG+2)                                                   DGEN      159
      XAD=DDAT(JG+6)                                                    DGEN      160
      XAQ=DDAT(JG+7)                                                    DGEN      161
      XAL=DDAT(JG+8)                                                    DGEN      162
      XF=DDAT(JG+36)                                                    DGEN      163
      RF=DDAT(JG+11)                                                    DGEN      164
      AXD=DDAT(JG+22)                                                   DGEN      165
      AXQ=DDAT(JG+23)                                                   DGEN      166
      WXBASE=DDAT(JG+5)                                                 DGEN      167
C                                                                       DGEN      168
*IF DEBUG                                                               DGEN      169
      IF (LDEB) WRITE(IUD6,8000) JG,DDAT(JG+5),WXBASE,WOBASE            DGEN      170
*ENDIF                                                                  DGEN      171
C                                                                       DGEN      172
      SD=DDAT(JG+32)                                                    DGEN      173
      SQ=DDAT(JG+33)                                                    DGEN      174
      EFDN=EFD(JYG+4)                                                   DGEN      175
      CDGN=CDG(1,N)                                                     DGEN      176
      CQGN=CDG(2,N)                                                     DGEN      177
      IREP=0                                                            DGEN      178
  150 CONTINUE                                                          DGEN      179
      DELTA=XSTATE(JSTATE+2)                                            DGEN      180
      CSX=COS(DELTA)                                                    DGEN      181
      SNX=SIN(DELTA)                                                    DGEN      182
      CD1=CSX*CDGN+SNX*CQGN                                             DGEN      183
      CQ1=CSX*CQGN-SNX*CDGN                                             DGEN      184
C                                                                       DGEN      185
      XADS=SD*XAD                                                       DGEN      186
      XAQS=SQ*XAQ                                                       DGEN      187
C                                                                       DGEN      188
      FLXL=XSTATE(JSTATE+3)*DDAT(JG+36)                                 DGEN      189
      IF(MD.EQ.2)THEN                                                   DGEN      190
      FLXL=FLXL+XSTATE(JSTATE+4)*DDAT(JG+37)                            DGEN      191
      ELSEIF(MD.EQ.3)THEN                                               DGEN      192
      FLXL=FLXL+XSTATE(JSTATE+4)*DDAT(JG+37)                            DGEN      193
     *+XSTATE(JSTATE+5)*DDAT(JG+38)                                     DGEN      194
      ENDIF                                                             DGEN      195
C                                                                       DGEN      196
      C3=1./(AXD+1./XADS)                                               DGEN      197
C                                                                       DGEN      198
      SIAD=C3*(FLXL-CD1)                                                DGEN      199
C                                                                       DGEN      200
      SIAQ=0.0                                                          DGEN      201
      IF(MQ.GT.1)THEN                                                   DGEN      202
      JJ=JSTATE+MD                                                      DGEN      203
      XKQ1=DDAT(JG+12)                                                  DGEN      204
      SIAQ=XSTATE(JJ+3)/XKQ1                                            DGEN      205
      IF(MQ.EQ.3)THEN                                                   DGEN      206
      XKQ2=DDAT(JG+16)                                                  DGEN      207
      SIAQ=SIAQ+XSTATE(JJ+4)/XKQ2                                       DGEN      208
      ELSEIF(MQ.EQ.4)THEN                                               DGEN      209
      XKQ2=DDAT(JG+16)                                                  DGEN      210
      XKQ3=DDAT(JG+20)                                                  DGEN      211
      SIAQ=SIAQ+XSTATE(JJ+4)/XKQ2+XSTATE(JJ+5)/XKQ3                     DGEN      212
      ENDIF                                                             DGEN      213
      ENDIF                                                             DGEN      214
C                                                                       DGEN      215
      C4=1./(AXQ+1./XAQS)                                               DGEN      216
      SIAQ=C4*(SIAQ-CQ1)                                                DGEN      217
C                                                                       DGEN      218
      IF (ABS(SIAD).GT.5.0.OR.ABS(SIAQ).GT.5.0) THEN                    DGEN      219
C                                                                       DGEN      220
C     MACHINE FLUX EXCEEDS 5.0 PU. CHECK SYSTEM VOLTAGES TO DETERMINE   DGEN      221
C     THE POSSIBLE CAUSE.                                               DGEN      222
C                                                                       DGEN      223
         MAXBUS=0                                                       DGEN      224
         MINBUS=0                                                       DGEN      225
         DO 250 KK=1,IVLAST                                             DGEN      226
            IVMAXK=IVMAX(KK)                                            DGEN      227
            IF (IVMAXK.EQ.0.OR.IVMTI(IVMAXK+1).EQ.0) GOTO 200           DGEN      228
            MAXBUS=MAXBUS+1                                             DGEN      229
  200       IF (IVMAXK.EQ.0.OR.IVMTI(IVMAXK+3).EQ.0) GOTO 250           DGEN      230
            MINBUS=MINBUS+1                                             DGEN      231
  250    CONTINUE                                                       DGEN      232
C                                                                       DGEN      233
         WRITE(MSG(1),9000) NLF,INAME(KN-2),INAME(KN-1),INAME(KN),CID   DGEN      234
         IF (MAXBUS.EQ.1.AND.MINBUS.EQ.0) THEN                          DGEN      235
         WRITE(MSG(2),9100)                                             DGEN      236
         WRITE(MSG(3),9200)                                             DGEN      237
         CALL PRTMSG(3)                                                 DGEN      238
         ELSE                                                           DGEN      239
         WRITE(MSG(2),9300)                                             DGEN      240
         WRITE(MSG(3),9400) MAXBUS+MINBUS                               DGEN      241
         WRITE(MSG(4),9500)                                             DGEN      242
         CALL PRTMSG(4)                                                 DGEN      243
         END IF                                                         DGEN      244
         CALL ASTOP('DGEN: FATAL ERROR',17)                             DGEN      245
C                                                                       DGEN      246
      END IF                                                            DGEN      247
C                                                                       DGEN      248
      IF (.NOT.LIR4) GOTO 300                                           DGEN      249
      IF (ISATN.EQ.0) GOTO 300                                          DGEN      250
C                                                                       DGEN      251
C  NEW SATURATION FACTOR                                                DGEN      252
C                                                                       DGEN      253
      BAT=SQRT(SIAD**2+SIAQ**2)                                         DGEN      254
      BATL=DDAT(JG+28)                                                  DGEN      255
      BATM=DDAT(JG+29)                                                  DGEN      256
      IF (BAT.GT.BATL)THEN                                              DGEN      257
      IF (BAT.LT.BATM)THEN                                              DGEN      258
C                                                                       DGEN      259
C   REGION 2                                                            DGEN      260
C                                                                       DGEN      261
      XSAT=BAT-BATL                                                     DGEN      262
      DBAT=DDAT(JG+26)*EXP(DDAT(JG+27)*XSAT)                            DGEN      263
      BATA=BAT+DBAT                                                     DGEN      264
C                                                                       DGEN      265
      ELSE                                                              DGEN      266
C                                                                       DGEN      267
C   REGION 3                                                            DGEN      268
C                                                                       DGEN      269
      DBAT=DDAT(JG+26)*EXP(DDAT(JG+27)*(BATM-BATL))                     DGEN      270
      DBAT=DBAT+(DDAT(JG+30)*(BAT-BATM))                                DGEN      271
      BATA=BATM+DBAT                                                    DGEN      272
C                                                                       DGEN      273
C   ENDIF BAT.LT.BATM                                                   DGEN      274
C                                                                       DGEN      275
      ENDIF                                                             DGEN      276
      DDAT(JG+32)=BAT/BATA                                              DGEN      277
      ELSE                                                              DGEN      278
      DDAT(JG+32)=1.                                                    DGEN      279
      ENDIF                                                             DGEN      280
C                                                                       DGEN      281
      DDAT(JG+33)=1.0                                                   DGEN      282
C                                                                       DGEN      283
      IF (ISATN.EQ.2)THEN                                               DGEN      284
      DDAT(JG+33)=DDAT(JG+32)                                           DGEN      285
      ELSE IF (ISATN.EQ.3)THEN                                          DGEN      286
      BATLQ=DDAT(JG+47)                                                 DGEN      287
      BATMQ=DDAT(JG+48)                                                 DGEN      288
      IF (BAT.GT.BATLQ)THEN                                             DGEN      289
      IF (BAT.LT.BATMQ)THEN                                             DGEN      290
C                                                                       DGEN      291
C   REGION 2                                                            DGEN      292
C                                                                       DGEN      293
      XSAT=BAT-BATLQ                                                    DGEN      294
      ASATQ=DDAT(JG+45)                                                 DGEN      295
      BSATQ=DDAT(JG+46)                                                 DGEN      296
      DBAT=ASATQ*EXP(BSATQ*XSAT)                                        DGEN      297
      BATA=BAT+DBAT                                                     DGEN      298
C                                                                       DGEN      299
      ELSE                                                              DGEN      300
C                                                                       DGEN      301
C     REGION 3                                                          DGEN      302
C                                                                       DGEN      303
      DBAT=ASATQ*EXP(BSATQ*(BATMQ-BATLQ))                               DGEN      304
      DBAT=DBAT+(DDAT(JG+49)*(BAT-BATMQ))                               DGEN      305
      BATA=BATMQ+DBAT                                                   DGEN      306
C                                                                       DGEN      307
C   ENDIF BAT.LT.BATMQ                                                  DGEN      308
C                                                                       DGEN      309
      ENDIF                                                             DGEN      310
C                                                                       DGEN      311
      DDAT(JG+33)=BAT/BATA                                              DGEN      312
C                                                                       DGEN      313
C   ENDIF BAT.GT.BATLQ                                                  DGEN      314
C                                                                       DGEN      315
      ENDIF                                                             DGEN      316
C                                                                       DGEN      317
C   ENDIF ISATN.EQ.2                                                    DGEN      318
C                                                                       DGEN      319
      ENDIF                                                             DGEN      320
C                                                                       DGEN      321
  300 CONTINUE                                                          DGEN      322
C                                                                       DGEN      323
C   D-AXIS ROTOR CURRENTS                                               DGEN      324
C   FIELD CURRENT IN RECIPROCAL P.U. SYSTEM                             DGEN      325
C                                                                       DGEN      326
      IF (IDDAT(JG+24).EQ.0.AND.IDDAT(JG+25).EQ.0) THEN                 DGEN      327
C                                                                       DGEN      328
C     XC1, XC2 ARE NOT PRESENTED                                        DGEN      329
C                                                                       DGEN      330
      CFDR=(XSTATE(JSTATE+3)-SIAD)*XF                                   DGEN      331
      IF(MD.EQ.2)THEN                                                   DGEN      332
      XKD1=DDAT(JG+37)                                                  DGEN      333
      CKD=(XSTATE(JSTATE+4)-SIAD)*XKD1                                  DGEN      334
      ELSEIF(MD.EQ.3)THEN                                               DGEN      335
      XKD1=DDAT(JG+37)                                                  DGEN      336
      XKD2=DDAT(JG+38)                                                  DGEN      337
      CKD=(XSTATE(JSTATE+4)-SIAD)*XKD1                                  DGEN      338
      CKD2=(XSTATE(JSTATE+5)-SIAD)*XKD2                                 DGEN      339
      ENDIF                                                             DGEN      340
C                                                                       DGEN      341
      ELSE                                                              DGEN      342
C                                                                       DGEN      343
C     XC1, XC2 ARE PRESENTED                                            DGEN      344
C                                                                       DGEN      345
      CFDR=(XSTATE(JSTATE+3)-SIAD)                                      DGEN      346
      CKD=(XSTATE(JSTATE+4)-SIAD)                                       DGEN      347
C                                                                       DGEN      348
      IF(MD.EQ.2)THEN                                                   DGEN      349
C                                                                       DGEN      350
      X11=DDAT(JG+39)                                                   DGEN      351
      X12=DDAT(JG+40)                                                   DGEN      352
      X22=DDAT(JG+41)                                                   DGEN      353
      CFDRM=X11*CFDR+X12*CKD                                            DGEN      354
      CKD=X12*CFDR+X22*CKD                                              DGEN      355
      CFDR=CFDRM                                                        DGEN      356
C                                                                       DGEN      357
      ELSEIF(MD.EQ.3)THEN                                               DGEN      358
C                                                                       DGEN      359
      CKD2=(XSTATE(JSTATE+5)-SIAD)                                      DGEN      360
C                                                                       DGEN      361
      X11=DDAT(JG+39)                                                   DGEN      362
      X12=DDAT(JG+40)                                                   DGEN      363
      X13=DDAT(JG+41)                                                   DGEN      364
      X22=DDAT(JG+42)                                                   DGEN      365
      X23=DDAT(JG+43)                                                   DGEN      366
      X33=DDAT(JG+44)                                                   DGEN      367
C                                                                       DGEN      368
      CFDRM=X11*CFDR+X12*CKD+X13*CKD2                                   DGEN      369
      CKDM=X12*CFDR+X22*CKD+X23*CKD2                                    DGEN      370
      CKD2=X13*CFDR+X23*CKD+X33*CKD2                                    DGEN      371
      CFDR=CFDRM                                                        DGEN      372
      CKD=CKDM                                                          DGEN      373
C                                                                       DGEN      374
      ENDIF                                                             DGEN      375
      ENDIF                                                             DGEN      376
C                                                                       DGEN      377
      IF(MQ.GT.1)THEN                                                   DGEN      378
      CKQ=(XSTATE(JJ+3)-SIAQ)/XKQ1                                      DGEN      379
      IF(MQ.EQ.3)THEN                                                   DGEN      380
      CKQ1=(XSTATE(JJ+4)-SIAQ)/XKQ2                                     DGEN      381
      ELSEIF(MQ.EQ.4)THEN                                               DGEN      382
      CKQ1=(XSTATE(JJ+4)-SIAQ)/XKQ2                                     DGEN      383
      CKQ2=(XSTATE(JJ+5)-SIAQ)/XKQ3                                     DGEN      384
      ENDIF                                                             DGEN      385
      ENDIF                                                             DGEN      386
C                                                                       DGEN      387
C     SPECIAL PATH FOR NEGATIVE FIELD CURRENT                           DGEN      388
C                                                                       DGEN      389
      IF (CFDR.LT.0.0) THEN                                             DGEN      390
         IF (ICBRN.NE.0) THEN                                           DGEN      391
            IF (ICBRN.EQ.1) THEN                                        DGEN      392
               IF (IREP.EQ.0) THEN                                      DGEN      393
                  IREP=1                                                DGEN      394
                  XF=999999.0                                           DGEN      395
                  AXD=999999.0                                          DGEN      396
                  GOTO 150                                              DGEN      397
               ELSE                                                     DGEN      398
                  CFDR=0.0                                              DGEN      399
                  GOTO 350                                              DGEN      400
               END IF                                                   DGEN      401
            ELSE IF (ICBRN.EQ.2) THEN                                   DGEN      402
               EFDN=0.0                                                 DGEN      403
               JCB=JCONTA(8,N)                                          DGEN      404
               RF=RF+DDAT(JCB+2)                                        DGEN      405
            ELSE                                                        DGEN      406
               EFDN=0.0                                                 DGEN      407
               JCB=JCONTA(8,N)                                          DGEN      408
               RF=RF+DDAT(JCB+2)*(ABS(CFDR)**DDAT(JCB+4))               DGEN      409
            END IF                                                      DGEN      410
         ELSE                                                           DGEN      411
            IF (LIR4.AND.ICONTA(13,N).EQ.1) THEN                        DGEN      412
               WRITE(MSG(1),9600) NLF,INAME(KN-2),INAME(KN-1)           DGEN      413
     *                           ,INAME(KN),CID                         DGEN      414
               WRITE(MSG(2),9700) TS+STEP,CFDR*XAD                      DGEN      415
               CALL PRTMSG(2)                                           DGEN      416
               ICONTA(13,N)=-1                                          DGEN      417
            END IF                                                      DGEN      418
         END IF                                                         DGEN      419
      ELSE IF (LIR4.AND.ICONTA(13,N).EQ.-1) THEN                        DGEN      420
         WRITE(MSG(1),9600) NLF,INAME(KN-2),INAME(KN-1)                 DGEN      421
     *                     ,INAME(KN),CID                               DGEN      422
         WRITE(MSG(2),9800) TS+STEP,CFDR*XAD                            DGEN      423
         CALL PRTMSG(2)                                                 DGEN      424
         ICONTA(13,N)=1                                                 DGEN      425
      END IF                                                            DGEN      426
C                                                                       DGEN      427
  350 CFDN=CFDR*XAD                                                     DGEN      428
      CFD(JYG+5)=CFDN                                                   DGEN      429
C                                                                       DGEN      430
      ND=3                                                              DGEN      431
      DSTATE(ND)=(EFDN/XAD-CFDR)*RF*WXBASE                              DGEN      432
      IF(MD.EQ.2)THEN                                                   DGEN      433
      DSTATE(4)=-DDAT(JG+15)*CKD                                        DGEN      434
      ND=4                                                              DGEN      435
      ELSEIF(MD.EQ.3)THEN                                               DGEN      436
      DSTATE(4)=-DDAT(JG+15)*CKD                                        DGEN      437
      DSTATE(5)=-DDAT(JG+19)*CKD2                                       DGEN      438
      ND=5                                                              DGEN      439
      ENDIF                                                             DGEN      440
      IF(MQ.GT.1)THEN                                                   DGEN      441
      DSTATE(ND+1)=-DDAT(JG+13)*CKQ                                     DGEN      442
      IF(MQ.EQ.3)THEN                                                   DGEN      443
      DSTATE(ND+2)=-DDAT(JG+17)*CKQ1                                    DGEN      444
      ELSEIF(MQ.EQ.4)THEN                                               DGEN      445
      DSTATE(ND+2)=-DDAT(JG+17)*CKQ1                                    DGEN      446
      DSTATE(ND+3)=-DDAT(JG+21)*CKQ2                                    DGEN      447
      ENDIF                                                             DGEN      448
      ND=ND+MQ-1                                                        DGEN      449
      ENDIF                                                             DGEN      450
C                                                                       DGEN      451
      TELEC=VR*CDGN+VIM*CQGN                                            DGEN      452
      PDGN=TELEC                                                        DGEN      453
      PDG(JYG+2)=PDGN                                                   DGEN      454
      PQGN=VIM*CDGN-VR*CQGN                                             DGEN      455
      PQG(JYG+3)=PQGN                                                   DGEN      456
      TELEC=TELEC+(CDGN**2+CQGN**2)*DDAT(JG+9)                          DGEN      457
      TGAPG(N)=TELEC                                                    DGEN      458
*IF DEBUG                                                               DGEN      459
      IF (LDEB) WRITE(IUD6,8400) IR,N,K,IFC,DDAT(JG+9),VOLT(K),CDGN,    DGEN      460
     +CQGN,TELEC,TGAPG(N)                                               DGEN      461
*ENDIF                                                                  DGEN      462
      IF(IFC.NE.0)THEN                                                  DGEN      463
      TELEC=TELEC+TGAPG(N-1)                                            DGEN      464
*IF DEBUG                                                               DGEN      465
      IF (LDEB) WRITE(IUD6,8500) N,IFC,TELEC,TGAPG(N-1)                 DGEN      466
*ENDIF                                                                  DGEN      467
      IFC=0                                                             DGEN      468
      GOTO 400                                                          DGEN      469
      ELSE                                                              DGEN      470
        IF(N.EQ.NT)GOTO 400                                             DGEN      471
        JGP1=JCONTA(1,N+1)+5                                            DGEN      472
        RAP1=DDAT(JGP1+4)                                               DGEN      473
*IF DEBUG                                                               DGEN      474
         IF (LDEB) WRITE (IUD6,8600) N,IFC,RAP1,DDAT(JG+5),DDAT(JGP1)   DGEN      475
*ENDIF                                                                  DGEN      476
         IF((IDDAT(JG+5)-IDDAT(JGP1)).NE.0)THEN                         DGEN      477
         CDGN1=CDG(1,N+1)                                               DGEN      478
         CQGN1=CDG(2,N+1)                                               DGEN      479
         CMAG2=CDGN1**2+CQGN1**2                                        DGEN      480
         VOLTK1=VOLT(K+1)                                               DGEN      481
         TELEC=TELEC+VR1*CDGN1+VIM1*CQGN1+CMAG2*RAP1                    DGEN      482
*IF DEBUG                                                               DGEN      483
         IF (LDEB) WRITE(IUD6,8700) N,IFC,K,RAP1,CDGN1,CQGN1,VOLT(K+1)  DGEN      484
*ENDIF                                                                  DGEN      485
         IFC=1                                                          DGEN      486
         ENDIF                                                          DGEN      487
      ENDIF                                                             DGEN      488
C                                                                       DGEN      489
  400 CONTINUE                                                          DGEN      490
C                                                                       DGEN      491
C  EQUATIONS OF MOTION                                                  DGEN      492
C                                                                       DGEN      493
      TINN=TIN(JYG+1)                                                   DGEN      494
C                                                                       DGEN      495
*IF DEBUG                                                               DGEN      496
      IF (LDEB) WRITE(IUD6,8100) TINN                                   DGEN      497
*ENDIF                                                                  DGEN      498
C                                                                       DGEN      499
      IF (IDDAT(JG+31).NE.0)THEN                                        DGEN      500
      XFREQ=1.0+XSTATE(JSTATE+1)/WXBASE                                 DGEN      501
      TINN=TINN*XFREQ**DDAT(JG+31)                                      DGEN      502
      ENDIF                                                             DGEN      503
C                                                                       DGEN      504
*IF DEBUG                                                               DGEN      505
      IF (LDEB) WRITE(IUD6,8200) TINN,DAMP,XSTATE(JSTATE+1),TELEC,HM    DGEN      506
*ENDIF                                                                  DGEN      507
C                                                                       DGEN      508
      PACCL=TINN-DAMP*XSTATE(JSTATE+1)-TELEC                            DGEN      509
C                                                                       DGEN      510
      IF(ABS(STEP).LE.0.0)THEN                                          DGEN      511
       IF(ITMACH.EQ.0)THEN                                              DGEN      512
        IF(TINN.GT.0.01)THEN                                            DGEN      513
         ACCEL=PACCL/TINN                                               DGEN      514
         DV=VBUS(N)-GTV                                                 DGEN      515
         IF( ACCEL.GT.0.2.AND. DV.GT.0.2)THEN                           DGEN      516
           IFAUTO=0                                                     DGEN      517
           ITMACH=1                                                     DGEN      518
         ELSE                                                           DGEN      519
           IFAUTO=1                                                     DGEN      520
         ENDIF                                                          DGEN      521
        ENDIF                                                           DGEN      522
       ENDIF                                                            DGEN      523
      ENDIF                                                             DGEN      524
C                                                                       DGEN      525
      ACCP(JYG+6)=PACCL                                                 DGEN      526
      DSTATE(1)=PACCL*HM                                                DGEN      527
      DSTATE(2)=XSTATE(JSTATE+1)                                        DGEN      528
C                                                                       DGEN      529
*IF DEBUG                                                               DGEN      530
      IF (LDEB) WRITE(IUD6,8300) DSTATE(1),DSTATE(2)                    DGEN      531
*ENDIF                                                                  DGEN      532
C                                                                       DGEN      533
      LSTATE=ND                                                         DGEN      534
      KSTATE=JSTATE+ND                                                  DGEN      535
      JSTATE=JSTATE+ND                                                  DGEN      536
C                                                                       DGEN      537
      IF(IEXN.NE.0)THEN                                                 DGEN      538
C                                                                       DGEN      539
      JE=JCONTA(3,N)                                                    DGEN      540
      JYE=MYVAR(2,N)                                                    DGEN      541
      IF(ISTABN.GT.0) JYS=MYVAR(3,N)                                    DGEN      542
      IF(IUALN.NE.0) JYU=MYVAR(4,N)                                     DGEN      543
      IF(IMXLN.NE.0) JYMX=MYVAR(8,N)                                    DGEN      544
      IF(IEXN.EQ.50) THEN                                               DGEN      545
         JE0=JE                                                         DGEN      546
         IF(STEP.LT.0.001) THEN                                         DGEN      547
            NSUBD=1                                                     DGEN      548
         ELSE                                                           DGEN      549
            NSUBD=IDDAT(JE0+3)                                          DGEN      550
         ENDIF                                                          DGEN      551
         IF(NSUBD.GT.1.AND..NOT.LIR1) GO TO 800                         DGEN      552
         HSUB=STEP/NSUBD                                                DGEN      553
C                                                                       DGEN      554
C     GET THE INPUT VALUES                                              DGEN      555
C                                                                       DGEN      556
         JE1=JE0+9                                                      DGEN      557
         CALL RINUDM                                                    DGEN      558
C                                                                       DGEN      559
         IF(NRBUS.EQ.0) THEN                                            DGEN      560
            VCR=VR                                                      DGEN      561
            VCI=VIM                                                     DGEN      562
         ELSE                                                           DGEN      563
            IBUSR=IDDAT(JE1+1)                                          DGEN      564
            VCR=REAL(VOLT(IBUSR))                                       DGEN      565
            VCI=AIMAG(VOLT(IBUSR))                                      DGEN      566
         ENDIF                                                          DGEN      567
         RC=DDAT(JE0+1)                                                 DGEN      568
         XC=DDAT(JE0+2)                                                 DGEN      569
         VCD=VCR+(RC*CDGN-XC*CQGN)                                      DGEN      570
         VCQ=VCI+(RC*CQGN+XC*CDGN)                                      DGEN      571
         VCM=SQRT(VCD*VCD+VCQ*VCQ)                                      DGEN      572
         VALIN(1)=VCM                                                   DGEN      573
         IF(VCM.GT.0.05) THEN                                           DGEN      574
            VAG=ATAN2(VCQ,VCD)                                          DGEN      575
            VAGD=DDAT(JE0+5)-VAG                                        DGEN      576
            DDAT(JE0+5)=VAG                                             DGEN      577
            IF(VAGD.GT.3.15) THEN                                       DGEN      578
               IDDAT(JE0+4)=IDDAT(JE0+4)+1                              DGEN      579
            ELSEIF(VAGD.LT.-3.15) THEN                                  DGEN      580
               IDDAT(JE0+4)=IDDAT(JE0+4)-1                              DGEN      581
            ENDIF                                                       DGEN      582
            VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                         DGEN      583
         ELSE                                                           DGEN      584
            VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)                 DGEN      585
         ENDIF                                                          DGEN      586
         IF(GTV.GT.0.05) THEN                                           DGEN      587
            VAGD=DDAT(JE0+7)-AT                                         DGEN      588
            DDAT(JE0+7)=AT                                              DGEN      589
            IF(VAGD.GT.3.15) THEN                                       DGEN      590
               IDDAT(JE0+6)=IDDAT(JE0+6)+1                              DGEN      591
            ELSEIF(VAGD.LT.-3.15) THEN                                  DGEN      592
               IDDAT(JE0+6)=IDDAT(JE0+6)-1                              DGEN      593
            ENDIF                                                       DGEN      594
            VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                          DGEN      595
         ELSE                                                           DGEN      596
            VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)                 DGEN      597
         ENDIF                                                          DGEN      598
         VALIN(3)=ACCP(JYG+6)                                           DGEN      599
         VALIN(4)=GTV                                                   DGEN      600
         VALIN(6)=VR                                                    DGEN      601
         VALIN(7)=VIM                                                   DGEN      602
         VALIN(8)=CDGN                                                  DGEN      603
         VALIN(9)=CQGN                                                  DGEN      604
         VALIN(10)=PDGN                                                 DGEN      605
         VALIN(11)=PQGN                                                 DGEN      606
         VALIN(12)=XSTATE(IDOMG)                                        DGEN      607
         VALIN(16)=CFDN                                                 DGEN      608
         IF(ISTABN.GT.0) THEN                                           DGEN      609
            VALIN(17)=VSS(JYS+1)                                        DGEN      610
         ELSE                                                           DGEN      611
            VALIN(17)=0.0                                               DGEN      612
         ENDIF                                                          DGEN      613
         IF(IUALN.NE.0) THEN                                            DGEN      614
            VALIN(18)=VUAL(JYU+1)                                       DGEN      615
         ELSE                                                           DGEN      616
            VALIN(18)=0.0                                               DGEN      617
         ENDIF                                                          DGEN      618
         VALIN(20)=VREF(JYE+2)                                          DGEN      619
C                                                                       DGEN      620
         DO 750 JJ=1,NSUBD                                              DGEN      621
         GOTO ( 450, 500, 550, 550, 550, 600), INTMTH                   DGEN      622
  450    CONTINUE                                                       DGEN      623
         IR1=0                                                          DGEN      624
         GOTO 600                                                       DGEN      625
  500    CONTINUE                                                       DGEN      626
         IR1=1                                                          DGEN      627
         GOTO 600                                                       DGEN      628
  550    CONTINUE                                                       DGEN      629
         IR1=2                                                          DGEN      630
  600    IR1=IR1+1                                                      DGEN      631
C                                                                       DGEN      632
         KORD=0                                                         DGEN      633
         VALIN(15)=EFD(JYG+4)                                           DGEN      634
         VALIN(19)=VRFIN(JYE+3)                                         DGEN      635
         CALL DEUDM(HSUB,KORD,NLF,KN,CID)                               DGEN      636
         IDDAT(JE0+8)=KORD                                              DGEN      637
C                                                                       DGEN      638
         IOUT=IDDAT(JE7+1)                                              DGEN      639
         VREG(JYE+1)=VALIN(1)                                           DGEN      640
         EFD(JYG+4)=VALOUT(IOUT)                                        DGEN      641
         VRFIN(JYE+3)=VALIN(19)                                         DGEN      642
C                                                                       DGEN      643
         IF(NSUBD.EQ.1) THEN                                            DGEN      644
            IF(LIR4) THEN                                               DGEN      645
               JYUDM=JYE+4                                              DGEN      646
               DO 650 J=1,NUDB                                          DGEN      647
               YVAR(JYUDM+J)=VALOUT(J)                                  DGEN      648
  650          CONTINUE                                                 DGEN      649
            ENDIF                                                       DGEN      650
            LSTATE=LSTATE+KORD                                          DGEN      651
            GO TO 1550                                                  DGEN      652
         ELSE                                                           DGEN      653
            CALL ICOEF1                                                 DGEN      654
            CALL RKG1(KORD,LSTATE,JSTATE,XSTATE,DSTATE,QSTATE,ZSTATE,   DGEN      655
     *      HSUB)                                                       DGEN      656
            IF(IR1.LT.4) GO TO 600                                      DGEN      657
            IF(JJ.EQ.NSUBD) THEN                                        DGEN      658
               JYUDM=JYE+4                                              DGEN      659
               DO 700 J=1,NUDB                                          DGEN      660
               YVAR(JYUDM+J)=VALOUT(J)                                  DGEN      661
  700          CONTINUE                                                 DGEN      662
            ENDIF                                                       DGEN      663
            CALL UDMNWL(1)                                              DGEN      664
         ENDIF                                                          DGEN      665
  750    CONTINUE                                                       DGEN      666
  800    KORD=IDDAT(JE0+8)                                              DGEN      667
         IF(KORD.GT.0) THEN                                             DGEN      668
            DO 850 JJ=1,KORD                                            DGEN      669
            DSTATE(LSTATE+JJ)=0.0                                       DGEN      670
  850       CONTINUE                                                    DGEN      671
            LSTATE=LSTATE+KORD                                          DGEN      672
         ENDIF                                                          DGEN      673
         GOTO 1550                                                      DGEN      674
      ENDIF                                                             DGEN      675
C                                                                       DGEN      676
      IVTN=IDDAT(JE+1)                                                  DGEN      677
      IF(IVTN.EQ.0)THEN                                                 DGEN      678
      ET=GTV                                                            DGEN      679
      VR1=VR                                                            DGEN      680
      VIM1=VIM                                                          DGEN      681
      ELSE                                                              DGEN      682
      VOLTK1=VOLT(IVTN)                                                 DGEN      683
      ET=CABS(VOLTK1)                                                   DGEN      684
      ENDIF                                                             DGEN      685
C                                                                       DGEN      686
C   COMPENSATOR                                                         DGEN      687
C                                                                       DGEN      688
      IF (IDDAT(JE+19).NE.0.OR.IDDAT(JE+20).NE.0)THEN                   DGEN      689
      VRR=VR1+CDGN*DDAT(JE+19)-CQGN*DDAT(JE+20)                         DGEN      690
      VRI=VIM1+CDGN*DDAT(JE+20)+CQGN*DDAT(JE+19)                        DGEN      691
      VREG(JYE+1)=SQRT(VRR**2+VRI**2)                                   DGEN      692
      ELSE                                                              DGEN      693
      VREG(JYE+1)=ET                                                    DGEN      694
      ENDIF                                                             DGEN      695
C                                                                       DGEN      696
C  SENSING CIRCUIT                                                      DGEN      697
C                                                                       DGEN      698
      IF (IDDAT(JE+18).NE.0)THEN                                        DGEN      699
      DSTATE(LSTATE+1)=(VREG(JYE+1)-XSTATE(JSTATE+1))/DDAT(JE+18)       DGEN      700
      ELSE                                                              DGEN      701
      DSTATE(LSTATE+1)=0.                                               DGEN      702
      XSTATE(JSTATE+1)=VREG(JYE+1)                                      DGEN      703
      ENDIF                                                             DGEN      704
C                                                                       DGEN      705
      V1=XSTATE(JSTATE+1)                                               DGEN      706
*IF DEBUG                                                               DGEN      707
      IF(LDEB) WRITE(IUD6,8900)IR,TS,EFDN,CFDN,V1                       DGEN      708
*ENDIF                                                                  DGEN      709
C                                                                       DGEN      710
C               1   2   3    4   5    6    7    8    9   10   11   12   DGEN      711
        GOTO (900,900,950,1000,950,1050,1100,1100,1150,1200,1550,1550,  DGEN      712
C                                                                       DGEN      713
C       13   14   15   16   17   18   19   20   21   22   23   24       DGEN      714
     +1550,1250,1300,3500,3500,3500,3500,3500,3500,3500,3500,3500,      DGEN      715
C                                                                       DGEN      716
C       25   26   27   28   29   30   31   32   33  34                  DGEN      717
     +3500,3500,3500,3500,3500,1350,1400,1450,1550,1500),IEXN           DGEN      718
C                                                                       DGEN      719
  900 CONTINUE                                                          DGEN      720
      LVUEL=ICONTA(14,N)                                                DGEN      721
      CALL DE1N2(STEP)                                                  DGEN      722
      GOTO 1550                                                         DGEN      723
  950 CONTINUE                                                          DGEN      724
      XSPU=1.0+XSTATE(IDOMG)/WXBASE                                     DGEN      725
      LVUEL=ICONTA(14,N)                                                DGEN      726
      LVOEL=ICONTA(15,N)                                                DGEN      727
      CALL DE3N5(STEP)                                                  DGEN      728
      GOTO 1550                                                         DGEN      729
 1000 CONTINUE                                                          DGEN      730
      LVUEL=ICONTA(14,N)                                                DGEN      731
      CALL DE4(STEP)                                                    DGEN      732
      GOTO 1550                                                         DGEN      733
 1050 CONTINUE                                                          DGEN      734
      LVUEL=ICONTA(14,N)                                                DGEN      735
      LVOEL=ICONTA(15,N)                                                DGEN      736
      CALL DE6(STEP)                                                    DGEN      737
      GOTO 1550                                                         DGEN      738
 1100 CONTINUE                                                          DGEN      739
      LVUEL=ICONTA(14,N)                                                DGEN      740
      CALL DE7N8(VR1,VIM1)                                              DGEN      741
      GOTO 1550                                                         DGEN      742
 1150 CONTINUE                                                          DGEN      743
      CALL DE9                                                          DGEN      744
      GOTO 1550                                                         DGEN      745
 1200 CONTINUE                                                          DGEN      746
      CALL DE10(STEP)                                                   DGEN      747
      GOTO 1550                                                         DGEN      748
 1250 CONTINUE                                                          DGEN      749
      CALL DE14                                                         DGEN      750
      GOTO 1550                                                         DGEN      751
 1300 CONTINUE                                                          DGEN      752
      CALL DE15(STEP)                                                   DGEN      753
      GOTO 1550                                                         DGEN      754
 1350 CONTINUE                                                          DGEN      755
      LVUEL=ICONTA(14,N)                                                DGEN      756
      CALL DE30(STEP)                                                   DGEN      757
      GOTO 1550                                                         DGEN      758
 1400 CONTINUE                                                          DGEN      759
      CALL DE31                                                         DGEN      760
      GOTO 1550                                                         DGEN      761
 1450 CONTINUE                                                          DGEN      762
      CALL DE32(STEP)                                                   DGEN      763
      GOTO 1550                                                         DGEN      764
 1500 CONTINUE                                                          DGEN      765
      LVUEL=ICONTA(14,N)                                                DGEN      766
      LVOEL=ICONTA(15,N)                                                DGEN      767
      LVS=ICONTA(16,N)                                                  DGEN      768
      CALL DE34(STEP)                                                   DGEN      769
      GOTO 1550                                                         DGEN      770
C                                                                       DGEN      771
C   STABILIZERS                                                         DGEN      772
C                                                                       DGEN      773
 1550 CONTINUE                                                          DGEN      774
C                                                                       DGEN      775
      IF(ISTABN.GT.0)THEN                                               DGEN      776
C                                                                       DGEN      777
      JSTATE=MSTATE(3,N)                                                DGEN      778
      JS=JCONTA(4,N)                                                    DGEN      779
      KSTATE=0                                                          DGEN      780
      SPDPU=DSTATE(2)/WXBASE                                            DGEN      781
C                                                                       DGEN      782
      IF(ISTABN.EQ.50) THEN                                             DGEN      783
         JE0=JS                                                         DGEN      784
         IF(STEP.LT.0.001) THEN                                         DGEN      785
            NSUBD=1                                                     DGEN      786
         ELSE                                                           DGEN      787
            NSUBD=IDDAT(JE0+3)                                          DGEN      788
         ENDIF                                                          DGEN      789
         IF(NSUBD.GT.1.AND..NOT.LIR1) GO TO 1950                        DGEN      790
         HSUB=STEP/NSUBD                                                DGEN      791
C                                                                       DGEN      792
C     GET THE INPUT VALUES                                              DGEN      793
C                                                                       DGEN      794
         JE1=JE0+9                                                      DGEN      795
         CALL RINUDM                                                    DGEN      796
C                                                                       DGEN      797
         IF(NRBUS.EQ.0) THEN                                            DGEN      798
            VCR=VR                                                      DGEN      799
            VCI=VIM                                                     DGEN      800
         ELSE                                                           DGEN      801
            IBUSR=IDDAT(JE1+1)                                          DGEN      802
            VCR=REAL(VOLT(IBUSR))                                       DGEN      803
            VCI=AIMAG(VOLT(IBUSR))                                      DGEN      804
         ENDIF                                                          DGEN      805
         RC=DDAT(JE0+1)                                                 DGEN      806
         XC=DDAT(JE0+2)                                                 DGEN      807
         VCD=VCR+(RC*CDGN-XC*CQGN)                                      DGEN      808
         VCQ=VCI+(RC*CQGN+XC*CDGN)                                      DGEN      809
         VCM=SQRT(VCD*VCD+VCQ*VCQ)                                      DGEN      810
         VALIN(1)=VCM                                                   DGEN      811
         IF(VCM.GT.0.05) THEN                                           DGEN      812
            VAG=ATAN2(VCQ,VCD)                                          DGEN      813
            VAGD=DDAT(JE0+5)-VAG                                        DGEN      814
            DDAT(JE0+5)=VAG                                             DGEN      815
            IF(VAGD.GT.3.15) THEN                                       DGEN      816
               IDDAT(JE0+4)=IDDAT(JE0+4)+1                              DGEN      817
            ELSEIF(VAGD.LT.-3.15) THEN                                  DGEN      818
               IDDAT(JE0+4)=IDDAT(JE0+4)-1                              DGEN      819
            ENDIF                                                       DGEN      820
            VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                         DGEN      821
         ELSE                                                           DGEN      822
            VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)                 DGEN      823
         ENDIF                                                          DGEN      824
         IF(GTV.GT.0.05) THEN                                           DGEN      825
            VAGD=DDAT(JE0+7)-AT                                         DGEN      826
            DDAT(JE0+7)=AT                                              DGEN      827
            IF(VAGD.GT.3.15) THEN                                       DGEN      828
               IDDAT(JE0+6)=IDDAT(JE0+6)+1                              DGEN      829
            ELSEIF(VAGD.LT.-3.15) THEN                                  DGEN      830
               IDDAT(JE0+6)=IDDAT(JE0+6)-1                              DGEN      831
            ENDIF                                                       DGEN      832
            VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                          DGEN      833
         ELSE                                                           DGEN      834
            VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)                 DGEN      835
         ENDIF                                                          DGEN      836
         VALIN(3)=ACCP(JYG+6)                                           DGEN      837
         VALIN(4)=GTV                                                   DGEN      838
         VALIN(6)=VR                                                    DGEN      839
         VALIN(7)=VIM                                                   DGEN      840
         VALIN(8)=CDGN                                                  DGEN      841
         VALIN(9)=CQGN                                                  DGEN      842
         VALIN(10)=PDGN                                                 DGEN      843
         VALIN(11)=PQGN                                                 DGEN      844
         VALIN(12)=XSTATE(IDOMG)                                        DGEN      845
         VALIN(15)=EFDN                                                 DGEN      846
         VALIN(16)=CFDN                                                 DGEN      847
C                                                                       DGEN      848
         DO 1900 JJ=1,NSUBD                                             DGEN      849
         GOTO (1600,1650,1700,1700,1700,1750), INTMTH                   DGEN      850
 1600    CONTINUE                                                       DGEN      851
         IR1=0                                                          DGEN      852
         GOTO 1750                                                      DGEN      853
 1650    CONTINUE                                                       DGEN      854
         IR1=1                                                          DGEN      855
         GOTO 1750                                                      DGEN      856
 1700    CONTINUE                                                       DGEN      857
         IR1=2                                                          DGEN      858
 1750    IR1=IR1+1                                                      DGEN      859
C                                                                       DGEN      860
         KORD=0                                                         DGEN      861
         VALIN(17)=VSS(JYS+1)                                           DGEN      862
         IF(IUALN.EQ.50)THEN                                            DGEN      863
            VALIN(18)=VUAL(JYS+3)                                       DGEN      864
         ELSE                                                           DGEN      865
            VALIN(18)=VUAL(JYU+1)                                       DGEN      866
         ENDIF                                                          DGEN      867
         CALL DEUDM(HSUB,KORD,NLF,KN,CID)                               DGEN      868
         IDDAT(JE0+8)=KORD                                              DGEN      869
C                                                                       DGEN      870
         IOUT1=IDDAT(JE7+1)                                             DGEN      871
         IOUT2=IDDAT(JE7+2)                                             DGEN      872
         VSS(JYS+1)=VALOUT(IOUT1)                                       DGEN      873
         IF(IOUT2.EQ.0) THEN                                            DGEN      874
            VUAL(JYS+3)=0.0                                             DGEN      875
         ELSE                                                           DGEN      876
            VUAL(JYS+3)=VALOUT(IOUT2)                                   DGEN      877
         ENDIF                                                          DGEN      878
C                                                                       DGEN      879
         IF(NSUBD.EQ.1) THEN                                            DGEN      880
            IF(LIR4) THEN                                               DGEN      881
               JYUDM=JYS+3                                              DGEN      882
               DO 1800 J=1,NUDB                                         DGEN      883
               YVAR(JYUDM+J)=VALOUT(J)                                  DGEN      884
 1800          CONTINUE                                                 DGEN      885
            ENDIF                                                       DGEN      886
            LSTATE=LSTATE+KORD                                          DGEN      887
            GO TO 2400                                                  DGEN      888
         ELSE                                                           DGEN      889
            CALL ICOEF1                                                 DGEN      890
            CALL RKG1(KORD,LSTATE,JSTATE,XSTATE,DSTATE,QSTATE,ZSTATE,   DGEN      891
     *      HSUB)                                                       DGEN      892
            IF(IR1.LT.4) GO TO 1750                                     DGEN      893
            IF(JJ.EQ.NSUBD) THEN                                        DGEN      894
               JYUDM=JYS+3                                              DGEN      895
               DO 1850 J=1,NUDB                                         DGEN      896
               YVAR(JYUDM+J)=VALOUT(J)                                  DGEN      897
 1850          CONTINUE                                                 DGEN      898
            ENDIF                                                       DGEN      899
            CALL UDMNWL(0)                                              DGEN      900
         ENDIF                                                          DGEN      901
 1900    CONTINUE                                                       DGEN      902
 1950    KORD=IDDAT(JE0+8)                                              DGEN      903
         IF(KORD.GT.0) THEN                                             DGEN      904
            DO 2000 JJ=1,KORD                                           DGEN      905
            DSTATE(LSTATE+JJ)=0.0                                       DGEN      906
 2000       CONTINUE                                                    DGEN      907
            LSTATE=LSTATE+KORD                                          DGEN      908
         ENDIF                                                          DGEN      909
         GO TO 2400                                                     DGEN      910
      ENDIF                                                             DGEN      911
      ET=GTV                                                            DGEN      912
C                                                                       DGEN      913
C  TYPE        1    2    3    4    5    6    7    8    9                DGEN      914
C                                                                       DGEN      915
      GOTO (2050,2050,2050,2100,2100,2100,2150,2350,2200                DGEN      916
C                                                                       DGEN      917
C  TYPE  10   11   12                                                   DGEN      918
C                                                                       DGEN      919
     &,2250,2250,2300),ISTABN                                           DGEN      920
C                                                                       DGEN      921
C       TYPE 1,2,3 STABILIZER                                           DGEN      922
C                                                                       DGEN      923
 2050 CALL DSGNAL(K,STEP)                                               DGEN      924
      CALL DSTAB1(NXS,NWSS)                                             DGEN      925
      GOTO 2350                                                         DGEN      926
C                                                                       DGEN      927
C      TYPE 4,5,6,7 STABILIZER                                          DGEN      928
C                                                                       DGEN      929
 2100 CALL DSGNAL(K,STEP)                                               DGEN      930
 2150 CALL DSTAB4(NXS,NWSS)                                             DGEN      931
      GOTO 2350                                                         DGEN      932
C                                                                       DGEN      933
C       TYPE 9 STABILIZER                                               DGEN      934
C                                                                       DGEN      935
 2200 CALL DSGNAL(K,STEP)                                               DGEN      936
      CALL DSTAB9(KBUSNO,NXS)                                           DGEN      937
      GOTO 2350                                                         DGEN      938
C                                                                       DGEN      939
C       TYPE 10,11 STABILIZER                                           DGEN      940
C                                                                       DGEN      941
 2250 CALL DSGNAL(K,STEP)                                               DGEN      942
      CALL DSTA10(NXS)                                                  DGEN      943
      GOTO 2350                                                         DGEN      944
C                                                                       DGEN      945
C       TYPE 12 STABILIZER                                              DGEN      946
C                                                                       DGEN      947
 2300 CALL DSGNAL(K,STEP)                                               DGEN      948
      CALL DSTA12(NXS)                                                  DGEN      949
C                                                                       DGEN      950
 2350 IF(IFLTRN.NE.0)CALL DFLTER(NXS)                                   DGEN      951
C                                                                       DGEN      952
      ENDIF                                                             DGEN      953
C                                                                       DGEN      954
C   UNDER EXCITED LIMITERS                                              DGEN      955
C                                                                       DGEN      956
 2400 CONTINUE                                                          DGEN      957
C                                                                       DGEN      958
      IF(IUALN.NE.0)THEN                                                DGEN      959
         JSTATE=MSTATE(4,N)                                             DGEN      960
         JU=JCONTA(6,N)                                                 DGEN      961
         IF(ISTABN.NE.50) THEN                                          DGEN      962
            IF(IUALN.EQ.50) THEN                                        DGEN      963
               JE0=JU                                                   DGEN      964
               IF(STEP.LT.0.001) THEN                                   DGEN      965
                  NSUBD=1                                               DGEN      966
               ELSE                                                     DGEN      967
                  NSUBD=IDDAT(JE0+3)                                    DGEN      968
               ENDIF                                                    DGEN      969
               IF(NSUBD.GT.1.AND..NOT.LIR1) GO TO 2800                  DGEN      970
               HSUB=STEP/NSUBD                                          DGEN      971
C                                                                       DGEN      972
C     GET THE INPUT VALUES                                              DGEN      973
C                                                                       DGEN      974
               JE1=JE0+9                                                DGEN      975
               CALL RINUDM                                              DGEN      976
C                                                                       DGEN      977
               IF(NRBUS.EQ.0) THEN                                      DGEN      978
                  VCR=VR                                                DGEN      979
                  VCI=VIM                                               DGEN      980
               ELSE                                                     DGEN      981
                  IBUSR=IDDAT(JE1+1)                                    DGEN      982
                  VCR=REAL(VOLT(IBUSR))                                 DGEN      983
                  VCI=AIMAG(VOLT(IBUSR))                                DGEN      984
               ENDIF                                                    DGEN      985
               RC=DDAT(JE0+1)                                           DGEN      986
               XC=DDAT(JE0+2)                                           DGEN      987
               VCD=VCR+(RC*CDGN-XC*CQGN)                                DGEN      988
               VCQ=VCI+(RC*CQGN+XC*CDGN)                                DGEN      989
               VCM=SQRT(VCD*VCD+VCQ*VCQ)                                DGEN      990
               VALIN(1)=VCM                                             DGEN      991
               IF(VCM.GT.0.05) THEN                                     DGEN      992
                  VAG=ATAN2(VCQ,VCD)                                    DGEN      993
                  VAGD=DDAT(JE0+5)-VAG                                  DGEN      994
                  DDAT(JE0+5)=VAG                                       DGEN      995
                  IF(VAGD.GT.3.15) THEN                                 DGEN      996
                     IDDAT(JE0+4)=IDDAT(JE0+4)+1                        DGEN      997
                  ELSEIF(VAGD.LT.-3.15) THEN                            DGEN      998
                     IDDAT(JE0+4)=IDDAT(JE0+4)-1                        DGEN      999
                  ENDIF                                                 DGEN     1000
                  VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                   DGEN     1001
               ELSE                                                     DGEN     1002
                  VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)           DGEN     1003
               ENDIF                                                    DGEN     1004
               IF(GTV.GT.0.05) THEN                                     DGEN     1005
                  VAGD=DDAT(JE0+7)-AT                                   DGEN     1006
                  DDAT(JE0+7)=AT                                        DGEN     1007
                  IF(VAGD.GT.3.15) THEN                                 DGEN     1008
                     IDDAT(JE0+6)=IDDAT(JE0+6)+1                        DGEN     1009
                  ELSEIF(VAGD.LT.-3.15) THEN                            DGEN     1010
                     IDDAT(JE0+6)=IDDAT(JE0+6)-1                        DGEN     1011
                  ENDIF                                                 DGEN     1012
                  VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                    DGEN     1013
               ELSE                                                     DGEN     1014
                  VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)           DGEN     1015
               ENDIF                                                    DGEN     1016
               VALIN(3)=ACCP(JYG+6)                                     DGEN     1017
               VALIN(4)=GTV                                             DGEN     1018
               VALIN(6)=VR                                              DGEN     1019
               VALIN(7)=VIM                                             DGEN     1020
               VALIN(8)=CDGN                                            DGEN     1021
               VALIN(9)=CQGN                                            DGEN     1022
               VALIN(10)=PDGN                                           DGEN     1023
               VALIN(11)=PQGN                                           DGEN     1024
               VALIN(12)=XSTATE(IDOMG)                                  DGEN     1025
               VALIN(15)=EFDN                                           DGEN     1026
               VALIN(16)=CFDN                                           DGEN     1027
               IF(ISTABN.GT.0) THEN                                     DGEN     1028
                  VALIN(17)=VSS(JYS+1)                                  DGEN     1029
               ELSE                                                     DGEN     1030
                  VALIN(17)=0.0                                         DGEN     1031
               ENDIF                                                    DGEN     1032
C                                                                       DGEN     1033
               DO 2750 JJ=1,NSUBD                                       DGEN     1034
               GOTO (2450,2500,2550,2550,2550,2600), INTMTH             DGEN     1035
 2450          CONTINUE                                                 DGEN     1036
               IR1=0                                                    DGEN     1037
               GOTO 2600                                                DGEN     1038
 2500          CONTINUE                                                 DGEN     1039
               IR1=1                                                    DGEN     1040
               GOTO 2600                                                DGEN     1041
 2550          CONTINUE                                                 DGEN     1042
               IR1=2                                                    DGEN     1043
 2600          IR1=IR1+1                                                DGEN     1044
C                                                                       DGEN     1045
               KORD=0                                                   DGEN     1046
               VALIN(18)=VUAL(JYU+1)                                    DGEN     1047
               CALL DEUDM(HSUB,KORD,NLF,KN,CID)                         DGEN     1048
               IDDAT(JE0+8)=KORD                                        DGEN     1049
C                                                                       DGEN     1050
               IOUT=IDDAT(JE7+1)                                        DGEN     1051
               VUAL(JYU+1)=VALOUT(IOUT)                                 DGEN     1052
C                                                                       DGEN     1053
               IF(NSUBD.EQ.1) THEN                                      DGEN     1054
                  IF(LIR4) THEN                                         DGEN     1055
                     JYUDM=JYU+2                                        DGEN     1056
                     DO 2650 J=1,NUDB                                   DGEN     1057
                     YVAR(JYUDM+J)=VALOUT(J)                            DGEN     1058
 2650                CONTINUE                                           DGEN     1059
                  ENDIF                                                 DGEN     1060
                  LSTATE=LSTATE+KORD                                    DGEN     1061
                  GO TO 2900                                            DGEN     1062
               ELSE                                                     DGEN     1063
                  CALL ICOEF1                                           DGEN     1064
                  CALL RKG1(KORD,LSTATE,JSTATE,XSTATE,DSTATE,QSTATE,    DGEN     1065
     *            ZSTATE,HSUB)                                          DGEN     1066
                  IF(IR1.LT.4) GO TO 2600                               DGEN     1067
                  IF(JJ.EQ.NSUBD) THEN                                  DGEN     1068
                     JYUDM=JYU+2                                        DGEN     1069
                     DO 2700 J=1,NUDB                                   DGEN     1070
                     YVAR(JYUDM+J)=VALOUT(J)                            DGEN     1071
 2700                CONTINUE                                           DGEN     1072
                  ENDIF                                                 DGEN     1073
                  CALL UDMNWL(0)                                        DGEN     1074
               ENDIF                                                    DGEN     1075
 2750          CONTINUE                                                 DGEN     1076
 2800          KORD=IDDAT(JE0+8)                                        DGEN     1077
               IF(KORD.GT.0) THEN                                       DGEN     1078
                  DO 2850 JJ=1,KORD                                     DGEN     1079
                  DSTATE(LSTATE+JJ)=0.0                                 DGEN     1080
 2850             CONTINUE                                              DGEN     1081
                  LSTATE=LSTATE+KORD                                    DGEN     1082
               ENDIF                                                    DGEN     1083
               GO TO 2900                                               DGEN     1084
            ENDIF                                                       DGEN     1085
         ENDIF                                                          DGEN     1086
         IF(ISTABN.EQ.50) THEN                                          DGEN     1087
            IF(IUALN.EQ.50) THEN                                        DGEN     1088
               VUAL(JYU+1)=VUAL(JYS+3)                                  DGEN     1089
               GO TO 2900                                               DGEN     1090
            ENDIF                                                       DGEN     1091
         ENDIF                                                          DGEN     1092
         CALL DUAL                                                      DGEN     1093
      ENDIF                                                             DGEN     1094
C                                                                       DGEN     1095
C   ENDIF KGSTAT.EQ.0                                                   DGEN     1096
C                                                                       DGEN     1097
C      ENDIF                                                            DGEN     1098
 2900 CONTINUE                                                          DGEN     1099
C                                                                       DGEN     1100
C  MAXIMUM EXCITATION CURRENT LIMITER                                   DGEN     1101
C                                                                       DGEN     1102
      IF (IMXLN.NE.0) THEN                                              DGEN     1103
         JMX=JCONTA(11,N)                                               DGEN     1104
         JSTATE=MSTATE(7,N)                                             DGEN     1105
         IF(IMXLN.EQ.50) THEN                                           DGEN     1106
               JE0=JMX                                                  DGEN     1107
               IF(STEP.LT.0.001) THEN                                   DGEN     1108
                  NSUBD=1                                               DGEN     1109
               ELSE                                                     DGEN     1110
                  NSUBD=IDDAT(JE0+3)                                    DGEN     1111
               ENDIF                                                    DGEN     1112
               IF(NSUBD.GT.1.AND..NOT.LIR1) GO TO 3300                  DGEN     1113
               HSUB=STEP/NSUBD                                          DGEN     1114
C                                                                       DGEN     1115
C     GET THE INPUT VALUES                                              DGEN     1116
C                                                                       DGEN     1117
               JE1=JE0+9                                                DGEN     1118
               CALL RINUDM                                              DGEN     1119
C                                                                       DGEN     1120
               IF(NRBUS.EQ.0) THEN                                      DGEN     1121
                  VCR=VR                                                DGEN     1122
                  VCI=VIM                                               DGEN     1123
               ELSE                                                     DGEN     1124
                  IBUSR=IDDAT(JE1+1)                                    DGEN     1125
                  VCR=REAL(VOLT(IBUSR))                                 DGEN     1126
                  VCI=AIMAG(VOLT(IBUSR))                                DGEN     1127
               ENDIF                                                    DGEN     1128
               RC=DDAT(JE0+1)                                           DGEN     1129
               XC=DDAT(JE0+2)                                           DGEN     1130
               VCD=VCR+(RC*CDGN-XC*CQGN)                                DGEN     1131
               VCQ=VCI+(RC*CQGN+XC*CDGN)                                DGEN     1132
               VCM=SQRT(VCD*VCD+VCQ*VCQ)                                DGEN     1133
               VALIN(1)=VCM                                             DGEN     1134
               IF(VCM.GT.0.05) THEN                                     DGEN     1135
                  VAG=ATAN2(VCQ,VCD)                                    DGEN     1136
                  VAGD=DDAT(JE0+5)-VAG                                  DGEN     1137
                  DDAT(JE0+5)=VAG                                       DGEN     1138
                  IF(VAGD.GT.3.15) THEN                                 DGEN     1139
                     IDDAT(JE0+4)=IDDAT(JE0+4)+1                        DGEN     1140
                  ELSEIF(VAGD.LT.-3.15) THEN                            DGEN     1141
                     IDDAT(JE0+4)=IDDAT(JE0+4)-1                        DGEN     1142
                  ENDIF                                                 DGEN     1143
                  VALIN(2)=VAG+6.2831853*IDDAT(JE0+4)                   DGEN     1144
               ELSE                                                     DGEN     1145
                  VALIN(2)=DDAT(JE0+5)+6.2831853*IDDAT(JE0+4)           DGEN     1146
               ENDIF                                                    DGEN     1147
               IF(GTV.GT.0.05) THEN                                     DGEN     1148
                  VAGD=DDAT(JE0+7)-AT                                   DGEN     1149
                  DDAT(JE0+7)=AT                                        DGEN     1150
                  IF(VAGD.GT.3.15) THEN                                 DGEN     1151
                     IDDAT(JE0+6)=IDDAT(JE0+6)+1                        DGEN     1152
                  ELSEIF(VAGD.LT.-3.15) THEN                            DGEN     1153
                     IDDAT(JE0+6)=IDDAT(JE0+6)-1                        DGEN     1154
                  ENDIF                                                 DGEN     1155
                  VALIN(5)=AT+6.2831853*IDDAT(JE0+6)                    DGEN     1156
               ELSE                                                     DGEN     1157
                  VALIN(5)=DDAT(JE0+7)+6.2831853*IDDAT(JE0+6)           DGEN     1158
               ENDIF                                                    DGEN     1159
               VALIN(3)=ACCP(JYG+6)                                     DGEN     1160
               VALIN(4)=GTV                                             DGEN     1161
               VALIN(6)=VR                                              DGEN     1162
               VALIN(7)=VIM                                             DGEN     1163
               VALIN(8)=CDGN                                            DGEN     1164
               VALIN(9)=CQGN                                            DGEN     1165
               VALIN(10)=PDGN                                           DGEN     1166
               VALIN(11)=PQGN                                           DGEN     1167
               VALIN(12)=XSTATE(IDOMG)                                  DGEN     1168
               VALIN(15)=EFDN                                           DGEN     1169
               VALIN(16)=CFDN                                           DGEN     1170
C                                                                       DGEN     1171
               DO 3250 JJ=1,NSUBD                                       DGEN     1172
               GOTO (2950,3000,3050,3050,3050,3100), INTMTH             DGEN     1173
 2950          CONTINUE                                                 DGEN     1174
               IR1=0                                                    DGEN     1175
               GOTO 3100                                                DGEN     1176
 3000          CONTINUE                                                 DGEN     1177
               IR1=1                                                    DGEN     1178
               GOTO 3100                                                DGEN     1179
 3050          CONTINUE                                                 DGEN     1180
               IR1=2                                                    DGEN     1181
 3100          IR1=IR1+1                                                DGEN     1182
C                                                                       DGEN     1183
               KORD=0                                                   DGEN     1184
               CALL DEUDM(HSUB,KORD,NLF,KN,CID)                         DGEN     1185
               IDDAT(JE0+8)=KORD                                        DGEN     1186
C                                                                       DGEN     1187
               IOUT=IDDAT(JE7+1)                                        DGEN     1188
               VMXL(JYMX+1)=VALOUT(IOUT)                                DGEN     1189
C                                                                       DGEN     1190
               IF(NSUBD.EQ.1) THEN                                      DGEN     1191
                  IF(LIR4) THEN                                         DGEN     1192
                     JYUDM=JYMX+2                                       DGEN     1193
                     DO 3150 J=1,NUDB                                   DGEN     1194
                     YVAR(JYUDM+J)=VALOUT(J)                            DGEN     1195
 3150                CONTINUE                                           DGEN     1196
                  ENDIF                                                 DGEN     1197
                  LSTATE=LSTATE+KORD                                    DGEN     1198
                  GO TO 3450                                            DGEN     1199
               ELSE                                                     DGEN     1200
                  CALL ICOEF1                                           DGEN     1201
                  CALL RKG1(KORD,LSTATE,JSTATE,XSTATE,DSTATE,QSTATE,    DGEN     1202
     *            ZSTATE,HSUB)                                          DGEN     1203
                  IF(IR1.LT.4) GO TO 3100                               DGEN     1204
                  IF(JJ.EQ.NSUBD) THEN                                  DGEN     1205
                     JYUDM=JYMX+2                                       DGEN     1206
                     DO 3200 J=1,NUDB                                   DGEN     1207
                     YVAR(JYUDM+J)=VALOUT(J)                            DGEN     1208
 3200                CONTINUE                                           DGEN     1209
                  ENDIF                                                 DGEN     1210
                  CALL UDMNWL(0)                                        DGEN     1211
               ENDIF                                                    DGEN     1212
 3250          CONTINUE                                                 DGEN     1213
 3300          KORD=IDDAT(JE0+8)                                        DGEN     1214
               IF(KORD.GT.0) THEN                                       DGEN     1215
                  DO 3350 JJ=1,KORD                                     DGEN     1216
                  DSTATE(LSTATE+JJ)=0.0                                 DGEN     1217
 3350             CONTINUE                                              DGEN     1218
                  LSTATE=LSTATE+KORD                                    DGEN     1219
               ENDIF                                                    DGEN     1220
               GO TO 3450                                               DGEN     1221
         ELSE                                                           DGEN     1222
            CALL DEMXL1(STEP)                                           DGEN     1223
         ENDIF                                                          DGEN     1224
      ENDIF                                                             DGEN     1225
 3450 CONTINUE                                                          DGEN     1226
C                                                                       DGEN     1227
C  TRANSIENT EXCITATION BOOSTER                                         DGEN     1228
C                                                                       DGEN     1229
      IF(ITEBN.NE.0)THEN                                                DGEN     1230
            IF(LIR4)THEN                                                DGEN     1231
            JTB=JCONTA(10,N)                                            DGEN     1232
            JYTB=MYVAR(7,N)                                             DGEN     1233
            CALL DTEB(STEP)                                             DGEN     1234
            ENDIF                                                       DGEN     1235
      ENDIF                                                             DGEN     1236
C                                                                       DGEN     1237
 3500 CONTINUE                                                          DGEN     1238
C                                                                       DGEN     1239
C     ENDIF IEXN.EQ.0                                                   DGEN     1240
C                                                                       DGEN     1241
      ENDIF                                                             DGEN     1242
C                                                                       DGEN     1243
 3550 CONTINUE                                                          DGEN     1244
C                                                                       DGEN     1245
C  PRIME MOVER (GOVERNOR)                                               DGEN     1246
C                                                                       DGEN     1247
C                                                                       DGEN     1248
      IF(IGVN.NE.0)THEN                                                 DGEN     1249
C                                                                       DGEN     1250
C  STORE THE FOLLOWS USED LATER IN ROUTINES "DEGV04/10" AND "UPDATE"    DGEN     1251
C                                                                       DGEN     1252
      XSPU=XSTATE(IOFSET+1)/WXBASE                                      DGEN     1253
      XACPU=DSTATE(1)/WXBASE                                            DGEN     1254
C                                                                       DGEN     1255
      JGG=JCONTA(2,N)                                                   DGEN     1256
      JSTATE=MSTATE(5,N)                                                DGEN     1257
      JYP=MYVAR(5,N)                                                    DGEN     1258
C                                                                       DGEN     1259
      IF(IGVN.EQ.50) THEN                                               DGEN     1260
C                                                                       DGEN     1261
C     GET THE INPUT VALUES                                              DGEN     1262
C                                                                       DGEN     1263
         JE0=JGG                                                        DGEN     1264
         JE1=JE0+3                                                      DGEN     1265
         CALL RINUDM                                                    DGEN     1266
C                                                                       DGEN     1267
         VALIN(1)=VGOV(JYP+2)                                           DGEN     1268
         VALIN(2)=VGOV(JYP+4)                                           DGEN     1269
         VALIN(3)=ACCP(JYG+6)                                           DGEN     1270
         VALIN(4)=GTV                                                   DGEN     1271
         IF(GTV.GT.0.05) THEN                                           DGEN     1272
            VAGD=DDAT(JE0+2)-AT                                         DGEN     1273
            DDAT(JE0+2)=AT                                              DGEN     1274
            IF(VAGD.GT.3.15) THEN                                       DGEN     1275
               IDDAT(JE0+1)=IDDAT(JE0+1)+1                              DGEN     1276
            ELSEIF(VAGD.LT.-3.15) THEN                                  DGEN     1277
               IDDAT(JE0+1)=IDDAT(JE0+1)-1                              DGEN     1278
            ENDIF                                                       DGEN     1279
            VALIN(5)=AT+6.2831853*IDDAT(JE0+1)                          DGEN     1280
         ELSE                                                           DGEN     1281
            VALIN(5)=DDAT(JE0+2)+6.2831853*IDDAT(JE0+1)                 DGEN     1282
         ENDIF                                                          DGEN     1283
         VALIN(6)=VR                                                    DGEN     1284
         VALIN(7)=VIM                                                   DGEN     1285
         VALIN(8)=CDGN                                                  DGEN     1286
         VALIN(9)=CQGN                                                  DGEN     1287
         VALIN(10)=PDGN                                                 DGEN     1288
         VALIN(11)=PQGN                                                 DGEN     1289
         VALIN(12)=XSTATE(IDOMG)                                        DGEN     1290
         VALIN(15)=EFDN                                                 DGEN     1291
         VALIN(16)=CFDN                                                 DGEN     1292
         VALIN(20)=VREF(JYP+1)                                          DGEN     1293
C                                                                       DGEN     1294
         KORD=0                                                         DGEN     1295
         CALL DEUDM(STEP,KORD,NLF,KN,CID)                               DGEN     1296
         LSTATE=LSTATE+KORD                                             DGEN     1297
C                                                                       DGEN     1298
         IOUT=IDDAT(JE7+1)                                              DGEN     1299
         TIN(JYG+1)=VALOUT(IOUT)*BASER(JYP+3)                           DGEN     1300
         VGOV(JYP+2)=VALIN(1)                                           DGEN     1301
         VGOV(JYP+4)=VALIN(2)                                           DGEN     1302
C                                                                       DGEN     1303
         IF(LIR4) THEN                                                  DGEN     1304
            JYUDM=JYP+4                                                 DGEN     1305
            DO 3600 J=1,NUDB                                            DGEN     1306
            YVAR(JYUDM+J)=VALOUT(J)                                     DGEN     1307
 3600       CONTINUE                                                    DGEN     1308
         ENDIF                                                          DGEN     1309
         GO TO 4050                                                     DGEN     1310
      ENDIF                                                             DGEN     1311
*IF LTSP                                                                DGEN     1312
*ENDIF                                                                  DGEN     1398
C                                                                       DGEN     1399
C                                                                       DGEN     1400
C TYPE         1    2    3    4    5    6    7    8    9   10   11      DGEN     1401
C                                                                       DGEN     1402
      GOTO (3650,3650,3650,3700,3700,3750,3800,3850,4050,4050,4050      DGEN     1403
C                                                                       DGEN     1404
C TYPE   12   13   14   15   16   17   18   19   20   21   22           DGEN     1405
C                                                                       DGEN     1406
     &,4050,4050,4050,4050,4050,4050,4050,4050,3900,3950,4000), IGVN    DGEN     1407
C                                                                       DGEN     1408
C   TYPE 1,2 & 3                                                        DGEN     1409
C                                                                       DGEN     1410
 3650 CALL DEGV01(JSGV)                                                 DGEN     1411
*IF LTSP                                                                DGEN     1412
*ENDIF                                                                  DGEN     1421
      GOTO 4050                                                         DGEN     1422
C                                                                       DGEN     1423
C     TYPE 4 OR TYPE 5                                                  DGEN     1424
C                                                                       DGEN     1425
 3700 CALL DEGV04(JSGV)                                                 DGEN     1426
*IF LTSP                                                                DGEN     1427
*ENDIF                                                                  DGEN     1436
      GOTO 4050                                                         DGEN     1437
C                                                                       DGEN     1438
C     TYPE 6                                                            DGEN     1439
C                                                                       DGEN     1440
 3750 CALL DEGV06(JSGV)                                                 DGEN     1441
      GOTO 4050                                                         DGEN     1442
C                                                                       DGEN     1443
C     TYPE 7                                                            DGEN     1444
C                                                                       DGEN     1445
 3800 CALL DEGV07(JSGV)                                                 DGEN     1446
      GOTO 4050                                                         DGEN     1447
C                                                                       DGEN     1448
C     TYPE 8                                                            DGEN     1449
C                                                                       DGEN     1450
 3850 CALL DEGV08(JSGV)                                                 DGEN     1451
      GOTO 4050                                                         DGEN     1452
C                                                                       DGEN     1453
C     HYDRO GOVERNOR TYPE 20 / 21 / 22                                  DGEN     1454
C                                                                       DGEN     1455
 3900 CALL DEGV20(JSGV)                                                 DGEN     1456
      GOTO 4050                                                         DGEN     1457
 3950 CALL DEGV21(JSGV)                                                 DGEN     1458
      GOTO 4050                                                         DGEN     1459
 4000 CALL DEGV22(JSGV)                                                 DGEN     1460
 4050 CONTINUE                                                          DGEN     1461
C                                                                       DGEN     1462
C     ENDIF IGVN.NE.0                                                   DGEN     1463
C                                                                       DGEN     1464
      ENDIF                                                             DGEN     1465
C                                                                       DGEN     1466
*IF DEBUG                                                               DGEN     1467
      IF(LDEB)WRITE(IUD6,8800)LSTATE,IOFSET,(J,XSTATE(IOFSET+J)         DGEN     1468
     *,DSTATE(J),J=1,LSTATE)                                            DGEN     1469
*ENDIF                                                                  DGEN     1470
C                                                                       DGEN     1471
      CALL RKG(LSTATE,IOFSET,XSTATE,DSTATE,QSTATE,ZSTATE,STEP)          DGEN     1472
C                                                                       DGEN     1473
      IF(IGVN.NE.50)CALL UPDATE(JSGV)                                   DGEN     1474
      IF(LIR4) CALL NWDP(JSGV,NWSS,STEP)                                DGEN     1475
C                                                                       DGEN     1476
*IF DEBUG                                                               DGEN     1477
      IF(LDEB)WRITE(IUD6,8800)LSTATE,IOFSET,(J,XSTATE(IOFSET+J)         DGEN     1478
     *,DSTATE(J),J=1,LSTATE)                                            DGEN     1479
*ENDIF                                                                  DGEN     1480
C                                                                       DGEN     1481
C   COMPUTE U1 TO U6 OF DETAILED MACHINE FOR USE IN NETSOL              DGEN     1482
C                                                                       DGEN     1483
      IF(IGENS.NE.4)CALL UVARB (N,JG,MD,MQ,IOFSET)                      DGEN     1484
C                                                                       DGEN     1485
C   STORE CVP FOR TYPE 1,2 AND 4 GOVERNOR                               DGEN     1486
C                                                                       DGEN     1487
      IF(IGVN.NE.0)THEN                                                 DGEN     1488
         IF(IGVN.LT.4.OR.IGVN.EQ.31.OR.IGVN.EQ.32)                      DGEN     1489
     &                   CVP(JYP+2)=XSTATE(JSTATE+5)                    DGEN     1490
         IF(IGVN.EQ.4.OR.IGVN.EQ.34.OR.IGVN.EQ.35)                      DGEN     1491
     &                   CVP(JYP+2)=XSTATE(JSTATE+2)                    DGEN     1492
      ENDIF                                                             DGEN     1493
C                                                                       DGEN     1494
 4100 CONTINUE                                                          DGEN     1495
      IF(N.LT.NEND)GOTO 100                                             DGEN     1496
 4150 CONTINUE                                                          DGEN     1497
C                                                                       DGEN     1498
      RETURN                                                            DGEN     1499
C                                                                       DGEN     1500
 8000 FORMAT(1X,'DB-DGEN_NEW:JG,DDAT+5,WXBASE,WOBASE ',I5,3G12.5)       DGEN     1501
 8100 FORMAT(1X,'DB-DGEN_NEW:TINN ',G12.5)                              DGEN     1502
 8200 FORMAT(1X,'DB-DGEN_NEW:TINN,DAMP,X1,TELEC,HM ',5G12.5)            DGEN     1503
 8300 FORMAT(1X,'DB-DGEN_NEW:DX1,DX2 ',2G12.5)                          DGEN     1504
 8400 FORMAT(1X,'==DB-DGEN_NEW:N,K,IFC,RA,VR,VI,CR,CI,TE,TGAP.N==  IR=' DGEN     1505
     +,I2,/,5X,3I5,8G12.5)                                              DGEN     1506
 8500 FORMAT(1X,'DB-DGEN_NEW:N,IFC,TELEC,TGAP.N-1 ',2I5,4G12.5)         DGEN     1507
 8600 FORMAT(1X,'DGEN_NEW:N,IFC,RAP1,DDAT.JG+5,DDAT.JGP1 ',2I5,3G12.5)  DGEN     1508
 8700 FORMAT(1X,'N,IFC,K,RAP1,CR1,CI1,VR1,VI1 ',3I5,5G12.5)             DGEN     1509
 8800 FORMAT(1X,' DGEN: LSTATE',I5,' IOFSET',I5,/,3(I5,2G12.5))         DGEN     1510
 8900 FORMAT(1X,'DB-DGEN: IR=',I2,' TS=',F7.3,'  EFDN,CFDN,V1:',3G12.5) DGEN     1511
C                                                                       DGEN     1512
 9000 FORMAT(' *** ERROR GENERATOR AT BUS ',I5,' STATION: ',3A4         DGEN     1513
     1,' GID ',A2)                                                      DGEN     1514
 9100 FORMAT('     THE GENERATOR FLUXES EXCEED 5.0 P.U. THE DATA OF ',  DGEN     1515
     1'THIS GENERATOR')                                                 DGEN     1516
 9200 FORMAT('     MAY BE ERRONEOUS.')                                  DGEN     1517
 9300 FORMAT('     THE GENERATOR FLUXES EXCEED 5.0 P.U. IN ADDITION, ', DGEN     1518
     1'THE VOLTAGES OF')                                                DGEN     1519
 9400 FORMAT(5X,I5,' BUSES IN THE SYSTEM ARE OUTSIDE THE STABILITY ',   DGEN     1520
     1'CHECKING LIMITS.')                                               DGEN     1521
 9500 FORMAT('     THE SYSTEM MAY BE UNSTABLE OR SOME SYSTEM DATA MAY ',DGEN     1522
     1'BE ERRONEOUS.')                                                  DGEN     1523
 9600 FORMAT(' *** WARNING GENERATOR AT BUS ',I5,' STATION: ',3A4       DGEN     1524
     1,' GID ',A2)                                                      DGEN     1525
 9700 FORMAT('     AT TIME =',F8.3,', THE FIELD CURRENT BECOMES '       DGEN     1526
     1,'NEGATIVE. IFD =',F9.4)                                          DGEN     1527
 9800 FORMAT('     AT TIME =',F8.3,', THE FIELD CURRENT RETURNS TO '    DGEN     1528
     1,'POSITIVE. IFD =',F9.4)                                          DGEN     1529
      END                                                               DGEN     1530
