CFPRIME SPOWER                                                          SPOWER      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  SPOWER(INIT)                                          SPOWER      3
CD--------------------------------------------------------------------- SPOWER      4
CD                                                                      SPOWER      5
CD               *****     SPOWER  ROUTINE   *****                      SPOWER      6
CD                                                                      SPOWER      7
CD--------------------------------------------------------------------- SPOWER      8
CD                                                                      SPOWER      9
CD        PURPOSE:  Calculated the real and reactive power flow for     SPOWER     10
CD                  all converters.                                     SPOWER     11
CD                                                                      SPOWER     12
CD                                                                      SPOWER     13
CD        DEFINITION OF LOCAL VARIABLES:                                SPOWER     14
CD              K      - 'do' loop index.                               SPOWER     15
CD              NUM    -  pointer to location of voltage in dc          SPOWER     16
CD                        arrays from converter reference.              SPOWER     17
CD              NU2    -  pointer to location of second voltage in dc   SPOWER     18
CD                        arrays from converter reference.              SPOWER     19
CD              PA     -  component of real current injection.          SPOWER     20
CD              PB     -  component of real current injection.          SPOWER     21
CD              JPOSN  -  storage position for dc information.          SPOWER     22
CD              QA     -  component of imaginary current injection.     SPOWER     23
CD              QB     -  component of imaginary current injection.     SPOWER     24
CD              SIGN   -  sign term.                                    SPOWER     25
CD              SUBNAM -  subroutine name.                              SPOWER     26
CD              VALUE  -  power factor.                                 SPOWER     27
CD              VALUE2 -  voltage magnitude.                            SPOWER     28
CD              V1     -  temporary value, related to voltage.          SPOWER     29
CD--------------------------------------------------------------------- SPOWER     30
      INCLUDE 'CNUNIT.INS'                                              SPOWER     31
      INCLUDE 'PARX.INS'                                                SPOWER     32
      INCLUDE 'CNPARX.INS'                                              SPOWER     33
      INCLUDE 'CNFLAG.INS'                                              SPOWER     34
      INCLUDE 'GRDC01.INS'                                              SPOWER     35
      INCLUDE 'GRDC02.INS'                                              SPOWER     36
      INCLUDE 'GRDC03.INS'                                              SPOWER     37
C                                                                       SPOWER     38
      INCLUDE 'UDCA.INS'                                                SPOWER     39
      INCLUDE 'UDCF.INS'                                                SPOWER     40
      INCLUDE 'UDCJ.INS'                                                SPOWER     41
      INCLUDE 'CNMSG.INS'                                               SPOWER     42
      INCLUDE 'CNB4.INS'                                                SPOWER     43
C                                                                       SPOWER     44
      CHARACTER*20  SUBNAM                                              SPOWER     45
C                                                                       SPOWER     46
C---------------------------------------------------------------------  SPOWER     47
C                                                                       SPOWER     48
      LDEB=.FALSE.                                                      SPOWER     49
      IF(SDBG)THEN                                                      SPOWER     50
         SUBNAM = 'SPOWER ROUTINE.'                                     SPOWER     51
      ELSE                                                              SPOWER     52
         SUBNAM = ' '                                                   SPOWER     53
      END IF                                                            SPOWER     54
C                                                                       SPOWER     55
C  FOR PSF DC ONLY                                                      SPOWER     56
C                                                                       SPOWER     57
      IF(IPSF.EQ.1)THEN                                                 SPOWER     58
C                                                                       SPOWER     59
         DO 30 K = 1, ICDC                                              SPOWER     60
C                                                                       SPOWER     61
         IF(IDC(K) .NE. 0)THEN                                          SPOWER     62
            JPOSN = IDC(K)                                              SPOWER     63
            ICT=ICTYPE(JPOSN)                                           SPOWER     64
            ICTA=IABS(ICT)                                              SPOWER     65
