CFPRIME DUDB48                                                          DUDB48      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 DUDB48(LORD,KORD,NLF1,K13,CID)                         DUDB48      3
CD                                                                      DUDB48      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK  DUDB48      5
CD    TYPE 48 (TYPE OF2 END BLOCK) IN A USER DEFINED FACTS MODEL, USED  DUDB48      6
CD    BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                       DUDB48      7
CD                                                                      DUDB48      8
CD    EACH ENTRY POINT IN THIS SUBROUTINE HAS SIMILAR FUNCTION AND IS   DUDB48      9
CD    FOR A DIFFERENT TYPE OF FACTS DEVICE END BLOCK APPLICABLE TO A    DUDB48     10
CD    USER DEFINED FACTS MODEL (SVC, RANI, STC/SPS, SDB).               DUDB48     11
CD                                                                      DUDB48     12
      INCLUDE 'PARX.INS'                                                DUDB48     13
      INCLUDE 'CNPARX.INS'                                              DUDB48     14
      INCLUDE 'CNB4.INS'                                                DUDB48     15
      INCLUDE 'CNMDAT.INS'                                              DUDB48     16
      INCLUDE 'CNMSTA.INS'                                              DUDB48     17
      INCLUDE 'CNXSTA.INS'                                              DUDB48     18
      INCLUDE 'CNQSTA.INS'                                              DUDB48     19
      INCLUDE 'CNSTN.INS'                                               DUDB48     20
      INCLUDE 'CNYVAR.INS'                                              DUDB48     21
      INCLUDE 'CNUNIT.INS'                                              DUDB48     22
      INCLUDE 'CNFLAG.INS'                                              DUDB48     23
      INCLUDE 'CNUDM.INS'                                               DUDB48     24
      INCLUDE 'CNMSG.INS'                                               DUDB48     25
C                                                                       DUDB48     26
      CHARACTER*2 CID                                                   DUDB48     27
C                                                                       DUDB48     28
      LDEB=(JDEB(264).NE.0)                                             DUDB48     29
C                                                                       DUDB48     30
      IORD=IDDAT(JE4+LORD)                                              DUDB48     31
      JEI=JEB+2                                                         DUDB48     32
      UHX=DDAT(JEI+1)                                                   DUDB48     33
      UMX=DDAT(JEI+2)                                                   DUDB48     34
      ULX=DDAT(JEI+3)                                                   DUDB48     35
      XLX=DDAT(JEI+4)                                                   DUDB48     36
      TFX=DDAT(JEI+5)                                                   DUDB48     37
      II=0                                                              DUDB48     38
      VALI2=0.0                                                         DUDB48     39
      KINT=KINPU                                                        DUDB48     40
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48     41
      IF(KINT.LT.KINPU) THEN                                            DUDB48     42
         DO 110 J=KINT+1,KINPU                                          DUDB48     43
         XDAT=GAINS(J)                                                  DUDB48     44
         IOUT=INPUTS(J)                                                 DUDB48     45
         II=II+1                                                        DUDB48     46
         IF(II.EQ.1) THEN                                               DUDB48     47
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB48     48
            GO TO 110                                                   DUDB48     49
         ENDIF                                                          DUDB48     50
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB48     51
  110    CONTINUE                                                       DUDB48     52
      ENDIF                                                             DUDB48     53
      KINP=KINPU                                                        DUDB48     54
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48     55
      IF(KINP.LT.KINPU) THEN                                            DUDB48     56
         DO 120 J=KINP+1,KINPU                                          DUDB48     57
         XDAT=GAINS(J)                                                  DUDB48     58
         IIN=INPUTS(J)                                                  DUDB48     59
         II=II+1                                                        DUDB48     60
         IF(II.EQ.1) THEN                                               DUDB48     61
            VALI1=VALIN(IIN)*XDAT                                       DUDB48     62
            GO TO 120                                                   DUDB48     63
         ENDIF                                                          DUDB48     64
         VALI2=VALIN(IIN)*XDAT                                          DUDB48     65
  120    CONTINUE                                                       DUDB48     66
      ENDIF                                                             DUDB48     67
C                                                                       DUDB48     68
      VMAX=1.0-XLX                                                      DUDB48     69
      VMIN=-XLX                                                         DUDB48     70
      XX=VMIN                                                           DUDB48     71
      IF(VALI2.GE.UHX) THEN                                             DUDB48     72
         XX=VMAX                                                        DUDB48     73
         GO TO 130                                                      DUDB48     74
      ENDIF                                                             DUDB48     75
      IF(VALI2.LE.ULX) THEN                                             DUDB48     76
         XX=VMAX                                                        DUDB48     77
         IDDAT(JEI+6)=1                                                 DUDB48     78
         GO TO 130                                                      DUDB48     79
      ENDIF                                                             DUDB48     80
      IF(IDDAT(JEI+6).EQ.1)THEN                                         DUDB48     81
         IF(VALI2.LE.UMX) THEN                                          DUDB48     82
            XX=VMAX                                                     DUDB48     83
         ELSE                                                           DUDB48     84
            IDDAT(JEI+6)=0                                              DUDB48     85
         ENDIF                                                          DUDB48     86
      ENDIF                                                             DUDB48     87
  130 CONTINUE                                                          DUDB48     88
      KORD=KORD+1                                                       DUDB48     89
      DSTATE(LSTATE+KORD)=XX/TFX                                        DUDB48     90
      VALO=XSTATE(JSTATE+KORD)                                          DUDB48     91
      IF (VALO.GE.VMAX) THEN                                            DUDB48     92
         VALO=VMAX                                                      DUDB48     93
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48     94
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48     95
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48     96
         END IF                                                         DUDB48     97
      ELSE IF (VALO.LE.VMIN) THEN                                       DUDB48     98
         VALO=VMIN                                                      DUDB48     99
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    100
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    101
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    102
         END IF                                                         DUDB48    103
      END IF                                                            DUDB48    104
      XX1=VALO+XLX                                                      DUDB48    105
      XX2=XX+XLX                                                        DUDB48    106
      IF(XX2.LT.XX1) XX2=XX1                                            DUDB48    107
      XX2=XX2-0.00001                                                   DUDB48    108
      IF(VALI1.GT.1.0) THEN                                             DUDB48    109
         VALI1=1.0                                                      DUDB48    110
         GO TO 150                                                      DUDB48    111
      ENDIF                                                             DUDB48    112
      IF(VALI1.LT.0.0) VALI1=0.0                                        DUDB48    113
  150 IF(VALI1.GE.XX2) THEN                                             DUDB48    114
         IF(IDDAT(JEI+7).EQ.1)THEN                                      DUDB48    115
            IDDAT(JEI+7)=0                                              DUDB48    116
            IF(BLNAM1(1:1).EQ.'P')THEN                                  DUDB48    117
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    118
                WRITE(MSG(2),1010) IORD                                 DUDB48    119
                WRITE(MSG(3),1020) TS,VALI1                             DUDB48    120
                CALL PRTMSG(3)                                          DUDB48    121
            ENDIF                                                       DUDB48    122
         ENDIF                                                          DUDB48    123
         GO TO 160                                                      DUDB48    124
      ENDIF                                                             DUDB48    125
      IF(VALI1.LT.XX2) THEN                                             DUDB48    126
         VALI1=XX2                                                      DUDB48    127
         IF(IDDAT(JEI+7).EQ.0)THEN                                      DUDB48    128
            IDDAT(JEI+7)=1                                              DUDB48    129
            IF(BLNAM1(1:1).EQ.'P')THEN                                  DUDB48    130
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    131
                WRITE(MSG(2),1010) IORD                                 DUDB48    132
                WRITE(MSG(3),1011) TS,VALI1                             DUDB48    133
                CALL PRTMSG(3)                                          DUDB48    134
            ENDIF                                                       DUDB48    135
         ENDIF                                                          DUDB48    136
      ENDIF                                                             DUDB48    137
  160 VALOUT(IORD)=VALI1                                                DUDB48    138
      IF(LDEB) WRITE(IUD6,1000) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    139
