CFPRIME DUDB31                                                          DUDB31      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 DUDB31(LORD,KORD,NLF1,KN,CID)                          DUDB31      3
CD                                                                      DUDB31      4
CD    CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK     DUDB31      5
CD    TYPES 31 AND 32 (TYPES E1 AND E2 EXCITER END BLOCKS) IN A USER    DUDB31      6
CD    DEFINED EXCITER MODEL, USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL   DUDB31      7
CD    METHOD.                                                           DUDB31      8
CD                                                                      DUDB31      9
CD    EACH ENTRY POINT IN THIS SUBROUTINE HAS SIMILAR FUNCTION AND IS   DUDB31     10
CD    FOR A DIFFERENT TYPE OF EXCITER END BLOCK APPLICABLE TO A USER    DUDB31     11
CD    DEFINED EXCITER MODEL.                                            DUDB31     12
CD                                                                      DUDB31     13
      INCLUDE 'PARX.INS'                                                DUDB31     14
      INCLUDE 'CNB4.INS'                                                DUDB31     15
      INCLUDE 'CNB9.INS'                                                DUDB31     16
      INCLUDE 'CNPARX.INS'                                              DUDB31     17
      INCLUDE 'CNMDAT.INS'                                              DUDB31     18
      INCLUDE 'CNMSTA.INS'                                              DUDB31     19
      INCLUDE 'CNXSTA.INS'                                              DUDB31     20
      INCLUDE 'CNQSTA.INS'                                              DUDB31     21
      INCLUDE 'CNSTN.INS'                                               DUDB31     22
      INCLUDE 'CNYVAR.INS'                                              DUDB31     23
      INCLUDE 'CNUNIT.INS'                                              DUDB31     24
      INCLUDE 'CNFLAG.INS'                                              DUDB31     25
      INCLUDE 'CNUDM.INS'                                               DUDB31     26
      INCLUDE 'CNMSG.INS'                                               DUDB31     27
C                                                                       DUDB31     28
      CHARACTER*2 CID                                                   DUDB31     29
C                                                                       DUDB31     30
      LDEB=(JDEB(264).NE.0)                                             DUDB31     31
C                                                                       DUDB31     32
      IORD=IDDAT(JE4+LORD)                                              DUDB31     33
      JEI=JEB+2                                                         DUDB31     34
      KINT=KINPU                                                        DUDB31     35
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31     36
      IF(KINT.LT.KINPU) THEN                                            DUDB31     37
         J=KINT+1                                                       DUDB31     38
         XDAT=GAINS(J)                                                  DUDB31     39
         IOUT=INPUTS(J)                                                 DUDB31     40
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31     41
         GO TO 100                                                      DUDB31     42
      ENDIF                                                             DUDB31     43
      KINP=KINPU                                                        DUDB31     44
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31     45
      IF(KINP.LT.KINPU) THEN                                            DUDB31     46
         J=KINP+1                                                       DUDB31     47
         XDAT=GAINS(J)                                                  DUDB31     48
         IIN=INPUTS(J)                                                  DUDB31     49
         VALI=VALIN(IIN)*XDAT                                           DUDB31     50
      ENDIF                                                             DUDB31     51
  100 CONTINUE                                                          DUDB31     52
      KORD=KORD+1                                                       DUDB31     53
C                                                                       DUDB31     54
      SEKX=DDAT(JEI+1)*XSTATE(JSTATE+KORD)                              DUDB31     55
      SEKX=SEKX+DDAT(JEI+3)*EXP(DDAT(JEI+4)*XSTATE(JSTATE+KORD))        DUDB31     56
      VEIN=VALI-SEKX                                                    DUDB31     57
C                                                                       DUDB31     58
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31     59
      VE=XSTATE(JSTATE+KORD)                                            DUDB31     60
      VEMIN=DDAT(JEI+6)                                                 DUDB31     61
      IF (VE.LE.VEMIN) THEN                                             DUDB31     62
         VE=VEMIN                                                       DUDB31     63
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31     64
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31     65
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31     66
         END IF                                                         DUDB31     67
      END IF                                                            DUDB31     68
      VALOUT(IORD)=VE                                                   DUDB31     69
      VALIN(19)=VALI                                                    DUDB31     70
      IF(LDEB) WRITE(IUD6,1000) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31     71
C                                                                       DUDB31     72
      RETURN                                                            DUDB31     73
 1000 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31     74
C                                                                       DUDB31     75
C-----------------------------------------------------------------------DUDB31     76
C                                                                       DUDB31     77
      ENTRY DUDB33(LORD,KORD,NLF1,KN,CID)                               DUDB31     78
CD                                                                      DUDB31     79
CD    FOR BLOCK TYPE 33 (TYPE E3 EXCITER END BLOCK).                    DUDB31     80
CD                                                                      DUDB31     81
      LDEB=(JDEB(264).NE.0)                                             DUDB31     82
C                                                                       DUDB31     83
      IORD=IDDAT(JE4+LORD)                                              DUDB31     84
      JEI=JEB+2                                                         DUDB31     85
      KINT=KINPU                                                        DUDB31     86
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31     87
      IF(KINT.LT.KINPU) THEN                                            DUDB31     88
         J=KINT+1                                                       DUDB31     89
         XDAT=GAINS(J)                                                  DUDB31     90
         IOUT=INPUTS(J)                                                 DUDB31     91
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31     92
         GO TO 110                                                      DUDB31     93
      ENDIF                                                             DUDB31     94
      KINP=KINPU                                                        DUDB31     95
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31     96
      IF(KINP.LT.KINPU) THEN                                            DUDB31     97
         J=KINP+1                                                       DUDB31     98
         XDAT=GAINS(J)                                                  DUDB31     99
         IIN=INPUTS(J)                                                  DUDB31    100
         VALI=VALIN(IIN)*XDAT                                           DUDB31    101
      ENDIF                                                             DUDB31    102
  110 CONTINUE                                                          DUDB31    103
      KORD=KORD+1                                                       DUDB31    104
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    105
C                                                                       DUDB31    106
      CFDN=VALIN(16)                                                    DUDB31    107
      SEKX=DDAT(JEI+1)*VE                                               DUDB31    108
      SEKX=SEKX+DDAT(JEI+3)*EXP(DDAT(JEI+4)*VE)                         DUDB31    109
      SEKX=SEKX+CFDN*(DDAT(JEI+7)-DDAT(JEI+8))                          DUDB31    110
C                                                                       DUDB31    111
      VEIN=VALI-SEKX                                                    DUDB31    112
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31    113
C                                                                       DUDB31    114
      VEMIN=DDAT(JEI+11)                                                DUDB31    115
      IF (VE.LE.VEMIN) THEN                                             DUDB31    116
         VE=VEMIN                                                       DUDB31    117
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    118
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    119
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    120
         END IF                                                         DUDB31    121
      END IF                                                            DUDB31    122
      VTH=VE-CFDN*DDAT(JEI+8)                                           DUDB31    123