C                                                                       SPOWER     66
            IF(ICTA.EQ.1) THEN                                          SPOWER     67
C                                                                       SPOWER     68
C              line commutation                                         SPOWER     69
C                                                                       SPOWER     70
               NUM = IDCBNU(JPOSN)                                      SPOWER     71
               IF(NUM .EQ. 0) THEN                                      SPOWER     72
                  VALUE2 = 1.0                                          SPOWER     73
               ELSE                                                     SPOWER     74
                  VALUE2 = DCEA(NUM) * DCEA(NUM)                        SPOWER     75
     1                   + DCEB(NUM) * DCEB(NUM)                        SPOWER     76
               ENDIF                                                    SPOWER     77
               IF(ICT.GT.0.OR.INIT.EQ.0) THEN                           SPOWER     78
C                                                                       SPOWER     79
C                 Full converter or simplified at initialization.       SPOWER     80
C                                                                       SPOWER     81
C                 Determine if inverter or rectifier, and set the       SPOWER     82
C                 sign term.                                            SPOWER     83
C                                                                       SPOWER     84
                  IF(QINV(JPOSN))THEN                                   SPOWER     85
                     SIGN = 1.0                                         SPOWER     86
                  ELSE                                                  SPOWER     87
                     SIGN = -1.0                                        SPOWER     88
                  END IF                                                SPOWER     89
C                                                                       SPOWER     90
C                                                                       SPOWER     91
                  PAHVDC(JPOSN) = -VDCONV(JPOSN) * XDCONV(JPOSN)        SPOWER     92
C                                                                       SPOWER     93
                  V1 = TAPPOS(JPOSN) * VAHVDC(JPOSN)                    SPOWER     94
                  IF(ABS(V1).LT.0.0001) V1 = 0.0001                     SPOWER     95
                  VALUE = VDCONV(JPOSN) / V1                            SPOWER     96
C                                                                       SPOWER     97
                  IF(CONTYP(JPOSN).EQ.'BLOCK')THEN                      SPOWER     98
                     VALUE = 0.0                                        SPOWER     99
                  END IF                                                SPOWER    100
C                                                                       SPOWER    101
                  IF(VALUE .GT. 1.0)THEN                                SPOWER    102
                     VALUE = 1.0                                        SPOWER    103
                     WRITE (MSG(1),9002) SUBNAM                         SPOWER    104
                     WRITE(MSG(2),9003) DCCNAM(JPOSN)                   SPOWER    105
                     WRITE(MSG(3),9004)                                 SPOWER    106
                     CALL PRTMSG(3)                                     SPOWER    107
                  END IF                                                SPOWER    108
                  IF(VALUE .LT. -1.0)THEN                               SPOWER    109
                     VALUE = -1.0                                       SPOWER    110
                     WRITE (MSG(1),9002) SUBNAM                         SPOWER    111
                     WRITE(MSG(2),9003) DCCNAM(JPOSN)                   SPOWER    112
                     WRITE(MSG(3),9004)                                 SPOWER    113
                     CALL PRTMSG(3)                                     SPOWER    114
                  END IF                                                SPOWER    115
C                                                                       SPOWER    116
C                 To prevent taking tangent of 90 degrees.              SPOWER    117
C                                                                       SPOWER    118
                  IF(ABS(VALUE) .LT. 0.00001) VALUE = -0.00001          SPOWER    119
C                                                                       SPOWER    120
                  PHIDC(JPOSN) = ACOS(VALUE)                            SPOWER    121
C                                                                       SPOWER    122
                  QAHVDC(JPOSN) = -ABS( VDCONV(JPOSN) * XDCONV(JPOSN) * SPOWER    123
     1                            TAN(PHIDC(JPOSN)))                    SPOWER    124
               ENDIF                                                    SPOWER    125
C                                                                       SPOWER    126
               IF(ICT.LT.0) THEN                                        SPOWER    127