C                                                                       DUDB48    140
      RETURN                                                            DUDB48    141
 1000 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB48    142
 1010 FORMAT(5X,'OF2 BLOCK (BL# ',I2,'): OVERRIDE SIGNAL')              DUDB48    143
 1011 FORMAT(5X,'STARTS AT T=',F11.4,' SEC.    OUTPUT=',F8.3)           DUDB48    144
 1020 FORMAT(5X,'ENDS AT T=',F11.4,' SEC.    OUTPUT=',F8.3)             DUDB48    145
C                                                                       DUDB48    146
C-----------------------------------------------------------------------DUDB48    147
C                                                                       DUDB48    148
      ENTRY DUDB49(LORD,NLF1,K13,CID)                                   DUDB48    149
CD                                                                      DUDB48    150
CD    FOR BLOCK TYPE 49 (TYPE OF1 END BLOCK).                           DUDB48    151
CD                                                                      DUDB48    152
      LDEB=(JDEB(264).NE.0)                                             DUDB48    153
C                                                                       DUDB48    154
      IORD=IDDAT(JE4+LORD)                                              DUDB48    155
      JEI=JEB+2                                                         DUDB48    156
      DVH=DDAT(JEI+1)                                                   DUDB48    157
      DVL=DDAT(JEI+2)                                                   DUDB48    158
      XKH=DDAT(JEI+3)                                                   DUDB48    159
      XKL=DDAT(JEI+4)                                                   DUDB48    160
      VHX=DDAT(JEI+5)                                                   DUDB48    161
      VLX=DDAT(JEI+6)                                                   DUDB48    162
      II=0                                                              DUDB48    163
      VALI2=0.0                                                         DUDB48    164
      KINT=KINPU                                                        DUDB48    165
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    166
      IF(KINT.LT.KINPU) THEN                                            DUDB48    167
         DO 170 J=KINT+1,KINPU                                          DUDB48    168
         XDAT=GAINS(J)                                                  DUDB48    169
         IOUT=INPUTS(J)                                                 DUDB48    170
         II=II+1                                                        DUDB48    171
         IF(II.EQ.1) THEN                                               DUDB48    172
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB48    173
            GO TO 170                                                   DUDB48    174
         ENDIF                                                          DUDB48    175
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB48    176
  170    CONTINUE                                                       DUDB48    177
      ENDIF                                                             DUDB48    178
      KINP=KINPU                                                        DUDB48    179
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    180
      IF(KINP.LT.KINPU) THEN                                            DUDB48    181
         DO 180 J=KINP+1,KINPU                                          DUDB48    182
         XDAT=GAINS(J)                                                  DUDB48    183
         IIN=INPUTS(J)                                                  DUDB48    184
         II=II+1                                                        DUDB48    185
         IF(II.EQ.1) THEN                                               DUDB48    186
            VALI1=VALIN(IIN)*XDAT                                       DUDB48    187
            GO TO 180                                                   DUDB48    188
         ENDIF                                                          DUDB48    189
         VALI2=VALIN(IIN)*XDAT                                          DUDB48    190
  180    CONTINUE                                                       DUDB48    191
      ENDIF                                                             DUDB48    192
C                                                                       DUDB48    193
      IF(VALI1.GT.1.0) THEN                                             DUDB48    194
         VALI1=1.0                                                      DUDB48    195
         GO TO 190                                                      DUDB48    196
      ENDIF                                                             DUDB48    197
      IF(VALI1.LT.0.0) VALI1=0.0                                        DUDB48    198
  190 IF(VALI2.LT.DVH.AND.VALI2.GT.DVL) THEN                            DUDB48    199
         IF(IDDAT(JEI+7).EQ.1) THEN                                     DUDB48    200
            IDDAT(JEI+7)=0                                              DUDB48    201
            IF(BLNAM1(1:1).EQ.'P')THEN                                  DUDB48    202
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    203
               WRITE(MSG(2),1110) IORD                                  DUDB48    204
               WRITE(MSG(3),1020) TS,VALI1                              DUDB48    205
               CALL PRTMSG(3)                                           DUDB48    206
            ENDIF                                                       DUDB48    207
         ENDIF                                                          DUDB48    208
         GO TO 200                                                      DUDB48    209
      ENDIF                                                             DUDB48    210
      IF(VALI2.GE.DVH) THEN                                             DUDB48    211
         UHX=VHX+XKH*(VALI2-DVH)                                        DUDB48    212
         IF(UHX.GT.0.99999) UHX=0.99999                                 DUDB48    213
         IF(UHX.GT.VALI1) THEN                                          DUDB48    214
            VALI1=UHX                                                   DUDB48    215
            IF(IDDAT(JEI+7).EQ.0)THEN                                   DUDB48    216
               IDDAT(JEI+7)=1                                           DUDB48    217
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB48    218
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    219
                  WRITE(MSG(2),1110) IORD                               DUDB48    220
                  WRITE(MSG(3),1011) TS,VALI1                           DUDB48    221
                  CALL PRTMSG(3)                                        DUDB48    222
               ENDIF                                                    DUDB48    223
            ENDIF                                                       DUDB48    224
         ENDIF                                                          DUDB48    225
         GO TO 200                                                      DUDB48    226
      ENDIF                                                             DUDB48    227
      IF(VALI2.LE.DVL) THEN                                             DUDB48    228
         ULX=VLX+XKL*(VALI2-DVL)                                        DUDB48    229
         IF(ULX.LT.0.0000001) ULX=0.0000001                             DUDB48    230
         IF(ULX.LT.VALI1) THEN                                          DUDB48    231
            VALI1=ULX                                                   DUDB48    232
            IF(IDDAT(JEI+7).EQ.0)THEN                                   DUDB48    233
               IDDAT(JEI+7)=1                                           DUDB48    234
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB48    235
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    236
                  WRITE(MSG(2),1110) IORD                               DUDB48    237
                  WRITE(MSG(3),1011) TS,VALI1                           DUDB48    238
                  CALL PRTMSG(3)                                        DUDB48    239
               ENDIF                                                    DUDB48    240
            ENDIF                                                       DUDB48    241
         ENDIF                                                          DUDB48    242
      ENDIF                                                             DUDB48    243
  200 VALOUT(IORD)=VALI1                                                DUDB48    244
      IF(LDEB) WRITE(IUD6,1100) LORD,IORD,VALOUT(IORD)                  DUDB48    245
C                                                                       DUDB48    246
      RETURN                                                            DUDB48    247
 1100 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB48    248
 1110 FORMAT(5X,'OF1 BLOCK (BL# ',I2,'): OVERRIDE SIGNAL')              DUDB48    249
C                                                                       DUDB48    250
C-----------------------------------------------------------------------DUDB48    251
C                                                                       DUDB48    252
      ENTRY DUDB50(LORD,NLF1,K13,CID)                                   DUDB48    253
CD                                                                      DUDB48    254
CD    FOR BLOCK TYPE 50 (TYPE LF END BLOCK).                            DUDB48    255
CD                                                                      DUDB48    256
      LDEB=(JDEB(264).NE.0)                                             DUDB48    257