C                                                                       DUDB31    124
C     RECTIFIER LOADING EFFECTS                                         DUDB31    125
C                                                                       DUDB31    126
      IF(IDDAT(JEI+6).NE.0)THEN                                         DUDB31    127
         IF(VTH.GT.0.0)THEN                                             DUDB31    128
            FACT=DDAT(JEI+6)*CFDN/VTH                                   DUDB31    129
            IF(FACT.GE.0.75)THEN                                        DUDB31    130
               VALO=VTH*1.732*(1.0-FACT)                                DUDB31    131
            ELSEIF(FACT.GE.0.433)THEN                                   DUDB31    132
               VALO=VTH*SQRT(0.75-FACT*FACT)                            DUDB31    133
            ELSE                                                        DUDB31    134
               VALO=VTH*(1.0-0.577*FACT)                                DUDB31    135
            ENDIF                                                       DUDB31    136
         ENDIF                                                          DUDB31    137
      ELSE                                                              DUDB31    138
         VALO=VTH                                                       DUDB31    139
      ENDIF                                                             DUDB31    140
      IF(VALO.LE.0.0) VALO=0.0                                          DUDB31    141
      VALOUT(IORD)=VALO                                                 DUDB31    142
      VALIN(19)=VALI                                                    DUDB31    143
      IF(LDEB) WRITE(IUD6,1010) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    144
C                                                                       DUDB31    145
      RETURN                                                            DUDB31    146
 1010 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    147
C                                                                       DUDB31    148
C-----------------------------------------------------------------------DUDB31    149
C                                                                       DUDB31    150
      ENTRY DUDB34(LORD,KORD,NLF1,KN,CID)                               DUDB31    151
CD                                                                      DUDB31    152
CD    FOR BLOCK TYPE 34 (TYPE E4 EXCITER END BLOCK).                    DUDB31    153
CD                                                                      DUDB31    154
      LDEB=(JDEB(264).NE.0)                                             DUDB31    155
C                                                                       DUDB31    156
      IORD=IDDAT(JE4+LORD)                                              DUDB31    157
      JEI=JEB+2                                                         DUDB31    158
      KINT=KINPU                                                        DUDB31    159
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    160
      IF(KINT.LT.KINPU) THEN                                            DUDB31    161
         J=KINT+1                                                       DUDB31    162
         XDAT=GAINS(J)                                                  DUDB31    163
         IOUT=INPUTS(J)                                                 DUDB31    164
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    165
         GO TO 120                                                      DUDB31    166
      ENDIF                                                             DUDB31    167
      KINP=KINPU                                                        DUDB31    168
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    169
      IF(KINP.LT.KINPU) THEN                                            DUDB31    170
         J=KINP+1                                                       DUDB31    171
         XDAT=GAINS(J)                                                  DUDB31    172
         IIN=INPUTS(J)                                                  DUDB31    173
         VALI=VALIN(IIN)*XDAT                                           DUDB31    174
      ENDIF                                                             DUDB31    175
  120 CONTINUE                                                          DUDB31    176
      KORD=KORD+1                                                       DUDB31    177
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    178
C                                                                       DUDB31    179
      EFDN=VALIN(15)                                                    DUDB31    180
      CFDN=VALIN(16)                                                    DUDB31    181
      SEKX=DDAT(JEI+1)*VE                                               DUDB31    182
      SEKX=SEKX+DDAT(JEI+3)*EXP(DDAT(JEI+4)*VE)                         DUDB31    183
      VEMAX=(DDAT(JEI+9)-(DDAT(JEI+7)-DDAT(JEI+8))*CFDN)*VE/SEKX        DUDB31    184
      VEMIN=DDAT(JEI+11)                                                DUDB31    185
      IF(VEMAX.LE.VEMIN) THEN                                           DUDB31    186
C         WRITE(IU6,1030) IORD,BLNAM1,BLNAM2                            DUDB31    187
C         WRITE(IU6,1031) VEMAX,VEMIN                                   DUDB31    188
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB31    189
         WRITE(MSG(2),1030) IORD,BLNAM1,BLNAM2                          DUDB31    190
         WRITE(MSG(3),1031) VEMAX,VEMIN                                 DUDB31    191
         CALL PRTMSG(3)                                                 DUDB31    192
         MSG(1)='DUDB34: UD ERROR'                                      DUDB31    193
         CALL ASTOP(MSG(1),16)                                          DUDB31    194
      ENDIF                                                             DUDB31    195
      DDAT(JEI+10)=VEMAX                                                DUDB31    196
      SEKX=SEKX+CFDN*(DDAT(JEI+7)-DDAT(JEI+8))                          DUDB31    197
C                                                                       DUDB31    198
      VR=DDAT(JEI+12)*EFDN*VALI                                         DUDB31    199
      VEIN=VR-SEKX                                                      DUDB31    200
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31    201
C                                                                       DUDB31    202
      IF (VE.GE.VEMAX) THEN                                             DUDB31    203
         VE=VEMAX                                                       DUDB31    204
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB31    205
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    206
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    207
         END IF                                                         DUDB31    208
      ELSE IF (VE.LE.VEMIN) THEN                                        DUDB31    209
         VE=VEMIN                                                       DUDB31    210
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    211
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    212
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    213
         END IF                                                         DUDB31    214
      END IF                                                            DUDB31    215
      VTH=VE-CFDN*DDAT(JEI+8)                                           DUDB31    216
C                                                                       DUDB31    217
C     RECTIFIER LOADING EFFECTS                                         DUDB31    218
C                                                                       DUDB31    219
      IF(IDDAT(JEI+6).NE.0)THEN                                         DUDB31    220
         IF(VTH.GT.0.0)THEN                                             DUDB31    221
            FACT=DDAT(JEI+6)*CFDN/VTH                                   DUDB31    222
            IF(FACT.GE.0.75)THEN                                        DUDB31    223
               VALO=VTH*1.732*(1.0-FACT)                                DUDB31    224
            ELSEIF(FACT.GE.0.433)THEN                                   DUDB31    225
               VALO=VTH*SQRT(0.75-FACT*FACT)                            DUDB31    226
            ELSE                                                        DUDB31    227
               VALO=VTH*(1.0-0.577*FACT)                                DUDB31    228
            ENDIF                                                       DUDB31    229
         ENDIF                                                          DUDB31    230
      ELSE                                                              DUDB31    231
         VALO=VTH                                                       DUDB31    232
      ENDIF                                                             DUDB31    233
      IF(VALO.LE.0.0) VALO=0.0                                          DUDB31    234
      VALOUT(IORD)=VALO                                                 DUDB31    235
      VALIN(19)=VALI                                                    DUDB31    236
      IF(LDEB) WRITE(IUD6,1020) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    237