C                                                                       SPOWER    128
C                 simplified converter model                            SPOWER    129
C                                                                       SPOWER    130
                  IF(INIT.EQ.0) THEN                                    SPOWER    131
C                                                                       SPOWER    132
C                    at initialization                                  SPOWER    133
C                                                                       SPOWER    134
                     PIHVDC(JPOSN) = PAHVDC(JPOSN)                      SPOWER    135
                     QIHVDC(JPOSN) = QAHVDC(JPOSN)                      SPOWER    136
                     VICONV(JPOSN) = VMCONV(JPOSN)                      SPOWER    137
                  ELSE                                                  SPOWER    138
C                                                                       SPOWER    139
C                    during solution                                    SPOWER    140
C                                                                       SPOWER    141
                     VM0=VICONV(JPOSN)                                  SPOWER    142
                     VM02=VM0**2                                        SPOWER    143
                     VM2=VALUE2/VM02                                    SPOWER    144
                     VM=SQRT(VM2)                                       SPOWER    145
                     P0=PIHVDC(JPOSN)                                   SPOWER    146
                     Q0=QIHVDC(JPOSN)                                   SPOWER    147
                     P02=P0**2                                          SPOWER    148
                     Q02=Q0**2                                          SPOWER    149
                     Q2=(Q02+P02)*VM2-P02                               SPOWER    150
                     QMIN=0.95                                          SPOWER    151
                     QMIN2=QMIN**2                                      SPOWER    152
                     IF(VM.GT.0.3) THEN                                 SPOWER    153
                        IF(Q2.GE.Q02*QMIN2*VM2) THEN                    SPOWER    154
                           QAHVDC(JPOSN)=-SQRT(Q2)                      SPOWER    155
                           PAHVDC(JPOSN)=P0                             SPOWER    156
                        ELSE                                            SPOWER    157
                           QAHVDC(JPOSN)=Q0*QMIN*VM                     SPOWER    158
                           PAHVDC(JPOSN)=P0*VM*SQRT(Q02*(1.0-QMIN2)/    SPOWER    159
     1                     P02/(1.0-VM2))                               SPOWER    160
                        ENDIF                                           SPOWER    161
                     ELSE                                               SPOWER    162
                        QAHVDC(JPOSN)=0.0                               SPOWER    163
                        PAHVDC(JPOSN)=0.0                               SPOWER    164
                     ENDIF                                              SPOWER    165
C                                                                       SPOWER    166
                     IF(JTHDC.EQ.1) THEN                                SPOWER    167
                        VDCONV(JPOSN) = 0.0                             SPOWER    168
                        XDCONV(JPOSN) = 0.0                             SPOWER    169
                        CALPHA(JPOSN) = 0.0                             SPOWER    170
                        CGAMMA(JPOSN) = 1.0                             SPOWER    171
                     ENDIF                                              SPOWER    172
C                                                                       SPOWER    173
C                    set power factor angle                             SPOWER    174
C                                                                       SPOWER    175
                     PA = PAHVDC(JPOSN)                                 SPOWER    176
                     IF(ABS(PA).LT.0.0001) PA = 0.0001                  SPOWER    177
                     QA = QAHVDC(JPOSN)                                 SPOWER    178
                     PHIDC(JPOSN) = ATAN(QA/PA)                         SPOWER    179
                  ENDIF                                                 SPOWER    180
               ENDIF                                                    SPOWER    181
C                                                                       SPOWER    182
C              Calculate the current injection.                         SPOWER    183
C                                                                       SPOWER    184
               IF(NUM .NE. 0) THEN                                      SPOWER    185
                  IF(ABS(VALUE2).LT.0.0001) VALUE2 = 0.0001             SPOWER    186
                  PA = DCEA(NUM) * PAHVDC(JPOSN) / PABASE               SPOWER    187
                  QA = DCEA(NUM) * QAHVDC(JPOSN) / PABASE               SPOWER    188
                  PB = DCEB(NUM) * QAHVDC(JPOSN) / PABASE               SPOWER    189
                  QB = DCEB(NUM) * PAHVDC(JPOSN) / PABASE               SPOWER    190
                  REALI(JPOSN) = (PA + PB) / VALUE2                     SPOWER    191
                  XIMAGI(JPOSN) = (QB - QA) / VALUE2                    SPOWER    192
               ENDIF                                                    SPOWER    193