C                                                                       DUDB48    258
      IORD=IDDAT(JE4+LORD)                                              DUDB48    259
      JEI=JEB+2                                                         DUDB48    260
      KINPU=KINPU+1                                                     DUDB48    261
      XDAT=GAINS(KINPU)                                                 DUDB48    262
      IOUT=INPUTS(KINPU)                                                DUDB48    263
      VALI=VALOUT(IOUT)*XDAT                                            DUDB48    264
      VALI2=VALI                                                        DUDB48    265
C                                                                       DUDB48    266
      IF(VALI.GT.1.0) THEN                                              DUDB48    267
         VALI=1.0                                                       DUDB48    268
         GO TO 210                                                      DUDB48    269
      ENDIF                                                             DUDB48    270
      IF(VALI.GT.0.8016368) THEN                                        DUDB48    271
         VALI=0.9+(VALI-0.8016368)*0.5041259                            DUDB48    272
         GO TO 210                                                      DUDB48    273
      ENDIF                                                             DUDB48    274
      IF(VALI.GT.0.6129021) THEN                                        DUDB48    275
         VALI=0.8+(VALI-0.6129021)*0.5298444                            DUDB48    276
         GO TO 210                                                      DUDB48    277
      ENDIF                                                             DUDB48    278
      IF(VALI.GT.0.4424819) THEN                                        DUDB48    279
         VALI=0.7+(VALI-0.4424819)*0.5867849                            DUDB48    280
         GO TO 210                                                      DUDB48    281
      ENDIF                                                             DUDB48    282
      IF(VALI.GT.0.2972693) THEN                                        DUDB48    283
         VALI=0.6+(VALI-0.2972693)*0.6886455                            DUDB48    284
         GO TO 210                                                      DUDB48    285
      ENDIF                                                             DUDB48    286
      IF(VALI.GT.0.1816901) THEN                                        DUDB48    287
         VALI=0.5+(VALI-0.1816901)*0.8652077                            DUDB48    288
         GO TO 210                                                      DUDB48    289
      ENDIF                                                             DUDB48    290
      IF(VALI.GT.0.0972693) THEN                                        DUDB48    291
         VALI=0.4+(VALI-0.0972693)*1.1845423                            DUDB48    292
         GO TO 210                                                      DUDB48    293
      ENDIF                                                             DUDB48    294
      IF(VALI.GT.0.0424819) THEN                                        DUDB48    295
         VALI=0.3+(VALI-0.0424819)*1.8252369                            DUDB48    296
         GO TO 210                                                      DUDB48    297
      ENDIF                                                             DUDB48    298
      IF(VALI.GT.0.0129021) THEN                                        DUDB48    299
         VALI=0.2+(VALI-0.0129021)*3.3806904                            DUDB48    300
         GO TO 210                                                      DUDB48    301
      ENDIF                                                             DUDB48    302
      IF(VALI.GT.0.0016368) THEN                                        DUDB48    303
         VALI=0.1+(VALI-0.0016368)*8.8768443                            DUDB48    304
         GO TO 210                                                      DUDB48    305
      ENDIF                                                             DUDB48    306
      IF(VALI.GT.0.0) THEN                                              DUDB48    307
         VALI=VALI*61.094819                                            DUDB48    308
         GO TO 210                                                      DUDB48    309
      ENDIF                                                             DUDB48    310
      VALI=0.0                                                          DUDB48    311
  210 VALOUT(IORD)=VALI                                                 DUDB48    312
C      WS1=0.0                                                          DUDB48    313
C      IF (ABS(VALI2).GT.1.0E-4) WS1=VALI/VALI2                         DUDB48    314
C      DDAT(JEI+8)=WS1                                                  DUDB48    315
       IF(VALI.GT.0.0001) THEN                                          DUDB48    316
          DDAT(JEI+8)=1.0/(1.0-COS(PII*VALI))                           DUDB48    317
       ELSE                                                             DUDB48    318
          DDAT(JEI+8)=1.0/(1.0-COS(PII*0.0001))                         DUDB48    319
       ENDIF                                                            DUDB48    320
      IF(LDEB) WRITE(IUD6,1150) LORD,IORD,VALOUT(IORD)                  DUDB48    321
C                                                                       DUDB48    322
      RETURN                                                            DUDB48    323
 1150 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB48    324
C                                                                       DUDB48    325
C-----------------------------------------------------------------------DUDB48    326
C                                                                       DUDB48    327
      ENTRY DUDB51(LORD,NLF1,K13,CID)                                   DUDB48    328
CD                                                                      DUDB48    329
CD    FOR BLOCK TYPE 51 (TYPE SD1 END BLOCK).                           DUDB48    330
CD                                                                      DUDB48    331
      LDEB=(JDEB(264).NE.0)                                             DUDB48    332
C                                                                       DUDB48    333
      IORD=IDDAT(JE4+LORD)                                              DUDB48    334
      JEI=JEB+2                                                         DUDB48    335
      KINT=KINPU                                                        DUDB48    336
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    337
      IF(KINT.LT.KINPU) THEN                                            DUDB48    338
         J=KINT+1                                                       DUDB48    339
         XDAT=GAINS(J)                                                  DUDB48    340
         IOUT=INPUTS(J)                                                 DUDB48    341
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    342
         GO TO 220                                                      DUDB48    343
      ENDIF                                                             DUDB48    344
      KINP=KINPU                                                        DUDB48    345
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    346
      IF(KINP.LT.KINPU) THEN                                            DUDB48    347
         J=KINP+1                                                       DUDB48    348
         XDAT=GAINS(J)                                                  DUDB48    349
         IIN=INPUTS(J)                                                  DUDB48    350
         VALI=VALIN(IIN)*XDAT                                           DUDB48    351
      ENDIF                                                             DUDB48    352
  220 CONTINUE                                                          DUDB48    353
C                                                                       DUDB48    354
      VALIN(11)=VALI                                                    DUDB48    355
      IF(VALI.GT.1.0) THEN                                              DUDB48    356
         VALI=1.0                                                       DUDB48    357
         GO TO 230                                                      DUDB48    358
      ENDIF                                                             DUDB48    359
      IF(VALI.LT.0.0) VALI=0.0                                          DUDB48    360
  230 CONTINUE                                                          DUDB48    361
      VALIN(6)=VALI                                                     DUDB48    362
      VALI=VALI-DDAT(JEI+3)                                             DUDB48    363
      VALOUT(IORD)=VALI                                                 DUDB48    364
      IF(LDEB) WRITE(IUD6,1200) LORD,IORD,VALOUT(IORD)                  DUDB48    365
C                                                                       DUDB48    366
      RETURN                                                            DUDB48    367
 1200 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB48    368
C                                                                       DUDB48    369
C-----------------------------------------------------------------------DUDB48    370
C                                                                       DUDB48    371
      ENTRY DUDB52(LORD,KORD,NLF1,K13,CID)                              DUDB48    372
CD                                                                      DUDB48    373
CD    FOR BLOCK TYPE 52 (TYPE SD2 END BLOCK).                           DUDB48    374
CD                                                                      DUDB48    375
      LDEB=(JDEB(264).NE.0)                                             DUDB48    376
