CFPRIME IMPINT                                                          IMPINT      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 IMPINT(KRESUL,IIL,NRSTEP)                              IMPINT      3
CD                                                                      IMPINT      4
CD    THIS IS THE MAIN DRIVER FOR THE IMPLICIT INTEGRATION METHOD       IMPINT      5
CD    (USING THE TRAPEZOIDAL METHOD).                                   IMPINT      6
CD                                                                      IMPINT      7
CD    THE MAJOR COMPUTATIONS INVOLVED ARE:                              IMPINT      8
CD                                                                      IMPINT      9
CD    1. OBTAIN THE DC SOLUTION FOR THE NEXT TIME STEP BY CALLING       IMPINT     10
CD       SUBROUTINES DCNET1 OR DCNETS, IF DC LINKS ARE PRESENT.         IMPINT     11
CD                                                                      IMPINT     12
CD    2. PREDICT THE SYSTEM STATES AND VOLTAGES BY CALLING SUBROUTINE   IMPINT     13
CD       PREDIC.                                                        IMPINT     14
CD                                                                      IMPINT     15
CD    3. CALCULATE THE SYSTEM STATE DERIVATIVES FOR ALL DYNAMIC DEVICES,IMPINT     16
CD       BY CALLING SUBROUTINES GXDOT, MXDOT, TCXDOT, SXDOT, RXDOT,     IMPINT     17
CD       TPXDOT, AND DBXDOT.                                            IMPINT     18
CD                                                                      IMPINT     19
CD    4. CALCULATE THE RESIDUES OF THE SYSTEM STATES BASED ON THE       IMPINT     20
CD       TRAPEZOIDAL RULE.                                              IMPINT     21
CD                                                                      IMPINT     22
CD    5. CALCULATE THE CURRENT INJECTION VECTOR, INCLUDING ALL DYNAMIC  IMPINT     23
CD       DEVICES, NONLINEAR LOADS AND ULTC.                             IMPINT     24
CD                                                                      IMPINT     25
CD    6. SOLVE THE NETWORK EQUATIONS WITH THE CALCULATED CURRENT        IMPINT     26
CD       INJECTION VECTOR, BY CALLING SUBROUTINES AUPDSC AND ASOLSC.    IMPINT     27
CD                                                                      IMPINT     28
CD    7. UPDATE THE SYSTEM STATE VARIABLES AND THE ASSOCIATED ALGEBRAIC IMPINT     29
CD       VARIABLES (Y-VARIABLES, INTERNAL CURRENTS, ETC.), BY CALLING   IMPINT     30
CD       SUBROUTINE UPSTAT.                                             IMPINT     31
CD                                                                      IMPINT     32
CD    8. AFTER CONVERGENCE OF THE CALCULATIONS AT CURRENT TIME, CALL    IMPINT     33
CD       AGAIN SUBROUTINE ASOLSC TO COMPUTE ALL NECESSARY NETWORK       IMPINT     34
CD       VOLTAGES AND OTHER QUANTITIES FOR OUTPUT PURPOSE.              IMPINT     35
CD                                                                      IMPINT     36
CD    NOTE THAT THE STEPS 3 TO 7 ABOVE CONSTITUTE THE VDHN ITERATION    IMPINT     37
CD    LOOP. THE CONVERGENCE TEST IS PERFORMED AT THE END OF STEP 5 FOR  IMPINT     38
CD    ALL CURRENT INJECTIONS.                                           IMPINT     39
CD                                                                      IMPINT     40
      INCLUDE 'PARX.INS'                                                IMPINT     41
      INCLUDE 'CNPT.INS'                                                IMPINT     42
      INCLUDE 'CNB1.INS'                                                IMPINT     43
      INCLUDE 'CNB3.INS'                                                IMPINT     44
      INCLUDE 'CNB4.INS'                                                IMPINT     45
      INCLUDE 'CNB5.INS'                                                IMPINT     46
      INCLUDE 'CNB6.INS'                                                IMPINT     47
      INCLUDE 'CNB8.INS'                                                IMPINT     48
      INCLUDE 'CNB9.INS'                                                IMPINT     49
      INCLUDE 'CNB19.INS'                                               IMPINT     50
      INCLUDE 'UDCF.INS'                                                IMPINT     51
      INCLUDE 'UDCJ.INS'                                                IMPINT     52
      INCLUDE 'CNSTN.INS'                                               IMPINT     53
      INCLUDE 'CNEXC.INS'                                               IMPINT     54
      INCLUDE 'CNSVS.INS'                                               IMPINT     55
      INCLUDE 'CNRAN.INS'                                               IMPINT     56
      INCLUDE 'CNSTP.INS'                                               IMPINT     57
      INCLUDE 'CNSDB.INS'                                               IMPINT     58
      INCLUDE 'CNSTAB.INS'                                              IMPINT     59
      INCLUDE 'GRPDCS.INS'                                              IMPINT     60
      INCLUDE 'GRDC01.INS'                                              IMPINT     61
      INCLUDE 'GRDC03.INS'                                              IMPINT     62
      INCLUDE 'CNIPTR.INS'                                              IMPINT     63
      INCLUDE 'CNPRGV.INS'                                              IMPINT     64
      INCLUDE 'CNVOLT.INS'                                              IMPINT     65
      INCLUDE 'CNLSTA.INS'                                              IMPINT     66
      INCLUDE 'CNXSTA.INS'                                              IMPINT     67
      INCLUDE 'CNMPAR.INS'                                              IMPINT     68
      INCLUDE 'CNYVAR.INS'                                              IMPINT     69
      INCLUDE 'CNUVAR.INS'                                              IMPINT     70
      INCLUDE 'CNMDAT.INS'                                              IMPINT     71
      INCLUDE 'CNMSTA.INS'                                              IMPINT     72
      INCLUDE 'CNMYVA.INS'                                              IMPINT     73
      INCLUDE 'CNPREV.INS'                                              IMPINT     74
      INCLUDE 'CNXDOT.INS'                                              IMPINT     75
      INCLUDE 'CNIMPR.INS'                                              IMPINT     76
      INCLUDE 'CNMASK.INS'                                              IMPINT     77
      INCLUDE 'CNSPC1.INS'                                              IMPINT     78
      INCLUDE 'CNGEAR.INS'                                              IMPINT     79
      INCLUDE 'CNJCOB.INS'                                              IMPINT     80
      INCLUDE 'CNGOVE.INS'                                              IMPINT     81
      INCLUDE 'CNNNEW.INS'                                              IMPINT     82
      INCLUDE 'CNULTC.INS'                                              IMPINT     83
      INCLUDE 'CNRED.INS'                                               IMPINT     84
      INCLUDE 'CNFLAG.INS'                                              IMPINT     85
      INCLUDE 'CNUNIT.INS'                                              IMPINT     86
      INCLUDE 'CNMSG.INS'                                               IMPINT     87
      INCLUDE 'CNLSMB.INS'                                              IMPINT     88
C      INCLUDE 'CNUDMK.INS/LIST'                                        IMPINT     89
      INCLUDE 'CNLCOM.INS'                                              IMPINT     90
C                                                                       IMPINT     91
      PARAMETER (NNCURR=500)                                            IMPINT     92
      DIMENSION ICURRE(NNCURR),OPHVDC(NDCC),OQHVDC(NDCC)                IMPINT     93
      DIMENSION WV1(4)                                                  IMPINT     94
      DIMENSION EWS2(2)                                                 IMPINT     95
      COMPLEX OCURR(NDEV),CURRES(NNCURR),CURNLL(NZL)                    IMPINT     96
      COMPLEX CWS1,CMPLX,YTCO,YTCA,XICRRP,XICRRS                        IMPINT     97
      EQUIVALENCE (CWS1,EWS2(1)),(EWS2(1),VREAL),(EWS2(2),VIMAG)        IMPINT     98
      LOGICAL KRESUL,IVMG,IPREF                                         IMPINT     99
C                                                                       IMPINT    100
      COMMON /SCRAT8/ ICURRE,OCURR,CURRES                               IMPINT    101
C                                                                       IMPINT    102
      COMMON /CHGDC/ ICHGDC                                             IMPINT    103
C                                                                       IMPINT    104
      INCLUDE 'CDLCOM.INS'                                              IMPINT    105
C                                                                       IMPINT    106
      DATA DEGREE/57.29578/                                             IMPINT    107
C                                                                       IMPINT    108
*IF DEBUG                                                               IMPINT    109
      LDEB=(JDEB(320).NE.0)                                             IMPINT    110
*ENDIF                                                                  IMPINT    111
      IPREF=.FALSE.                                                     IMPINT    112
C                                                                       IMPINT    113
      VFACT=0.0                                                         IMPINT    114
      VXY=0.0                                                           IMPINT    115
      QCI=0.0                                                           IMPINT    116
C                                                                       IMPINT    117
C     STORE THE DC P AND Q OF THE PRESENT TIME STEP                     IMPINT    118
C     AND SET FLAG TO INDICATE ANY LARGE DC CHANGE                      IMPINT    119
C                                                                       IMPINT    120
      DO 100 I=1,NACBUS                                                 IMPINT    121
         OPHVDC(I)=PTHVDC(I)                                            IMPINT    122
         OQHVDC(I)=QTHVDC(I)                                            IMPINT    123
  100 CONTINUE                                                          IMPINT    124
      DO 101 I=LCDC+1,ICDC                                              IMPINT    125
         OPHVDC(I)=PAHVDC(I)                                            IMPINT    126
         OQHVDC(I)=QAHVDC(I)                                            IMPINT    127
  101 CONTINUE                                                          IMPINT    128
C                                                                       IMPINT    129
C     CALL DCNETS TO COMPUTE DC REPONSE FOR THE NEXT TIME STEP.         IMPINT    130
C                                                                       IMPINT    131
C     NOTE : IN ORDER TO AVOID CONVERGENCE PROBLEM RELATED TO THE       IMPINT    132
C            LARGE POWER CHANGE IN DC SYSTEM, A PARTICULAR SCHEME       IMPINT    133
C            IS ARRANGED WITH THE FLAG ICHGDC                           IMPINT    134
C                                                                       IMPINT    135
C            ICHGDC = 0   - NORMAL TRAPEZOIDAL ITERATIONS               IMPINT    136
C            ICHGDC = 1   - TRAPEZOIDAL ITERATIONS WITH OLD DC POWERS   IMPINT    137
C                           AND VOLTAGES, AND THEN A RK4 WITH ZERO STEP IMPINT    138
C                           SIZE                                        IMPINT    139
C                                                                       IMPINT    140
      ICHGDC=0                                                          IMPINT    141
      IF (KCDC.NE.0) THEN                                               IMPINT    142
         IF (JTHDC.EQ.1) THEN                                           IMPINT    143
            CALL DCNET1                                                 IMPINT    144
         ELSE                                                           IMPINT    145
            CALL DCNETS(TS)                                             IMPINT    146
         END IF                                                         IMPINT    147
         DO 150 JJ = 1, NACBUS                                          IMPINT    148
         WS1=OPHVDC(JJ)-PTHVDC(JJ)                                      IMPINT    149
         WS2=OQHVDC(JJ)-QTHVDC(JJ)                                      IMPINT    150
         WS1=BASPC*SQRT(WS1**2+WS2**2)                                  IMPINT    151
         IF (WS1.GT.TVAPDC) THEN                                        IMPINT    152
            ICHGDC=1                                                    IMPINT    153
            GOTO 200                                                    IMPINT    154
         END IF                                                         IMPINT    155
  150    CONTINUE                                                       IMPINT    156
         DO 151 JJ = LCDC+1, ICDC                                       IMPINT    157
         WS1=OPHVDC(JJ)-PAHVDC(JJ)                                      IMPINT    158
         WS2=OQHVDC(JJ)-QAHVDC(JJ)                                      IMPINT    159
         WS1=SQRT(WS1**2+WS2**2)                                        IMPINT    160
         IF (WS1.GT.TVAPDC) THEN                                        IMPINT    161
            ICHGDC=1                                                    IMPINT    162
            GOTO 200                                                    IMPINT    163
         END IF                                                         IMPINT    164
  151    CONTINUE                                                       IMPINT    165
      END IF                                                            IMPINT    166
C                                                                       IMPINT    167
  200 CONTINUE                                                          IMPINT    168
C                                                                       IMPINT    169
*IF LTSP                                                                IMPINT    170
*ENDIF                                                                  IMPINT    223
C                                                                       IMPINT    224
C     IF ULTC MOVED, ALWAYS ITERATE                                     IMPINT    225
C                                                                       IMPINT    226
      IF (ITCFLG .GT. 0 .AND. NREFUC .LE. 0) LITTER = 1                 IMPINT    227
C                                                                       IMPINT    228
*IF DEBUG                                                               IMPINT    229
      IF (LDEB) WRITE(IUD6,8700) TS                                     IMPINT    230
*ENDIF                                                                  IMPINT    231
      CSTIME=TS+H                                                       IMPINT    232
  250 NTSTEP=NTSTEP+1                                                   IMPINT    233
      CEFJM=H/2.0                                                       IMPINT    234
C                                                                       IMPINT    235
C     CALCULATE CONSTANT L1 AND L2 FOR GEAR'S METHOD                    IMPINT    236
C                                                                       IMPINT    237
      IF (IGEARS) THEN                                                  IMPINT    238
         HOLD=TS-TSOLD                                                  IMPINT    239
         AL1=2.0+HOLD/H                                                 IMPINT    240
         CEFJM=H/AL1                                                    IMPINT    241
      END IF                                                            IMPINT    242
C                                                                       IMPINT    243
C     PREDICT VALUES OF NEXT TIME STEP FOR BOTH VOLTAGES AND STATES     IMPINT    244
C                                                                       IMPINT    245
      CALL PREDIC                                                       IMPINT    246
C                                                                       IMPINT    247
C     BEGINNING OF VDHN ITERATIONS                                      IMPINT    248
C                                                                       IMPINT    249
      IF (NITER.GE.IJMCT) JMUPDT=.TRUE.                                 IMPINT    250
      CUROLD=1.0                                                        IMPINT    251
      IUDJM=0                                                           IMPINT    252
      NITER=0                                                           IMPINT    253
  300 CONTINUE                                                          IMPINT    254
C                                                                       IMPINT    255
      IITER=0                                                           IMPINT    256
C                                                                       IMPINT    257
C     CLACULATE XDOT WITH THE VALUES AT CURRENT ITERATION               IMPINT    258
C                                                                       IMPINT    259
C      KYUDM=0                                                          IMPINT    260
      IF(JTHDC.NE.2) THEN                                               IMPINT    261
         CALL GXDOT                                                     IMPINT    262
         IF(NMOTL.NE.0) CALL MXDOT                                      IMPINT    263
      ELSE                                                              IMPINT    264
         IAIDEX=0                                                       IMPINT    265
         IBIDEX=0                                                       IMPINT    266
         ICIDEX=0                                                       IMPINT    267
      ENDIF                                                             IMPINT    268
      IF (NTSCL.NE.0) CALL TCXDOT                                       IMPINT    269
      IF (NSVC.NE.0)  CALL SXDOT                                        IMPINT    270
      IF (NRANI.NE.0) CALL RXDOT                                        IMPINT    271
      IF (NTCPS.NE.0) CALL TPXDOT                                       IMPINT    272
      IF (NSDB.NE.0)  CALL DBXDOT                                       IMPINT    273
C                                                                       IMPINT    274
C     CALCULATE THE RESIDUE VECTOR AND OBTAIN THE MAXIMUM RESIDUE       IMPINT    275
C                                                                       IMPINT    276
      RESMAX=0.0                                                        IMPINT    277
      IRESM=1                                                           IMPINT    278
      IF (.NOT.IGEARS) THEN                                             IMPINT    279
C                                                                       IMPINT    280
         DO 350 I=1,NSTATE                                              IMPINT    281
            IF(IXDOT(I).NE.0)THEN                                       IMPINT    282
               XRES(I)=XSTATE(I)-XPREV(1,I)-CEFJM*(XDOT(I)+OXDOT(I))    IMPINT    283
               AXRESS=ABS(XRES(I))                                      IMPINT    284
               IF (AXRESS.GT.RESMAX) THEN                               IMPINT    285
                  RESMAX=AXRESS                                         IMPINT    286
                  IRESM=I                                               IMPINT    287
               END IF                                                   IMPINT    288
            ELSE                                                        IMPINT    289
               XRES(I)=0.0                                              IMPINT    290
            END IF                                                      IMPINT    291
  350   CONTINUE                                                        IMPINT    292
C                                                                       IMPINT    293
      ELSE                                                              IMPINT    294