C                                                                       DUDB31    238
      RETURN                                                            DUDB31    239
 1020 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    240
 1030 FORMAT(5X,'BLOCK: ',I3,'(',2A4,') HAS XCROSSING LIMITS.')         DUDB31    241
 1031 FORMAT(5X,'VEMAX = ',F10.5,'   VEMIN = ',F10.5)                   DUDB31    242
C                                                                       DUDB31    243
C-----------------------------------------------------------------------DUDB31    244
C                                                                       DUDB31    245
      ENTRY DUDB35(LORD,KORD,NLF1,KN,CID)                               DUDB31    246
CD                                                                      DUDB31    247
CD    FOR BLOCK TYPE 35 (TYPE E5 EXCITER END BLOCK).                    DUDB31    248
CD                                                                      DUDB31    249
      LDEB=(JDEB(264).NE.0)                                             DUDB31    250
C                                                                       DUDB31    251
      IORD=IDDAT(JE4+LORD)                                              DUDB31    252
      JEI=JEB+2                                                         DUDB31    253
      KINT=KINPU                                                        DUDB31    254
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    255
      IF(KINT.LT.KINPU) THEN                                            DUDB31    256
         J=KINT+1                                                       DUDB31    257
         XDAT=GAINS(J)                                                  DUDB31    258
         IOUT=INPUTS(J)                                                 DUDB31    259
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    260
         GO TO 140                                                      DUDB31    261
      ENDIF                                                             DUDB31    262
      KINP=KINPU                                                        DUDB31    263
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    264
      IF(KINP.LT.KINPU) THEN                                            DUDB31    265
         J=KINP+1                                                       DUDB31    266
         XDAT=GAINS(J)                                                  DUDB31    267
         IIN=INPUTS(J)                                                  DUDB31    268
         VALI=VALIN(IIN)*XDAT                                           DUDB31    269
      ENDIF                                                             DUDB31    270
  140 CONTINUE                                                          DUDB31    271
      KORD=KORD+1                                                       DUDB31    272
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    273
C                                                                       DUDB31    274
      CFDN=VALIN(16)                                                    DUDB31    275
      SEKX=DDAT(JEI+1)*VE                                               DUDB31    276
      SEKX=SEKX+DDAT(JEI+3)*EXP(DDAT(JEI+4)*VE)                         DUDB31    277
      SEKX=SEKX+CFDN*(DDAT(JEI+7)-DDAT(JEI+8))                          DUDB31    278
C                                                                       DUDB31    279
      VEIN=VALI-SEKX                                                    DUDB31    280
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31    281
C                                                                       DUDB31    282
      VEMIN=DDAT(JEI+11)                                                DUDB31    283
      IF (VE.LE.VEMIN) THEN                                             DUDB31    284
         VE=VEMIN                                                       DUDB31    285
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    286
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    287
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    288
         END IF                                                         DUDB31    289
      END IF                                                            DUDB31    290
      VTH=VE-CFDN*DDAT(JEI+8)                                           DUDB31    291
C                                                                       DUDB31    292
C     RECTIFIER LOADING EFFECTS                                         DUDB31    293
C                                                                       DUDB31    294
      IF(IDDAT(JEI+6).NE.0)THEN                                         DUDB31    295
         IF(VTH.GT.0.0)THEN                                             DUDB31    296
            FACT=DDAT(JEI+6)*CFDN/VTH                                   DUDB31    297
            IF(FACT.GE.0.75)THEN                                        DUDB31    298
               VALO=VTH*1.732*(1.0-FACT)                                DUDB31    299
            ELSEIF(FACT.GE.0.433)THEN                                   DUDB31    300
               VALO=VTH*SQRT(0.75-FACT*FACT)                            DUDB31    301
            ELSE                                                        DUDB31    302
               VALO=VTH*(1.0-0.577*FACT)                                DUDB31    303
            ENDIF                                                       DUDB31    304
         ENDIF                                                          DUDB31    305
      ELSE                                                              DUDB31    306
         VALO=VTH                                                       DUDB31    307
      ENDIF                                                             DUDB31    308
      IF(VALO.LE.0.0) VALO=0.0                                          DUDB31    309
      VALOUT(IORD)=VALO                                                 DUDB31    310
      VALIN(19)=SEKX                                                    DUDB31    311
      IF(LDEB) WRITE(IUD6,1040) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    312
C                                                                       DUDB31    313
      RETURN                                                            DUDB31    314
 1040 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    315
C                                                                       DUDB31    316
C-----------------------------------------------------------------------DUDB31    317
                                                                        DUDB31    318
      ENTRY DUDB36(LORD,KORD,NLF1,KN,CID)                               DUDB31    319
CD                                                                      DUDB31    320
CD    FOR BLOCK TYPE 36 (TYPE E6 EXCITER END BLOCK).                    DUDB31    321
CD                                                                      DUDB31    322
      LDEB=(JDEB(264).NE.0)                                             DUDB31    323
C                                                                       DUDB31    324
      IORD=IDDAT(JE4+LORD)                                              DUDB31    325
      JEI=JEB+2                                                         DUDB31    326
      KINT=KINPU                                                        DUDB31    327
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    328
      IF(KINT.LT.KINPU) THEN                                            DUDB31    329
         J=KINT+1                                                       DUDB31    330
         XDAT=GAINS(J)                                                  DUDB31    331
         IOUT=INPUTS(J)                                                 DUDB31    332
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    333
         GO TO 150                                                      DUDB31    334
      ENDIF                                                             DUDB31    335
      KINP=KINPU                                                        DUDB31    336
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    337
      IF(KINP.LT.KINPU) THEN                                            DUDB31    338
         J=KINP+1                                                       DUDB31    339
         XDAT=GAINS(J)                                                  DUDB31    340
         IIN=INPUTS(J)                                                  DUDB31    341
         VALI=VALIN(IIN)*XDAT                                           DUDB31    342
      ENDIF                                                             DUDB31    343
  150 CONTINUE                                                          DUDB31    344
      KORD=KORD+1                                                       DUDB31    345
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    346
C                                                                       DUDB31    347
      CFDN=VALIN(16)                                                    DUDB31    348
      SEKX=DDAT(JEI+1)                                                  DUDB31    349
      IF (VE.NE.0.0) SEKX=SEKX+DDAT(JEI+3)*EXP(DDAT(JEI+4)*VE)/VE       DUDB31    350
      VEMAX=(DDAT(JEI+9)-(DDAT(JEI+7)-DDAT(JEI+8))*CFDN)/SEKX           DUDB31    351
      VEMIN=DDAT(JEI+11)                                                DUDB31    352
      SEKX=SEKX*VE                                                      DUDB31    353
      IF(VEMAX.LE.VEMIN) THEN                                           DUDB31    354