C                                                                       DUDB48    377
      IORD=IDDAT(JE4+LORD)                                              DUDB48    378
      JEI=JEB+2                                                         DUDB48    379
      TTR=DDAT(JEI+3)                                                   DUDB48    380
      KINT=KINPU                                                        DUDB48    381
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    382
      IF(KINT.LT.KINPU) THEN                                            DUDB48    383
         J=KINT+1                                                       DUDB48    384
         XDAT=GAINS(J)                                                  DUDB48    385
         IOUT=INPUTS(J)                                                 DUDB48    386
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    387
         GO TO 240                                                      DUDB48    388
      ENDIF                                                             DUDB48    389
      KINP=KINPU                                                        DUDB48    390
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    391
      IF(KINP.LT.KINPU) THEN                                            DUDB48    392
         J=KINP+1                                                       DUDB48    393
         XDAT=GAINS(J)                                                  DUDB48    394
         IIN=INPUTS(J)                                                  DUDB48    395
         VALI=VALIN(IIN)*XDAT                                           DUDB48    396
      ENDIF                                                             DUDB48    397
  240 CONTINUE                                                          DUDB48    398
C                                                                       DUDB48    399
      VALIN(11)=VALI                                                    DUDB48    400
      IF (VALI.GT.1.0) THEN                                             DUDB48    401
         VALI=1.0                                                       DUDB48    402
      ELSE IF (VALI.LT.0.0) THEN                                        DUDB48    403
         VALI=0.0                                                       DUDB48    404
      END IF                                                            DUDB48    405
      KORD=KORD+1                                                       DUDB48    406
      IF(TTR.GT.0.0) GO TO 260                                          DUDB48    407
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    408
      GO TO 270                                                         DUDB48    409
  260 DSTATE(LSTATE+KORD)=(VALI-XSTATE(JSTATE+KORD))/TTR                DUDB48    410
      VALI=XSTATE(JSTATE+KORD)                                          DUDB48    411
      IF (VALI.GE.1.0) THEN                                             DUDB48    412
         VALI=1.0                                                       DUDB48    413
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    414
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    415
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    416
         END IF                                                         DUDB48    417
      ELSE IF (VALI.LE.0.0) THEN                                        DUDB48    418
         VALI=0.0                                                       DUDB48    419
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    420
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    421
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    422
         END IF                                                         DUDB48    423
      END IF                                                            DUDB48    424
  270 CONTINUE                                                          DUDB48    425
      VALO=VALI-SIN(PII*VALI)/PII                                       DUDB48    426
      VALIN(6)=VALO                                                     DUDB48    427
      VALOUT(IORD)=VALO-DDAT(JEI+4)                                     DUDB48    428
      IF(VALI.GT.0.0001) THEN                                           DUDB48    429
         DDAT(JEI+5)=1.0-COS(PII*VALI)                                  DUDB48    430
      ELSE                                                              DUDB48    431
         DDAT(JEI+5)=1.0-COS(PII*0.0001)                                DUDB48    432
      ENDIF                                                             DUDB48    433
      IF(LDEB) WRITE(IUD6,1250) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    434
C                                                                       DUDB48    435
      RETURN                                                            DUDB48    436
 1250 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB48    437
C                                                                       DUDB48    438
C-----------------------------------------------------------------------DUDB48    439
C                                                                       DUDB48    440
      ENTRY DUDB53(LORD,KORD,STEP1,NLF1,K13,CID)                        DUDB48    441
CD                                                                      DUDB48    442
CD    FOR BLOCK TYPE 53 (TYPE SD3 END BLOCK).                           DUDB48    443
CD                                                                      DUDB48    444
      LDEB=(JDEB(264).NE.0)                                             DUDB48    445
C                                                                       DUDB48    446
      IORD=IDDAT(JE4+LORD)                                              DUDB48    447
      JEI=JEB+2                                                         DUDB48    448
      TTR=DDAT(JEI+3)                                                   DUDB48    449
      TTC=DDAT(JEI+4)                                                   DUDB48    450
      NCS=IDDAT(JEI+6)                                                  DUDB48    451
      XNCS=NCS                                                          DUDB48    452
      II=0                                                              DUDB48    453
      VALI2=0.0                                                         DUDB48    454
      KINT=KINPU                                                        DUDB48    455
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    456
      IF(KINT.LT.KINPU) THEN                                            DUDB48    457
         DO 280 J=KINT+1,KINPU                                          DUDB48    458
         XDAT=GAINS(J)                                                  DUDB48    459
         IOUT=INPUTS(J)                                                 DUDB48    460
         II=II+1                                                        DUDB48    461
         IF(II.EQ.1) THEN                                               DUDB48    462
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB48    463
            GO TO 280                                                   DUDB48    464
         ENDIF                                                          DUDB48    465
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB48    466
  280    CONTINUE                                                       DUDB48    467
      ENDIF                                                             DUDB48    468
      KINP=KINPU                                                        DUDB48    469
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    470
      IF(KINP.LT.KINPU) THEN                                            DUDB48    471
         DO 290 J=KINP+1,KINPU                                          DUDB48    472
         XDAT=GAINS(J)                                                  DUDB48    473
         IIN=INPUTS(J)                                                  DUDB48    474
         II=II+1                                                        DUDB48    475
         IF(II.EQ.1) THEN                                               DUDB48    476
            VALI1=VALIN(IIN)*XDAT                                       DUDB48    477
            GO TO 290                                                   DUDB48    478
         ENDIF                                                          DUDB48    479
         VALI2=VALIN(IIN)*XDAT                                          DUDB48    480
  290    CONTINUE                                                       DUDB48    481
      ENDIF                                                             DUDB48    482
C                                                                       DUDB48    483
      VALIN(11)=VALI1                                                   DUDB48    484
      IF (VALI1.GT.1.0) THEN                                            DUDB48    485
         VALI1=1.0                                                      DUDB48    486
      ELSE IF (VALI1.LT.0.0) THEN                                       DUDB48    487
         VALI1=0.0                                                      DUDB48    488
      END IF                                                            DUDB48    489
      KORD=KORD+1                                                       DUDB48    490
      IF(TTR.GT.0.0) GO TO 310                                          DUDB48    491
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    492
      GO TO 320                                                         DUDB48    493
  310 DSTATE(LSTATE+KORD)=(VALI1-XSTATE(JSTATE+KORD))/TTR               DUDB48    494
      VALI1=XSTATE(JSTATE+KORD)                                         DUDB48    495
      IF (VALI1.GE.1.0) THEN                                            DUDB48    496
         VALI1=1.0                                                      DUDB48    497
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    498
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    499
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    500
         END IF                                                         DUDB48    501
      ELSE IF (VALI1.LE.0.0) THEN                                       DUDB48    502
         VALI1=0.0                                                      DUDB48    503
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    504
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    505
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    506
         END IF                                                         DUDB48    507
      END IF                                                            DUDB48    508
  320 CONTINUE                                                          DUDB48    509
      IF(VALI1.GT.0.0001) THEN                                          DUDB48    510
         DDAT(JEI+11)=1.0-COS(PII*VALI1)                                DUDB48    511
      ELSE                                                              DUDB48    512
         DDAT(JEI+11)=1.0-COS(PII*0.0001)                               DUDB48    513
      ENDIF                                                             DUDB48    514
      VALI1=VALI1-SIN(PII*VALI1)/PII                                    DUDB48    515
      VALIN(6)=VALI1                                                    DUDB48    516