C                                                                       IMPINT    295
         DO 400 I=1,NSTATE                                              IMPINT    296
            IF (IXDOT(I).NE.0) THEN                                     IMPINT    297
               XRESS=XSTATE(I)-XPREV(1,I)-CEFJM*(XDOT(I)-XDOTP(I))      IMPINT    298
               IF (ABS(XRESS).GT.RESMAX) THEN                           IMPINT    299
                  RESMAX=ABS(XRESS)                                     IMPINT    300
                  IRESM=I                                               IMPINT    301
               END IF                                                   IMPINT    302
               XRES(I)=XRESS                                            IMPINT    303
            ELSE                                                        IMPINT    304
               XRES(I)=0.0                                              IMPINT    305
            END IF                                                      IMPINT    306
  400    CONTINUE                                                       IMPINT    307
C                                                                       IMPINT    308
      END IF                                                            IMPINT    309
C                                                                       IMPINT    310
C-----------------------------------------------------------------------IMPINT    311
C                                                                       IMPINT    312
C     OBTAIN MAXIMUM VOLTAGE DEVIATION AND CHECK AGAINST THE TOLERANCE  IMPINT    313
C     THIS PART IS INACTIVE NOW                                         IMPINT    314
C                                                                       IMPINT    315
C      ERMAX=0.0                                                        IMPINT    316
C      EIMAX=0.0                                                        IMPINT    317
C      DO 130 I=1,LASTCU                                                IMPINT    318
C         CWS1=VOLT(I)-OVOLT(I)                                         IMPINT    319
C         WSR=ABS(VREAL)                                                IMPINT    320
C         WSI=ABS(VIMAG)                                                IMPINT    321
C         IF (WSR.GT.ERMAX) ERMAX=WSR                                   IMPINT    322
C         IF (WSI.GT.EIMAX) EIMAX=WSI                                   IMPINT    323
C 130  CONTINUE                                                         IMPINT    324
C                                                                       IMPINT    325
C      IF (ERMAX.LE.ERTOL.AND.EIMAX.LE.ERTOL.AND.RESMAX.LE.RESTOL       IMPINT    326
C     *    .AND.NITER.NE.0) GOTO 333                                    IMPINT    327
C                                                                       IMPINT    328
C-----------------------------------------------------------------------IMPINT    329
C                                                                       IMPINT    330
*IF DEBUG                                                               IMPINT    331
      IF (LDEB) WRITE(IUD6,8800) NITER,RESMAX,IRESM                     IMPINT    332
*ENDIF                                                                  IMPINT    333
C                                                                       IMPINT    334
C     CONVERGENCE CHECK FOR RESIDUES OF STATES                          IMPINT    335
C                                                                       IMPINT    336
C      IF (RESMAX.LE.RESTOL.AND.NITER.NE.0) GOTO 333                    IMPINT    337
C                                                                       IMPINT    338
      ICHPLP=0                                                          IMPINT    339
      IAIDEX=0                                                          IMPINT    340
      ICIDEX=0                                                          IMPINT    341
      N=0                                                               IMPINT    342
C                                                                       IMPINT    343
      DO 140 I=1,IPNODE                                                 IMPINT    344
C                                                                       IMPINT    345
         CCDG(1,I)=0.0                                                  IMPINT    346
         CCDG(2,I)=0.0                                                  IMPINT    347
         CWS1=VOLT(I)                                                   IMPINT    348
C                                                                       IMPINT    349
         L=0                                                            IMPINT    350
 155     L=L+1                                                          IMPINT    351
         N=N+1                                                          IMPINT    352
         JG=JCONTA(1,N)                                                 IMPINT    353
         JSTATE=MSTATE(1,N)                                             IMPINT    354
         ISTATE=MSTATE(1,N+1)-JSTATE                                    IMPINT    355
C                                                                       IMPINT    356
         IGENS=ICONTA(1,N)                                              IMPINT    357
         IGVN=ICONTA(2,N)                                               IMPINT    358
         IF(IGVN.EQ.46) IGVN=0                                          IMPINT    359
C                                                                       IMPINT    360
         HM=DDAT(JG+1)                                                  IMPINT    361
C                                                                       IMPINT    362
         IF (IGENS.EQ.4) THEN                                           IMPINT    363
C                                                                       IMPINT    364
C     MACHINES REPRESENTED BY CLASSICAL MODEL                           IMPINT    365
C                                                                       IMPINT    366
            IF (HM.LT.1.0E-5) THEN                                      IMPINT    367
               IF (JTHDC.EQ.2) GOTO 170                                 IMPINT    368
               IF (IGVN.EQ.0) THEN                                      IMPINT    369
                  IAIDEX=IAIDEX+4                                       IMPINT    370
                  ICIDEX=ICIDEX+2                                       IMPINT    371
               ELSE                                                     IMPINT    372
                  IAIDEX=IAIDEX+ISTATE*ISTATE                           IMPINT    373
                  ICIDEX=ICIDEX+2*ISTATE                                IMPINT    374
               END IF                                                   IMPINT    375
               GOTO 170                                                 IMPINT    376
            END IF                                                      IMPINT    377
C                                                                       IMPINT    378
C     FORM THE COMPLETE CURRENT INJECTION AT MACHINE INTERNAL BUS       IMPINT    379
C                                                                       IMPINT    380
            RES1=0.0                                                    IMPINT    381
            RES2=0.0                                                    IMPINT    382
            IF (JTHDC.NE.2) THEN                                        IMPINT    383
               IF (IGVN.EQ.0) THEN                                      IMPINT    384
C                                                                       IMPINT    385
C     NO GOVERNOR REPRESENTED                                           IMPINT    386
C                                                                       IMPINT    387
                  RES2=AJCOB(IAIDEX+3)*XRES(JSTATE+1)+                  IMPINT    388
     1                 AJCOB(IAIDEX+4)*XRES(JSTATE+2)                   IMPINT    389
                  RES1=CJCOB(ICIDEX+1)*RES2                             IMPINT    390
                  RES2=CJCOB(ICIDEX+2)*RES2                             IMPINT    391
                  IAIDEX=IAIDEX+4                                       IMPINT    392
                  ICIDEX=ICIDEX+2                                       IMPINT    393
               ELSE                                                     IMPINT    394
C                                                                       IMPINT    395
C     GOVERNOR IS REPRESENTED                                           IMPINT    396
C                                                                       IMPINT    397
                  IF (IGVN.EQ.5) THEN                                   IMPINT    398
C                                                                       IMPINT    399
C     INCLUDE HP TERMS FOR LP MACHINE                                   IMPINT    400
C                                                                       IMPINT    401
                     ICHPLP=ICHPLP+3                                    IMPINT    402
                     HPLPC=CHPLP(ICHPLP-2)*XRES(JSTATE-2)+              IMPINT    403
     1                     CHPLP(ICHPLP-1)*XRES(JSTATE-1)+              IMPINT    404
     2                     CHPLP(ICHPLP)*XRES(JSTATE)                   IMPINT    405
                     XRES(JSTATE+1)=XRES(JSTATE+1)-HPLPC                IMPINT    406
                  END IF                                                IMPINT    407
                  NAIDEX=IAIDEX+ISTATE                                  IMPINT    408
                  CALL FBSUB(NAIDEX,ISTATE,JSTATE)                      IMPINT    409
C                                                                       IMPINT    410
C     CALCULATE AK*INVERSE(A)*XRES                                      IMPINT    411
C                                                                       IMPINT    412
                  DO 195 ICC=1,ISTATE                                   IMPINT    413
                     ICIDEX=ICIDEX+1                                    IMPINT    414
                     RES1=RES1+CJCOB(ICIDEX)*XRES(JSTATE+ICC)           IMPINT    415
                     RES2=RES2+CJCOB(ICIDEX+ISTATE)*XRES(JSTATE+ICC)    IMPINT    416
  195             CONTINUE                                              IMPINT    417
                  ICIDEX=ICIDEX+ISTATE                                  IMPINT    418
               END IF                                                   IMPINT    419
            END IF                                                      IMPINT    420
C                                                                       IMPINT    421
            CCDG(1,I)=CCDG(1,I)+CDG(1,N)+RES1                           IMPINT    422
            CCDG(2,I)=CCDG(2,I)+CDG(2,N)+RES2                           IMPINT    423
C                                                                       IMPINT    424
         ELSE                                                           IMPINT    425
C                                                                       IMPINT    426
C     MACHINES REPRESENTED BY DETAILED MODEL                            IMPINT    427
C                                                                       IMPINT    428
            MD=IDDAT(JG+34)                                             IMPINT    429
            MQ=IDDAT(JG+35)-1                                           IMPINT    430
            IF (HM.LT.1.0E-5) THEN                                      IMPINT    431
               IF (JTHDC.EQ.2) GOTO 170                                 IMPINT    432
               IAIDEX=IAIDEX+ISTATE+2                                   IMPINT    433
               ICIDEX=ICIDEX+2*(MD+MQ+1)                                IMPINT    434
               GOTO 170                                                 IMPINT    435
            END IF                                                      IMPINT    436
C                                                                       IMPINT    437
C     MACHINE INTERNAL CURRENT                                          IMPINT    438
C                                                                       IMPINT    439
            CCDG(1,I)=CCDG(1,I)-UVAR(5,N)                               IMPINT    440
            CCDG(2,I)=CCDG(2,I)-UVAR(6,N)                               IMPINT    441
C                                                                       IMPINT    442
C     SALIENCY COMPENSATION CURRENT                                     IMPINT    443
C                                                                       IMPINT    444
            IF (ISAL(N)) THEN                                           IMPINT    445
               U1K=UVAR(1,N)-BUVAR(1,N)                                 IMPINT    446
               U2K=UVAR(2,N)-BUVAR(2,N)                                 IMPINT    447
               U3K=UVAR(3,N)-BUVAR(3,N)                                 IMPINT    448
               U4K=UVAR(4,N)-BUVAR(4,N)                                 IMPINT    449
               CCDG(1,I)=CCDG(1,I)+U1K*VREAL+U2K*VIMAG                  IMPINT    450
               CCDG(2,I)=CCDG(2,I)+U3K*VREAL+U4K*VIMAG                  IMPINT    451
            END IF                                                      IMPINT    452
C                                                                       IMPINT    453
C     CALCULATE INVERSE(A)*XRES. RESULTS ARE IN ARRAY XRES              IMPINT    454
C                                                                       IMPINT    455
            IF (JTHDC.NE.2) THEN                                        IMPINT    456
               IF (IGVN.EQ.5) THEN                                      IMPINT    457
C                                                                       IMPINT    458
C     INCLUDE HP TERMS FOR LP MACHINE                                   IMPINT    459
C                                                                       IMPINT    460
                  ICHPLP=ICHPLP+3                                       IMPINT    461
                  HPLPC=CHPLP(ICHPLP-2)*XRES(JSTATE-2)+                 IMPINT    462
     1                  CHPLP(ICHPLP-1)*XRES(JSTATE-1)+                 IMPINT    463
     2                  CHPLP(ICHPLP)*XRES(JSTATE)                      IMPINT    464
                  XRES(JSTATE+1)=XRES(JSTATE+1)-HPLPC                   IMPINT    465
               END IF                                                   IMPINT    466
               CALL FBSUBS(ISTATE,JSTATE)                               IMPINT    467
C                                                                       IMPINT    468
C     CALCULATE AK*INVERSE(A)*XRES                                      IMPINT    469
C                                                                       IMPINT    470
               MT=MD+MQ+2                                               IMPINT    471
               MT1=MT-1                                                 IMPINT    472
               DO 190 ICC=2,MT                                          IMPINT    473
                  ICIDEX=ICIDEX+1                                       IMPINT    474
                  CCDG(1,I)=CCDG(1,I)+CJCOB(ICIDEX)*XRES(JSTATE+ICC)    IMPINT    475
                  CCDG(2,I)=CCDG(2,I)+CJCOB(ICIDEX+MT1)*XRES(JSTATE+ICC)IMPINT    476
  190          CONTINUE                                                 IMPINT    477
               ICIDEX=ICIDEX+MT1                                        IMPINT    478
            END IF                                                      IMPINT    479
         END IF                                                         IMPINT    480
C                                                                       IMPINT    481
  170    IF (L.LT.KTHGE(I)) GOTO 155                                    IMPINT    482
  140 CONTINUE                                                          IMPINT    483
C                                                                       IMPINT    484
C     STORE CURRENT VOLTAGE FOR CONVERGENCE CHECK                       IMPINT    485
C                                                                       IMPINT    486
C     NOTE : THE FOLLOWING LASTV2 SHOULD BE REPLACED BY                 IMPINT    487
C            LASTV1 WHEN IT IS AVAILABLE                                IMPINT    488
C                                                                       IMPINT    489
      IF (LOBUS.EQ.1) THEN                                              IMPINT    490
      DO 145 I=1,NLAST                                                  IMPINT    491
      OVOLT(I)=VOLT(I)                                                  IMPINT    492
  145 CONTINUE                                                          IMPINT    493
      ELSE                                                              IMPINT    494
      DO 146 I=1,LASTV2                                                 IMPINT    495
      OVOLT(I)=VOLT(I)                                                  IMPINT    496
  146 CONTINUE                                                          IMPINT    497
      DO 147 I=1,NVADD                                                  IMPINT    498
      K=IVADD(I)                                                        IMPINT    499
  147 OVOLT(K)=VOLT(K)                                                  IMPINT    500
      END IF                                                            IMPINT    501
C                                                                       IMPINT    502
      DO 750 K=1,NLAST                                                  IMPINT    503
         VOLT(K)=(0.0,0.0)                                              IMPINT    504
  750 CONTINUE                                                          IMPINT    505
C                                                                       IMPINT    506
C     INITIALIZE THE CURRENT VECTOR (IN VOLT)                           IMPINT    507
C     NOTE THAT THE CURRENTS OF DETAILED AND CLASSICAL                  IMPINT    508
C     MACHINES ARE DIRECTLY PUT INTO THE VOLT ARRAY                     IMPINT    509
C                                                                       IMPINT    510
      DO 700 K=1,IPNODE                                                 IMPINT    511
         MSKK=MSK(K)                                                    IMPINT    512
         VOLT(MSKK)=VOLT(MSKK)+CMPLX(CCDG(1,K),CCDG(2,K))               IMPINT    513
  700 CONTINUE                                                          IMPINT    514
C                                                                       IMPINT    515
C     INDUCTION MOTOR                                                   IMPINT    516
C                                                                       IMPINT    517
      IF (NMOTL.EQ.0) GOTO 1000                                         IMPINT    518
      DO 950 I=1,NMOTL                                                  IMPINT    519
         K=NMOLD(I)                                                     IMPINT    520
         JM=JMDAT(I)                                                    IMPINT    521
         MOTYPK=IDDAT(JM+1)                                             IMPINT    522
         IF (DDAT(JM+15).LT.-999998.0) THEN                             IMPINT    523
            IF (JTHDC.NE.2) THEN                                        IMPINT    524
               IF (MOTYPK.GE.10) MOTYPK=MOTYPK-10                       IMPINT    525
               IF (MOTYPK.LE.3) THEN                                    IMPINT    526
                  IAIDEX=IAIDEX+10                                      IMPINT    527
                  ICIDEX=ICIDEX+6                                       IMPINT    528
               ELSE                                                     IMPINT    529
                  IAIDEX=IAIDEX+2                                       IMPINT    530
                  ICIDEX=ICIDEX+2                                       IMPINT    531
               END IF                                                   IMPINT    532
            END IF                                                      IMPINT    533
            GOTO 950                                                    IMPINT    534
         END IF                                                         IMPINT    535
C                                                                       IMPINT    536
         IF (DDAT(JM+15).GE.0.0) THEN                                   IMPINT    537
C                                                                       IMPINT    538
         JZT=JXIMO(I)                                                   IMPINT    539
         JY=JVIMO(I)                                                    IMPINT    540
         GLK=GSM(JY+4)                                                  IMPINT    541
         BLK=BSM(JY+5)                                                  IMPINT    542
         GLK0=GLK-GSMO(JY+6)                                            IMPINT    543
         BLK0=BLK-BSMO(JY+7)                                            IMPINT    544
         IF (MOTYPK.LT.10) THEN                                         IMPINT    545
            CWS1=OVOLT(K)                                               IMPINT    546
            KK=1                                                        IMPINT    547
         ELSE                                                           IMPINT    548
            CWS1=(0.0,0.0)                                              IMPINT    549
            MOTYPK=MOTYPK-10                                            IMPINT    550
            KK=-1                                                       IMPINT    551
         END IF                                                         IMPINT    552