C         WRITE(IU6,1030) IORD,BLNAM1,BLNAM2                            DUDB31    355
C         WRITE(IU6,1031) VEMAX,VEMIN                                   DUDB31    356
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB31    357
         WRITE(MSG(2),1030) IORD,BLNAM1,BLNAM2                          DUDB31    358
         WRITE(MSG(3),1031) VEMAX,VEMIN                                 DUDB31    359
         CALL PRTMSG(3)                                                 DUDB31    360
         MSG(1)='DUDB36: UD ERROR'                                      DUDB31    361
         CALL ASTOP(MSG(1),16)                                          DUDB31    362
      ENDIF                                                             DUDB31    363
      DDAT(JEI+10)=VEMAX                                                DUDB31    364
      SEKX=SEKX+CFDN*(DDAT(JEI+7)-DDAT(JEI+8))                          DUDB31    365
C                                                                       DUDB31    366
      VEIN=VALI-SEKX                                                    DUDB31    367
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31    368
C                                                                       DUDB31    369
      IF (VE.GE.VEMAX) THEN                                             DUDB31    370
         VE=VEMAX                                                       DUDB31    371
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB31    372
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    373
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    374
         END IF                                                         DUDB31    375
      ELSE IF (VE.LE.VEMIN) THEN                                        DUDB31    376
         VE=VEMIN                                                       DUDB31    377
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    378
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    379
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    380
         END IF                                                         DUDB31    381
      END IF                                                            DUDB31    382
      VTH=VE-CFDN*DDAT(JEI+8)                                           DUDB31    383
C                                                                       DUDB31    384
C     RECTIFIER LOADING EFFECTS                                         DUDB31    385
C                                                                       DUDB31    386
      IF(IDDAT(JEI+6).NE.0)THEN                                         DUDB31    387
         IF(VTH.GT.0.0)THEN                                             DUDB31    388
            FACT=DDAT(JEI+6)*CFDN/VTH                                   DUDB31    389
            IF(FACT.GE.0.75)THEN                                        DUDB31    390
               VALO=VTH*1.732*(1.0-FACT)                                DUDB31    391
            ELSEIF(FACT.GE.0.433)THEN                                   DUDB31    392
               VALO=VTH*SQRT(0.75-FACT*FACT)                            DUDB31    393
            ELSE                                                        DUDB31    394
               VALO=VTH*(1.0-0.577*FACT)                                DUDB31    395
            ENDIF                                                       DUDB31    396
         ENDIF                                                          DUDB31    397
      ELSE                                                              DUDB31    398
         VALO=VTH                                                       DUDB31    399
      ENDIF                                                             DUDB31    400
      IF(VALO.LE.0.0) VALO=0.0                                          DUDB31    401
      VALOUT(IORD)=VALO                                                 DUDB31    402
      VALIN(19)=SEKX                                                    DUDB31    403
      IF(LDEB) WRITE(IUD6,1050) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    404
C                                                                       DUDB31    405
      RETURN                                                            DUDB31    406
 1050 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    407
C                                                                       DUDB31    408
C-----------------------------------------------------------------------DUDB31    409
C                                                                       DUDB31    410
      ENTRY DUDB37(LORD,KORD,NLF1,KN,CID)                               DUDB31    411
CD                                                                      DUDB31    412
CD    FOR BLOCK TYPE 37 (TYPE E7 EXCITER END BLOCK).                    DUDB31    413
CD                                                                      DUDB31    414
      LDEB=(JDEB(264).NE.0)                                             DUDB31    415
C                                                                       DUDB31    416
      IORD=IDDAT(JE4+LORD)                                              DUDB31    417
      JEI=JEB+2                                                         DUDB31    418
      KINT=KINPU                                                        DUDB31    419
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    420
      IF(KINT.LT.KINPU) THEN                                            DUDB31    421
         J=KINT+1                                                       DUDB31    422
         XDAT=GAINS(J)                                                  DUDB31    423
         IOUT=INPUTS(J)                                                 DUDB31    424
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    425
         GO TO 170                                                      DUDB31    426
      ENDIF                                                             DUDB31    427
      KINP=KINPU                                                        DUDB31    428
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    429
      IF(KINP.LT.KINPU) THEN                                            DUDB31    430
         J=KINP+1                                                       DUDB31    431
         XDAT=GAINS(J)                                                  DUDB31    432
         IIN=INPUTS(J)                                                  DUDB31    433
         VALI=VALIN(IIN)*XDAT                                           DUDB31    434
      ENDIF                                                             DUDB31    435
  170 CONTINUE                                                          DUDB31    436
      KORD=KORD+1                                                       DUDB31    437
      IF(NRBUS.EQ.0) THEN                                               DUDB31    438
         VRE=VALIN(6)                                                   DUDB31    439
         VIM=VALIN(7)                                                   DUDB31    440
      ELSE                                                              DUDB31    441
         VM=VALIN(21)                                                   DUDB31    442
         AM=VALIN(31)                                                   DUDB31    443
         VRE=VM*COS(AM)                                                 DUDB31    444
         VIM=VM*SIN(AM)                                                 DUDB31    445
      ENDIF                                                             DUDB31    446
      CRE=VALIN(8)                                                      DUDB31    447
      CIM=VALIN(9)                                                      DUDB31    448
C                                                                       DUDB31    449
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    450
      VSC1=VRE*DDAT(JEI+4)-CIM*DDAT(JEI+5)                              DUDB31    451
      VSC2=VIM*DDAT(JEI+4)+CRE*DDAT(JEI+5)                              DUDB31    452
      VSC=SQRT(VSC1*VSC1+VSC2*VSC2)                                     DUDB31    453
      XIN=DDAT(JEI+6)*VALIN(16)/VSC                                     DUDB31    454
      IF(XIN.GT.0.750)THEN                                              DUDB31    455
         FIN=1.732*(1.0-XIN)                                            DUDB31    456
      ELSEIF(XIN.GT.0.433)THEN                                          DUDB31    457
         FIN=SQRT(0.75-XIN*XIN)                                         DUDB31    458
      ELSE                                                              DUDB31    459
         FIN=1.0-0.577*XIN                                              DUDB31    460
      ENDIF                                                             DUDB31    461
      VB=VSC*FIN                                                        DUDB31    462
      SEKX=VE*DDAT(JEI+1)                                               DUDB31    463
CC                                                                      DUDB31    464
CC    CODE FOR OLD TYPE ST2 EXCITER                                     DUDB31    465
CC                                                                      DUDB31    466
CC      VEIN=VALI+VB-SEKX                                               DUDB31    467
CC                                                                      DUDB31    468
      VEIN=VALI*VB-SEKX                                                 DUDB31    469