C                                                                       DUDB48    517
      IF(JE0.NE.0) GO TO 330                                            DUDB48    518
      IF(VALI2.GT.DDAT(JEI+7)) THEN                                     DUDB48    519
         DDAT(JEI+10)=DDAT(JEI+10)+STEP1                                DUDB48    520
         IF(DDAT(JEI+10).GE.DDAT(JEI+5)) THEN                           DUDB48    521
            IF(IDDAT(JEI+9).GT.0) THEN                                  DUDB48    522
               IDDAT(JEI+9)=IDDAT(JEI+9)-1                              DUDB48    523
               DDAT(JEI+10)=0.0                                         DUDB48    524
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB48    525
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    526
                  WRITE(MSG(2),1310) IORD                               DUDB48    527
                  WRITE(MSG(3),1311) TS,IDDAT(JEI+9),VALI2              DUDB48    528
                  CALL PRTMSG(3)                                        DUDB48    529
               ENDIF                                                    DUDB48    530
            ENDIF                                                       DUDB48    531
         ENDIF                                                          DUDB48    532
         GO TO 330                                                      DUDB48    533
      ELSE                                                              DUDB48    534
         DDAT(JEI+10)=0.0                                               DUDB48    535
      ENDIF                                                             DUDB48    536
      IF(VALI2.LT.DDAT(JEI+8)) THEN                                     DUDB48    537
         DDAT(JEI+12)=DDAT(JEI+12)+STEP1                                DUDB48    538
         IF(DDAT(JEI+12).GE.DDAT(JEI+5)) THEN                           DUDB48    539
            IF(IDDAT(JEI+9).LT.NCS) THEN                                DUDB48    540
               IDDAT(JEI+9)=IDDAT(JEI+9)+1                              DUDB48    541
               DDAT(JEI+12)=0.0                                         DUDB48    542
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB48    543
      WRITE(MSG(1),2000) NLF1,INAME(K13-2),INAME(K13-1),INAME(K13),CID  DUDB48    544
                  WRITE(MSG(2),1310) IORD                               DUDB48    545
                  WRITE(MSG(3),1320) TS,IDDAT(JEI+9),VALI2              DUDB48    546
                  CALL PRTMSG(3)                                        DUDB48    547
               ENDIF                                                    DUDB48    548
            ENDIF                                                       DUDB48    549
         ENDIF                                                          DUDB48    550
      ELSE                                                              DUDB48    551
         DDAT(JEI+12)=0.0                                               DUDB48    552
      ENDIF                                                             DUDB48    553
  330 VALI2=IDDAT(JEI+9)/XNCS                                           DUDB48    554
      KORD=KORD+1                                                       DUDB48    555
      IF(TTC.GT.0.0) GO TO 340                                          DUDB48    556
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    557
      GO TO 350                                                         DUDB48    558
  340 DSTATE(LSTATE+KORD)=(VALI2-XSTATE(JSTATE+KORD))/TTC               DUDB48    559
      VALI2=XSTATE(JSTATE+KORD)                                         DUDB48    560
      IF (VALI2.GE.1.0) THEN                                            DUDB48    561
         VALI2=1.0                                                      DUDB48    562
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    563
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    564
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    565
         END IF                                                         DUDB48    566
      ELSE IF (VALI2.LE.0.0) THEN                                       DUDB48    567
         VALI2=0.0                                                      DUDB48    568
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    569
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    570
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    571
         END IF                                                         DUDB48    572
      END IF                                                            DUDB48    573
  350 CONTINUE                                                          DUDB48    574
      VALOUT(IORD)=VALI1*DDAT(JEI+1)-VALI2*DDAT(JEI+2)                  DUDB48    575
      IF(LDEB) WRITE(IUD6,1300) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    576
C                                                                       DUDB48    577
      RETURN                                                            DUDB48    578
 1300 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB48    579
 1310 FORMAT(5X,'SD3 BLOCK (BL# ',I2,'): A TSC STEP IS DEMANDED TO')    DUDB48    580
 1311 FORMAT(5X,'BE SWITCHED OUT AT T=',F11.4,' SEC. NTSC=',I1          DUDB48    581
     *,'  STSC=',F6.3)                                                  DUDB48    582
 1320 FORMAT(5X,'BE SWITCHED IN AT T=',F11.4,' SEC. NTSC=',I1           DUDB48    583
     *,'  STSC=',F6.3)                                                  DUDB48    584
C                                                                       DUDB48    585
C-----------------------------------------------------------------------DUDB48    586
C                                                                       DUDB48    587
      ENTRY DUDB54(LORD,KORD,NLF1,K13,CID)                              DUDB48    588
CD                                                                      DUDB48    589
CD    FOR BLOCK TYPE 54 (TYPE SD4 END BLOCK).                           DUDB48    590
CD                                                                      DUDB48    591
      LDEB=(JDEB(264).NE.0)                                             DUDB48    592
C                                                                       DUDB48    593
      IORD=IDDAT(JE4+LORD)                                              DUDB48    594
      JEI=JEB+2                                                         DUDB48    595
      KINT=KINPU                                                        DUDB48    596
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    597
      IF(KINT.LT.KINPU) THEN                                            DUDB48    598
         J=KINT+1                                                       DUDB48    599
         XDAT=GAINS(J)                                                  DUDB48    600
         IOUT=INPUTS(J)                                                 DUDB48    601
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    602
         GO TO 360                                                      DUDB48    603
      ENDIF                                                             DUDB48    604
      KINP=KINPU                                                        DUDB48    605
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    606
      IF(KINP.LT.KINPU) THEN                                            DUDB48    607
         J=KINP+1                                                       DUDB48    608
         XDAT=GAINS(J)                                                  DUDB48    609
         IIN=INPUTS(J)                                                  DUDB48    610
         VALI=VALIN(IIN)*XDAT                                           DUDB48    611
      ENDIF                                                             DUDB48    612
  360 CONTINUE                                                          DUDB48    613