C                                                                       IMPINT    553
C      MOTOR INTERNAL CURRENT PLUS COMPENSATION CURRENT                 IMPINT    554
C                                                                       IMPINT    555
         MSKK=MSK(K)                                                    IMPINT    556
         IF (MOTYPK.LE.3) THEN                                          IMPINT    557
            XS1=XSTATE(JZT+1)                                           IMPINT    558
            XS2=XSTATE(JZT+2)                                           IMPINT    559
            WS1=GLK*XS1+BLK*XS2-GLK0*VREAL-BLK0*VIMAG                   IMPINT    560
            WS2=GLK*XS2-BLK*XS1+BLK0*VREAL-GLK0*VIMAG                   IMPINT    561
C            WS1=GLK*(XS1-VREAL)+BLK*(XS2-VIMAG)                        IMPINT    562
C            WS2=GLK*(XS2-VIMAG)-BLK*(XS1-VREAL)                        IMPINT    563
C            IF (DDAT(JM+14).LT.0.0) THEN                               IMPINT    564
C               WS1=WS1+GSMOX*XS1+BSMOX*XS2                             IMPINT    565
C               WS2=WS2+GSMOX*XS2-BSMOX*XS1                             IMPINT    566
C            END IF                                                     IMPINT    567
            IF(JTHDC.NE.2) NAIDEX=IAIDEX+4                              IMPINT    568
            NOSAT=3                                                     IMPINT    569
         ELSE                                                           IMPINT    570
            WS1=-GLK0*VREAL-BLK0*VIMAG                                  IMPINT    571
            WS2=+BLK0*VREAL-GLK0*VIMAG                                  IMPINT    572
C            WS1=-GLK*VREAL-BLK*VIMAG                                   IMPINT    573
C            WS2=+BLK*VREAL-GLK*VIMAG                                   IMPINT    574
            IF(JTHDC.NE.2) NAIDEX=IAIDEX+2                              IMPINT    575
            NOSAT=1                                                     IMPINT    576
         END IF                                                         IMPINT    577
C                                                                       IMPINT    578
         IF(JTHDC.NE.2) THEN                                            IMPINT    579
         CALL FBSUB(NAIDEX,NOSAT,JZT)                                   IMPINT    580
C                                                                       IMPINT    581
         DO 850 ICC=1,NOSAT                                             IMPINT    582
            ICIDEX=ICIDEX+1                                             IMPINT    583
            WS1=WS1+CJCOB(ICIDEX)*XRES(JZT+ICC)                         IMPINT    584
  850    CONTINUE                                                       IMPINT    585
         DO 900 ICC=1,NOSAT                                             IMPINT    586
            ICIDEX=ICIDEX+1                                             IMPINT    587
            WS2=WS2+CJCOB(ICIDEX)*XRES(JZT+ICC)                         IMPINT    588
  900    CONTINUE                                                       IMPINT    589
         ENDIF                                                          IMPINT    590
C                                                                       IMPINT    591
         ELSE                                                           IMPINT    592
C                                                                       IMPINT    593
C     NOTE : OVOLT HERE MAY BE REPLACED BY VPREV                        IMPINT    594
C                                                                       IMPINT    595
         IF (JTHDC.NE.2) THEN                                           IMPINT    596
            IF (MOTYPK.GE.10) MOTYPK=MOTYPK-10                          IMPINT    597
            IF (MOTYPK.LE.3) THEN                                       IMPINT    598
               IAIDEX=IAIDEX+10                                         IMPINT    599
               ICIDEX=ICIDEX+6                                          IMPINT    600
            ELSE                                                        IMPINT    601
               IAIDEX=IAIDEX+2                                          IMPINT    602
               ICIDEX=ICIDEX+2                                          IMPINT    603
            END IF                                                      IMPINT    604
         END IF                                                         IMPINT    605
         JY=JVIMO(I)                                                    IMPINT    606
         DGSM=GSMO(JY+6)                                                IMPINT    607
         DBSM=BSMO(JY+7)                                                IMPINT    608
         ERGK=REAL(OVOLT(K))                                            IMPINT    609
         EIGK=AIMAG(OVOLT(K))                                           IMPINT    610
         WS1=DGSM*ERGK+DBSM*EIGK                                        IMPINT    611
         WS2=DBSM*ERGK-DGSM*EIGK                                        IMPINT    612
         KK=1                                                           IMPINT    613
C                                                                       IMPINT    614
         END IF                                                         IMPINT    615
C                                                                       IMPINT    616
         IF (JTHDC.NE.2) THEN                                           IMPINT    617
         IF (KK.GT.0) THEN                                              IMPINT    618
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(WS1,WS2)                        IMPINT    619
         ELSE                                                           IMPINT    620
            CDM(JY+8)=WS1                                               IMPINT    621
            CQM(JY+9)=WS2                                               IMPINT    622
         END IF                                                         IMPINT    623
         END IF                                                         IMPINT    624
  950 CONTINUE                                                          IMPINT    625
 1000 CONTINUE                                                          IMPINT    626
C                                                                       IMPINT    627
C     TSC LOAD                                                          IMPINT    628
C                                                                       IMPINT    629
      IF (NTSCL.EQ.0) GOTO 1100                                         IMPINT    630
      DO 1050 I=1,NTSCL                                                 IMPINT    631
         JTSC=JTCDAT(I)                                                 IMPINT    632
         JZT=JXTSC(I)                                                   IMPINT    633
         NLF=IDDAT(JTSC+1)                                              IMPINT    634
         GTSC=DDAT(JTSC+11)                                             IMPINT    635
         GTSC0=GTSC-DDAT(JTSC+10)                                       IMPINT    636
         CWS1=OVOLT(NLF)                                                IMPINT    637
C                                                                       IMPINT    638
C      TSC COMPENSATION CURRENT                                         IMPINT    639
C                                                                       IMPINT    640
         MSKK=MSK(NLF)                                                  IMPINT    641
         WS1=-GTSC0*VREAL                                               IMPINT    642
         WS2=-GTSC0*VIMAG                                               IMPINT    643
         VOLT(MSKK)=VOLT(MSKK)+CMPLX(WS1,WS2)                           IMPINT    644
C                                                                       IMPINT    645
         IF (IDDAT(JTSC+15).EQ.0) THEN                                  IMPINT    646
            NAIDEX=IAIDEX+2                                             IMPINT    647
            CALL FBSUB(NAIDEX,2,JZT)                                    IMPINT    648
C                                                                       IMPINT    649
            ICIDEX=ICIDEX+2                                             IMPINT    650
            WS1=CJCOB(ICIDEX-1)*XRES(JZT+1)+CJCOB(ICIDEX)*XRES(JZT+2)   IMPINT    651
            ICIDEX=ICIDEX+2                                             IMPINT    652
            WS2=CJCOB(ICIDEX-1)*XRES(JZT+1)+CJCOB(ICIDEX)*XRES(JZT+2)   IMPINT    653
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(WS1,WS2)                        IMPINT    654
         ELSE                                                           IMPINT    655
            IAIDEX=IAIDEX+4                                             IMPINT    656
            ICIDEX=ICIDEX+4                                             IMPINT    657
         END IF                                                         IMPINT    658
 1050 CONTINUE                                                          IMPINT    659
 1100 CONTINUE                                                          IMPINT    660
C                                                                       IMPINT    661
C     SVC                                                               IMPINT    662
C                                                                       IMPINT    663
      IF (NSVC.EQ.0) GOTO 1250                                          IMPINT    664
      DO 1200 I=1,NSVC                                                  IMPINT    665
         JS=JSDAT(I)                                                    IMPINT    666
         JSM=JXSVR(I)                                                   IMPINT    667
         ISTATE=JXSVR(I+1)-JSM                                          IMPINT    668
         JY=JVSVR(I)                                                    IMPINT    669
         NRTYPN=IDDAT(JS+9)                                             IMPINT    670
C                                                                       IMPINT    671
         K=NROLD(I)                                                     IMPINT    672
         CWS1=OVOLT(K)                                                  IMPINT    673
         EPD=VREAL                                                      IMPINT    674
         EPQ=VIMAG                                                      IMPINT    675
         MSKK=MSK(K)                                                    IMPINT    676
C                                                                       IMPINT    677
         IF(IDDAT(JS+9).EQ.50) THEN                                     IMPINT    678
            IF(BASER(JY+4).GT.0.0) THEN                                 IMPINT    679
               U2K=BSVCO(JY+3)-BSVC(JY+2)                               IMPINT    680
            ELSE                                                        IMPINT    681
               U2K=BSVCO(JY+3)                                          IMPINT    682
               U3K=BSVC(JY+2)                                           IMPINT    683
            ENDIF                                                       IMPINT    684
         ELSE                                                           IMPINT    685
            U2K=BSVC(JY+2)                                              IMPINT    686
            IF(IDDAT(JS+9).EQ.6) U2K=U2K*DDAT(JS+6)                     IMPINT    687
            U2K=BSVCO(JY+3)-U2K                                         IMPINT    688
         ENDIF                                                          IMPINT    689
C                                                                       IMPINT    690
         VOLT(MSKK)=VOLT(MSKK)+CMPLX(U2K*EPQ,-U2K*EPD)                  IMPINT    691
         IF(IDDAT(JS+9).EQ.50) THEN                                     IMPINT    692
            IF(BASER(JY+4).LT.0.0) THEN                                 IMPINT    693
               VMG=SQRT(EPQ**2+EPD**2)                                  IMPINT    694
               IF(VMG.GT.0.0001) THEN                                   IMPINT    695
                  COSF=EPD/VMG                                          IMPINT    696
                  SINF=EPQ/VMG                                          IMPINT    697
                  VOLT(MSKK)=VOLT(MSKK)+CMPLX(-U3K*SINF,U3K*COSF)       IMPINT    698
               ENDIF                                                    IMPINT    699
            ENDIF                                                       IMPINT    700
         ENDIF                                                          IMPINT    701
C                                                                       IMPINT    702
         IF ((NRTYPN.LE.5.OR.NRTYPN.EQ.50).AND.ISTATE.NE.0) THEN        IMPINT    703
            NAIDEX=IAIDEX+ISTATE                                        IMPINT    704
            CALL FBSUB(NAIDEX,ISTATE,JSM)                               IMPINT    705
            IWS1=ICIDEX+ISTATE                                          IMPINT    706
            DO 1150 ICC=1,ISTATE                                        IMPINT    707
               ICIDEX=ICIDEX+1                                          IMPINT    708
               WS1=CJCOB(ICIDEX)*XRES(JSM+ICC)                          IMPINT    709
               IWS1=IWS1+1                                              IMPINT    710
               WS2=CJCOB(IWS1)*XRES(JSM+ICC)                            IMPINT    711
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(WS1,WS2)                     IMPINT    712
 1150       CONTINUE                                                    IMPINT    713
            ICIDEX=ICIDEX+ISTATE                                        IMPINT    714
         END IF                                                         IMPINT    715
C                                                                       IMPINT    716
 1200 CONTINUE                                                          IMPINT    717
 1250 CONTINUE                                                          IMPINT    718
C                                                                       IMPINT    719
C     RANI                                                              IMPINT    720
C                                                                       IMPINT    721
      IF (NRANI.EQ.0) GOTO 1400                                         IMPINT    722
      DO 1350 I=1,NRANI                                                 IMPINT    723
         JR=JRDAT(I)                                                    IMPINT    724
         JSM=JXRAN(I)                                                   IMPINT    725
         ISTATE=JXRAN(I+1)-JXRAN(I)                                     IMPINT    726
         JY=JVRAN(I)                                                    IMPINT    727
         K1=IDDAT(JR+1)                                                 IMPINT    728
         K2=IDDAT(JR+2)                                                 IMPINT    729
         IRANF=IDDAT(JR+6)                                              IMPINT    730
C                                                                       IMPINT    731
         VREAL1=REAL(OVOLT(K1))                                         IMPINT    732
         VIMAG1=AIMAG(OVOLT(K1))                                        IMPINT    733
         VREAL2=REAL(OVOLT(K2))                                         IMPINT    734
         VIMAG2=AIMAG(OVOLT(K2))                                        IMPINT    735
C                                                                       IMPINT    736
         MSKK1=MSK(K1)                                                  IMPINT    737
         MSKK2=MSK(K2)                                                  IMPINT    738
C                                                                       IMPINT    739
         IF(IRANF.EQ.0.OR.IRANF.EQ.1) THEN                              IMPINT    740
            U2K=BRANO(JY+3)-BRANI(JY+2)                                 IMPINT    741
         ELSEIF(IRANF.EQ.2) THEN                                        IMPINT    742
            U1K=BRANO(JY+9)-BRANI(JY+8)                                 IMPINT    743
            U2K=BRANO(JY+3)-BRANI(JY+2)                                 IMPINT    744
         ELSEIF(IRANF.EQ.3) THEN                                        IMPINT    745
            U2K=BRANO(JY+3)                                             IMPINT    746
            U3K=BRANI(JY+2)                                             IMPINT    747
         ENDIF                                                          IMPINT    748
C                                                                       IMPINT    749
         VREAL=VREAL1-VREAL2                                            IMPINT    750
         VIMAG=VIMAG1-VIMAG2                                            IMPINT    751
         IF(IRANF.EQ.0) THEN                                            IMPINT    752
            CREAL=U2K*VIMAG                                             IMPINT    753
            CIMAG=-U2K*VREAL                                            IMPINT    754
         ELSEIF(IRANF.EQ.1) THEN                                        IMPINT    755
            CREAL=U2K*VREAL                                             IMPINT    756
            CIMAG=U2K*VIMAG                                             IMPINT    757
         ELSEIF(IRANF.EQ.2) THEN                                        IMPINT    758
            CREAL=U1K*VREAL+U2K*VIMAG                                   IMPINT    759
            CIMAG=U1K*VIMAG-U2K*VREAL                                   IMPINT    760
         ELSEIF(IRANF.EQ.3) THEN                                        IMPINT    761
            VMG=SQRT(VREAL**2+VIMAG**2)                                 IMPINT    762
            CREAL=( U2K-U3K/VMG)*VIMAG                                  IMPINT    763
            CIMAG=(-U2K+U3K/VMG)*VREAL                                  IMPINT    764
         ENDIF                                                          IMPINT    765
C                                                                       IMPINT    766
         NAIDEX=IAIDEX+ISTATE                                           IMPINT    767
         CALL FBSUB(NAIDEX,ISTATE,JSM)                                  IMPINT    768
         WV1(1)=0.0                                                     IMPINT    769
         WV1(2)=0.0                                                     IMPINT    770
         WV1(3)=0.0                                                     IMPINT    771
         WV1(4)=0.0                                                     IMPINT    772
         DO 1300 ICC=1,ISTATE                                           IMPINT    773
         ICIDEX=ICIDEX+1                                                IMPINT    774
         WV1(1)=WV1(1)+CJCOB(ICIDEX)*XRES(JSM+ICC)                      IMPINT    775
         WV1(2)=WV1(2)+CJCOB(ICIDEX+ISTATE)*XRES(JSM+ICC)               IMPINT    776
         WV1(3)=WV1(3)+CJCOB(ICIDEX+2*ISTATE)*XRES(JSM+ICC)             IMPINT    777
         WV1(4)=WV1(4)+CJCOB(ICIDEX+3*ISTATE)*XRES(JSM+ICC)             IMPINT    778
 1300    CONTINUE                                                       IMPINT    779
         ICIDEX=ICIDEX+3*ISTATE                                         IMPINT    780
C                                                                       IMPINT    781
         VOLT(MSKK1)=VOLT(MSKK1)+CMPLX(CREAL,CIMAG)+CMPLX(WV1(1),WV1(2))IMPINT    782
         VOLT(MSKK2)=VOLT(MSKK2)-CMPLX(CREAL,CIMAG)+CMPLX(WV1(3),WV1(4))IMPINT    783
C                                                                       IMPINT    784
 1350 CONTINUE                                                          IMPINT    785
 1400 CONTINUE                                                          IMPINT    786