C                                                                       SPOWER    194
            ELSEIF(ICTA.EQ.2) THEN                                      SPOWER    195
C                                                                       SPOWER    196
C              self commutated voltage sourced converter                SPOWER    197
C                                                                       SPOWER    198
               NUM = IDCBNU(JPOSN)                                      SPOWER    199
               NU2 = IDCBN2(JPOSN)                                      SPOWER    200
               IF(NUM .EQ. 0) THEN                                      SPOWER    201
                  VALUE2 = 1.0                                          SPOWER    202
               ELSE                                                     SPOWER    203
                  IF(NU2.EQ.0) THEN                                     SPOWER    204
                     VALUE2 = DCEA(NUM) * DCEA(NUM)                     SPOWER    205
     1                      + DCEB(NUM) * DCEB(NUM)                     SPOWER    206
                  ELSE                                                  SPOWER    207
                     VALUE2 = (DCEA(NUM) - DCEA(NU2) ) **2              SPOWER    208
     1                      + (DCEB(NUM) - DCEB(NU2) ) **2              SPOWER    209
                  ENDIF                                                 SPOWER    210
               ENDIF                                                    SPOWER    211
C                                                                       SPOWER    212
               IF(ICT.GT.0.OR.INIT.EQ.0) THEN                           SPOWER    213
C                                                                       SPOWER    214
C                 Full converter or simplified at initialization.       SPOWER    215
C                                                                       SPOWER    216
                  IF(CONTYP(JPOSN) .EQ. 'BLOCK' .OR.                    SPOWER    217
     1               CONTYP(JPOSN) .EQ. 'BYPASS' .OR.                   SPOWER    218
     2               CONTYP(JPOSN) .EQ. 'COMFAIL') THEN                 SPOWER    219
                     PAHVDC(JPOSN) = 0.0                                SPOWER    220
                     QAHVDC(JPOSN) = 0.0                                SPOWER    221
                  ELSE                                                  SPOWER    222
                     ANG = CALPHA(JPOSN) + VACONV(JPOSN)                SPOWER    223
C                     PAHVDC(JPOSN) = -VDCONV(JPOSN) * XDCONV(JPOSN)    SPOWER    224
                     PAHVDC(JPOSN) =  VDCONV(JPOSN) * VAHVDC(JPOSN) *   SPOWER    225
     1                                CGAMMA(JPOSN) * SIN(ANG)/         SPOWER    226
     2                               (XCCONV(JPOSN) * TAPPOS(JPOSN))    SPOWER    227
                     QAHVDC(JPOSN) =  VDCONV(JPOSN) * VAHVDC(JPOSN) *   SPOWER    228
     1                                CGAMMA(JPOSN) * COS(ANG)/         SPOWER    229
     2                               (XCCONV(JPOSN) * TAPPOS(JPOSN))    SPOWER    230
                  ENDIF                                                 SPOWER    231
                  Q2HVDC(JPOSN) = -VABASE(JPOSN) * VABASE(JPOSN) *      SPOWER    232
     1                                    VALUE2 / XCCONV(JPOSN)        SPOWER    233
               ENDIF                                                    SPOWER    234
C                                                                       SPOWER    235
               IF(ICT.LT.0) THEN                                        SPOWER    236
C                                                                       SPOWER    237
C                 simplified converter model                            SPOWER    238
C                                                                       SPOWER    239
                  IF(INIT.EQ.0) THEN                                    SPOWER    240