C                                                                       DUDB31    470
      DSTATE(LSTATE+KORD)=VEIN/DDAT(JEI+2)                              DUDB31    471
      EFDMAX=DDAT(JEI+3)                                                DUDB31    472
      IF (VE.GE.EFDMAX) THEN                                            DUDB31    473
         VE=EFDMAX                                                      DUDB31    474
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB31    475
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    476
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    477
         END IF                                                         DUDB31    478
      ELSE IF (VE.LE.0.0) THEN                                          DUDB31    479
         VE=0.0                                                         DUDB31    480
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    481
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    482
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    483
         END IF                                                         DUDB31    484
      END IF                                                            DUDB31    485
      VALOUT(IORD)=VE                                                   DUDB31    486
      VALIN(19)=VALI                                                    DUDB31    487
      IF(LDEB) WRITE(IUD6,1070) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    488
C                                                                       DUDB31    489
      RETURN                                                            DUDB31    490
 1070 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    491
C                                                                       DUDB31    492
C-----------------------------------------------------------------------DUDB31    493
C                                                                       DUDB31    494
      ENTRY DUDB38(LORD,NLF1,KN,CID)                                    DUDB31    495
CD                                                                      DUDB31    496
CD    FOR BLOCK TYPE 38 (TYPE E8 EXCITER END BLOCK).                    DUDB31    497
CD                                                                      DUDB31    498
      LDEB=(JDEB(264).NE.0)                                             DUDB31    499
C                                                                       DUDB31    500
      IORD=IDDAT(JE4+LORD)                                              DUDB31    501
      JEI=JEB+2                                                         DUDB31    502
      KINT=KINPU                                                        DUDB31    503
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    504
      IF(KINT.LT.KINPU) THEN                                            DUDB31    505
         J=KINT+1                                                       DUDB31    506
         XDAT=GAINS(J)                                                  DUDB31    507
         IOUT=INPUTS(J)                                                 DUDB31    508
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    509
         GO TO 180                                                      DUDB31    510
      ENDIF                                                             DUDB31    511
      KINP=KINPU                                                        DUDB31    512
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    513
      IF(KINP.LT.KINPU) THEN                                            DUDB31    514
         J=KINP+1                                                       DUDB31    515
         XDAT=GAINS(J)                                                  DUDB31    516
         IIN=INPUTS(J)                                                  DUDB31    517
         VALI=VALIN(IIN)*XDAT                                           DUDB31    518
      ENDIF                                                             DUDB31    519
  180 CONTINUE                                                          DUDB31    520
      IF(NRBUS.EQ.0) THEN                                               DUDB31    521
         VRE=VALIN(6)                                                   DUDB31    522
         VIM=VALIN(7)                                                   DUDB31    523
      ELSE                                                              DUDB31    524
         VM=VALIN(21)                                                   DUDB31    525
         AM=VALIN(31)                                                   DUDB31    526
         VRE=VM*COS(AM)                                                 DUDB31    527
         VIM=VM*SIN(AM)                                                 DUDB31    528
      ENDIF                                                             DUDB31    529
      CRE=VALIN(8)                                                      DUDB31    530
      CIM=VALIN(9)                                                      DUDB31    531
C                                                                       DUDB31    532
      XKPR=DDAT(JEI+4)*COS(DDAT(JEI+5))                                 DUDB31    533
      XKPI=DDAT(JEI+4)*SIN(DDAT(JEI+5))                                 DUDB31    534
      VSC1=VRE*XKPR-VIM*XKPI-CIM*(DDAT(JEI+3)                           DUDB31    535
     &+XKPR*DDAT(JEI+2))-CRE*XKPI*DDAT(JEI+2)                           DUDB31    536
      VSC2=VRE*XKPI+VIM*XKPR+CRE*(DDAT(JEI+3)                           DUDB31    537
     &+XKPR*DDAT(JEI+2))-CIM*XKPI*DDAT(JEI+2)                           DUDB31    538
      VSC=SQRT(VSC1*VSC1+VSC2*VSC2)                                     DUDB31    539
      XIN=DDAT(JEI+6)*VALIN(16)/VSC                                     DUDB31    540
      IF(XIN.GT.0.750)THEN                                              DUDB31    541
         FIN=1.732*(1.0-XIN)                                            DUDB31    542
      ELSEIF(XIN.GT.0.433)THEN                                          DUDB31    543
         FIN=SQRT(0.75-XIN*XIN)                                         DUDB31    544
      ELSE                                                              DUDB31    545
         FIN=1.0-0.577*XIN                                              DUDB31    546
      ENDIF                                                             DUDB31    547
      VB=VSC*FIN                                                        DUDB31    548
      VBMAX=DDAT(JEI+10)                                                DUDB31    549
      IF(VB.GT.VBMAX) VB=VBMAX                                          DUDB31    550
C                                                                       DUDB31    551
      VE=VB*VALI                                                        DUDB31    552
      EFMAX=DDAT(JEI+9)                                                 DUDB31    553
      IF(VE.GT.EFMAX) VE=EFMAX                                          DUDB31    554
      VALOUT(IORD)=VE                                                   DUDB31    555
      VALIN(19)=VALI                                                    DUDB31    556
      IF(LDEB) WRITE(IUD6,1080) LORD,IORD,VALOUT(IORD)                  DUDB31    557
C                                                                       DUDB31    558
      RETURN                                                            DUDB31    559
 1080 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB31    560
C                                                                       DUDB31    561
C-----------------------------------------------------------------------DUDB31    562
C                                                                       DUDB31    563
      ENTRY DUDB39(LORD,NLF1,KN,CID)                                    DUDB31    564
CD                                                                      DUDB31    565
CD    FOR BLOCK TYPE 39 (TYPE E15 EXCITER END BLOCK).                   DUDB31    566
CD                                                                      DUDB31    567
      LDEB=(JDEB(264).NE.0)                                             DUDB31    568
C                                                                       DUDB31    569
      IORD=IDDAT(JE4+LORD)                                              DUDB31    570
      JEI=JEB+2                                                         DUDB31    571
      KINT=KINPU                                                        DUDB31    572
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    573
      IF(KINT.LT.KINPU) THEN                                            DUDB31    574
         J=KINT+1                                                       DUDB31    575
         XDAT=GAINS(J)                                                  DUDB31    576
         IOUT=INPUTS(J)                                                 DUDB31    577
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    578
         GO TO 190                                                      DUDB31    579
      ENDIF                                                             DUDB31    580
      KINP=KINPU                                                        DUDB31    581
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    582
      IF(KINP.LT.KINPU) THEN                                            DUDB31    583
         J=KINP+1                                                       DUDB31    584
         XDAT=GAINS(J)                                                  DUDB31    585
         IIN=INPUTS(J)                                                  DUDB31    586
         VALI=VALIN(IIN)*XDAT                                           DUDB31    587
      ENDIF                                                             DUDB31    588
  190 CONTINUE                                                          DUDB31    589