C                                                                       IMPINT    787
C     COMPUTE STP CURRENT                                               IMPINT    788
C                                                                       IMPINT    789
      IF (NTCPS.EQ.0) GOTO 1600                                         IMPINT    790
      DO 1550 I=1,NTCPS                                                 IMPINT    791
         JTP=JTPDAT(I)                                                  IMPINT    792
         K1=IDDAT(JTP+1)                                                IMPINT    793
         K2=IDDAT(JTP+2)                                                IMPINT    794
         VREAL1=REAL(OVOLT(K1))                                         IMPINT    795
         VIMAG1=AIMAG(OVOLT(K1))                                        IMPINT    796
         VREAL2=REAL(OVOLT(K2))                                         IMPINT    797
         VIMAG2=AIMAG(OVOLT(K2))                                        IMPINT    798
         JY=JVSTP(I)                                                    IMPINT    799
         G11=YVAR(JY+9)-YVAR(JY+1)                                      IMPINT    800
         B11=YVAR(JY+10)-YVAR(JY+2)                                     IMPINT    801
         G12=YVAR(JY+11)-YVAR(JY+3)                                     IMPINT    802
         B12=YVAR(JY+12)-YVAR(JY+4)                                     IMPINT    803
         G21=YVAR(JY+13)-YVAR(JY+5)                                     IMPINT    804
         B21=YVAR(JY+14)-YVAR(JY+6)                                     IMPINT    805
         G22=YVAR(JY+15)-YVAR(JY+7)                                     IMPINT    806
         B22=YVAR(JY+16)-YVAR(JY+8)                                     IMPINT    807
C                                                                       IMPINT    808
         MSKK1=MSK(K1)                                                  IMPINT    809
         MSKK2=MSK(K2)                                                  IMPINT    810
         CREAL1=G11*VREAL1-B11*VIMAG1+G12*VREAL2-B12*VIMAG2             IMPINT    811
         CIMAG1=B11*VREAL1+G11*VIMAG1+B12*VREAL2+G12*VIMAG2             IMPINT    812
         CREAL2=G21*VREAL1-B21*VIMAG1+G22*VREAL2-B22*VIMAG2             IMPINT    813
         CIMAG2=B21*VREAL1+G21*VIMAG1+B22*VREAL2+G22*VIMAG2             IMPINT    814
         VOLT(MSKK1)=VOLT(MSKK1)+CMPLX(CREAL1,CIMAG1)                   IMPINT    815
         VOLT(MSKK2)=VOLT(MSKK2)+CMPLX(CREAL2,CIMAG2)                   IMPINT    816
C                                                                       IMPINT    817
         NTTYPN=IDDAT(JTP+4)                                            IMPINT    818
         NPTYPN=IDDAT(JTP+5)                                            IMPINT    819
         IF (NTTYPN.NE.50.AND.NPTYPN.NE.50) GOTO 1550                   IMPINT    820
C                                                                       IMPINT    821
         JSM=JXSTC(I)                                                   IMPINT    822
         ISTATE=JXSTC(I+1)-JSM                                          IMPINT    823
         NAIDEX=IAIDEX+ISTATE                                           IMPINT    824
         CALL FBSUB(NAIDEX,ISTATE,JSM)                                  IMPINT    825
            WV1(1)=0.0                                                  IMPINT    826
            WV1(2)=0.0                                                  IMPINT    827
            WV1(3)=0.0                                                  IMPINT    828
            WV1(4)=0.0                                                  IMPINT    829
            DO 1450 ICC=1,ISTATE                                        IMPINT    830
            ICIDEX=ICIDEX+1                                             IMPINT    831
            WV1(1)=WV1(1)+CJCOB(ICIDEX)*XRES(JSM+ICC)                   IMPINT    832
            WV1(2)=WV1(2)+CJCOB(ICIDEX+ISTATE)*XRES(JSM+ICC)            IMPINT    833
            WV1(3)=WV1(3)+CJCOB(ICIDEX+2*ISTATE)*XRES(JSM+ICC)          IMPINT    834
            WV1(4)=WV1(4)+CJCOB(ICIDEX+3*ISTATE)*XRES(JSM+ICC)          IMPINT    835
 1450       CONTINUE                                                    IMPINT    836
            ICIDEX=ICIDEX+3*ISTATE                                      IMPINT    837
 1500    CONTINUE                                                       IMPINT    838
C                                                                       IMPINT    839
         VOLT(MSKK1)=VOLT(MSKK1)+CMPLX(WV1(1),WV1(2))                   IMPINT    840
         VOLT(MSKK2)=VOLT(MSKK2)+CMPLX(WV1(3),WV1(4))                   IMPINT    841
C                                                                       IMPINT    842
 1550 CONTINUE                                                          IMPINT    843
 1600 CONTINUE                                                          IMPINT    844
C                                                                       IMPINT    845
C     COMPUTE SDB CURRENT                                               IMPINT    846
C                                                                       IMPINT    847
      IF (NSDB.EQ.0) GOTO 1750                                          IMPINT    848
      DO 1700 I=1,NSDB                                                  IMPINT    849
         JD=JDDAT(I)                                                    IMPINT    850
         K=IDDAT(JD+1)                                                  IMPINT    851
         VREAL=REAL(OVOLT(K))                                           IMPINT    852
         VIMAG=AIMAG(OVOLT(K))                                          IMPINT    853
         JY=JVSDB(I)                                                    IMPINT    854
         U2K=-YSDB(JY+1)                                                IMPINT    855
C                                                                       IMPINT    856
         CREAL=0.0                                                      IMPINT    857
         CIMAG=0.0                                                      IMPINT    858
         NDTYPN=IDDAT(JD+2)                                             IMPINT    859
         IF (NDTYPN.NE.50) GOTO 1700                                    IMPINT    860
         JSM=JXSDB(I)                                                   IMPINT    861
         ISTATE=JXSDB(I+1)-JSM                                          IMPINT    862
         NAIDEX=IAIDEX+ISTATE                                           IMPINT    863
         CALL FBSUB(NAIDEX,ISTATE,JSM)                                  IMPINT    864
         IWS1=ICIDEX+ISTATE                                             IMPINT    865
         DO 1650 ICC=1,ISTATE                                           IMPINT    866
            ICIDEX=ICIDEX+1                                             IMPINT    867
            CREAL=CREAL+CJCOB(ICIDEX)*XRES(JSM+ICC)                     IMPINT    868
            IWS1=IWS1+1                                                 IMPINT    869
            CIMAG=CIMAG+CJCOB(IWS1)*XRES(JSM+ICC)                       IMPINT    870
 1650    CONTINUE                                                       IMPINT    871
         ICIDEX=ICIDEX+ISTATE                                           IMPINT    872
C                                                                       IMPINT    873
         MSKK=MSK(K)                                                    IMPINT    874
         IF (U2K.GT.0.0) THEN                                           IMPINT    875
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(U2K*VIMAG,-U2K*VREAL)+          IMPINT    876
     *                 CMPLX(CREAL,CIMAG)                               IMPINT    877
         ELSE                                                           IMPINT    878
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(U2K*VREAL,U2K*VIMAG)+           IMPINT    879
     *                 CMPLX(CREAL,CIMAG)                               IMPINT    880
         END IF                                                         IMPINT    881
C                                                                       IMPINT    882
 1700 CONTINUE                                                          IMPINT    883
 1750 CONTINUE                                                          IMPINT    884
C                                                                       IMPINT    885
C     HVDC LINE COMMUTATION                                             IMPINT    886
C                                                                       IMPINT    887
      IF (NACBUS.EQ.0) GOTO 1850                                        IMPINT    888
      DO 1800 J=1,NACBUS                                                IMPINT    889
         K=IUQABU(J)                                                    IMPINT    890
         VROLD=DCEAT(J)                                                 IMPINT    891
         VIOLD=DCEBT(J)                                                 IMPINT    892
         VMOLD=(VROLD**2+VIOLD**2)                                      IMPINT    893
C                                                                       IMPINT    894
         VREAL=REAL(OVOLT(K))                                           IMPINT    895
         VIMAG=AIMAG(OVOLT(K))                                          IMPINT    896
         VMG=(VREAL**2+VIMAG**2)                                        IMPINT    897
C                                                                       IMPINT    898
         IF(VMG.LT.0.1.OR.VMOLD.LT.0.1) GO TO 1800                      IMPINT    899
         VMM=SQRT(VMG*VMOLD)                                            IMPINT    900
         IF(ICHGDC.EQ.1)THEN                                            IMPINT    901
           VX=(VREAL*OPHVDC(J)+VIMAG*OQHVDC(J))/VMM                     IMPINT    902
           VY=(VIMAG*OPHVDC(J)-VREAL*OQHVDC(J))/VMM                     IMPINT    903
         ELSE                                                           IMPINT    904
           VX=(VREAL*PTHVDC(J)+VIMAG*QTHVDC(J))/VMM                     IMPINT    905
           VY=(VIMAG*PTHVDC(J)-VREAL*QTHVDC(J))/VMM                     IMPINT    906
         ENDIF                                                          IMPINT    907
C                                                                       IMPINT    908
         MSKK=MSK(K)                                                    IMPINT    909
         VOLT(MSKK)=VOLT(MSKK)+CMPLX(VX,VY)                             IMPINT    910
 1800 CONTINUE                                                          IMPINT    911
 1850 CONTINUE                                                          IMPINT    912
C                                                                       IMPINT    913
C     HVDC SELF COMMUTATED CONVERTERS                                   IMPINT    914
C                                                                       IMPINT    915
      IF(ICDC.GT.LCDC)THEN                                              IMPINT    916
         DO 1501 J1=LCDC+1,ICDC                                         IMPINT    917
         JPOSN=IDC(J1)                                                  IMPINT    918
         J=IDCBNU(JPOSN)                                                IMPINT    919
         IF(J.EQ.0) GO TO 1501                                          IMPINT    920
         K=IUQABU(J)                                                    IMPINT    921
         J2=IDCBN2(JPOSN)                                               IMPINT    922
         IF(J2.EQ.0) THEN                                               IMPINT    923
            VROLD=DCEAT(J)                                              IMPINT    924
            VIOLD=DCEBT(J)                                              IMPINT    925
            VREAL=REAL(OVOLT(K))                                        IMPINT    926
            VIMAG=AIMAG(OVOLT(K))                                       IMPINT    927
            VMOLD=(VROLD**2+VIOLD**2)                                   IMPINT    928
            VMG=(VREAL**2+VIMAG**2)                                     IMPINT    929
            IF(VMG.LT.0.01.OR.VMOLD.LT.0.01) GO TO 1501                 IMPINT    930
            VMM=SQRT(VMG*VMOLD)                                         IMPINT    931
            IF(ICHGDC.EQ.1)THEN                                         IMPINT    932
               VX=(VREAL*OPHVDC(JPOSN)+VIMAG*OQHVDC(JPOSN))/VMM/BASPC   IMPINT    933
               VY=(VIMAG*OPHVDC(JPOSN)-VREAL*OQHVDC(JPOSN))/VMM/BASPC   IMPINT    934
            ELSE                                                        IMPINT    935
               VX=(VREAL*PAHVDC(JPOSN)+VIMAG*QAHVDC(JPOSN))/VMM/BASPC   IMPINT    936
               VY=(VIMAG*PAHVDC(JPOSN)-VREAL*QAHVDC(JPOSN))/VMM/BASPC   IMPINT    937
            ENDIF                                                       IMPINT    938
            MSKK=MSK(K)                                                 IMPINT    939
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(VX,VY)                          IMPINT    940
         ELSE                                                           IMPINT    941
            K2=IUQABU(J2)                                               IMPINT    942
            VR1O=DCEAT(J)                                               IMPINT    943
            VI1O=DCEBT(J)                                               IMPINT    944
            VROLD=VR1O-DCEAT(J2)                                        IMPINT    945
            VIOLD=VI1O-DCEBT(J2)                                        IMPINT    946
            VREAL1=REAL(OVOLT(K))                                       IMPINT    947
            VIMAG1=AIMAG(OVOLT(K))                                      IMPINT    948
            VREAL2=REAL(OVOLT(K2))                                      IMPINT    949
            VIMAG2=AIMAG(OVOLT(K2))                                     IMPINT    950
            VREAL=VREAL1-VREAL2                                         IMPINT    951
            VIMAG=VIMAG1-VIMAG2                                         IMPINT    952
            VMOLD=(VROLD**2+VIOLD**2)                                   IMPINT    953
            VMG=(VREAL**2+VIMAG**2)                                     IMPINT    954
            IF(VMG.LT.1.0E-10.OR.VMOLD.LT.1.0E-10) GO TO 1501           IMPINT    955
            VM1O=(VR1O**2+VI1O**2)                                      IMPINT    956
            VM1N=(VREAL1**2+VIMAG1**2)                                  IMPINT    957
            IF(VM1N.LT.0.01.OR.VM1O.LT.0.01) GO TO 1501                 IMPINT    958
            VMM=SQRT(VM1N*VM1O)                                         IMPINT    959
            IF(ICHGDC.EQ.1)THEN                                         IMPINT    960
               PA=OPHVDC(JPOSN)/VMM/VMOLD/BASPC                         IMPINT    961
               QA=OQHVDC(JPOSN)/VMM/VMOLD/BASPC                         IMPINT    962
            ELSE                                                        IMPINT    963
               PA=PAHVDC(JPOSN)/VMM/VMOLD/BASPC                         IMPINT    964
               QA=QAHVDC(JPOSN)/VMM/VMOLD/BASPC                         IMPINT    965
            ENDIF                                                       IMPINT    966
            VX1=VROLD*PA+VIOLD*QA                                       IMPINT    967
            VX2=VREAL1*VR1O+VIMAG1*VI1O                                 IMPINT    968
            VY1=VIOLD*PA-VROLD*QA                                       IMPINT    969
            VY2=VIMAG1*VR1O-VREAL1*VI1O                                 IMPINT    970
            VX=VX1*VX2-VY1*VY2                                          IMPINT    971
            VY=VX1*VY2+VY1*VX2                                          IMPINT    972
            MSKK=MSK(K)                                                 IMPINT    973
            VOLT(MSKK)=VOLT(MSKK)+CMPLX(VX,VY)                          IMPINT    974
            MSKK=MSK(K2)                                                IMPINT    975
            VOLT(MSKK)=VOLT(MSKK)-CMPLX(VX,VY)                          IMPINT    976
         ENDIF                                                          IMPINT    977
 1501    CONTINUE                                                       IMPINT    978
      ENDIF                                                             IMPINT    979
C                                                                       IMPINT    980
C     END OF ALL DYNAMIC DEVICES                                        IMPINT    981
C                                                                       IMPINT    982
      IF (LITTER.EQ.1) THEN                                             IMPINT    983
         DO 1900 I=1,ICNODX-1                                           IMPINT    984
            PVOLT(I)=OVOLT(I)                                           IMPINT    985
 1900    CONTINUE                                                       IMPINT    986
C                                                                       IMPINT    987
C       ULTC. THIS CODE MAY HAVE TO BE CHANGED LATER                    IMPINT    988
C                                                                       IMPINT    989
         IF (NULTC .GT. 0 .AND. NREFUC .LE. 0) THEN                     IMPINT    990
            DO 1950 ITC = 1,NULTC                                       IMPINT    991
               ITC4 = 4*ITC                                             IMPINT    992
               JTC = JULTCD(ITC)                                        IMPINT    993
               NLFPN = IDDAT(JTC+1)                                     IMPINT    994
               NLFSN = IDDAT(JTC+2)                                     IMPINT    995
C                                                                       IMPINT    996
               MSKKP = MSK(NLFPN)                                       IMPINT    997
               MSKKS = MSK(NLFSN)                                       IMPINT    998
               PVOLT(MSKKP) = VOLT(MSKKP)                               IMPINT    999
               PVOLT(MSKKS) = VOLT(MSKKS)                               IMPINT   1000
 1950       CONTINUE                                                    IMPINT   1001
         END IF                                                         IMPINT   1002
      END IF                                                            IMPINT   1003
C                                                                       IMPINT   1004
C     CALCULATE CURRENT INJECTION OF NOLINEAR LOAD (ALL TYPES)          IMPINT   1005
C     NOTE THAT THE OLD VOLTAGE (OVOLT ARRAY) IS USED IN ALL            IMPINT   1006
C     CALCULATIONS                                                      IMPINT   1007
C                                                                       IMPINT   1008
C------------------------------------------------------------           IMPINT   1009
C                                                                       IMPINT   1010
 2000 IF (NLOD.NE.0) THEN                                               IMPINT   1011
C                                                                       IMPINT   1012
C     COMPUTE CURRENT FOR NON-LINEAR LOAD BUSES                         IMPINT   1013
C                                                                       IMPINT   1014
C     NTYPE =1 CONST. CUR  ,  NTYPE=2  CONST. MVA,                      IMPINT   1015
C                                                                       IMPINT   1016
C     NTYPE=3 VOLT-EXP     ,  NTYPE=4 COMP. LOAD                        IMPINT   1017
C                                                                       IMPINT   1018
         ISHIFT=0                                                       IMPINT   1019