C                                                                       SPOWER    241
C                    at initialization                                  SPOWER    242
C                                                                       SPOWER    243
                     PIHVDC(JPOSN) = PAHVDC(JPOSN)                      SPOWER    244
                     QIHVDC(JPOSN) = QAHVDC(JPOSN)                      SPOWER    245
C                                                                       SPOWER    246
                     IF(VMCONV(JPOSN) .GT. 0.0001) THEN                 SPOWER    247
                        VICONV(JPOSN) = VMCONV(JPOSN)                   SPOWER    248
                     ELSE                                               SPOWER    249
                        VICONV(JPOSN) = 0.0001                          SPOWER    250
                     ENDIF                                              SPOWER    251
                  ELSE                                                  SPOWER    252
C                                                                       SPOWER    253
C                    during solution                                    SPOWER    254
C                                                                       SPOWER    255
                     PAHVDC(JPOSN) = PIHVDC(JPOSN)                      SPOWER    256
                     QAHVDC(JPOSN) = QIHVDC(JPOSN) * VALUE2 /           SPOWER    257
     1                              (VICONV(JPOSN) * VICONV(JPOSN))     SPOWER    258
                     Q2HVDC(JPOSN) =-VABASE(JPOSN) * VABASE(JPOSN) *    SPOWER    259
     1                                      VALUE2 / XCCONV(JPOSN)      SPOWER    260
C                                                                       SPOWER    261
                     IF(JTHDC.EQ.1) THEN                                SPOWER    262
                        VDCONV(JPOSN) = 0.0                             SPOWER    263
                        XDCONV(JPOSN) = 0.0                             SPOWER    264
                        CALPHA(JPOSN) = 0.0                             SPOWER    265
                        CGAMMA(JPOSN) = 0.0                             SPOWER    266
                     ENDIF                                              SPOWER    267
                  ENDIF                                                 SPOWER    268
               ENDIF                                                    SPOWER    269
C                                                                       SPOWER    270
C              set power factor angle                                   SPOWER    271
C                                                                       SPOWER    272
               PA = PAHVDC(JPOSN)                                       SPOWER    273
               IF(ABS(PA).LT.0.0001) PA = 0.0001                        SPOWER    274
               QA = QAHVDC(JPOSN) + Q2HVDC(JPOSN)                       SPOWER    275
               PHIDC(JPOSN) = ATAN(QA/PA)                               SPOWER    276
            ENDIF                                                       SPOWER    277
C                                                                       SPOWER    278
         END IF                                                         SPOWER    279
30       CONTINUE                                                       SPOWER    280
         RETURN                                                         SPOWER    281
      ENDIF                                                             SPOWER    282
C                                                                       SPOWER    283
C     ENDIF FOR PSF ONLY                                                SPOWER    284
C                                                                       SPOWER    285
C                                                                       SPOWER    286
C                                                                       SPOWER    287
      DO 20 K = 1, ICDC                                                 SPOWER    288
C                                                                       SPOWER    289
         IF(IDC(K) .NE. 0)THEN                                          SPOWER    290
            JPOSN = IDC(K)                                              SPOWER    291
            ICT=ICTYPE(JPOSN)                                           SPOWER    292
            NUM = IDCBNU(JPOSN)                                         SPOWER    293
            IF(NUM .EQ. 0) THEN                                         SPOWER    294
               VALUE2 = 1.0                                             SPOWER    295
            ELSE                                                        SPOWER    296
               VALUE2 = DCEA(NUM) * DCEA(NUM)                           SPOWER    297
     1                + DCEB(NUM) * DCEB(NUM)                           SPOWER    298
            ENDIF                                                       SPOWER    299
C                                                                       SPOWER    300
            IF(ICT.GT.0.OR.INIT.EQ.0) THEN                              SPOWER    301