C                                                                       DUDB48    614
      VALIN(11)=VALI                                                    DUDB48    615
      VALIN(12)=VALI                                                    DUDB48    616
      IF(VALI.GT.1.0) THEN                                              DUDB48    617
         VALI=1.0                                                       DUDB48    618
      ELSEIF (VALI.LT.-1.0) THEN                                        DUDB48    619
         VALI=-1.0                                                      DUDB48    620
      ENDIF                                                             DUDB48    621
      TT=DDAT(JEI+1)                                                    DUDB48    622
      IPATH=IDDAT(JEI+4)                                                DUDB48    623
      KORD=KORD+1                                                       DUDB48    624
      IF(IPATH.EQ.1.OR.IPATH.EQ.2) THEN                                 DUDB48    625
         HYS=DDAT(JEI+2)                                                DUDB48    626
         NTS=IDDAT(JEI+3)                                               DUDB48    627
         STEPS=DDAT(JEI+5)                                              DUDB48    628
         XDEV=DDAT(JEI+6)                                               DUDB48    629
         ODEV=DDAT(JEI+7)                                               DUDB48    630
         TDEV=0.0                                                       DUDB48    631
         DO 370,I=1,NTS                                                 DUDB48    632
         IF(VALI.GT.0.0) THEN                                           DUDB48    633
            IF(VALI.LT.XDEV) THEN                                       DUDB48    634
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    635
                  GO TO 380                                             DUDB48    636
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    637
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    638
                     GO TO 380                                          DUDB48    639
                  ELSE                                                  DUDB48    640
                     TDEV=TDEV+STEPS                                    DUDB48    641
                     GO TO 380                                          DUDB48    642
                  ENDIF                                                 DUDB48    643
               ELSE                                                     DUDB48    644
                  TDEV=TDEV+STEPS                                       DUDB48    645
               ENDIF                                                    DUDB48    646
            ELSEIF(VALI.GT.XDEV) THEN                                   DUDB48    647
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    648
                  GO TO 380                                             DUDB48    649
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    650
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    651
                     GO TO 380                                          DUDB48    652
                  ELSE                                                  DUDB48    653
                     TDEV=TDEV+STEPS                                    DUDB48    654
                     GO TO 380                                          DUDB48    655
                  ENDIF                                                 DUDB48    656
               ELSE                                                     DUDB48    657
                  TDEV=TDEV+STEPS                                       DUDB48    658
               ENDIF                                                    DUDB48    659
            ELSE                                                        DUDB48    660
               TDEV=ODEV                                                DUDB48    661
               GO TO 380                                                DUDB48    662
            ENDIF                                                       DUDB48    663
         ELSEIF(VALI.LT.0.0) THEN                                       DUDB48    664
            IF(VALI.GT.XDEV) THEN                                       DUDB48    665
               IF(VALI.GT.TDEV-STEPS+HYS) THEN                          DUDB48    666
                  GO TO 380                                             DUDB48    667
               ELSEIF(VALI.GT.TDEV-STEPS) THEN                          DUDB48    668
                  IF(TDEV-ODEV.LT.0.5*STEPS) THEN                       DUDB48    669
                     GO TO 380                                          DUDB48    670
                  ELSE                                                  DUDB48    671
                     TDEV=TDEV-STEPS                                    DUDB48    672
                     GO TO 380                                          DUDB48    673
                  ENDIF                                                 DUDB48    674
               ELSE                                                     DUDB48    675
                  TDEV=TDEV-STEPS                                       DUDB48    676
               ENDIF                                                    DUDB48    677
            ELSEIF(VALI.LT.XDEV) THEN                                   DUDB48    678
               IF(VALI.GT.TDEV-STEPS+HYS) THEN                          DUDB48    679
                  GO TO 380                                             DUDB48    680
               ELSEIF(VALI.GT.TDEV-STEPS) THEN                          DUDB48    681
                  IF(TDEV-ODEV.LT.0.5*STEPS) THEN                       DUDB48    682
                     GO TO 380                                          DUDB48    683
                  ELSE                                                  DUDB48    684
                     TDEV=TDEV-STEPS                                    DUDB48    685
                     GO TO 380                                          DUDB48    686
                  ENDIF                                                 DUDB48    687
               ELSE                                                     DUDB48    688
                  TDEV=TDEV-STEPS                                       DUDB48    689
               ENDIF                                                    DUDB48    690
            ELSE                                                        DUDB48    691
               TDEV=ODEV                                                DUDB48    692
               GO TO 380                                                DUDB48    693
            ENDIF                                                       DUDB48    694
         ELSE                                                           DUDB48    695
            GO TO 380                                                   DUDB48    696
         ENDIF                                                          DUDB48    697
  370    CONTINUE                                                       DUDB48    698
  380    DDAT(JEI+6)=VALI                                               DUDB48    699
         DDAT(JEI+7)=TDEV                                               DUDB48    700
      ELSE                                                              DUDB48    701
         TDEV=VALI                                                      DUDB48    702
      ENDIF                                                             DUDB48    703
      IF(TT.GT.0.0) GO TO 390                                           DUDB48    704
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    705
      GO TO 400                                                         DUDB48    706
  390 DSTATE(LSTATE+KORD)=(TDEV-XSTATE(JSTATE+KORD))/TT                 DUDB48    707
      TDEV=XSTATE(JSTATE+KORD)                                          DUDB48    708
      IF (TDEV.GE.1.0) THEN                                             DUDB48    709
         TDEV=1.0                                                       DUDB48    710
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    711
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    712
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    713
         END IF                                                         DUDB48    714
      ELSE IF (TDEV.LE.-1.0) THEN                                       DUDB48    715
         TDEV=-1.0                                                      DUDB48    716
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    717
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    718
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    719
         END IF                                                         DUDB48    720
      END IF                                                            DUDB48    721
  400 VALOUT(IORD)=TDEV                                                 DUDB48    722
      IF(LDEB) WRITE(IUD6,1330) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    723
C                                                                       DUDB48    724
      RETURN                                                            DUDB48    725
 1330 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB48    726
C                                                                       DUDB48    727
C-----------------------------------------------------------------------DUDB48    728
C                                                                       DUDB48    729
      ENTRY DUDB55(LORD,KORD,NLF1,K13,CID)                              DUDB48    730
CD                                                                      DUDB48    731
CD    FOR BLOCKS TYPE 55 AND 56 (TYPE SD5 AND SD6 END BLOCKS).          DUDB48    732
CD                                                                      DUDB48    733
      LDEB=(JDEB(264).NE.0)                                             DUDB48    734
C                                                                       DUDB48    735
      IORD=IDDAT(JE4+LORD)                                              DUDB48    736
      JEI=JEB+2                                                         DUDB48    737
      KINT=KINPU                                                        DUDB48    738
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    739
      IF(KINT.LT.KINPU) THEN                                            DUDB48    740
         J=KINT+1                                                       DUDB48    741
         XDAT=GAINS(J)                                                  DUDB48    742
         IOUT=INPUTS(J)                                                 DUDB48    743
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    744
         GO TO 410                                                      DUDB48    745
      ENDIF                                                             DUDB48    746
      KINP=KINPU                                                        DUDB48    747
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    748
      IF(KINP.LT.KINPU) THEN                                            DUDB48    749
         J=KINP+1                                                       DUDB48    750
         XDAT=GAINS(J)                                                  DUDB48    751
         IIN=INPUTS(J)                                                  DUDB48    752
         VALI=VALIN(IIN)*XDAT                                           DUDB48    753
      ENDIF                                                             DUDB48    754
  410 CONTINUE                                                          DUDB48    755
C                                                                       DUDB48    756
      VALIN(12)=VALI                                                    DUDB48    757
      IF (VALI.GT.1.0) THEN                                             DUDB48    758
         VALI=1.0                                                       DUDB48    759
      ELSE IF (VALI.LT.0.0) THEN                                        DUDB48    760
         VALI=0.0                                                       DUDB48    761
      END IF                                                            DUDB48    762
      TT=DDAT(JEI+2)                                                    DUDB48    763
      IPATH=IDDAT(JEI+5)                                                DUDB48    764
      KORD=KORD+1                                                       DUDB48    765
      IF(IPATH.EQ.1.OR.IPATH.EQ.2) THEN                                 DUDB48    766
         HYS=DDAT(JEI+3)                                                DUDB48    767
         NYS=IDDAT(JEI+4)                                               DUDB48    768
         STEPS=DDAT(JEI+6)                                              DUDB48    769
         XDEV=DDAT(JEI+7)                                               DUDB48    770
         ODEV=DDAT(JEI+8)                                               DUDB48    771
         TDEV=0.0                                                       DUDB48    772
         IF(VALI.GT.0.0) THEN                                           DUDB48    773
            DO 420,I=1,NYS                                              DUDB48    774
            IF(VALI.LT.XDEV) THEN                                       DUDB48    775
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    776
                  GO TO 430                                             DUDB48    777
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    778
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    779
                     GO TO 430                                          DUDB48    780
                  ELSE                                                  DUDB48    781
                     TDEV=TDEV+STEPS                                    DUDB48    782
                     GO TO 430                                          DUDB48    783
                  ENDIF                                                 DUDB48    784
               ELSE                                                     DUDB48    785
                  TDEV=TDEV+STEPS                                       DUDB48    786
               ENDIF                                                    DUDB48    787
            ELSEIF(VALI.GT.XDEV) THEN                                   DUDB48    788
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    789
                  GO TO 430                                             DUDB48    790
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    791
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    792
                     GO TO 430                                          DUDB48    793
                  ELSE                                                  DUDB48    794
                     TDEV=TDEV+STEPS                                    DUDB48    795
                     GO TO 430                                          DUDB48    796
                  ENDIF                                                 DUDB48    797
               ELSE                                                     DUDB48    798
                  TDEV=TDEV+STEPS                                       DUDB48    799
               ENDIF                                                    DUDB48    800
            ELSE                                                        DUDB48    801
               TDEV=ODEV                                                DUDB48    802
               GO TO 430                                                DUDB48    803
            ENDIF                                                       DUDB48    804
  420       CONTINUE                                                    DUDB48    805
         ENDIF                                                          DUDB48    806
  430    DDAT(JEI+7)=VALI                                               DUDB48    807
         DDAT(JEI+8)=TDEV                                               DUDB48    808
      ELSE                                                              DUDB48    809
         TDEV=VALI                                                      DUDB48    810
      ENDIF                                                             DUDB48    811
      IF(TT.GT.0.0) GO TO 440                                           DUDB48    812
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    813
      GO TO 450                                                         DUDB48    814
  440 DSTATE(LSTATE+KORD)=(TDEV-XSTATE(JSTATE+KORD))/TT                 DUDB48    815
      TDEV=XSTATE(JSTATE+KORD)                                          DUDB48    816
      IF (TDEV.GE.1.0) THEN                                             DUDB48    817
         TDEV=1.0                                                       DUDB48    818
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    819
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    820
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    821
         END IF                                                         DUDB48    822
      ELSE IF (TDEV.LE.0.0) THEN                                        DUDB48    823
         TDEV=0.0                                                       DUDB48    824
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    825
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    826
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    827
         END IF                                                         DUDB48    828
      END IF                                                            DUDB48    829
  450 CONTINUE                                                          DUDB48    830
      VALOUT(IORD)=TDEV                                                 DUDB48    831
      IF(LDEB) WRITE(IUD6,1340) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    832