C                                                                       IMPINT   1020
         DO 2850 I=1,NLOD                                               IMPINT   1021
            NCOMP=NLCOMP(1,I)                                           IMPINT   1022
            NVOLT=NLCOMP(2,I)                                           IMPINT   1023
            K=NLDOLD(I)                                                 IMPINT   1024
            MSKK=MSK(K)                                                 IMPINT   1025
C                                                                       IMPINT   1026
            IF (NITER.GT.1) THEN                                        IMPINT   1027
               VOLT(MSKK)=VOLT(MSKK)+CURNLL(I)                          IMPINT   1028
               GOTO 2850                                                IMPINT   1029
            END IF                                                      IMPINT   1030
            CURNLL(I)=(0.0,0.0)                                         IMPINT   1031
C                                                                       IMPINT   1032
C            CWS1=OVOLT(K)                                              IMPINT   1033
            CWS1=VPREV(K)                                               IMPINT   1034
            VMG=SQRT(VREAL**2+VIMAG**2)                                 IMPINT   1035
C                                                                       IMPINT   1036
            DO 2800 ICOMP=1,NCOMP                                       IMPINT   1037
               ISHIFT=ISHIFT+1                                          IMPINT   1038
               IF (KNLBS(I).EQ.1) GOTO 2800                             IMPINT   1039
               NTYPE=NLTYPE(ISHIFT)                                     IMPINT   1040
C                                                                       IMPINT   1041
C                                                                       IMPINT   1042
               GOTO (2050,2100,2150,2200) NTYPE                         IMPINT   1043
C                                                                       IMPINT   1044
C     FOR CONSTANT CURRENT LOAD REPRESENTATION                          IMPINT   1045
C                                                                       IMPINT   1046
 2050          CONTINUE                                                 IMPINT   1047
               IF (NVOLT.EQ.1) THEN                                     IMPINT   1048
                  CDLI=0.0                                              IMPINT   1049
                  CQLI=0.0                                              IMPINT   1050
               ELSE                                                     IMPINT   1051
                  JNL=JDNLL(ISHIFT)                                     IMPINT   1052
                  CDKZ=DDAT(JNL+4)*VREAL-DDAT(JNL+5)*VIMAG              IMPINT   1053
                  CQKZ=DDAT(JNL+4)*VIMAG+DDAT(JNL+5)*VREAL              IMPINT   1054
                  CDLI=CDKZ-(DDAT(JNL+2)*VREAL+DDAT(JNL+3)*VIMAG)/VMG   IMPINT   1055
                  CQLI=CQKZ-(DDAT(JNL+2)*VIMAG-DDAT(JNL+3)*VREAL)/VMG   IMPINT   1056
               END IF                                                   IMPINT   1057
C                                                                       IMPINT   1058
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1059
               CURNLL(I)=CURNLL(I)+CMPLX(CDLI,CQLI)                     IMPINT   1060
C                                                                       IMPINT   1061
               GOTO 2800                                                IMPINT   1062
C                                                                       IMPINT   1063
C     CONSTANT MVA LOAD REPRESENTATION                                  IMPINT   1064
C                                                                       IMPINT   1065
 2100          CONTINUE                                                 IMPINT   1066
               IF (NVOLT.EQ.1) THEN                                     IMPINT   1067
                  CDLI=0.0                                              IMPINT   1068
                  CQLI=0.0                                              IMPINT   1069
               ELSE                                                     IMPINT   1070
                  JNL=JDNLL(ISHIFT)                                     IMPINT   1071
                  VMG1=VMG*VMG                                          IMPINT   1072
                  CMW=DDAT(JNL+2)                                       IMPINT   1073
                  CMX=DDAT(JNL+3)                                       IMPINT   1074
                  VMG2=DDAT(JNL+4)                                      IMPINT   1075
                  CD1=CMW*VREAL+CMX*VIMAG                               IMPINT   1076
                  CQ1=CMW*VIMAG-CMX*VREAL                               IMPINT   1077
                  CDLI=CD1*(1.0/VMG2-1.0/VMG1)                          IMPINT   1078
                  CQLI=CQ1*(1.0/VMG2-1.0/VMG1)                          IMPINT   1079
               END IF                                                   IMPINT   1080
C                                                                       IMPINT   1081
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1082
               CURNLL(I)=CURNLL(I)+CMPLX(CDLI,CQLI)                     IMPINT   1083
C                                                                       IMPINT   1084
               GOTO 2800                                                IMPINT   1085
C                                                                       IMPINT   1086
C     VOLTAGE EXP LOAD                                                  IMPINT   1087
C                                                                       IMPINT   1088
 2150          CONTINUE                                                 IMPINT   1089
C                                                                       IMPINT   1090
C     IF BUS VOLTAGE MAGNITUDE GREATER THAN ZERO, CALCULATE CURRENT     IMPINT   1091
C     OTHERWISE SET CURRENT TO ZERO                                     IMPINT   1092
C                                                                       IMPINT   1093
               JNL=JDNLL(ISHIFT)                                        IMPINT   1094
               IF (VMG.GT.0.0) THEN                                     IMPINT   1095
C                                                                       IMPINT   1096
C     RESTORE THE POINTER TO "DDAT"                                     IMPINT   1097
C                                                                       IMPINT   1098
                  JK=IDDAT(JNL+1)                                       IMPINT   1099
                  ITERMP=ITERML(JK,1)                                   IMPINT   1100
                  ITERMQ=ITERML(JK,2)                                   IMPINT   1101
                  DEF=DDAT(JNL+8)                                       IMPINT   1102
                  VMNL=DDAT(JNL+3)                                      IMPINT   1103
C                                                                       IMPINT   1104
C     ACCOUNT FOR THE VOLTAGE EFFECT ON EXPONENTIAL ADJUSTMENT          IMPINT   1105
C                                                                       IMPINT   1106
                  IF (VMG.LT.VTHZH) THEN                                IMPINT   1107
                     IVMG=.TRUE.                                        IMPINT   1108
                     VMGL=VMG-VTHZL                                     IMPINT   1109
                     IF(VMGL.LT.0.0) VMGL=0.0                           IMPINT   1110
                     VTHZ=VTHZH-VTHZL                                   IMPINT   1111
                     IF (VTHZ.LE.0.0) THEN                              IMPINT   1112
                        VXY=0.0                                         IMPINT   1113
                     ELSE                                               IMPINT   1114
                        VXY=VMGL/VTHZ                                   IMPINT   1115
                     END IF                                             IMPINT   1116
                     VFACT=1.0-VXY                                      IMPINT   1117
                  ELSE                                                  IMPINT   1118
                     IVMG=.FALSE.                                       IMPINT   1119
                  END IF                                                IMPINT   1120
C                                                                       IMPINT   1121
C     CURRENT COMPUTATION                                               IMPINT   1122
C                                                                       IMPINT   1123
                  JL=JNL+10                                             IMPINT   1124
C                                                                       IMPINT   1125
C     ACCOUNT FOR TERMS IN P                                            IMPINT   1126
C                                                                       IMPINT   1127
                  IF (ITERMP.EQ.0) THEN                                 IMPINT   1128
                     CMW=0.0                                            IMPINT   1129
                     JL=JL-4                                            IMPINT   1130
                  ELSE                                                  IMPINT   1131
                     APPWR=DDAT(JL+2)                                   IMPINT   1132
                     APPWR1=APPWR                                       IMPINT   1133
                     CKMW=DDAT(JL+4)                                    IMPINT   1134
                     IF (IVMG) THEN                                     IMPINT   1135
                        APPWR1=APPWR*VXY                                IMPINT   1136
                        IF (IDDAT(JL+2).NE.0)                           IMPINT   1137
     *                     CKMW=CKMW*VMNL**(APPWR*VFACT)                IMPINT   1138
                     END IF                                             IMPINT   1139
                     FKMW=1.0+DEF*DDAT(JL+3)                            IMPINT   1140
                     CMW=DDAT(JL+4)*VMNL**APPWR-CKMW*FKMW*VMG**APPWR1   IMPINT   1141
                     IF (ITERMP.EQ.2) THEN                              IMPINT   1142
                        JL=JL+4                                         IMPINT   1143
                        APPWR=DDAT(JL+2)                                IMPINT   1144
                        APPWR1=APPWR                                    IMPINT   1145
                        CKMW=DDAT(JL+4)                                 IMPINT   1146
                        IF (IVMG) THEN                                  IMPINT   1147
                           APPWR1=APPWR*VXY                             IMPINT   1148
                           IF (IDDAT(JL+2).NE.0)                        IMPINT   1149
     *                        CKMW=CKMW*VMNL**(APPWR*VFACT)             IMPINT   1150
                        END IF                                          IMPINT   1151
                        FKMW=1.0+DEF*DDAT(JL+3)                         IMPINT   1152
                        CMW=CMW+DDAT(JL+4)*VMNL**APPWR                  IMPINT   1153
     *                      -CKMW*FKMW*VMG**APPWR1                      IMPINT   1154
                     END IF                                             IMPINT   1155
                  END IF                                                IMPINT   1156
C                                                                       IMPINT   1157
C     ACCOUNT FOR TERMS IN Q                                            IMPINT   1158
C                                                                       IMPINT   1159
                  IF (ITERMQ.EQ.0) THEN                                 IMPINT   1160
                     CMX=0.0                                            IMPINT   1161
                  ELSE                                                  IMPINT   1162
                     JL=JL+4                                            IMPINT   1163
                     AQPWR=DDAT(JL+2)                                   IMPINT   1164
                     AQPWR1=AQPWR                                       IMPINT   1165
                     CKMX=DDAT(JL+4)                                    IMPINT   1166
                     IF (IVMG) THEN                                     IMPINT   1167
                        AQPWR1=AQPWR*VXY                                IMPINT   1168
                        IF (IDDAT(JL+2).NE.0)                           IMPINT   1169
     *                     CKMX=CKMX*VMNL**(AQPWR*VFACT)                IMPINT   1170
                     END IF                                             IMPINT   1171
                     FKMX=1.0+DEF*DDAT(JL+3)                            IMPINT   1172
                     CMX=DDAT(JL+4)*VMNL**AQPWR-CKMX*FKMX*VMG**AQPWR1   IMPINT   1173
                     IF (ITERMQ.EQ.2) THEN                              IMPINT   1174
                        JL=JL+4                                         IMPINT   1175
                        AQPWR=DDAT(JL+2)                                IMPINT   1176
                        AQPWR1=AQPWR                                    IMPINT   1177
                        CKMX=DDAT(JL+4)                                 IMPINT   1178
                        IF (IVMG) THEN                                  IMPINT   1179
                           AQPWR1=AQPWR*VXY                             IMPINT   1180
                           IF (IDDAT(JL+2).NE.0)                        IMPINT   1181
     *                        CKMX=CKMX*VMNL**(AQPWR*VFACT)             IMPINT   1182
                        END IF                                          IMPINT   1183
                        FKMX=1.0+DEF*DDAT(JL+3)                         IMPINT   1184
                        CMX=CMX+DDAT(JL+4)*VMNL**AQPWR                  IMPINT   1185
     *                      -CKMX*FKMX*VMG**AQPWR1                      IMPINT   1186
                     END IF                                             IMPINT   1187
                  END IF                                                IMPINT   1188
C                                                                       IMPINT   1189
C     EVALUATE THE NON-LINEAR LOAD CURRENT                              IMPINT   1190
C                                                                       IMPINT   1191
                  CDLI=CMW*VREAL+CMX*VIMAG                              IMPINT   1192
                  CQLI=CMW*VIMAG-CMX*VREAL                              IMPINT   1193
C                                                                       IMPINT   1194
               ELSE                                                     IMPINT   1195
                  CDLI=0.0                                              IMPINT   1196
                  CQLI=0.0                                              IMPINT   1197
C                                                                       IMPINT   1198
C     END OF IF (VMG.GT.0.0)                                            IMPINT   1199
C                                                                       IMPINT   1200
               END IF                                                   IMPINT   1201
C                                                                       IMPINT   1202
C     ACCOUNT FOR THE NON-LINEAR LOAD CURRENT IN THE CURRENT VECTOR     IMPINT   1203
C                                                                       IMPINT   1204
               DDAT(JNL+4)=CDLI                                         IMPINT   1205
               DDAT(JNL+5)=CQLI                                         IMPINT   1206
C                                                                       IMPINT   1207
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1208
               CURNLL(I)=CURNLL(I)+CMPLX(CDLI,CQLI)                     IMPINT   1209
C                                                                       IMPINT   1210
               GOTO 2800                                                IMPINT   1211
C                                                                       IMPINT   1212
C     FOR COMPOSITE LOAD REPRESENTATION                                 IMPINT   1213
C                                                                       IMPINT   1214
 2200          CONTINUE                                                 IMPINT   1215
               JNL=JDNLL(ISHIFT)                                        IMPINT   1216
C                                                                       IMPINT   1217
C     IF BUS VOLTAGE MAGNITUDE GREATER THAN ZERO, CALCULATE CURRENT     IMPINT   1218
C     OTHERWISE SET CURRENT TO ZERO                                     IMPINT   1219
C                                                                       IMPINT   1220
               CDLI=0.0                                                 IMPINT   1221
               CQLI=0.0                                                 IMPINT   1222
               IF (VMG.LE.0.0) GOTO 2800                                IMPINT   1223
C                                                                       IMPINT   1224
C     GET DATA AT BAR BUS                                               IMPINT   1225
C                                                                       IMPINT   1226
               RTB=DDAT(JNL+1)                                          IMPINT   1227
               XTB=DDAT(JNL+2)                                          IMPINT   1228
               GKKB=DDAT(JNL+4)                                         IMPINT   1229
               BKKB=DDAT(JNL+5)                                         IMPINT   1230
               VBAR2=DDAT(JNL+6)                                        IMPINT   1231
               VBARVR=DDAT(JNL+7)                                       IMPINT   1232
               VBARVI=DDAT(JNL+8)                                       IMPINT   1233
               CBARVR=VBARVR*RTB-VBARVI*XTB                             IMPINT   1234
               CBARVI=VBARVR*XTB+VBARVI*RTB                             IMPINT   1235
               VBARR=VREAL*VBARVR-VIMAG*VBARVI                          IMPINT   1236
               VBARI=VREAL*VBARVI+VIMAG*VBARVR                          IMPINT   1237
               VBAR=SQRT(VBAR2)                                         IMPINT   1238
               JL=JNL+11                                                IMPINT   1239
C                                                                       IMPINT   1240
               ITRN=0                                                   IMPINT   1241
C                                                                       IMPINT   1242
C     ACCOUNT FOR THE VOLTAGE EFFECT ON EACH CLOAD COMPONENT            IMPINT   1243
C                                                                       IMPINT   1244
               VBARRK=VBARR                                             IMPINT   1245
               VBARIK=VBARI                                             IMPINT   1246
C                                                                       IMPINT   1247
               JLOLD=JL                                                 IMPINT   1248
C                                                                       IMPINT   1249
 2250          CONTINUE                                                 IMPINT   1250
               JL=JLOLD                                                 IMPINT   1251
               IF (VBARRK.LE.0..AND.VBARIK.LE.0.) GOTO 2800             IMPINT   1252
               VBARK2=VBARRK*VBARRK+VBARIK*VBARIK                       IMPINT   1253
               VBARK=SQRT(VBARK2)                                       IMPINT   1254
               IF (ABS(VBARK2).GT.0) THEN                               IMPINT   1255
                  VBVBK2=VBAR2/VBARK2                                   IMPINT   1256
               ELSE                                                     IMPINT   1257
                  VBVBK2=1.0                                            IMPINT   1258
               END IF                                                   IMPINT   1259
               VBVBK=SQRT(VBVBK2)                                       IMPINT   1260
               GKVRB=GKKB*VBARRK                                        IMPINT   1261
               GKVIB=GKKB*VBARIK                                        IMPINT   1262
               BKVRB=-BKKB*VBARRK                                       IMPINT   1263
               BKVIB=-BKKB*VBARIK                                       IMPINT   1264
C                                                                       IMPINT   1265
C     CLOAD MOTOR                                                       IMPINT   1266
C                                                                       IMPINT   1267
C     LARGE MOTOR                                                       IMPINT   1268
C                                                                       IMPINT   1269
               NLF=NOLD(K)                                              IMPINT   1270
               KK=NLFLMB(NLF)                                           IMPINT   1271
               IF (KK.EQ.0) GOTO 2300                                   IMPINT   1272
               IF (NMOLD(KK).EQ.K) THEN                                 IMPINT   1273
                  ASSIGN 2300 TO I600                                   IMPINT   1274
                  GOTO 2350                                             IMPINT   1275
               END IF                                                   IMPINT   1276
 2300          CONTINUE                                                 IMPINT   1277