C                                                                       SPOWER    302
C              Full converter or simplified at initialization.          SPOWER    303
C                                                                       SPOWER    304
C                                                                       SPOWER    305
C              Determine if inverter or rectifier, and set the          SPOWER    306
C              sign term.                                               SPOWER    307
C                                                                       SPOWER    308
               IF(QINV(JPOSN))THEN                                      SPOWER    309
                  SIGN = 1.0                                            SPOWER    310
               ELSE                                                     SPOWER    311
                  SIGN = -1.0                                           SPOWER    312
               END IF                                                   SPOWER    313
C                                                                       SPOWER    314
C                                                                       SPOWER    315
               PAHVDC(JPOSN) = -VDCONV(JPOSN) * XDCONV(JPOSN)           SPOWER    316
C                                                                       SPOWER    317
               IF(KLFO.EQ.0) THEN                                       SPOWER    318
                  ALPHA = ACOS(CALPHA(JPOSN))                           SPOWER    319
                  GAMMA = ACOS(CGAMMA(JPOSN))                           SPOWER    320
                  AMU = PII-ALPHA-GAMMA                                 SPOWER    321
                  TWOALP = 2.0*ALPHA                                    SPOWER    322
                  TWOAMU = 2.0*(ALPHA+AMU)                              SPOWER    323
                  DCOS=COS(TWOALP)-COS(TWOAMU)                          SPOWER    324
                  IF(ABS(DCOS).GT.0.0001) THEN                          SPOWER    325
                     TANPHI = 2.0*AMU+SIN(TWOALP)-SIN(TWOAMU)           SPOWER    326
                     TANPHI = TANPHI/DCOS                               SPOWER    327
                     TANPHI = ABS(TANPHI)                               SPOWER    328
                     PHIDC(JPOSN)=ATAN(TANPHI)                          SPOWER    329
C                                                                       SPOWER    330
                     IF(CONTYP(JPOSN).EQ.'BLOCK')THEN                   SPOWER    331
                        TANPHI = 0.0                                    SPOWER    332
                        PHIDC(JPOSN)=PII/2.0                            SPOWER    333
                     END IF                                             SPOWER    334
                     QAHVDC(JPOSN) = -ABS( VDCONV(JPOSN) *              SPOWER    335
     1                             XDCONV(JPOSN) * TANPHI)              SPOWER    336
                  ELSE                                                  SPOWER    337
                     V1 = TAPPOS(JPOSN) * VAHVDC(JPOSN)                 SPOWER    338
                     IF(ABS(V1).LT.0.0001) V1 = 0.0001                  SPOWER    339
                     VALUE = VDCONV(JPOSN) / V1                         SPOWER    340
C                                                                       SPOWER    341
                     IF(CONTYP(JPOSN).EQ.'BLOCK')THEN                   SPOWER    342
                        VALUE = 0.0                                     SPOWER    343
                     END IF                                             SPOWER    344
                     IF(VALUE .GT. 1.0)THEN                             SPOWER    345
                        VALUE = 1.0                                     SPOWER    346
                        WRITE (MSG(1),9002) SUBNAM                      SPOWER    347
                        WRITE(MSG(2),9003) DCCNAM(JPOSN)                SPOWER    348
                        WRITE(MSG(3),9004)                              SPOWER    349
                        CALL PRTMSG(3)                                  SPOWER    350
                     END IF                                             SPOWER    351
                     IF(VALUE .LT. -1.0)THEN                            SPOWER    352
                        VALUE = -1.0                                    SPOWER    353
                        WRITE (MSG(1),9002) SUBNAM                      SPOWER    354
                        WRITE(MSG(2),9003) DCCNAM(JPOSN)                SPOWER    355
                        WRITE(MSG(3),9004)                              SPOWER    356
                        CALL PRTMSG(3)                                  SPOWER    357
                     END IF                                             SPOWER    358
                     PHIDC(JPOSN)=ACOS(ABS(VALUE))                      SPOWER    359
                     QAHVDC(JPOSN)=-ABS(V1*XDCONV(JPOSN)*               SPOWER    360
     1                              SIN(PHIDC(JPOSN)))                  SPOWER    361
                  ENDIF                                                 SPOWER    362