C                                                                       DUDB31    590
      VALIN(19)=VALI                                                    DUDB31    591
      EFDMAX=DDAT(JEI+3)                                                DUDB31    592
      EFDMIN=DDAT(JEI+4)                                                DUDB31    593
      IF (VALI.GT.EFDMAX) THEN                                          DUDB31    594
         VALI=EFDMAX                                                    DUDB31    595
      ELSE IF (VALI.LT.EFDMIN) THEN                                     DUDB31    596
         VALI=EFDMIN                                                    DUDB31    597
      END IF                                                            DUDB31    598
      VALOUT(IORD)=VALI*VALIN(1)                                        DUDB31    599
      IF(LDEB) WRITE(IUD6,1090) LORD,IORD,VALOUT(IORD)                  DUDB31    600
C                                                                       DUDB31    601
      RETURN                                                            DUDB31    602
 1090 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB31    603
C                                                                       DUDB31    604
C-----------------------------------------------------------------------DUDB31    605
C                                                                       DUDB31    606
      ENTRY DUDB40(LORD,KORD,NLF1,KN,CID)                               DUDB31    607
CD                                                                      DUDB31    608
CD    FOR BLOCK TYPE 40 (TYPE E30 EXCITER END BLOCK).                   DUDB31    609
CD                                                                      DUDB31    610
      LDEB=(JDEB(264).NE.0)                                             DUDB31    611
C                                                                       DUDB31    612
      IORD=IDDAT(JE4+LORD)                                              DUDB31    613
      JEI=JEB+2                                                         DUDB31    614
      KINT=KINPU                                                        DUDB31    615
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    616
      IF(KINT.LT.KINPU) THEN                                            DUDB31    617
         J=KINT+1                                                       DUDB31    618
         XDAT=GAINS(J)                                                  DUDB31    619
         IOUT=INPUTS(J)                                                 DUDB31    620
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    621
         GO TO 200                                                      DUDB31    622
      ENDIF                                                             DUDB31    623
      KINP=KINPU                                                        DUDB31    624
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    625
      IF(KINP.LT.KINPU) THEN                                            DUDB31    626
         J=KINP+1                                                       DUDB31    627
         XDAT=GAINS(J)                                                  DUDB31    628
         IIN=INPUTS(J)                                                  DUDB31    629
         VALI=VALIN(IIN)*XDAT                                           DUDB31    630
      ENDIF                                                             DUDB31    631
  200 CONTINUE                                                          DUDB31    632
C                                                                       DUDB31    633
      KORD=KORD+1                                                       DUDB31    634
      VEIN=VALI*DDAT(JEI+1)                                             DUDB31    635
      VE=XSTATE(JSTATE+KORD)                                            DUDB31    636
      DSTATE(LSTATE+KORD)=(VEIN-VE)/DDAT(JEI+2)                         DUDB31    637
C                                                                       DUDB31    638
      VRMAX=DDAT(JEI+3)                                                 DUDB31    639
      VRMIN=DDAT(JEI+4)                                                 DUDB31    640
      DLIM=DDAT(JEI+6)*VALIN(16)                                        DUDB31    641
      IF(IDDAT(JEI+5).EQ.0) THEN                                        DUDB31    642
         RATIO=1.0                                                      DUDB31    643
      ELSE                                                              DUDB31    644
         RATIO=VALIN(4)/DDAT(JEI+5)                                     DUDB31    645
      ENDIF                                                             DUDB31    646
      VEMAX=VRMAX*RATIO-DLIM                                            DUDB31    647
      VEMIN=VRMIN*RATIO+DLIM                                            DUDB31    648
      DDAT(JEI+9)=VEMAX                                                 DUDB31    649
      DDAT(JEI+10)=VEMIN                                                DUDB31    650
      IF(VEMAX.LE.VEMIN) THEN                                           DUDB31    651
C         WRITE(IU6,1110)                                               DUDB31    652
C         WRITE(IU6,1031) VEMAX,VEMIN                                   DUDB31    653
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB31    654
         WRITE(MSG(2),1110)                                             DUDB31    655
         WRITE(MSG(3),1031) VEMAX,VEMIN                                 DUDB31    656
         CALL PRTMSG(3)                                                 DUDB31    657
         MSG(1)='DUDB40: UD ERROR'                                      DUDB31    658
         CALL ASTOP(MSG(1),16)                                          DUDB31    659
      ENDIF                                                             DUDB31    660
C                                                                       DUDB31    661
      IF (VE.GE.VEMAX) THEN                                             DUDB31    662
         VE=VEMAX                                                       DUDB31    663
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB31    664
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    665
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    666
         END IF                                                         DUDB31    667
      ELSE IF (VE.LE.VEMIN) THEN                                        DUDB31    668
         VE=VEMIN                                                       DUDB31    669
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB31    670
            DSTATE(LSTATE+KORD)=0.0                                     DUDB31    671
            QSTATE(JSTATE+KORD)=0.0                                     DUDB31    672
         END IF                                                         DUDB31    673
      END IF                                                            DUDB31    674
      VALOUT(IORD)=VE                                                   DUDB31    675
      VALIN(19)=VALI                                                    DUDB31    676
      IF(LDEB) WRITE(IUD6,1100) KORD,LORD,IORD,JSTATE,VALOUT(IORD)      DUDB31    677
C                                                                       DUDB31    678
      RETURN                                                            DUDB31    679
 1100 FORMAT(1X,'KORD,LORD,IORD,JSTATE,VALOUT(IORD): ',4I5,F10.3)       DUDB31    680
 1110 FORMAT(5X,'BLOCK TYPE E30 HAS XCROSSING LIMITS.')                 DUDB31    681
C                                                                       DUDB31    682
C-----------------------------------------------------------------------DUDB31    683
C                                                                       DUDB31    684
      ENTRY DUDB41(LORD,NLF,KN,CID)                                     DUDB31    685
CD                                                                      DUDB31    686
CD    FOR BLOCK TYPE 41 (TYPE E31 EXCITER END BLOCK).                   DUDB31    687
CD                                                                      DUDB31    688
      LDEB=(JDEB(264).NE.0)                                             DUDB31    689
C                                                                       DUDB31    690
      IORD=IDDAT(JE4+LORD)                                              DUDB31    691
      JEI=JEB+2                                                         DUDB31    692
      KINT=KINPU                                                        DUDB31    693
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    694
      IF(KINT.LT.KINPU) THEN                                            DUDB31    695
         J=KINT+1                                                       DUDB31    696
         XDAT=GAINS(J)                                                  DUDB31    697
         IOUT=INPUTS(J)                                                 DUDB31    698
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    699
         GO TO 220                                                      DUDB31    700
      ENDIF                                                             DUDB31    701
      KINP=KINPU                                                        DUDB31    702
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    703
      IF(KINP.LT.KINPU) THEN                                            DUDB31    704
         J=KINP+1                                                       DUDB31    705
         XDAT=GAINS(J)                                                  DUDB31    706
         IIN=INPUTS(J)                                                  DUDB31    707
         VALI=VALIN(IIN)*XDAT                                           DUDB31    708
      ENDIF                                                             DUDB31    709
  220 CONTINUE                                                          DUDB31    710