C                                                                       IMPINT   1278
C     SMALL MOTOR                                                       IMPINT   1279
C                                                                       IMPINT   1280
               NLF=NOLD(K)                                              IMPINT   1281
               KK=NLFSMB(NLF)                                           IMPINT   1282
               IF (KK.EQ.0) GOTO 2400                                   IMPINT   1283
               IF (NMOLD(KK).EQ.K) ASSIGN 2400 TO I600                  IMPINT   1284
C                                                                       IMPINT   1285
C     COMPUTE TERMINAL CURRENT FOR INDUCTION MOTOR(S)                   IMPINT   1286
C                                                                       IMPINT   1287
 2350          CONTINUE                                                 IMPINT   1288
               JM=JMDAT(KK)                                             IMPINT   1289
               IF (DDAT(JM+15).LT.0.0) GOTO I600                        IMPINT   1290
               JY=JVIMO(KK)                                             IMPINT   1291
C               JSTATE=JXIMO(KK)                                        IMPINT   1292
C               NTYPE=IDDAT(JM+1)-10                                    IMPINT   1293
               DDAT(JM+37)=VBARRK                                       IMPINT   1294
               DDAT(JM+38)=VBARIK                                       IMPINT   1295
               GLK=GSM(JY+4)                                            IMPINT   1296
               BLK=BSM(JY+5)                                            IMPINT   1297
C               IF (NTYPE.LE.3) THEN                                    IMPINT   1298
C                  VDBAR=XSTATE(JSTATE+1)                               IMPINT   1299
C                  VQBAR=XSTATE(JSTATE+2)                               IMPINT   1300
C               ELSE                                                    IMPINT   1301
C                  VDBAR=0.0                                            IMPINT   1302
C                  VQBAR=0.0                                            IMPINT   1303
C               END IF                                                  IMPINT   1304
C               CDM(JY+8)=GLK*(VBARRK-VDBAR)+BLK*(VBARIK-VQBAR)         IMPINT   1305
C               CQM(JY+9)=GLK*(VBARIK-VQBAR)-BLK*(VBARRK-VDBAR)         IMPINT   1306
               CDM(JY+8)=GLK*VBARRK+BLK*VBARIK                          IMPINT   1307
               CQM(JY+9)=GLK*VBARIK-BLK*VBARRK                          IMPINT   1308
C                                                                       IMPINT   1309
               CLMTP=IDDAT(JM+2)/100.                                   IMPINT   1310
               CLMTQ=DDAT(JM+3)/100.                                    IMPINT   1311
               CDLT=CDM(JY+8)-GKVRB*CLMTP-BKVIB*CLMTQ                   IMPINT   1312
               CQLT=CQM(JY+9)-GKVIB*CLMTP+BKVRB*CLMTQ                   IMPINT   1313
               CDLI=CDLI+CDLT                                           IMPINT   1314
               CQLI=CQLI+CQLT                                           IMPINT   1315
               GOTO I600                                                IMPINT   1316
C                                                                       IMPINT   1317
C     END OF CLOAD MOTOR                                                IMPINT   1318
C                                                                       IMPINT   1319
 2400          CONTINUE                                                 IMPINT   1320
               FCI=1.0-VBVBK                                            IMPINT   1321
               FCP=1.0-VBVBK2                                           IMPINT   1322
C                                                                       IMPINT   1323
 2450          JTYPE=IDDAT(JL+1)                                        IMPINT   1324
               IF (JTYPE.EQ.0) GOTO 2700                                IMPINT   1325
C                                                                       IMPINT   1326
               GOTO (2500,2550,2600,2650) JTYPE                         IMPINT   1327
C                                                                       IMPINT   1328
 2500          CONTINUE                                                 IMPINT   1329
C                                                                       IMPINT   1330
C     DISCHARGE LIGHTING                                                IMPINT   1331
C                                                                       IMPINT   1332
               CLDLP=IDDAT(JL+2)/100.                                   IMPINT   1333
               PK1=DDAT(JL+3)                                           IMPINT   1334
               PK2=DDAT(JL+4)                                           IMPINT   1335
               QK=DDAT(JL+5)                                            IMPINT   1336
               JL=JL+6                                                  IMPINT   1337
C                                                                       IMPINT   1338
               GRAT=VBARVR*GKKB-VBARVI*BKKB                             IMPINT   1339
               BRAT=VBARVI*GKKB+VBARVR*BKKB                             IMPINT   1340
               QCV=-0.435890*CLDLP*GRAT/BRAT                            IMPINT   1341
               IF (VBARK.GT.0.75) THEN                                  IMPINT   1342
                  PCI=CLDLP*PK2*VBAR                                    IMPINT   1343
                  PCP=CLDLP*(1.0-PK2*VBAR)                              IMPINT   1344
                  FCVDL=1.0-VBVBK**(2.0-QK)                             IMPINT   1345
                  CDLI=CDLI+(PCI*FCI+PCP*FCP)*GKVRB+QCV*BKVIB*FCVDL     IMPINT   1346
                  CQLI=CQLI+(PCI*FCI+PCP*FCP)*GKVIB-QCV*BKVRB*FCVDL     IMPINT   1347
               ELSE                                                     IMPINT   1348
                  IF (VBARK.GT.0.65) THEN                               IMPINT   1349
                     PCI1=CLDLP*(PK1-PK2)*(VBAR-0.75)                   IMPINT   1350
                     PCI=CLDLP*PK1*VBAR                                 IMPINT   1351
                     PCP=CLDLP*((1.0-PK2*VBAR)-0.75*(PK1-PK2))          IMPINT   1352
                     FCVDL=1.0-VBVBK**(2.0-QK)                          IMPINT   1353
                     CDLI=CDLI+(PCI*FCI+PCP*FCP-PCI1)*GKVRB             IMPINT   1354
     *                    +QCV*BKVIB*FCVDL                              IMPINT   1355
                     CQLI=CQLI+(PCI*FCI+PCP*FCP-PCI1)*GKVIB             IMPINT   1356
     *                    -QCV*BKVRB*FCVDL                              IMPINT   1357
                  ELSE                                                  IMPINT   1358
                     CDLI=CDLI+GKVRB*CLDLP+BKVIB*QCV                    IMPINT   1359
                     CQLI=CQLI+GKVIB*CLDLP-BKVRB*QCV                    IMPINT   1360
                  END IF                                                IMPINT   1361
               END IF                                                   IMPINT   1362
C                                                                       IMPINT   1363
               GOTO 2450                                                IMPINT   1364
C                                                                       IMPINT   1365
 2550          CONTINUE                                                 IMPINT   1366
C                                                                       IMPINT   1367
C     TRANSFORMER SATURATION                                            IMPINT   1368
C                                                                       IMPINT   1369
               CLTSQ=IDDAT(JL+2)/100.                                   IMPINT   1370
               TV1=DDAT(JL+3)                                           IMPINT   1371
               TG1=1.0/DDAT(JL+4)                                       IMPINT   1372
               TG2=1.0/DDAT(JL+5)                                       IMPINT   1373
               TG12=TG2-TG1                                             IMPINT   1374
               JL=JL+6                                                  IMPINT   1375
C                                                                       IMPINT   1376
               IF (VBARK.LE.TV1) THEN                                   IMPINT   1377
                  IF (VBAR.GT.TV1) QCI=1.0-TV1/VBARK                    IMPINT   1378
               ELSE                                                     IMPINT   1379
                  IF (VBAR.GT.TV1) THEN                                 IMPINT   1380
                     QCI=TV1*(1.0-VBVBK)/VBAR                           IMPINT   1381
                  ELSE                                                  IMPINT   1382
                     QCI=TV1/VBAR-1.0                                   IMPINT   1383
                  END IF                                                IMPINT   1384
               END IF                                                   IMPINT   1385
               QCI=QCI*TG12                                             IMPINT   1386
               CDLI=CDLI-QCI*VBARIK                                     IMPINT   1387
               CQLI=CQLI+QCI*VBARRK                                     IMPINT   1388
               GOTO 2450                                                IMPINT   1389
C                                                                       IMPINT   1390
 2600          CONTINUE                                                 IMPINT   1391
C                                                                       IMPINT   1392
C     CONSTANT MVA                                                      IMPINT   1393
C                                                                       IMPINT   1394
               CLCPP=IDDAT(JL+2)/100.                                   IMPINT   1395
               CLCPQ=IDDAT(JL+3)/100.                                   IMPINT   1396
               JL=JL+5                                                  IMPINT   1397
C                                                                       IMPINT   1398
               IF (VBARK.GT.VTHZH) THEN                                 IMPINT   1399
                  PCP=CLCPP                                             IMPINT   1400
                  QCP=CLCPQ                                             IMPINT   1401
                  CDLI=CDLI+(PCP*GKVRB+QCP*BKVIB)*FCP                   IMPINT   1402
                  CQLI=CQLI+(PCP*GKVIB-QCP*BKVRB)*FCP                   IMPINT   1403
               ELSE                                                     IMPINT   1404
                  IF (VBARK.GT.VTHZL) THEN                              IMPINT   1405
                     PCP=CLCPP                                          IMPINT   1406
                     QCP=CLCPQ                                          IMPINT   1407
                     VKP=2.0*(VBARK-VTHZL)/(VTHZH-VTHZL)                IMPINT   1408
                     FCVCP=1.0-VBVBK**VKP                               IMPINT   1409
                     CDLI=CDLI+(PCP*GKVRB+QCP*BKVIB)*FCVCP              IMPINT   1410
                     CQLI=CQLI+(PCP*GKVIB-QCP*BKVRB)*FCVCP              IMPINT   1411
                  END IF                                                IMPINT   1412
               END IF                                                   IMPINT   1413
               GOTO 2450                                                IMPINT   1414
C                                                                       IMPINT   1415
 2650          CONTINUE                                                 IMPINT   1416
C                                                                       IMPINT   1417
C     REMANING LOAD                                                     IMPINT   1418
C                                                                       IMPINT   1419
               CLRMP=DDAT(JL+2)/100.                                    IMPINT   1420
               CLRMQ=DDAT(JL+3)/100.                                    IMPINT   1421
               RMKP=DDAT(JL+4)                                          IMPINT   1422
               JL=JL+6                                                  IMPINT   1423
C                                                                       IMPINT   1424
               IF (VBARK.GT.VTHZH) THEN                                 IMPINT   1425
                  PCV=CLRMP                                             IMPINT   1426
                  IF(ABS(RMKP-2.0).LE.0.0) THEN                         IMPINT   1427
                     FCVRM=0.0                                          IMPINT   1428
                  ELSE                                                  IMPINT   1429
                     FCVRM=1.0-VBVBK**(2.0-RMKP)                        IMPINT   1430
                  END IF                                                IMPINT   1431
                  CDLI=CDLI+PCV*GKVRB*FCVRM                             IMPINT   1432
                  CQLI=CQLI+PCV*GKVIB*FCVRM                             IMPINT   1433
               ELSE                                                     IMPINT   1434
                  IF (VBARK.GT.VTHZL) THEN                              IMPINT   1435
                     PCV=CLRMP                                          IMPINT   1436
                     VKP=(2.0-RMKP)*(VBARK-VTHZL)/(VTHZH-VTHZL)         IMPINT   1437
                     FCVRM=1.0-VBVBK**VKP                               IMPINT   1438
                     CDLI=CDLI+PCV*GKVRB*FCVRM                          IMPINT   1439
                     CQLI=CQLI+PCV*GKVIB*FCVRM                          IMPINT   1440
                  END IF                                                IMPINT   1441
               END IF                                                   IMPINT   1442
C                                                                       IMPINT   1443
               GOTO 2450                                                IMPINT   1444
C                                                                       IMPINT   1445
 2700          CONTINUE                                                 IMPINT   1446
C                                                                       IMPINT   1447
               VBARRN=VBARRK+CBARVR*CDLI-CBARVI*CQLI                    IMPINT   1448
               VBARIN=VBARIK+CBARVR*CQLI+CBARVI*CDLI                    IMPINT   1449
C                                                                       IMPINT   1450
               DFVBR=ABS(VBARRK-VBARRN)                                 IMPINT   1451
               DFVBI=ABS(VBARIK-VBARIN)                                 IMPINT   1452
C                                                                       IMPINT   1453
               IF (DFVBR.LT.ERTOL.AND.DFVBI.LT.ERTOL) GOTO 2750         IMPINT   1454
               VBARRK=VBARRN                                            IMPINT   1455
               VBARIK=VBARIN                                            IMPINT   1456
               ITRN=ITRN+1                                              IMPINT   1457
               IF (ITRN.LE.5) GOTO 2250                                 IMPINT   1458
 2750          CONTINUE                                                 IMPINT   1459
C                                                                       IMPINT   1460
C               VOLBAR(I)=CMPLX(VBARRN,VBARIN)                          IMPINT   1461
               CDLI=VBARVR*CDLI-VBARVI*CQLI                             IMPINT   1462
               CQLI=VBARVR*CQLI+VBARVI*CDLI                             IMPINT   1463
C                                                                       IMPINT   1464
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1465
               CURNLL(I)=CURNLL(I)+CMPLX(CDLI,CQLI)                     IMPINT   1466
C                                                                       IMPINT   1467
C                                                                       IMPINT   1468
 2800       CONTINUE                                                    IMPINT   1469
C                                                                       IMPINT   1470
 2850    CONTINUE                                                       IMPINT   1471
C                                                                       IMPINT   1472
C     END IF FOR NLOD .NE. 0                                            IMPINT   1473
C                                                                       IMPINT   1474
      END IF                                                            IMPINT   1475
C                                                                       IMPINT   1476
C     REDUCED LOAD BUSES                                                IMPINT   1477
C                                                                       IMPINT   1478
      IF (LOBUS.EQ.1) THEN                                              IMPINT   1479
C                                                                       IMPINT   1480
C     FOR CONSTANT CURRENT LOAD REPRESENTATION                          IMPINT   1481
C                                                                       IMPINT   1482
         IF (IKCUR.NE.0) THEN                                           IMPINT   1483
            DO 2900 I=1,IKCUR                                           IMPINT   1484
               II=I*3                                                   IMPINT   1485
               K=ICBUS(II-2)                                            IMPINT   1486
               K3=K*3                                                   IMPINT   1487
C                                                                       IMPINT   1488
               CWS1=OVOLT(K)                                            IMPINT   1489
C                                                                       IMPINT   1490
               VMG=SQRT(VREAL**2+VIMAG**2)                              IMPINT   1491
C                                                                       IMPINT   1492
               IF (VMG .GT. 1.0E-6) THEN                                IMPINT   1493
                  CDLI=(CBUS(II-1)*VREAL+CBUS(II)*VIMAG)/VMG            IMPINT   1494
                  CQLI=(CBUS(II-1)*VIMAG-CBUS(II)*VREAL)/VMG            IMPINT   1495
               ELSE                                                     IMPINT   1496
                  CDLI=0.                                               IMPINT   1497
                  CQLI=0.                                               IMPINT   1498
               END IF                                                   IMPINT   1499
C                                                                       IMPINT   1500
               MSKK=MSK(K)                                              IMPINT   1501
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1502
C                                                                       IMPINT   1503
 2900       CONTINUE                                                    IMPINT   1504
         END IF                                                         IMPINT   1505
C                                                                       IMPINT   1506
C     CONSTANT MVA LOAD REPRESENTATION                                  IMPINT   1507
C                                                                       IMPINT   1508
         IF (IKMVA.NE.0) THEN                                           IMPINT   1509
            DO 2950 I=1,IKMVA                                           IMPINT   1510
               II=I*3                                                   IMPINT   1511
               K=IPBUS(II-2)                                            IMPINT   1512
               K3=K*3                                                   IMPINT   1513
               CWS1=OVOLT(K)                                            IMPINT   1514
               VMG2=VREAL**2+VIMAG**2                                   IMPINT   1515
C                                                                       IMPINT   1516
               IF (VMG2.GT.1.0E-6) THEN                                 IMPINT   1517
                  CDLI=(PBUS(II-1)*VREAL+PBUS(II)*VIMAG)/VMG2           IMPINT   1518
                  CQLI=(PBUS(II-1)*VIMAG-PBUS(II)*VREAL)/VMG2           IMPINT   1519
               ELSE                                                     IMPINT   1520
                  CDLI=0.0                                              IMPINT   1521
                  CQLI=0.0                                              IMPINT   1522
               END IF                                                   IMPINT   1523
C                                                                       IMPINT   1524
               MSKK=MSK(K)                                              IMPINT   1525
               VOLT(MSKK)=VOLT(MSKK)+CMPLX(CDLI,CQLI)                   IMPINT   1526