C                                                                       SPOWER    363
               ELSE                                                     SPOWER    364
                  V1 = TAPPOS(JPOSN) * VAHVDC(JPOSN)                    SPOWER    365
                  IF(ABS(V1).LT.0.0001) V1 = 0.0001                     SPOWER    366
                  VALUE = VDCONV(JPOSN) / V1                            SPOWER    367
C                                                                       SPOWER    368
                  IF(CONTYP(JPOSN).EQ.'BLOCK')THEN                      SPOWER    369
                     VALUE = 0.0                                        SPOWER    370
                  END IF                                                SPOWER    371
C                                                                       SPOWER    372
                  IF(VALUE .GT. 1.0)THEN                                SPOWER    373
                     VALUE = 1.0                                        SPOWER    374
                     WRITE (MSG(1),9002) SUBNAM                         SPOWER    375
                     WRITE(MSG(2),9003) DCCNAM(JPOSN)                   SPOWER    376
                     WRITE(MSG(3),9004)                                 SPOWER    377
                     CALL PRTMSG(3)                                     SPOWER    378
                  END IF                                                SPOWER    379
                  IF(VALUE .LT. -1.0)THEN                               SPOWER    380
                     VALUE = -1.0                                       SPOWER    381
                     WRITE (MSG(1),9002) SUBNAM                         SPOWER    382
                     WRITE(MSG(2),9003) DCCNAM(JPOSN)                   SPOWER    383
                     WRITE(MSG(3),9004)                                 SPOWER    384
                     CALL PRTMSG(3)                                     SPOWER    385
                  END IF                                                SPOWER    386
C                                                                       SPOWER    387
C                 To prevent taking tangent of 90 degrees.              SPOWER    388
C                                                                       SPOWER    389
                  IF(ABS(VALUE) .LT. 0.00001) VALUE = -0.00001          SPOWER    390
C                                                                       SPOWER    391
                  PHIDC(JPOSN) = ACOS(VALUE)                            SPOWER    392
C                                                                       SPOWER    393
                  QAHVDC(JPOSN) = -ABS( VDCONV(JPOSN) * XDCONV(JPOSN) * SPOWER    394
     1                            TAN(PHIDC(JPOSN)))                    SPOWER    395
               END IF                                                   SPOWER    396
            ENDIF                                                       SPOWER    397
C                                                                       SPOWER    398
            IF(ICT.LT.0) THEN                                           SPOWER    399
C                                                                       SPOWER    400
C              simplified converter model                               SPOWER    401
C                                                                       SPOWER    402
               IF(INIT.EQ.0) THEN                                       SPOWER    403
C                                                                       SPOWER    404
C                 at initialization                                     SPOWER    405
C                                                                       SPOWER    406
                  PIHVDC(JPOSN) = PAHVDC(JPOSN)                         SPOWER    407
                  QIHVDC(JPOSN) = QAHVDC(JPOSN)                         SPOWER    408
                  VICONV(JPOSN) = VMCONV(JPOSN)                         SPOWER    409
               ELSE                                                     SPOWER    410