C                                                                       DUDB31    711
      VALIN(19)=VALI                                                    DUDB31    712
      VAMAX=DDAT(JEI+2)                                                 DUDB31    713
      VALI=VALI*DDAT(JEI+1)/VAMAX                                       DUDB31    714
      PHIMAX=DDAT(JEI+3)                                                DUDB31    715
      PHIMIN=DDAT(JEI+4)                                                DUDB31    716
      IF (VALI.GT.PHIMAX) THEN                                          DUDB31    717
         VALI=PHIMAX                                                    DUDB31    718
      ELSE IF (VALI.LT.PHIMIN) THEN                                     DUDB31    719
         VALI=PHIMIN                                                    DUDB31    720
      END IF                                                            DUDB31    721
      VALI=SIN(VALI)                                                    DUDB31    722
      VALOUT(IORD)=VALI*(VALIN(4)*VAMAX-DDAT(JEI+6)*VALIN(16))          DUDB31    723
      IF(LDEB) WRITE(IUD6,1120) LORD,IORD,VALOUT(IORD)                  DUDB31    724
C                                                                       DUDB31    725
      RETURN                                                            DUDB31    726
 1120 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB31    727
C                                                                       DUDB31    728
C-----------------------------------------------------------------------DUDB31    729
C                                                                       DUDB31    730
      ENTRY DUDB42(LORD,NLF1,KN,CID)                                    DUDB31    731
CD                                                                      DUDB31    732
CD    FOR BLOCK TYPE 42 (TYPE E34 EXCITER END BLOCK).                   DUDB31    733
CD                                                                      DUDB31    734
      LDEB=(JDEB(264).NE.0)                                             DUDB31    735
C                                                                       DUDB31    736
      IORD=IDDAT(JE4+LORD)                                              DUDB31    737
      JEI=JEB+2                                                         DUDB31    738
      KINT=KINPU                                                        DUDB31    739
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    740
      IF(KINT.LT.KINPU) THEN                                            DUDB31    741
         J=KINT+1                                                       DUDB31    742
         XDAT=GAINS(J)                                                  DUDB31    743
         IOUT=INPUTS(J)                                                 DUDB31    744
         VALI=VALOUT(IOUT)*XDAT                                         DUDB31    745
         GO TO 230                                                      DUDB31    746
      ENDIF                                                             DUDB31    747
      KINP=KINPU                                                        DUDB31    748
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    749
      IF(KINP.LT.KINPU) THEN                                            DUDB31    750
         J=KINP+1                                                       DUDB31    751
         XDAT=GAINS(J)                                                  DUDB31    752
         IIN=INPUTS(J)                                                  DUDB31    753
         VALI=VALIN(IIN)*XDAT                                           DUDB31    754
      ENDIF                                                             DUDB31    755
  230 CONTINUE                                                          DUDB31    756
C                                                                       DUDB31    757
      VALIN(19)=VALI                                                    DUDB31    758
      VTX=VALIN(4)                                                      DUDB31    759
      VEMAX=VTX*DDAT(JEI+3)-DDAT(JEI+6)*VALIN(16)                       DUDB31    760
      VEMIN=VTX*DDAT(JEI+4)                                             DUDB31    761
      IF(VEMAX.LE.VEMIN) THEN                                           DUDB31    762
C         WRITE(IU6,1140)                                               DUDB31    763
C         WRITE(IU6,1031) VEMAX,VEMIN                                   DUDB31    764
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB31    765
         WRITE(MSG(2),1140)                                             DUDB31    766
         WRITE(MSG(3),1031) VEMAX,VEMIN                                 DUDB31    767
         CALL PRTMSG(3)                                                 DUDB31    768
         MSG(1)='DUDB42: UD ERROR'                                      DUDB31    769
         CALL ASTOP(MSG(1),16)                                          DUDB31    770
      ENDIF                                                             DUDB31    771
      IF (VALI.GT.VEMAX) THEN                                           DUDB31    772
         VALI=VEMAX                                                     DUDB31    773
      ELSE IF (VALI.LT.VEMIN) THEN                                      DUDB31    774
         VALI=VEMIN                                                     DUDB31    775
      END IF                                                            DUDB31    776
      VALOUT(IORD)=VALI                                                 DUDB31    777
      IF(LDEB) WRITE(IUD6,1130) LORD,IORD,VALOUT(IORD)                  DUDB31    778
C                                                                       DUDB31    779
      RETURN                                                            DUDB31    780
 1130 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB31    781
 1140 FORMAT(5X,'BLOCK TYPE E34 HAS XCROSSING LIMITS.')                 DUDB31    782
C                                                                       DUDB31    783
C-----------------------------------------------------------------------DUDB31    784
C                                                                       DUDB31    785
      ENTRY DUDB43(LORD,NLF1,KN,CID)                                    DUDB31    786
CD                                                                      DUDB31    787
CD    FOR BLOCK TYPE 43 (TYPE RHL EXCITER END BLOCK).                   DUDB31    788
CD                                                                      DUDB31    789
      LDEB=(JDEB(264).NE.0)                                             DUDB31    790
C                                                                       DUDB31    791
      IORD=IDDAT(JE4+LORD)                                              DUDB31    792
      JEI=JEB+2                                                         DUDB31    793
      II=0                                                              DUDB31    794
      VALI2=0.0                                                         DUDB31    795
      KINT=KINPU                                                        DUDB31    796
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    797
      IF(KINT.LT.KINPU) THEN                                            DUDB31    798
         DO 240 J=KINT+1,KINPU                                          DUDB31    799
         XDAT=GAINS(J)                                                  DUDB31    800
         IOUT=INPUTS(J)                                                 DUDB31    801
         II=II+1                                                        DUDB31    802
         IF(II.EQ.1) THEN                                               DUDB31    803
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB31    804
            GO TO 240                                                   DUDB31    805
         ENDIF                                                          DUDB31    806
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB31    807
  240    CONTINUE                                                       DUDB31    808
      ENDIF                                                             DUDB31    809
      KINP=KINPU                                                        DUDB31    810
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    811
      IF(KINP.LT.KINPU) THEN                                            DUDB31    812
         DO 250 J=KINP+1,KINPU                                          DUDB31    813
         XDAT=GAINS(J)                                                  DUDB31    814
         IIN=INPUTS(J)                                                  DUDB31    815
         II=II+1                                                        DUDB31    816
         IF(II.EQ.1) THEN                                               DUDB31    817
            VALI1=VALIN(IIN)*XDAT                                       DUDB31    818
            GO TO 250                                                   DUDB31    819
         ENDIF                                                          DUDB31    820
         VALI2=VALIN(IIN)*XDAT                                          DUDB31    821
  250    CONTINUE                                                       DUDB31    822
      ENDIF                                                             DUDB31    823