C                                                                       IMPINT   1527
 2950       CONTINUE                                                    IMPINT   1528
         END IF                                                         IMPINT   1529
      END IF                                                            IMPINT   1530
C                                                                       IMPINT   1531
C     END IF FOR LOAD BUS REDUCTION                                     IMPINT   1532
C                                                                       IMPINT   1533
C-----------------------------------------------------------------------IMPINT   1534
C                                                                       IMPINT   1535
C     COMPUTE ULTC CURRENT INJECTION                                    IMPINT   1536
C                                                                       IMPINT   1537
      IF (NULTC .LE. 0 .OR. NREFUC .GT. 0) GOTO 3050                    IMPINT   1538
      IF (ITCFLG .EQ. 0) GOTO 3050                                      IMPINT   1539
C                                                                       IMPINT   1540
      DO 3000 ITC = 1,NULTC                                             IMPINT   1541
         IF (MOULTC(ITC) .EQ. 0) GOTO 3000                              IMPINT   1542
         ITC4 = 4*ITC                                                   IMPINT   1543
         JTC = JULTCD(ITC)                                              IMPINT   1544
         NLFPN = IDDAT(JTC+1)                                           IMPINT   1545
         NLFSN = IDDAT(JTC+2)                                           IMPINT   1546
C                                                                       IMPINT   1547
         MSKKP = MSK(NLFPN)                                             IMPINT   1548
         MSKKS = MSK(NLFSN)                                             IMPINT   1549
C                                                                       IMPINT   1550
         ATCO = DDAT(JTC+22)                                            IMPINT   1551
         ATCA = ONRSTA(ITC4-3)                                          IMPINT   1552
         GTCO = DDAT(JTC+20)                                            IMPINT   1553
         BTCO = DDAT(JTC+21)                                            IMPINT   1554
C                                                                       IMPINT   1555
C     GTCA & BTCA SHOULD BE MODIFIED IF TRANSFORMER IMPEDANCE           IMPINT   1556
C     CORRECTION IS TO BE CONSIDERED                                    IMPINT   1557
C                                                                       IMPINT   1558
C       YO = GTCO - J BTCO                                              IMPINT   1559
C       Y  = GTCA - J BTCA                                              IMPINT   1560
C                                                                       IMPINT   1561
         GTCA = GTCO                                                    IMPINT   1562
         BTCA = BTCO                                                    IMPINT   1563
         YTCO = CMPLX(GTCO,-BTCO)                                       IMPINT   1564
         YTCA = CMPLX(GTCA,-BTCA)                                       IMPINT   1565
C                                                                       IMPINT   1566
         XICRRP = (1./(ATCO**2)*YTCO-1./(ATCA**2)*YTCA)*PVOLT(NLFPN)    IMPINT   1567
     1            +(1./ATCA*YTCA-1./ATCO*YTCO)*PVOLT(NLFSN)             IMPINT   1568
         XICRRS = (1./ATCA*YTCA-1./ATCO*YTCO)*PVOLT(NLFPN)              IMPINT   1569
     1            +(YTCO-YTCA)*PVOLT(NLFSN)                             IMPINT   1570
C                                                                       IMPINT   1571
         VOLT(MSKKP) = VOLT(MSKKP)+XICRRP                               IMPINT   1572
         VOLT(MSKKS) = VOLT(MSKKS)+XICRRS                               IMPINT   1573
 3000 CONTINUE                                                          IMPINT   1574
 3050 CONTINUE                                                          IMPINT   1575
C                                                                       IMPINT   1576
C     INFINITE BUS CURRENTS                                             IMPINT   1577
C                                                                       IMPINT   1578
      IF (IFNBUS.NE.0) THEN                                             IMPINT   1579
         DO 3100 II=1,KFBUS                                             IMPINT   1580
            KK=KCINF(II)                                                IMPINT   1581
            MSKK=MSK(KK)                                                IMPINT   1582
            VOLT(MSKK)=VOLT(MSKK)+CINF(II)                              IMPINT   1583
 3100    CONTINUE                                                       IMPINT   1584
      END IF                                                            IMPINT   1585
C                                                                       IMPINT   1586
C     OBTAIN CURRENT INJECTION MISMATCHES                               IMPINT   1587
C                                                                       IMPINT   1588
      KCURRE=0                                                          IMPINT   1589
      NBCMAX=0                                                          IMPINT   1590
      CURMAX=-1.0                                                       IMPINT   1591
      IF (IITER.GT.0) GOTO 3350                                         IMPINT   1592
      IF (NITER.EQ.0) GOTO 3250                                         IMPINT   1593
      DO 3150 I=1,LASTCU                                                IMPINT   1594
         CWS1=VOLT(I)-OCURR(I)                                          IMPINT   1595
         WS1=CABS(CWS1)                                                 IMPINT   1596
         IF (WS1.GT.CURMAX) THEN                                        IMPINT   1597
            CURMAX=WS1                                                  IMPINT   1598
            NBCMAX=I                                                    IMPINT   1599
         END IF                                                         IMPINT   1600
         IF (WS1.GT.CURTOL.AND.KCURRE.LT.NNCURR) THEN                   IMPINT   1601
            KCURRE=KCURRE+1                                             IMPINT   1602
            CURRES(KCURRE)=CWS1                                         IMPINT   1603
            ICURRE(KCURRE)=I                                            IMPINT   1604
         END IF                                                         IMPINT   1605
 3150 CONTINUE                                                          IMPINT   1606
C                                                                       IMPINT   1607
      IF (CURMAX.LE.CURTOL) GOTO 4100                                   IMPINT   1608
      IF (ABS(CURMAX-CUROLD).LT.1.0E-4.AND.NITER.GE.3) GOTO 4100        IMPINT   1609
      IF (NITER.GE.5.AND.RESMAX.LE.RESTOL) GOTO 4100                    IMPINT   1610
      CUROLD=CURMAX                                                     IMPINT   1611
      IF (NITER.EQ.MAXNIT) THEN                                         IMPINT   1612
C                                                                       IMPINT   1613
C     MAXIMUM NUMBER OF ITERATIONS EXCEEDED. PROGRAM ABORTS.            IMPINT   1614
C                                                                       IMPINT   1615
         WRITE(LOUT,8400) TS+H,CURTOL                                   IMPINT   1616
         WRITE(IU16,8400) TS+H,CURTOL                                   IMPINT   1617
         DO 3200 I=1,KCURRE                                             IMPINT   1618
            KLF=ICURRE(I)                                               IMPINT   1619
            K3=3*KLF                                                    IMPINT   1620
            WRITE(LOUT,8500) NOLD(KLF),INAME(K3-2),INAME(K3-1)          IMPINT   1621
     *                      ,INAME(K3),CURRES(I)                        IMPINT   1622
            WRITE(IU16,8500) NOLD(KLF),INAME(K3-2),INAME(K3-1)          IMPINT   1623
     *                      ,INAME(K3),CURRES(I)                        IMPINT   1624
 3200    CONTINUE                                                       IMPINT   1625
         IF (KCURRE.EQ.NNCURR) THEN                                     IMPINT   1626
            WRITE(LOUT,8510)                                            IMPINT   1627
            WRITE(IU16,8510)                                            IMPINT   1628
         END IF                                                         IMPINT   1629
         CALL ASTOP('IMPINT: FATAL ERROR',19)                           IMPINT   1630
      END IF                                                            IMPINT   1631
C                                                                       IMPINT   1632
*IF DEBUG                                                               IMPINT   1633
      IF (LDEB) WRITE(IUD6,8600)                                        IMPINT   1634
     *   (ICURRE(I),NOLD(ICURRE(I)),CURRES(I),I=1,KCURRE)               IMPINT   1635
*ENDIF                                                                  IMPINT   1636
C                                                                       IMPINT   1637
 3250 DO 3300 I=1,LASTCU                                                IMPINT   1638
         OCURR(I)=VOLT(I)                                               IMPINT   1639
 3300 CONTINUE                                                          IMPINT   1640
 3350 CONTINUE                                                          IMPINT   1641
C                                                                       IMPINT   1642
C     CALL SUBROUTINES TO SOLVE FOR THE NETWORK VOLTAGES                IMPINT   1643
C                                                                       IMPINT   1644
      INSTR=4                                                           IMPINT   1645
      CALL AUPDSC(INSTR,NLAST)                                          IMPINT   1646
C                                                                       IMPINT   1647
      NV=1                                                              IMPINT   1648
      CALL ASOLSC(INSTR,NLAST,NV)                                       IMPINT   1649
C                                                                       IMPINT   1650
      IF (LITTER.EQ.0) GOTO 3850                                        IMPINT   1651
C                                                                       IMPINT   1652
      IF (IITER.GT.5) GOTO 3850                                         IMPINT   1653
C                                                                       IMPINT   1654
C      IF (IITER.EQ.MAXNIT) THEN                                        IMPINT   1655
C                                                                       IMPINT   1656
C         WRITE(*,*) ' NETWORK ITERATION FAILED.'                       IMPINT   1657
C         ITSTRN=2                                                      IMPINT   1658
C         GOTO 9999                                                     IMPINT   1659
C                                                                       IMPINT   1660
C      END IF                                                           IMPINT   1661
C                                                                       IMPINT   1662
C     VOLATGE CONVERGENCE CHECK                                         IMPINT   1663
C                                                                       IMPINT   1664
      DO 3400 I=1,ICNODX-1                                              IMPINT   1665
         WS1=CABS(VOLT(I)-PVOLT(I))                                     IMPINT   1666
         IF (WS1.GT.0.001) GOTO 3500                                    IMPINT   1667
 3400 CONTINUE                                                          IMPINT   1668
C                                                                       IMPINT   1669
C       ULTC. THIS CODE MAY HAVE TO BE CHANGED LATER                    IMPINT   1670
C                                                                       IMPINT   1671
        IF (NULTC .GT. 0 .AND. NREFUC .LE. 0) THEN                      IMPINT   1672
          DO 3450 ITC = 1,NULTC                                         IMPINT   1673
          ITC4 = 4*ITC                                                  IMPINT   1674
          JTC = JULTCD(ITC)                                             IMPINT   1675
          NLFPN = IDDAT(JTC+1)                                          IMPINT   1676
          NLFSN = IDDAT(JTC+2)                                          IMPINT   1677
C                                                                       IMPINT   1678
          MSKKP = MSK(NLFPN)                                            IMPINT   1679
          MSKKS = MSK(NLFSN)                                            IMPINT   1680
           WS1=CABS(VOLT(MSKKP)-PVOLT(MSKKP))                           IMPINT   1681
           IF (WS1.GT.0.001) GOTO 3500                                  IMPINT   1682
           WS1=CABS(VOLT(MSKKS)-PVOLT(MSKKS))                           IMPINT   1683
           IF (WS1.GT.0.001) GOTO 3500                                  IMPINT   1684
 3450   CONTINUE                                                        IMPINT   1685
      END IF                                                            IMPINT   1686
      GOTO 3850                                                         IMPINT   1687
 3500 N=0                                                               IMPINT   1688
C                                                                       IMPINT   1689
C       ULTC. THIS CODE MAY HAVE TO BE CHANGED LATER                    IMPINT   1690
C                                                                       IMPINT   1691
        IF (NULTC .GT. 0 .AND. NREFUC .LE. 0) THEN                      IMPINT   1692
          DO 3550 ITC = 1,NULTC                                         IMPINT   1693
          ITC4 = 4*ITC                                                  IMPINT   1694
          JTC = JULTCD(ITC)                                             IMPINT   1695
          NLFPN = IDDAT(JTC+1)                                          IMPINT   1696
          NLFSN = IDDAT(JTC+2)                                          IMPINT   1697
C                                                                       IMPINT   1698
          MSKKP = MSK(NLFPN)                                            IMPINT   1699
          MSKKS = MSK(NLFSN)                                            IMPINT   1700
         PVOLT(MSKKP) = VOLT(MSKKP)                                     IMPINT   1701
         PVOLT(MSKKS) = VOLT(MSKKS)                                     IMPINT   1702
 3550    CONTINUE                                                       IMPINT   1703
      END IF                                                            IMPINT   1704
C                                                                       IMPINT   1705
C     COMPUTE COMPENSATION CURRENTS                                     IMPINT   1706
C                                                                       IMPINT   1707
      DO 3700 I=1,IPNODE                                                IMPINT   1708
C                                                                       IMPINT   1709
         CWS1=VOLT(I)-PVOLT(I)                                          IMPINT   1710
         EPD=VREAL                                                      IMPINT   1711
         EPQ=VIMAG                                                      IMPINT   1712
C                                                                       IMPINT   1713
         CURRR=0.0                                                      IMPINT   1714
         CURRI=0.0                                                      IMPINT   1715
C                                                                       IMPINT   1716
         IF(JTHDC.NE.2) THEN                                            IMPINT   1717
         N=NTHG(I)-1                                                    IMPINT   1718
         NEND=NTHG(I+1)-1                                               IMPINT   1719
 3600       N=N+1                                                       IMPINT   1720
            JG=JCONTA(1,N)                                              IMPINT   1721
            HM=DDAT(JG+1)                                               IMPINT   1722
            IF(HM.LT.1.0E-5)GOTO 3650                                   IMPINT   1723
            IF(ICONTA(1,N).NE.4)THEN                                    IMPINT   1724
            CURRR=CURRR-YGJCOB(1,N)*EPD-YGJCOB(2,N)*EPQ                 IMPINT   1725
            CURRI=CURRI-YGJCOB(3,N)*EPD-YGJCOB(4,N)*EPQ                 IMPINT   1726
            ELSE                                                        IMPINT   1727
            CURRR=CURRR+CDG(1,N)                                        IMPINT   1728
            CURRI=CURRI+CDG(2,N)                                        IMPINT   1729
            ENDIF                                                       IMPINT   1730
 3650    CONTINUE                                                       IMPINT   1731
         IF(N.LT.NEND)GOTO 3600                                         IMPINT   1732
C                                                                       IMPINT   1733
            CURRR=CCDG(1,I)-CURRR                                       IMPINT   1734
            CURRI=CCDG(2,I)-CURRI                                       IMPINT   1735
C                                                                       IMPINT   1736
         ENDIF                                                          IMPINT   1737
C                                                                       IMPINT   1738
         PVOLT(I)=VOLT(I)                                               IMPINT   1739
         VOLT(I)=CMPLX(CURRR,CURRI)                                     IMPINT   1740
C                                                                       IMPINT   1741
 3700 CONTINUE                                                          IMPINT   1742
C                                                                       IMPINT   1743
      DO 3750 I=IPNODX,NLAST                                            IMPINT   1744
         VOLT(I)=(0.0,0.0)                                              IMPINT   1745
 3750 CONTINUE                                                          IMPINT   1746
C                                                                       IMPINT   1747
      IF (NSVC.NE.0) THEN                                               IMPINT   1748
         DO 3800 I=1,NSVC                                               IMPINT   1749
            K=NROLD(I)                                                  IMPINT   1750
            MSKK=MSK(K)                                                 IMPINT   1751
            VOLT(MSKK)=VOLT(MSKK)+CDS(I)                                IMPINT   1752
 3800    CONTINUE                                                       IMPINT   1753
      END IF                                                            IMPINT   1754
C                                                                       IMPINT   1755
      IITER=IITER+1                                                     IMPINT   1756
      GOTO 2000                                                         IMPINT   1757
C                                                                       IMPINT   1758
 3850 CONTINUE                                                          IMPINT   1759
C                                                                       IMPINT   1760
C     DETERMINE THE PROPER DAMPING FACTOR FOR STATE UPDATING            IMPINT   1761
C                                                                       IMPINT   1762
      IF (NITER.GT.2) GOTO 3900                                         IMPINT   1763
      GOTO (3900,3950,4000),NITER+1                                     IMPINT   1764
 3900 DPFACT=1.0                                                        IMPINT   1765
      GOTO 4050                                                         IMPINT   1766
 3950 DPFACT=0.8                                                        IMPINT   1767
      GOTO 4050                                                         IMPINT   1768
 4000 DPFACT=0.6                                                        IMPINT   1769
 4050 CONTINUE                                                          IMPINT   1770
C                                                                       IMPINT   1771
C     UPDATE STATE VARIABLES (XSTATE ARRAY) AND                         IMPINT   1772
C     CURRENT (CDG ARRAY)                                               IMPINT   1773
C                                                                       IMPINT   1774
      CALL UPSTAT                                                       IMPINT   1775