C                                                                       SPOWER    411
C                 during solution                                       SPOWER    412
C                                                                       SPOWER    413
                  VM0=VICONV(JPOSN)                                     SPOWER    414
                  VM02=VM0**2                                           SPOWER    415
                  VM2=VALUE2/VM02                                       SPOWER    416
                  VM=SQRT(VM2)                                          SPOWER    417
                  P0=PIHVDC(JPOSN)                                      SPOWER    418
                  Q0=QIHVDC(JPOSN)                                      SPOWER    419
                  P02=P0**2                                             SPOWER    420
                  Q02=Q0**2                                             SPOWER    421
                  Q2=(Q02+P02)*VM2-P02                                  SPOWER    422
                  QMIN=0.95                                             SPOWER    423
                  QMIN2=QMIN**2                                         SPOWER    424
                  IF(VM.GT.0.3) THEN                                    SPOWER    425
                     IF(Q2.GE.Q02*QMIN2*VM2) THEN                       SPOWER    426
                        QAHVDC(JPOSN)=-SQRT(Q2)                         SPOWER    427
                        PAHVDC(JPOSN)=P0                                SPOWER    428
                     ELSE                                               SPOWER    429
                        QAHVDC(JPOSN)=Q0*QMIN*VM                        SPOWER    430
                        PAHVDC(JPOSN)=P0*VM*SQRT(Q02*(1.0-QMIN2)/       SPOWER    431
     1                  P02/(1.0-VM2))                                  SPOWER    432
                     ENDIF                                              SPOWER    433
                  ELSE                                                  SPOWER    434
                     QAHVDC(JPOSN)=0.0                                  SPOWER    435
                     PAHVDC(JPOSN)=0.0                                  SPOWER    436
                  ENDIF                                                 SPOWER    437
C                                                                       SPOWER    438
                  IF(JTHDC.EQ.1) THEN                                   SPOWER    439
                     VDCONV(JPOSN) = 0.0                                SPOWER    440
                     XDCONV(JPOSN) = 0.0                                SPOWER    441
                     CALPHA(JPOSN) = 0.0                                SPOWER    442
                     CGAMMA(JPOSN) = 1.0                                SPOWER    443
                  ENDIF                                                 SPOWER    444
C                                                                       SPOWER    445
C                 set power factor angle                                SPOWER    446
C                                                                       SPOWER    447
                  PA = PAHVDC(JPOSN)                                    SPOWER    448
                  IF(ABS(PA).LT.0.0001) PA = 0.0001                     SPOWER    449
                  QA = QAHVDC(JPOSN)                                    SPOWER    450
                  PHIDC(JPOSN) = ATAN(QA/PA)                            SPOWER    451
               ENDIF                                                    SPOWER    452
            ENDIF                                                       SPOWER    453
C                                                                       SPOWER    454
C           Calculate the current injection.                            SPOWER    455
C                                                                       SPOWER    456
            IF(NUM .NE. 0) THEN                                         SPOWER    457
               IF(ABS(VALUE2).LT.0.0001) VALUE2 = 0.0001                SPOWER    458
               PA = DCEA(NUM) * PAHVDC(JPOSN) / PABASE                  SPOWER    459
               QA = DCEA(NUM) * QAHVDC(JPOSN) / PABASE                  SPOWER    460
               PB = DCEB(NUM) * QAHVDC(JPOSN) / PABASE                  SPOWER    461
               QB = DCEB(NUM) * PAHVDC(JPOSN) / PABASE                  SPOWER    462
               REALI(JPOSN) = (PA + PB) / VALUE2                        SPOWER    463
               XIMAGI(JPOSN) = (QB - QA) / VALUE2                       SPOWER    464
            ENDIF                                                       SPOWER    465
         END IF                                                         SPOWER    466
20    CONTINUE                                                          SPOWER    467
C                                                                       SPOWER    468
C                                                                       SPOWER    469
C---------------------------------------------------------------------  SPOWER    470
C                                                                       SPOWER    471
      RETURN                                                            SPOWER    472
C                                                                       SPOWER    473
C---------------------------------------------------------------------  SPOWER    474
C                                                                       SPOWER    475
9002  FORMAT (' *** WARNING MTDC', 5X, A)                               SPOWER    476
9003  FORMAT(1X,'CONVERTER ', A)                                        SPOWER    477
9004  FORMAT(1X,'EXCEEDED COSINE LIMITS IN CALCULATION OF PHI.')        SPOWER    478
C                                                                       SPOWER    479
C---------------------------------------------------------------------  SPOWER    480
C                                                                       SPOWER    481
      END                                                               SPOWER    482