C                                                                       DUDB48    833
      RETURN                                                            DUDB48    834
 1340 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB48    835
C-----------------------------------------------------------------------DUDB48    836
C                                                                       DUDB48    837
      ENTRY DUDB57(LORD,KORD,NLF1,K13,CID)                              DUDB48    838
CD                                                                      DUDB48    839
CD    FOR BLOCK TYPE 57 (TYPE SD7 END BLOCK).                           DUDB48    840
CD                                                                      DUDB48    841
      LDEB=(JDEB(264).NE.0)                                             DUDB48    842
C                                                                       DUDB48    843
      IORD=IDDAT(JE4+LORD)                                              DUDB48    844
      JEI=JEB+2                                                         DUDB48    845
      KINT=KINPU                                                        DUDB48    846
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    847
      IF(KINT.LT.KINPU) THEN                                            DUDB48    848
         J=KINT+1                                                       DUDB48    849
         XDAT=GAINS(J)                                                  DUDB48    850
         IOUT=INPUTS(J)                                                 DUDB48    851
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    852
         GO TO 460                                                      DUDB48    853
      ENDIF                                                             DUDB48    854
      KINP=KINPU                                                        DUDB48    855
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    856
      IF(KINP.LT.KINPU) THEN                                            DUDB48    857
         J=KINP+1                                                       DUDB48    858
         XDAT=GAINS(J)                                                  DUDB48    859
         IIN=INPUTS(J)                                                  DUDB48    860
         VALI=VALIN(IIN)*XDAT                                           DUDB48    861
      ENDIF                                                             DUDB48    862
  460 CONTINUE                                                          DUDB48    863
C                                                                       DUDB48    864
      VALIN(12)=VALI                                                    DUDB48    865
      V1R=VALIN(7)*COS(VALIN(9))                                        DUDB48    866
      V1I=VALIN(7)*SIN(VALIN(9))                                        DUDB48    867
      V2R=VALIN(8)*COS(VALIN(10))                                       DUDB48    868
      V2I=VALIN(8)*SIN(VALIN(10))                                       DUDB48    869
      VDEV2=(V1R-V2R)**2+(V1I-V2I)**2                                   DUDB48    870
      VCO=DDAT(JEI+5)                                                   DUDB48    871
      IF(VCO.GT.0.00001) THEN                                           DUDB48    872
         VDEV=SQRT(VDEV2)/VCO                                           DUDB48    873
         IF(VDEV.GT.1.0) VDEV=1.0                                       DUDB48    874
      ELSE                                                              DUDB48    875
         VDEV=1.0                                                       DUDB48    876
      ENDIF                                                             DUDB48    877
      XHIG=VDEV*DDAT(JEI+9)                                             DUDB48    878
      XLOW=VDEV*DDAT(JEI+10)                                            DUDB48    879
      AX=DDAT(JEI+3)                                                    DUDB48    880
      BX=DDAT(JEI+4)                                                    DUDB48    881
      KORD=KORD+1                                                       DUDB48    882
      IF(AX.GT.0.0) GO TO 470                                           DUDB48    883
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48    884
      VALI=VALI/BX                                                      DUDB48    885
      IF(VALI.GT.XHIG) THEN                                             DUDB48    886
         VALI=XHIG                                                      DUDB48    887
         GO TO 480                                                      DUDB48    888
      ENDIF                                                             DUDB48    889
      IF(VALI.LT.XLOW) VALI=XLOW                                        DUDB48    890
      GO TO 480                                                         DUDB48    891
  470 DSTATE(LSTATE+KORD)=(VALI-BX*XSTATE(JSTATE+KORD))/AX              DUDB48    892
      DDAT(JEI+11)=XHIG                                                 DUDB48    893
      DDAT(JEI+12)=XLOW                                                 DUDB48    894
      VALI=XSTATE(JSTATE+KORD)                                          DUDB48    895
      IF (VALI.GE.XHIG) THEN                                            DUDB48    896
         VALI=XHIG                                                      DUDB48    897
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48    898
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    899
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    900
         END IF                                                         DUDB48    901
      ELSEIF(VALI.LE.XLOW) THEN                                         DUDB48    902
         VALI=XLOW                                                      DUDB48    903
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48    904
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48    905
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48    906
         ENDIF                                                          DUDB48    907
      ENDIF                                                             DUDB48    908
  480 VALOUT(IORD)=VALI                                                 DUDB48    909
C                                                                       DUDB48    910
      IF(LDEB) WRITE(IUD6,1330) KORD,LORD,IORD,VALOUT(IORD)             DUDB48    911
C                                                                       DUDB48    912
      RETURN                                                            DUDB48    913
C                                                                       DUDB48    914
C-----------------------------------------------------------------------DUDB48    915
C                                                                       DUDB48    916
      ENTRY DUDB58(LORD,KORD,NLF1,K13,CID)                              DUDB48    917
CD                                                                      DUDB48    918
CD    FOR BLOCKS TYPE 58 AND 59 (TYPE SD8 AND SD9 END BLOCKS).          DUDB48    919
CD                                                                      DUDB48    920
      LDEB=(JDEB(264).NE.0)                                             DUDB48    921
C                                                                       DUDB48    922
      IORD=IDDAT(JE4+LORD)                                              DUDB48    923
      JEI=JEB+2                                                         DUDB48    924
      KINT=KINPU                                                        DUDB48    925
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB48    926
      IF(KINT.LT.KINPU) THEN                                            DUDB48    927
         J=KINT+1                                                       DUDB48    928
         XDAT=GAINS(J)                                                  DUDB48    929
         IOUT=INPUTS(J)                                                 DUDB48    930
         VALI=VALOUT(IOUT)*XDAT                                         DUDB48    931
         GO TO 490                                                      DUDB48    932
      ENDIF                                                             DUDB48    933
      KINP=KINPU                                                        DUDB48    934
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB48    935
      IF(KINP.LT.KINPU) THEN                                            DUDB48    936
         J=KINP+1                                                       DUDB48    937
         XDAT=GAINS(J)                                                  DUDB48    938
         IIN=INPUTS(J)                                                  DUDB48    939
         VALI=VALIN(IIN)*XDAT                                           DUDB48    940
      ENDIF                                                             DUDB48    941
  490 CONTINUE                                                          DUDB48    942