C                                                                       DUDB31    824
      AKV=DDAT(JEI+1)                                                   DUDB31    825
      IF (VALI2.GT.AKV) THEN                                            DUDB31    826
         VR=DDAT(JEI+2)                                                 DUDB31    827
      ELSE IF (VALI2.LT.-AKV) THEN                                      DUDB31    828
         VR=DDAT(JEI+3)                                                 DUDB31    829
      ELSE                                                              DUDB31    830
         VR=VALI1                                                       DUDB31    831
      END IF                                                            DUDB31    832
      VALOUT(IORD)=VR                                                   DUDB31    833
      IF(LDEB) WRITE(IUD6,1150) LORD,IORD,VALOUT(IORD)                  DUDB31    834
C                                                                       DUDB31    835
      RETURN                                                            DUDB31    836
 1150 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB31    837
C                                                                       DUDB31    838
C-----------------------------------------------------------------------DUDB31    839
C                                                                       DUDB31    840
      ENTRY DUDB71(LORD,KORD,NLF1,KN,CID)                               DUDB31    841
CD                                                                      DUDB31    842
CD    FOR BLOCK TYPE 71 (FEEDBACK LOOP EXCITER END BLOCK).              DUDB31    843
CD                                                                      DUDB31    844
      LDEB=(JDEB(264).NE.0)                                             DUDB31    845
C                                                                       DUDB31    846
      VALI=0.0                                                          DUDB31    847
      IORD=IDDAT(JE4+LORD)                                              DUDB31    848
      JEI=JEB+2                                                         DUDB31    849
      KINT=KINPU                                                        DUDB31    850
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB31    851
      IF(KINT.LT.KINPU) THEN                                            DUDB31    852
         DO 260 J=KINT+1,KINPU                                          DUDB31    853
         XDAT=GAINS(J)                                                  DUDB31    854
         IOUT=INPUTS(J)                                                 DUDB31    855
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB31    856
  260    CONTINUE                                                       DUDB31    857
      ENDIF                                                             DUDB31    858
      KINP=KINPU                                                        DUDB31    859
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB31    860
      IF(KINP.LT.KINPU) THEN                                            DUDB31    861
         DO 270 J=KINP+1,KINPU                                          DUDB31    862
         XDAT=GAINS(J)                                                  DUDB31    863
         IIN=INPUTS(J)                                                  DUDB31    864
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB31    865
  270    CONTINUE                                                       DUDB31    866
      ENDIF                                                             DUDB31    867
C                                                                       DUDB31    868
      KORD=KORD+2                                                       DUDB31    869
      VALX=XSTATE(JSTATE+KORD-1)                                        DUDB31    870
      VALX1=VALX                                                        DUDB31    871
      LL2=IDDAT(JEI+12)                                                 DUDB31    872
      IF (LL2.EQ.0) THEN                                                DUDB31    873
         VMAX2=DDAT(JEI+9)                                              DUDB31    874
         VMIN2=DDAT(JEI+10)                                             DUDB31    875
         IF (VALX1.GT.VMAX2) THEN                                       DUDB31    876
            VALX1=VMAX2                                                 DUDB31    877
         ELSE IF (VALX1.LT.VMIN2) THEN                                  DUDB31    878
            VALX1=VMIN2                                                 DUDB31    879
         END IF                                                         DUDB31    880
      END IF                                                            DUDB31    881
      VALI=VALI+VALX1                                                   DUDB31    882
      IF (IDDAT(JEI+3).EQ.0.OR.DDAT(JEI+3).EQ.DDAT(JEI+2)) THEN         DUDB31    883
         DSTATE(LSTATE+KORD)=0.0                                        DUDB31    884
         VALO=VALI*DDAT(JEI+1)                                          DUDB31    885
      ELSE                                                              DUDB31    886
         TRATIO=DDAT(JEI+2)/DDAT(JEI+3)                                 DUDB31    887
         VALI=VALI*DDAT(JEI+1)                                          DUDB31    888
         VALI1=VALI*(1.0-TRATIO)                                        DUDB31    889
         VALI2=VALI*TRATIO                                              DUDB31    890
         DSTATE(LSTATE+KORD)=(VALI1-XSTATE(JSTATE+KORD))/DDAT(JEI+3)    DUDB31    891
         VALO=XSTATE(JSTATE+KORD)+VALI2                                 DUDB31    892
      END IF                                                            DUDB31    893
      VALOUT(IORD)=VALO                                                 DUDB31    894
      VALO=VALO*DDAT(JEI+4)                                             DUDB31    895
      LL1=IDDAT(JEI+11)                                                 DUDB31    896
      IF (LL1.EQ.0) THEN                                                DUDB31    897
         VMAX1=DDAT(JEI+7)                                              DUDB31    898
         VMIN1=DDAT(JEI+8)                                              DUDB31    899
         IF (VALO.GT.VMAX1) THEN                                        DUDB31    900
            VALO=VMAX1                                                  DUDB31    901
         ELSE IF (VALO.LT.VMIN1) THEN                                   DUDB31    902
            VALO=VMIN1                                                  DUDB31    903
         END IF                                                         DUDB31    904
      END IF                                                            DUDB31    905
C                                                                       DUDB31    906
      DSTATE(LSTATE+KORD-1)=VALO*DDAT(JEI+5)                            DUDB31    907
      IF (LL2.EQ.0) THEN                                                DUDB31    908
         IF (VALX.GE.VMAX2) THEN                                        DUDB31    909
            IF (DSTATE(LSTATE+KORD-1).GT.0.0) THEN                      DUDB31    910
               DSTATE(LSTATE+KORD-1)=0.0                                DUDB31    911
               QSTATE(JSTATE+KORD-1)=0.0                                DUDB31    912
            END IF                                                      DUDB31    913
         ELSE IF (VALX.LT.VMIN2) THEN                                   DUDB31    914
            IF (DSTATE(LSTATE+KORD-1).LT.0.0) THEN                      DUDB31    915
               DSTATE(LSTATE+KORD-1)=0.0                                DUDB31    916
               QSTATE(JSTATE+KORD-1)=0.0                                DUDB31    917
            END IF                                                      DUDB31    918
         END IF                                                         DUDB31    919
      END IF                                                            DUDB31    920
C                                                                       DUDB31    921
      IF(LDEB) WRITE(IUD6,1160) KORD,LORD,IORD,VALOUT(IORD)             DUDB31    922
C                                                                       DUDB31    923
      RETURN                                                            DUDB31    924
 1160 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB31    925
 2000 FORMAT(' *** ERROR USER DEFINED MODEL AT BUS:',I6,' STATION: '    DUDB31    926
     *,3A4,' ID:',A4)                                                   DUDB31    927
      END                                                               DUDB31    928