C                                                                       IMPINT   1776
C     UPDATE COUNTERS                                                   IMPINT   1777
C                                                                       IMPINT   1778
      NITER=NITER+1                                                     IMPINT   1779
      IUDJM=IUDJM+1                                                     IMPINT   1780
      IF (JMUPDT) JMUPDT=.FALSE.                                        IMPINT   1781
C                                                                       IMPINT   1782
C     END OF EACH ITERATION                                             IMPINT   1783
C                                                                       IMPINT   1784
      GOTO 300                                                          IMPINT   1785
C                                                                       IMPINT   1786
 4100 CONTINUE                                                          IMPINT   1787
C                                                                       IMPINT   1788
*IF LTSP                                                                IMPINT   1789
*ENDIF                                                                  IMPINT   1866
C                                                                       IMPINT   1867
C     INTERATION CONVERGED                                              IMPINT   1868
C                                                                       IMPINT   1869
C     RESTORE VOLTAGE VECTOR                                            IMPINT   1870
C                                                                       IMPINT   1871
      DO 4150 I=1,LASTV2                                                IMPINT   1872
         VOLT(I)=OVOLT(I)                                               IMPINT   1873
 4150 CONTINUE                                                          IMPINT   1874
      DO 4155 I=1,NVADD                                                 IMPINT   1875
      K=IVADD(I)                                                        IMPINT   1876
 4155 VOLT(K)=OVOLT(K)                                                  IMPINT   1877
C                                                                       IMPINT   1878
      NTITER=NTITER+NITER                                               IMPINT   1879
C                                                                       IMPINT   1880
*IF DEBUG                                                               IMPINT   1881
*ENDIF                                                                  IMPINT   1882
C     CHECK IF STEP ADJUSTMENT IS NEEDED IN GEAR'S METHOD               IMPINT   1883
C                                                                       IMPINT   1884
      IF (IGEARS) THEN                                                  IMPINT   1885
C                                                                       IMPINT   1886
         WS1=0.0                                                        IMPINT   1887
         DO 4200 I=1,NSTATE                                             IMPINT   1888
            XRES(I)=XSTATE(I)-XPREV(1,I)                                IMPINT   1889
            WS2=ABS(XRES(I))                                            IMPINT   1890
            IF (WS2.GT.WS1) WS1=WS2                                     IMPINT   1891
 4200    CONTINUE                                                       IMPINT   1892
         EPST=WS1/(3.0*AL1)                                             IMPINT   1893
         ALP=SQRT(EPSGR/EPST)                                           IMPINT   1894
         IF (ALP.LT.0.8) THEN                                           IMPINT   1895
            NGMINS=0                                                    IMPINT   1896
            H=ALP*H                                                     IMPINT   1897
            DO 4250 I=1,NSTATE                                          IMPINT   1898
               XSTATE(I)=XPREV(2,I)                                     IMPINT   1899
               XDOT(I)=OXDOT(I)                                         IMPINT   1900
 4250       CONTINUE                                                    IMPINT   1901
C                                                                       IMPINT   1902
            DO 4300 I=1,LASTCU                                          IMPINT   1903
               VOLT(I)=VPREV(I)                                         IMPINT   1904
 4300       CONTINUE                                                    IMPINT   1905
C                                                                       IMPINT   1906
            GOTO 250                                                    IMPINT   1907
         ELSE IF (ALP.GT.3.16.AND.NGMINS.EQ.IGMINS) THEN                IMPINT   1908
            HSTEP=0.5*ALP*H                                             IMPINT   1909
            NGMINS=0                                                    IMPINT   1910
         END IF                                                         IMPINT   1911
C                                                                       IMPINT   1912
         NGMINS=NGMINS+1                                                IMPINT   1913
C                                                                       IMPINT   1914
         TCRT=TS+H                                                      IMPINT   1915
         IF (ABS(TNEXT-TCRT).LT.1.0E-4) THEN                            IMPINT   1916
            ISTEP=NSTEP-1                                               IMPINT   1917
         ELSE IF ((TCRT+HSTEP).GT.TNEXT) THEN                           IMPINT   1918
            HSTEP=TNEXT-TCRT                                            IMPINT   1919
         END IF                                                         IMPINT   1920
C                                                                       IMPINT   1921
         TSOLD=TS                                                       IMPINT   1922
C                                                                       IMPINT   1923
      END IF                                                            IMPINT   1924
C                                                                       IMPINT   1925
C     CALL ASOLSC AGAIN TO COMPUTE VOLTAGES AT ALL NETWORK BUSES        IMPINT   1926
C                                                                       IMPINT   1927
C      IF (KRESUL) THEN                                                 IMPINT   1928
C         NV=1                                                          IMPINT   1929
C         INSTR=3                                                       IMPINT   1930
C         CALL ASOLSC(INSTR,NLAST,NV)                                   IMPINT   1931
C      END IF                                                           IMPINT   1932
C                                                                       IMPINT   1933
      IF(NRSTEP.EQ.1)THEN                                               IMPINT   1934
C                                                                       IMPINT   1935
         NRSTEP=0                                                       IMPINT   1936
C                                                                       IMPINT   1937
C     FIND GENERATOR WITH MAXIMUM ANGLE CHANGE                          IMPINT   1938
C                                                                       IMPINT   1939
         MGANCH=0                                                       IMPINT   1940
         KGANCH=0                                                       IMPINT   1941
         GANCH=0.0                                                      IMPINT   1942
         N=0                                                            IMPINT   1943
         DO 4400 K=1,IPNODE                                             IMPINT   1944
            L=0                                                         IMPINT   1945
 4410       L=L+1                                                       IMPINT   1946
            N=N+1                                                       IMPINT   1947
            JG=JCONTA(1,N)                                              IMPINT   1948
            IF (DDAT(JG+1).GT.1.0E-5) THEN                              IMPINT   1949
               JSM=MSTATE(1,N)                                          IMPINT   1950
               ANGCH=ABS(XSTATE(JSM+2)-XPREV(1,JSM+2))                  IMPINT   1951
               IF (ANGCH.GT.GANCH) THEN                                 IMPINT   1952
                  MGANCH=N                                              IMPINT   1953
                  KGANCH=K                                              IMPINT   1954
                  GANCH=ANGCH                                           IMPINT   1955
               END IF                                                   IMPINT   1956
            END IF                                                      IMPINT   1957
            IF (L.LT.KTHGE(K)) GOTO 4410                                IMPINT   1958
 4400    CONTINUE                                                       IMPINT   1959
C                                                                       IMPINT   1960
         L3=NBCMAX*3                                                    IMPINT   1961
         GANCH=GANCH*DEGREE                                             IMPINT   1962
         CALL PVMXMN(IIL)                                               IMPINT   1963
         IF (IIL.GE.60) THEN                                            IMPINT   1964
            IF (IIL.GE.100) IIL=MOD(IIL,100)+4                          IMPINT   1965
            IF (IIL.GE.52) THEN                                         IMPINT   1966
               CALL PAGE6                                               IMPINT   1967
               IIL=7                                                    IMPINT   1968
            END IF                                                      IMPINT   1969
            WRITE(IU6,8200)                                             IMPINT   1970
         END IF                                                         IMPINT   1971
         K3=KGANCH*3                                                    IMPINT   1972
         IF (KGANCH.GT.0.AND.KGANCH.LT.IPNODX.AND.                      IMPINT   1973
     *       ABS(GANCH).GT.0.0) THEN                                    IMPINT   1974
            WRITE(LOUT,8000) CSTIME,NOLD(KGANCH),INAME(K3-2)            IMPINT   1975
     *                      ,INAME(K3-1),INAME(K3),NDGC(MGANCH),GANCH   IMPINT   1976
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1977
     *                      ,INAME(L3),CURMAX                           IMPINT   1978
            WRITE(IU6,8000)  CSTIME,NOLD(KGANCH),INAME(K3-2)            IMPINT   1979
     *                      ,INAME(K3-1),INAME(K3),NDGC(MGANCH),GANCH   IMPINT   1980
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1981
     *                      ,INAME(L3),CURMAX                           IMPINT   1982
         ELSE IF (KGANCH.GE.IPNODX.AND.KGANCH.LE.ICNODE.AND.            IMPINT   1983
     *            ABS(GANCH).GT.0.0) THEN                               IMPINT   1984
            WRITE(LOUT,8100) CSTIME,NOLD(KGANCH),INAME(K3-2)            IMPINT   1985
     *                      ,INAME(K3-1),INAME(K3),GANCH                IMPINT   1986
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1987
     *                      ,INAME(L3),CURMAX                           IMPINT   1988
            WRITE(IU6,8100)  CSTIME,NOLD(KGANCH),INAME(K3-2)            IMPINT   1989
     *                      ,INAME(K3-1),INAME(K3),GANCH                IMPINT   1990
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1991
     *                      ,INAME(L3),CURMAX                           IMPINT   1992
         ELSE                                                           IMPINT   1993
            WRITE(IU6,8300)  CSTIME,GANCH                               IMPINT   1994
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1995
     *                      ,INAME(L3),CURMAX                           IMPINT   1996
            WRITE(LOUT,8300) CSTIME,GANCH                               IMPINT   1997
     *                      ,NOLD(NBCMAX),INAME(L3-2),INAME(L3-1)       IMPINT   1998
     *                      ,INAME(L3),CURMAX                           IMPINT   1999
         END IF                                                         IMPINT   2000
         IIL=IIL+1                                                      IMPINT   2001
C                                                                       IMPINT   2002
      END IF                                                            IMPINT   2003
C                                                                       IMPINT   2004
C     UPDATE XDDOT                                                      IMPINT   2005
C                                                                       IMPINT   2006
      IF (IGEARS) THEN                                                  IMPINT   2007
         CALL GXDDOT                                                    IMPINT   2008
C                                                                       IMPINT   2009
C     CODES TO NUMERICALLY CALCULATE THE SECOND ORDER DERIVATIVES       IMPINT   2010
C                                                                       IMPINT   2011
C         DO 1730 I=1,NSTATE                                            IMPINT   2012
C            XDDOT(I)=(XDOT(I)-OXDOT(I))/H                              IMPINT   2013
C 1730    CONTINUE                                                      IMPINT   2014
      END IF                                                            IMPINT   2015
C                                                                       IMPINT   2016
C     OBTAIN EXTERNAL CURRENT FOR CLASSICAL MACHINES                    IMPINT   2017
C     (DETAILED MACHINES ARE HANDLED IN GXDOT)                          IMPINT   2018
C                                                                       IMPINT   2019
      DO 4450 I=1,NBFT                                                  IMPINT   2020
         K=KCGEN(1,I)                                                   IMPINT   2021
         N=KCGEN(2,I)                                                   IMPINT   2022
         CWS1=VOLT(K)                                                   IMPINT   2023
         EPD=VREAL                                                      IMPINT   2024
         EPQ=VIMAG                                                      IMPINT   2025
         CDG(1,N)=CDG(1,N)-EPQ*XPD(N)                                   IMPINT   2026
         CDG(2,N)=CDG(2,N)+EPD*XPD(N)                                   IMPINT   2027
 4450 CONTINUE                                                          IMPINT   2028
C                                                                       IMPINT   2029
C     UPDATE BUS ANGLE FOR NONLINEAR LOAD BEFORE NEXT SWITCHING         IMPINT   2030
C                                                                       IMPINT   2031
 4500 IF (NLBS.EQ.0) GOTO 4650                                          IMPINT   2032
      IF (.NOT.LDISC) GOTO 4650                                         IMPINT   2033
      DO 4600 I=1,NLOD                                                  IMPINT   2034
         IF(NLCOMP(2,I).EQ.0)GOTO 4600                                  IMPINT   2035
         NCOMP=NLCOMP(1,I)                                              IMPINT   2036
         ICS=NTHL(1,I)                                                  IMPINT   2037
         ICE=ICS+NCOMP-1                                                IMPINT   2038
C                                                                       IMPINT   2039
         DO 4550 J=ICS,ICE                                              IMPINT   2040
         IF(NLTYPE(J).NE.3)GOTO 4550                                    IMPINT   2041
         K=NLDOLD(I)                                                    IMPINT   2042
         CWS1=VOLT(K)                                                   IMPINT   2043
         JNL=JDNLL(J)                                                   IMPINT   2044
         IF (ABS(VREAL).GT.1.0E-6.OR.ABS(VIMAG).GT.1.0E-6) THEN         IMPINT   2045
            ANGNEW=ATAN2(VIMAG,VREAL)                                   IMPINT   2046
         ELSE                                                           IMPINT   2047
            ANGNEW=0.0                                                  IMPINT   2048
         END IF                                                         IMPINT   2049
         DDAT(JNL+6)=ANGNEW                                             IMPINT   2050
 4550 CONTINUE                                                          IMPINT   2051
 4600 CONTINUE                                                          IMPINT   2052
C                                                                       IMPINT   2053
C     FOR LARGE POWER CHANGES IN DC SYSTEM, CALL RK4 WITH H=0.0         IMPINT   2054
C     TO OBTAIN THE POST-DISTURBANCE CONDITIONS.                        IMPINT   2055
C                                                                       IMPINT   2056
 4650 CONTINUE                                                          IMPINT   2057
C                                                                       IMPINT   2058
      IF (ICHGDC.EQ.1) THEN                                             IMPINT   2059
         HCHGDC=H                                                       IMPINT   2060
         H=0.0                                                          IMPINT   2061
         INTMTH=1                                                       IMPINT   2062
         LDISC=.TRUE.                                                   IMPINT   2063
         CALL INTRKG(H,KRESUL,IPREF,IIL,NRSTEP)                         IMPINT   2064
         H=HCHGDC                                                       IMPINT   2065
         INTMTH=11                                                      IMPINT   2066
         CALL PREINT                                                    IMPINT   2067
      END IF                                                            IMPINT   2068
C                                                                       IMPINT   2069
 4700 CONTINUE                                                          IMPINT   2070
C                                                                       IMPINT   2071
      RETURN                                                            IMPINT   2072
C                                                                       IMPINT   2073
 8000 FORMAT(1X,F8.3,4X,I5,2X,3A4,A4,F9.2,4X,I5,2X,3A4,F10.4)           IMPINT   2074
 8100 FORMAT(1X,F8.3,4X,I5,2X,3A4,4X,F9.2,4X,I5,2X,3A4,F10.4)           IMPINT   2075
 8200 FORMAT(/'                                    MAX. ANG.'           IMPINT   2076
     *,'                        MAX. CUR.',/                            IMPINT   2077
     *,'     TIME     BUS#  STATION NAME GID   CHANGE'                  IMPINT   2078
     *,'     BUS#    BUS NAME    MISMATCH',/                            IMPINT   2079
     *,'    -----    -----  ------------ --- --------'                  IMPINT   2080
     *,'    -----  ------------ ---------')                             IMPINT   2081
 8300 FORMAT(1X,F8.3,27X,F9.2,4X,I5,2X,3A4,F10.4)                       IMPINT   2082
 8400 FORMAT(/,' *** ERROR MAXIMUM NUMBER OF ITERATIONS EXCEEDED IN ',  IMPINT   2083
     1'TRAPEZOIDAL INTEGRATION',/,'     METHOD AT T =',F8.3,' SECONDS.',IMPINT   2084
     2' THE FOLLOWING ARE THE MISMATCHES OF ',/,'     CURRENT ',        IMPINT   2085
     3'INJECTIONS EXCEEDING THE TOLERANCE OF ',F7.4,' PU AT THE END OF',IMPINT   2086
     4/,'     THE LAST ITERATION:',//,                                  IMPINT   2087
     5'          BUS NO.      BUS NAME        CURRENT MISMATCH',/,      IMPINT   2088
     6'          -------    ------------    --------------------')      IMPINT   2089
 8500 FORMAT(11X,I5,5X,3A4,4X,'(',F8.4,', ',F8.4,')')                   IMPINT   2090
 8510 FORMAT(/,' *** THE ABOVE IS ONLY A PARTIAL LIST ***',/)           IMPINT   2091
*IF DEBUG                                                               IMPINT   2092
 8600 FORMAT(2(2X,'NEW # = ',I5,1X,'OLD # = ',I5,1X,                    IMPINT   2093
     *'CUR. MIS. =',2G12.4))                                            IMPINT   2094
 8700 FORMAT(/1X,'TS = ',F11.6)                                         IMPINT   2095
 8800 FORMAT(1X,'NO. OF ITERATIONS = ',I2,5X,'MAX. RESIDUE = ',         IMPINT   2096
     *E12.6,5X,'AT STATE NO. = ',I5)                                    IMPINT   2097
*ENDIF                                                                  IMPINT   2098
C                                                                       IMPINT   2099
      END                                                               IMPINT   2100