C                                                                       DUDB48    943
      VALIN(12)=VALI                                                    DUDB48    944
      XHIG=DDAT(JEI+11)                                                 DUDB48    945
      XLOW=DDAT(JEI+12)                                                 DUDB48    946
      IF(VALI.GT.XHIG) THEN                                             DUDB48    947
         VALI=XHIG                                                      DUDB48    948
      ELSEIF (VALI.LT.XLOW) THEN                                        DUDB48    949
         VALI=XLOW                                                      DUDB48    950
      ENDIF                                                             DUDB48    951
      TT=DDAT(JEI+2)                                                    DUDB48    952
      IPATH=IDDAT(JEI+6)                                                DUDB48    953
      KORD=KORD+1                                                       DUDB48    954
      IF(IPATH.EQ.1.OR.IPATH.EQ.2) THEN                                 DUDB48    955
         HYS=DDAT(JEI+3)                                                DUDB48    956
         NLS=IDDAT(JEI+4)                                               DUDB48    957
         NCS=IDDAT(JEI+5)                                               DUDB48    958
         STEPS=DDAT(JEI+7)                                              DUDB48    959
         XDEV=DDAT(JEI+8)                                               DUDB48    960
         ODEV=DDAT(JEI+9)                                               DUDB48    961
         TDEV=0.0                                                       DUDB48    962
         IF(VALI.GT.0.0) THEN                                           DUDB48    963
            DO 500,I=1,NLS                                              DUDB48    964
            IF(VALI.LT.XDEV) THEN                                       DUDB48    965
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    966
                  GO TO 520                                             DUDB48    967
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    968
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    969
                     GO TO 520                                          DUDB48    970
                  ELSE                                                  DUDB48    971
                     TDEV=TDEV+STEPS                                    DUDB48    972
                     GO TO 520                                          DUDB48    973
                  ENDIF                                                 DUDB48    974
               ELSE                                                     DUDB48    975
                  TDEV=TDEV+STEPS                                       DUDB48    976
               ENDIF                                                    DUDB48    977
            ELSEIF(VALI.GT.XDEV) THEN                                   DUDB48    978
               IF(VALI.LT.TDEV+STEPS-HYS) THEN                          DUDB48    979
                  GO TO 520                                             DUDB48    980
               ELSEIF(VALI.LT.TDEV+STEPS) THEN                          DUDB48    981
                  IF(ODEV-TDEV.LT.0.5*STEPS) THEN                       DUDB48    982
                     GO TO 520                                          DUDB48    983
                  ELSE                                                  DUDB48    984
                     TDEV=TDEV+STEPS                                    DUDB48    985
                     GO TO 520                                          DUDB48    986
                  ENDIF                                                 DUDB48    987
               ELSE                                                     DUDB48    988
                  TDEV=TDEV+STEPS                                       DUDB48    989
               ENDIF                                                    DUDB48    990
            ELSE                                                        DUDB48    991
               TDEV=ODEV                                                DUDB48    992
               GO TO 520                                                DUDB48    993
            ENDIF                                                       DUDB48    994
  500       CONTINUE                                                    DUDB48    995
         ELSEIF(VALI.LT.0.0) THEN                                       DUDB48    996
            DO 510,I=1,NCS                                              DUDB48    997
            IF(VALI.GT.XDEV) THEN                                       DUDB48    998
               IF(VALI.GT.TDEV-STEPS+HYS) THEN                          DUDB48    999
                  GO TO 520                                             DUDB48   1000
               ELSEIF(VALI.GT.TDEV-STEPS) THEN                          DUDB48   1001
                  IF(TDEV-ODEV.LT.0.5*STEPS) THEN                       DUDB48   1002
                     GO TO 520                                          DUDB48   1003
                  ELSE                                                  DUDB48   1004
                     TDEV=TDEV-STEPS                                    DUDB48   1005
                     GO TO 520                                          DUDB48   1006
                  ENDIF                                                 DUDB48   1007
               ELSE                                                     DUDB48   1008
                  TDEV=TDEV-STEPS                                       DUDB48   1009
               ENDIF                                                    DUDB48   1010
            ELSEIF(VALI.LT.XDEV) THEN                                   DUDB48   1011
               IF(VALI.GT.TDEV-STEPS+HYS) THEN                          DUDB48   1012
                  GO TO 520                                             DUDB48   1013
               ELSEIF(VALI.GT.TDEV-STEPS) THEN                          DUDB48   1014
                  IF(TDEV-ODEV.LT.0.5*STEPS) THEN                       DUDB48   1015
                     GO TO 520                                          DUDB48   1016
                  ELSE                                                  DUDB48   1017
                     TDEV=TDEV-STEPS                                    DUDB48   1018
                     GO TO 520                                          DUDB48   1019
                  ENDIF                                                 DUDB48   1020
               ELSE                                                     DUDB48   1021
                  TDEV=TDEV-STEPS                                       DUDB48   1022
               ENDIF                                                    DUDB48   1023
            ELSE                                                        DUDB48   1024
               TDEV=ODEV                                                DUDB48   1025
               GO TO 520                                                DUDB48   1026
            ENDIF                                                       DUDB48   1027
  510       CONTINUE                                                    DUDB48   1028
         ENDIF                                                          DUDB48   1029
  520    DDAT(JEI+8)=VALI                                               DUDB48   1030
         DDAT(JEI+9)=TDEV                                               DUDB48   1031
      ELSE                                                              DUDB48   1032
         TDEV=VALI                                                      DUDB48   1033
      ENDIF                                                             DUDB48   1034
      IF(TT.GT.0.0) GO TO 530                                           DUDB48   1035
      DSTATE(LSTATE+KORD)=0.0                                           DUDB48   1036
      GO TO 540                                                         DUDB48   1037
  530 DSTATE(LSTATE+KORD)=(TDEV-XSTATE(JSTATE+KORD))/TT                 DUDB48   1038
      TDEV=XSTATE(JSTATE+KORD)                                          DUDB48   1039
      IF (TDEV.GE.XHIG) THEN                                            DUDB48   1040
         TDEV=XHIG                                                      DUDB48   1041
         IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                           DUDB48   1042
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48   1043
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48   1044
         END IF                                                         DUDB48   1045
      ELSE IF (TDEV.LE.XLOW) THEN                                       DUDB48   1046
         TDEV=XLOW                                                      DUDB48   1047
         IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                           DUDB48   1048
            DSTATE(LSTATE+KORD)=0.0                                     DUDB48   1049
            QSTATE(JSTATE+KORD)=0.0                                     DUDB48   1050
         END IF                                                         DUDB48   1051
      END IF                                                            DUDB48   1052
  540 VALOUT(IORD)=TDEV                                                 DUDB48   1053
      IF(LDEB) WRITE(IUD6,1330) KORD,LORD,IORD,VALOUT(IORD)             DUDB48   1054
C                                                                       DUDB48   1055
      RETURN                                                            DUDB48   1056
C                                                                       DUDB48   1057
C-----------------------------------------------------------------------DUDB48   1058
C                                                                       DUDB48   1059
 2000 FORMAT(' *** MESSAGE USER DEFINED MODEL AT BUS:',I6,' STATION: '  DUDB48   1060
     *,3A4,' ID:',A4)                                                   DUDB48   1061
      END                                                               DUDB48   1062
