CFPRIME DUDB1                                                           DUDB1       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 DUDB1(LORD,NLF1,KN,CID)                                DUDB1       3
CD                                                                      DUDB1       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF USER DEFINED BLOCK  DUDB1       5
CD    TYPE 1 (GAIN BLOCK) IN ANY USER DEFINED MODEL, USED BY BOTH       DUDB1       6
CD    RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                               DUDB1       7
CD                                                                      DUDB1       8
CD    EACH ENTRY POINT IN THIS SUBROUTINE HAS SIMILAR FUNCTION AND IS   DUDB1       9
CD    FOR A DIFFERENT TYPE OF GENERAL BLOCK APPLICABLE TO ANY USER      DUDB1      10
CD    DEFINED MODEL.                                                    DUDB1      11
CD                                                                      DUDB1      12
      INCLUDE 'PARX.INS'                                                DUDB1      13
      INCLUDE 'CNB4.INS'                                                DUDB1      14
      INCLUDE 'CNPARX.INS'                                              DUDB1      15
      INCLUDE 'CNMDAT.INS'                                              DUDB1      16
      INCLUDE 'CNMSTA.INS'                                              DUDB1      17
      INCLUDE 'CNXSTA.INS'                                              DUDB1      18
      INCLUDE 'CNQSTA.INS'                                              DUDB1      19
      INCLUDE 'CNSTN.INS'                                               DUDB1      20
      INCLUDE 'CNYVAR.INS'                                              DUDB1      21
      INCLUDE 'CNUNIT.INS'                                              DUDB1      22
      INCLUDE 'CNFLAG.INS'                                              DUDB1      23
      INCLUDE 'CNUDM.INS'                                               DUDB1      24
      INCLUDE 'CNMSG.INS'                                               DUDB1      25
C                                                                       DUDB1      26
      CHARACTER*2 CID                                                   DUDB1      27
C                                                                       DUDB1      28
      LDEB=(JDEB(264).NE.0)                                             DUDB1      29
C                                                                       DUDB1      30
      VALI=0.0                                                          DUDB1      31
      IORD=IDDAT(JE4+LORD)                                              DUDB1      32
      JEI=JEB+2                                                         DUDB1      33
      KINT=KINPU                                                        DUDB1      34
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1      35
      IF(KINT.LT.KINPU) THEN                                            DUDB1      36
         DO 110 J=KINT+1,KINPU                                          DUDB1      37
         XDAT=GAINS(J)                                                  DUDB1      38
         IOUT=INPUTS(J)                                                 DUDB1      39
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1      40
  110    CONTINUE                                                       DUDB1      41
      ENDIF                                                             DUDB1      42
      KINP=KINPU                                                        DUDB1      43
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1      44
      IF(KINP.LT.KINPU) THEN                                            DUDB1      45
         DO 120 J=KINP+1,KINPU                                          DUDB1      46
         XDAT=GAINS(J)                                                  DUDB1      47
         IIN=INPUTS(J)                                                  DUDB1      48
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1      49
  120    CONTINUE                                                       DUDB1      50
      ENDIF                                                             DUDB1      51
      VALO=VALI*DDAT(JEI+1)                                             DUDB1      52
      LL=IDDAT(JEI+6)                                                   DUDB1      53
      IF (LL.EQ.0) THEN                                                 DUDB1      54
         VMAX=DDAT(JEI+2)                                               DUDB1      55
         VMIN=DDAT(JEI+3)                                               DUDB1      56
         IF (VALO.GE.VMAX) THEN                                         DUDB1      57
            VALO=VMAX                                                   DUDB1      58
            IDDAT(JEI+8)=1                                              DUDB1      59
         ELSE IF (VALO.LE.VMIN) THEN                                    DUDB1      60
            VALO=VMIN                                                   DUDB1      61
            IDDAT(JEI+8)=-1                                             DUDB1      62
         ELSE                                                           DUDB1      63
            IDDAT(JEI+8)=0                                              DUDB1      64
         END IF                                                         DUDB1      65
      END IF                                                            DUDB1      66
      VALOUT(IORD)=VALO                                                 DUDB1      67
      IF(LDEB) WRITE(IUD6,1000) LORD,IORD,VALOUT(IORD)                  DUDB1      68
C                                                                       DUDB1      69
      RETURN                                                            DUDB1      70
 1000 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1      71
C                                                                       DUDB1      72
C-----------------------------------------------------------------------DUDB1      73
C                                                                       DUDB1      74
      ENTRY DUDB2(LORD,KORD,NLF1,KN,CID)                                DUDB1      75
CD                                                                      DUDB1      76
CD    FOR BLOCK TYPE 2 (INTEGRATION BLOCK).                             DUDB1      77
CD                                                                      DUDB1      78
      LDEB=(JDEB(264).NE.0)                                             DUDB1      79
C                                                                       DUDB1      80
      VALI=0.0                                                          DUDB1      81
      IORD=IDDAT(JE4+LORD)                                              DUDB1      82
      JEI=JEB+2                                                         DUDB1      83
      KINT=KINPU                                                        DUDB1      84
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1      85
      IF(KINT.LT.KINPU) THEN                                            DUDB1      86
         DO 140 J=KINT+1,KINPU                                          DUDB1      87
         XDAT=GAINS(J)                                                  DUDB1      88
         IOUT=INPUTS(J)                                                 DUDB1      89
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1      90
  140    CONTINUE                                                       DUDB1      91
      ENDIF                                                             DUDB1      92
      KINP=KINPU                                                        DUDB1      93
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1      94
      IF(KINP.LT.KINPU) THEN                                            DUDB1      95
         DO 150 J=KINP+1,KINPU                                          DUDB1      96
         XDAT=GAINS(J)                                                  DUDB1      97
         IIN=INPUTS(J)                                                  DUDB1      98
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1      99
  150    CONTINUE                                                       DUDB1     100
      ENDIF                                                             DUDB1     101
      KORD=KORD+1                                                       DUDB1     102
      DSTATE(LSTATE+KORD)=VALI*DDAT(JEI+1)                              DUDB1     103
      VALO=XSTATE(JSTATE+KORD)                                          DUDB1     104
      LL=IDDAT(JEI+6)                                                   DUDB1     105
      IF (LL.EQ.0) THEN                                                 DUDB1     106
         VMAX=DDAT(JEI+2)                                               DUDB1     107
         VMIN=DDAT(JEI+3)                                               DUDB1     108
         IF (VALO.GE.VMAX) THEN                                         DUDB1     109
            VALO=VMAX                                                   DUDB1     110
            IDDAT(JEI+8)=1                                              DUDB1     111
            IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                        DUDB1     112
               DSTATE(LSTATE+KORD)=0.0                                  DUDB1     113
               QSTATE(JSTATE+KORD)=0.0                                  DUDB1     114
            END IF                                                      DUDB1     115
         ELSE IF (VALO.LE.VMIN) THEN                                    DUDB1     116
            VALO=VMIN                                                   DUDB1     117
            IDDAT(JEI+8)=-1                                             DUDB1     118
            IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                        DUDB1     119
               DSTATE(LSTATE+KORD)=0.0                                  DUDB1     120
               QSTATE(JSTATE+KORD)=0.0                                  DUDB1     121
            END IF                                                      DUDB1     122
         ELSE                                                           DUDB1     123
            IDDAT(JEI+8)=0                                              DUDB1     124
         END IF                                                         DUDB1     125
      END IF                                                            DUDB1     126
      VALOUT(IORD)=VALO                                                 DUDB1     127
      IF(LDEB) WRITE(IUD6,1010) KORD,LORD,IORD,VALOUT(IORD)             DUDB1     128
C                                                                       DUDB1     129
      RETURN                                                            DUDB1     130
 1010 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB1     131
C                                                                       DUDB1     132
C-----------------------------------------------------------------------DUDB1     133
C                                                                       DUDB1     134
      ENTRY DUDB3(LORD,KORD,NLF1,KN,CID)                                DUDB1     135
CD                                                                      DUDB1     136
CD    FOR BLOCK TYPE 3 (PI BLOCK).                                      DUDB1     137
CD                                                                      DUDB1     138
      LDEB=(JDEB(264).NE.0)                                             DUDB1     139
C                                                                       DUDB1     140
      VALI=0.0                                                          DUDB1     141
      IORD=IDDAT(JE4+LORD)                                              DUDB1     142
      JEI=JEB+2                                                         DUDB1     143
      KINT=KINPU                                                        DUDB1     144
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     145
      IF(KINT.LT.KINPU) THEN                                            DUDB1     146
         DO 170 J=KINT+1,KINPU                                          DUDB1     147
         XDAT=GAINS(J)                                                  DUDB1     148
         IOUT=INPUTS(J)                                                 DUDB1     149
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     150
  170    CONTINUE                                                       DUDB1     151
      ENDIF                                                             DUDB1     152
      KINP=KINPU                                                        DUDB1     153
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     154
      IF(KINP.LT.KINPU) THEN                                            DUDB1     155
         DO 180 J=KINP+1,KINPU                                          DUDB1     156
         XDAT=GAINS(J)                                                  DUDB1     157
         IIN=INPUTS(J)                                                  DUDB1     158
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     159
  180    CONTINUE                                                       DUDB1     160
      ENDIF                                                             DUDB1     161
      VALI=VALI*DDAT(JEI+1)                                             DUDB1     162
      VALI1=VALI*DDAT(JEI+2)                                            DUDB1     163
      KORD=KORD+1                                                       DUDB1     164
      DSTATE(LSTATE+KORD)=VALI                                          DUDB1     165
      VALO=XSTATE(JSTATE+KORD)+VALI1                                    DUDB1     166
      DDAT(JEI+7)=VALI1                                                 DUDB1     167
      LL=IDDAT(JEI+6)                                                   DUDB1     168
      IF (LL.EQ.0) THEN                                                 DUDB1     169
         VMAX=DDAT(JEI+3)                                               DUDB1     170
         VMIN=DDAT(JEI+4)                                               DUDB1     171
         IF (XSTATE(JSTATE+KORD).GE.VMAX) THEN                          DUDB1     172
            VALO=VMAX+VALI1                                             DUDB1     173
            IDDAT(JEI+8)=1                                              DUDB1     174
            IF (DSTATE(LSTATE+KORD).GT.0.0) THEN                        DUDB1     175
               DSTATE(LSTATE+KORD)=0.0                                  DUDB1     176
               QSTATE(JSTATE+KORD)=0.0                                  DUDB1     177
            END IF                                                      DUDB1     178
         ELSE IF (XSTATE(JSTATE+KORD).LE.VMIN) THEN                     DUDB1     179
            VALO=VMIN+VALI1                                             DUDB1     180
            IDDAT(JEI+8)=-1                                             DUDB1     181
            IF (DSTATE(LSTATE+KORD).LT.0.0) THEN                        DUDB1     182
               DSTATE(LSTATE+KORD)=0.0                                  DUDB1     183
               QSTATE(JSTATE+KORD)=0.0                                  DUDB1     184
            END IF                                                      DUDB1     185
         ELSE                                                           DUDB1     186
            IDDAT(JEI+8)=0                                              DUDB1     187
         END IF                                                         DUDB1     188
      END IF                                                            DUDB1     189
      VALOUT(IORD)=VALO                                                 DUDB1     190
      IF(LDEB) WRITE(IUD6,1020) KORD,LORD,IORD,VALOUT(IORD)             DUDB1     191
C                                                                       DUDB1     192
      RETURN                                                            DUDB1     193
 1020 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD): ',3I5,F10.3)              DUDB1     194
C                                                                       DUDB1     195
C-----------------------------------------------------------------------DUDB1     196
C                                                                       DUDB1     197
      ENTRY DUDB4(LORD,KORD,NLF1,KN,CID)                                DUDB1     198
CD                                                                      DUDB1     199
CD    FOR BLOCK TYPE 4 (WASHOUT BLOCK).                                 DUDB1     200
CD                                                                      DUDB1     201
      LDEB=(JDEB(264).NE.0)                                             DUDB1     202
C                                                                       DUDB1     203
      VALI=0.0                                                          DUDB1     204
      IORD=IDDAT(JE4+LORD)                                              DUDB1     205
      JEI=JEB+2                                                         DUDB1     206
      KINT=KINPU                                                        DUDB1     207
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     208
      IF(KINT.LT.KINPU) THEN                                            DUDB1     209
         DO 200 J=KINT+1,KINPU                                          DUDB1     210
         XDAT=GAINS(J)                                                  DUDB1     211
         IOUT=INPUTS(J)                                                 DUDB1     212
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     213
  200    CONTINUE                                                       DUDB1     214
      ENDIF                                                             DUDB1     215
      KINP=KINPU                                                        DUDB1     216
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     217
      IF(LDEB)WRITE(IUD6,1040)KINT,KINP,KINPU                           DUDB1     218
      IF(KINP.LT.KINPU) THEN                                            DUDB1     219
         DO 210 J=KINP+1,KINPU                                          DUDB1     220
         XDAT=GAINS(J)                                                  DUDB1     221
         IIN=INPUTS(J)                                                  DUDB1     222
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     223
         IF(LDEB)WRITE(IUD6,1050)IIN,XDAT,VALI                          DUDB1     224
  210    CONTINUE                                                       DUDB1     225
      ENDIF                                                             DUDB1     226
      KORD=KORD+1                                                       DUDB1     227
      DSTATE(LSTATE+KORD)=(VALI-XSTATE(JSTATE+KORD))/DDAT(JEI+2)        DUDB1     228
      VALOUT(IORD)=(VALI-XSTATE(JSTATE+KORD))*DDAT(JEI+1)               DUDB1     229
      IF(LDEB) WRITE(IUD6,1030) KORD,LORD,IORD,VALOUT(IORD)             DUDB1     230
     &,JSTATE,XSTATE(JSTATE+KORD)                                       DUDB1     231
C                                                                       DUDB1     232
      RETURN                                                            DUDB1     233
 1030 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD),JSTATE,XSTATE: ',3I5,F10.3,DUDB1     234
     &I5,F10.3)                                                         DUDB1     235
 1040 FORMAT(1X,'KINT,KINP,KINPU: ',3I5)                                DUDB1     236
 1050 FORMAT(1X,'IIN,XDAT,VALI: ',I5,2F10.3)                            DUDB1     237
C                                                                       DUDB1     238
C-----------------------------------------------------------------------DUDB1     239
C                                                                       DUDB1     240
      ENTRY DUDB5(LORD,KORD,NLF1,KN,CID)                                DUDB1     241
CD                                                                      DUDB1     242
CD    FOR BLOCK TYPE 5 (LEAD/LAG BLOCK).                                DUDB1     243
CD                                                                      DUDB1     244
      LDEB=(JDEB(264).NE.0)                                             DUDB1     245
C                                                                       DUDB1     246
      VALI=0.0                                                          DUDB1     247
      IORD=IDDAT(JE4+LORD)                                              DUDB1     248
      JEI=JEB+2                                                         DUDB1     249
      KINT=KINPU                                                        DUDB1     250
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     251
      IF(KINT.LT.KINPU) THEN                                            DUDB1     252
         DO 220 J=KINT+1,KINPU                                          DUDB1     253
         XDAT=GAINS(J)                                                  DUDB1     254
         IOUT=INPUTS(J)                                                 DUDB1     255
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     256
  220    CONTINUE                                                       DUDB1     257
      ENDIF                                                             DUDB1     258
      KINP=KINPU                                                        DUDB1     259
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     260
      IF(KINP.LT.KINPU) THEN                                            DUDB1     261
         DO 230 J=KINP+1,KINPU                                          DUDB1     262
         XDAT=GAINS(J)                                                  DUDB1     263
         IIN=INPUTS(J)                                                  DUDB1     264
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     265
  230    CONTINUE                                                       DUDB1     266
      ENDIF                                                             DUDB1     267
      TRATIO=DDAT(JEI+2)/DDAT(JEI+3)                                    DUDB1     268
      VALI=VALI*DDAT(JEI+1)                                             DUDB1     269
      VALI1=VALI*(1.0-TRATIO)                                           DUDB1     270
      VALI2=VALI*TRATIO                                                 DUDB1     271
      KORD=KORD+1                                                       DUDB1     272
      DSTATE(LSTATE+KORD)=(VALI1-XSTATE(JSTATE+KORD))/DDAT(JEI+3)       DUDB1     273
      VALO=XSTATE(JSTATE+KORD)+VALI2                                    DUDB1     274
      DDAT(JEI+7)=VALI2                                                 DUDB1     275
      LL=IDDAT(JEI+6)                                                   DUDB1     276
      IF (LL.EQ.0) THEN                                                 DUDB1     277
         VMAX=DDAT(JEI+4)                                               DUDB1     278
         VMIN=DDAT(JEI+5)                                               DUDB1     279
         IDDAT(JEI+8)=0                                                 DUDB1     280
         IF (VALO.GE.VMAX) THEN                                         DUDB1     281
            VALO=VMAX                                                   DUDB1     282
            IDDAT(JEI+8)=1                                              DUDB1     283
            IF(TRATIO.LT.1.0) THEN                                      DUDB1     284
               IF(XSTATE(JSTATE+KORD).GE.VALO*(1.0-TRATIO)) THEN        DUDB1     285
                  IF(DSTATE(LSTATE+KORD).GT.0.0) THEN                   DUDB1     286
                     DSTATE(LSTATE+KORD)=0.0                            DUDB1     287
                     QSTATE(JSTATE+KORD)=0.0                            DUDB1     288
                  END IF                                                DUDB1     289
               ELSE                                                     DUDB1     290
                  DSTATE(LSTATE+KORD)=(VALO*(1.0-TRATIO)                DUDB1     291
     &                 -XSTATE(JSTATE+KORD))/DDAT(JEI+2)                DUDB1     292
               END IF                                                   DUDB1     293
            END IF                                                      DUDB1     294
         ELSE IF (VALO.LE.VMIN) THEN                                    DUDB1     295
            VALO=VMIN                                                   DUDB1     296
            IDDAT(JEI+8)=-1                                             DUDB1     297
            IF(TRATIO.LT.1.0) THEN                                      DUDB1     298
               IF(XSTATE(JSTATE+KORD).LE.VALO*(1.0-TRATIO)) THEN        DUDB1     299
                  IF(DSTATE(LSTATE+KORD).LT.0.0) THEN                   DUDB1     300
                     DSTATE(LSTATE+KORD)=0.0                            DUDB1     301
                     QSTATE(JSTATE+KORD)=0.0                            DUDB1     302
                  END IF                                                DUDB1     303
               ELSE                                                     DUDB1     304
                  DSTATE(LSTATE+KORD)=(VALO*(1.0-TRATIO)                DUDB1     305
     &                 -XSTATE(JSTATE+KORD))/DDAT(JEI+2)                DUDB1     306
               END IF                                                   DUDB1     307
            END IF                                                      DUDB1     308
         END IF                                                         DUDB1     309
      END IF                                                            DUDB1     310
      VALOUT(IORD)=VALO                                                 DUDB1     311
      IF(LDEB) WRITE(IUD6,1060) KORD,LORD,IORD,VALOUT(IORD)             DUDB1     312
     &,JSTATE,XSTATE(JSTATE+KORD)                                       DUDB1     313
C                                                                       DUDB1     314
      RETURN                                                            DUDB1     315
 1060 FORMAT(1X,'KORD,LORD,IORD,VALOUT(IORD),JSTATE,XSTATE: '           DUDB1     316
     &,3I5,F10.3,I5,F10.3)                                              DUDB1     317
C                                                                       DUDB1     318
C-----------------------------------------------------------------------DUDB1     319
C                                                                       DUDB1     320
      ENTRY DUDB6(LORD,NLF1,KN,CID)                                     DUDB1     321
CD                                                                      DUDB1     322
CD    FOR BLOCK TYPE 6 (SWITCH BLOCK).                                  DUDB1     323
CD                                                                      DUDB1     324
      LDEB=(JDEB(264).NE.0)                                             DUDB1     325
C                                                                       DUDB1     326
      VALI=0.0                                                          DUDB1     327
      IORD=IDDAT(JE4+LORD)                                              DUDB1     328
      JEI=JEB+2                                                         DUDB1     329
      KINT=KINPU                                                        DUDB1     330
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     331
      IF(KINT.LT.KINPU) THEN                                            DUDB1     332
         DO 250 J=KINT+1,KINPU                                          DUDB1     333
         XDAT=GAINS(J)                                                  DUDB1     334
         IOUT=INPUTS(J)                                                 DUDB1     335
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     336
  250    CONTINUE                                                       DUDB1     337
      ENDIF                                                             DUDB1     338
      KINP=KINPU                                                        DUDB1     339
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     340
      IF(KINP.LT.KINPU) THEN                                            DUDB1     341
         DO 260 J=KINP+1,KINPU                                          DUDB1     342
         XDAT=GAINS(J)                                                  DUDB1     343
         IIN=INPUTS(J)                                                  DUDB1     344
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     345
  260    CONTINUE                                                       DUDB1     346
      ENDIF                                                             DUDB1     347
      IF(TS.GE.DDAT(JEI+1)) THEN                                        DUDB1     348
         VALOUT(IORD)=VALI                                              DUDB1     349
      ELSE                                                              DUDB1     350
         VALOUT(IORD)=0.0                                               DUDB1     351
      ENDIF                                                             DUDB1     352
      IF(LDEB) WRITE(IUD6,1070) LORD,IORD,VALOUT(IORD)                  DUDB1     353
C                                                                       DUDB1     354
      RETURN                                                            DUDB1     355
 1070 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     356
C                                                                       DUDB1     357
C-----------------------------------------------------------------------DUDB1     358
C                                                                       DUDB1     359
      ENTRY DUDB7(LORD,NLF1,KN,CID)                                     DUDB1     360
CD                                                                      DUDB1     361
CD    FOR BLOCK TYPE 7 (HIGH VALUE BLOCK).                              DUDB1     362
CD                                                                      DUDB1     363
      LDEB=(JDEB(264).NE.0)                                             DUDB1     364
C                                                                       DUDB1     365
      II=0                                                              DUDB1     366
      VALI1=0.0                                                         DUDB1     367
      VALI2=0.0                                                         DUDB1     368
      IORD=IDDAT(JE4+LORD)                                              DUDB1     369
      JEI=JEB+2                                                         DUDB1     370
      KINT=KINPU                                                        DUDB1     371
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     372
      IF(KINT.LT.KINPU) THEN                                            DUDB1     373
         DO 270 J=KINT+1,KINPU                                          DUDB1     374
         XDAT=GAINS(J)                                                  DUDB1     375
         IOUT=INPUTS(J)                                                 DUDB1     376
         II=II+1                                                        DUDB1     377
         IF(II.EQ.1) THEN                                               DUDB1     378
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB1     379
            GO TO 270                                                   DUDB1     380
         ENDIF                                                          DUDB1     381
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB1     382
  270    CONTINUE                                                       DUDB1     383
      ENDIF                                                             DUDB1     384
      KINP=KINPU                                                        DUDB1     385
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     386
      IF(KINP.LT.KINPU) THEN                                            DUDB1     387
         DO 280 J=KINP+1,KINPU                                          DUDB1     388
         XDAT=GAINS(J)                                                  DUDB1     389
         IIN=INPUTS(J)                                                  DUDB1     390
         II=II+1                                                        DUDB1     391
         IF(II.EQ.1) THEN                                               DUDB1     392
            VALI1=VALIN(IIN)*XDAT                                       DUDB1     393
            GO TO 280                                                   DUDB1     394
         ENDIF                                                          DUDB1     395
         VALI2=VALIN(IIN)*XDAT                                          DUDB1     396
  280    CONTINUE                                                       DUDB1     397
      ENDIF                                                             DUDB1     398
      IF (VALI1.GT.VALI2) THEN                                          DUDB1     399
         VALO=VALI1                                                     DUDB1     400
         IDDAT(JEI+1)=1                                                 DUDB1     401
      ELSE                                                              DUDB1     402
         VALO=VALI2                                                     DUDB1     403
         IDDAT(JEI+1)=2                                                 DUDB1     404
      END IF                                                            DUDB1     405
      VALOUT(IORD)=VALO                                                 DUDB1     406
      IF(LDEB) WRITE(IUD6,1080) LORD,IORD,VALOUT(IORD)                  DUDB1     407
C                                                                       DUDB1     408
      RETURN                                                            DUDB1     409
 1080 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     410
C                                                                       DUDB1     411
C-----------------------------------------------------------------------DUDB1     412
C                                                                       DUDB1     413
      ENTRY DUDB8(LORD,NLF1,KN,CID)                                     DUDB1     414
CD                                                                      DUDB1     415
CD    FOR BLOCK TYPE 8 (LOW VALUE BLOCK).                               DUDB1     416
CD                                                                      DUDB1     417
      LDEB=(JDEB(264).NE.0)                                             DUDB1     418
C                                                                       DUDB1     419
      II=0                                                              DUDB1     420
      VALI1=0.0                                                         DUDB1     421
      VALI2=0.0                                                         DUDB1     422
      IORD=IDDAT(JE4+LORD)                                              DUDB1     423
      JEI=JEB+2                                                         DUDB1     424
      KINT=KINPU                                                        DUDB1     425
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     426
      IF(KINT.LT.KINPU) THEN                                            DUDB1     427
         DO 290 J=KINT+1,KINPU                                          DUDB1     428
         XDAT=GAINS(J)                                                  DUDB1     429
         IOUT=INPUTS(J)                                                 DUDB1     430
         II=II+1                                                        DUDB1     431
         IF(II.EQ.1) THEN                                               DUDB1     432
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB1     433
            GO TO 290                                                   DUDB1     434
         ENDIF                                                          DUDB1     435
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB1     436
  290    CONTINUE                                                       DUDB1     437
      ENDIF                                                             DUDB1     438
      KINP=KINPU                                                        DUDB1     439
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     440
      IF(KINP.LT.KINPU) THEN                                            DUDB1     441
         DO 300 J=KINP+1,KINPU                                          DUDB1     442
         XDAT=GAINS(J)                                                  DUDB1     443
         IIN=INPUTS(J)                                                  DUDB1     444
         II=II+1                                                        DUDB1     445
         IF(II.EQ.1) THEN                                               DUDB1     446
            VALI1=VALIN(IIN)*XDAT                                       DUDB1     447
            GO TO 300                                                   DUDB1     448
         ENDIF                                                          DUDB1     449
         VALI2=VALIN(IIN)*XDAT                                          DUDB1     450
  300    CONTINUE                                                       DUDB1     451
      ENDIF                                                             DUDB1     452
      IF (VALI1.LT.VALI2) THEN                                          DUDB1     453
         VALO=VALI1                                                     DUDB1     454
         IDDAT(JEI+1)=1                                                 DUDB1     455
      ELSE                                                              DUDB1     456
         VALO=VALI2                                                     DUDB1     457
         IDDAT(JEI+1)=2                                                 DUDB1     458
      END IF                                                            DUDB1     459
      VALOUT(IORD)=VALO                                                 DUDB1     460
      IF(LDEB) WRITE(IUD6,1090) LORD,IORD,VALOUT(IORD)                  DUDB1     461
C                                                                       DUDB1     462
      RETURN                                                            DUDB1     463
 1090 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     464
C                                                                       DUDB1     465
C-----------------------------------------------------------------------DUDB1     466
C                                                                       DUDB1     467
      ENTRY DUDB9(LORD,NLF1,KN,CID)                                     DUDB1     468
CD                                                                      DUDB1     469
CD    FOR BLOCK TYPE 9 (MULTIPLICATION BLOCK).                          DUDB1     470
CD                                                                      DUDB1     471
      LDEB=(JDEB(264).NE.0)                                             DUDB1     472
C                                                                       DUDB1     473
      II=0                                                              DUDB1     474
      VALI1=0.0                                                         DUDB1     475
      VALI2=0.0                                                         DUDB1     476
      IORD=IDDAT(JE4+LORD)                                              DUDB1     477
      JEI=JEB+2                                                         DUDB1     478
      KINT=KINPU                                                        DUDB1     479
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     480
      IF(KINT.LT.KINPU) THEN                                            DUDB1     481
         DO 310 J=KINT+1,KINPU                                          DUDB1     482
         XDAT=GAINS(J)                                                  DUDB1     483
         IOUT=INPUTS(J)                                                 DUDB1     484
         II=II+1                                                        DUDB1     485
         IF(II.EQ.1) THEN                                               DUDB1     486
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB1     487
            GO TO 310                                                   DUDB1     488
         ENDIF                                                          DUDB1     489
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB1     490
  310    CONTINUE                                                       DUDB1     491
      ENDIF                                                             DUDB1     492
      KINP=KINPU                                                        DUDB1     493
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     494
      IF(KINP.LT.KINPU) THEN                                            DUDB1     495
         DO 320 J=KINP+1,KINPU                                          DUDB1     496
         XDAT=GAINS(J)                                                  DUDB1     497
         IIN=INPUTS(J)                                                  DUDB1     498
         II=II+1                                                        DUDB1     499
         IF(II.EQ.1) THEN                                               DUDB1     500
            VALI1=VALIN(IIN)*XDAT                                       DUDB1     501
            GO TO 320                                                   DUDB1     502
         ENDIF                                                          DUDB1     503
         VALI2=VALIN(IIN)*XDAT                                          DUDB1     504
  320    CONTINUE                                                       DUDB1     505
      ENDIF                                                             DUDB1     506
      VALOUT(IORD)=VALI1*VALI2                                          DUDB1     507
      DDAT(JEI+1)=VALI1                                                 DUDB1     508
      DDAT(JEI+2)=VALI2                                                 DUDB1     509
      IF(LDEB) WRITE(IUD6,1100) LORD,IORD,VALOUT(IORD)                  DUDB1     510
C                                                                       DUDB1     511
      RETURN                                                            DUDB1     512
 1100 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     513
C                                                                       DUDB1     514
C-----------------------------------------------------------------------DUDB1     515
C                                                                       DUDB1     516
      ENTRY DUDB10(LORD,NLF1,KN,CID)                                    DUDB1     517
CD                                                                      DUDB1     518
CD    FOR BLOCK TYPE 10 (DIVISION BLOCK).                               DUDB1     519
CD                                                                      DUDB1     520
      LDEB=(JDEB(264).NE.0)                                             DUDB1     521
C                                                                       DUDB1     522
      II=0                                                              DUDB1     523
      VALI1=0.0                                                         DUDB1     524
      VALI2=0.0                                                         DUDB1     525
      IORD=IDDAT(JE4+LORD)                                              DUDB1     526
      JEI=JEB+2                                                         DUDB1     527
      KINT=KINPU                                                        DUDB1     528
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     529
      IF(KINT.LT.KINPU) THEN                                            DUDB1     530
         DO 330 J=KINT+1,KINPU                                          DUDB1     531
         XDAT=GAINS(J)                                                  DUDB1     532
         IOUT=INPUTS(J)                                                 DUDB1     533
         II=II+1                                                        DUDB1     534
         IF(II.EQ.1) THEN                                               DUDB1     535
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB1     536
            GO TO 330                                                   DUDB1     537
         ENDIF                                                          DUDB1     538
         VALI2=VALOUT(IOUT)*XDAT                                        DUDB1     539
  330    CONTINUE                                                       DUDB1     540
      ENDIF                                                             DUDB1     541
      KINP=KINPU                                                        DUDB1     542
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     543
      IF(KINP.LT.KINPU) THEN                                            DUDB1     544
         DO 340 J=KINP+1,KINPU                                          DUDB1     545
         XDAT=GAINS(J)                                                  DUDB1     546
         IIN=INPUTS(J)                                                  DUDB1     547
         II=II+1                                                        DUDB1     548
         IF(II.EQ.1) THEN                                               DUDB1     549
            VALI1=VALIN(IIN)*XDAT                                       DUDB1     550
            GO TO 340                                                   DUDB1     551
         ENDIF                                                          DUDB1     552
         VALI2=VALIN(IIN)*XDAT                                          DUDB1     553
  340    CONTINUE                                                       DUDB1     554
      ENDIF                                                             DUDB1     555
      IF(ABS(VALI2).LT.0.0001) THEN                                     DUDB1     556
         IF(VALI2.LT.0.0) THEN                                          DUDB1     557
            VALI2=-0.0001                                               DUDB1     558
         ELSE                                                           DUDB1     559
            VALI2=0.0001                                                DUDB1     560
         ENDIF                                                          DUDB1     561
      ENDIF                                                             DUDB1     562
      VALOUT(IORD)=VALI1/VALI2                                          DUDB1     563
      DDAT(JEI+1)=-VALI1/(VALI2**2.0)                                   DUDB1     564
      DDAT(JEI+2)=1.0/VALI2                                             DUDB1     565
      IF(LDEB) WRITE(IUD6,1110) LORD,IORD,VALOUT(IORD)                  DUDB1     566
C                                                                       DUDB1     567
      RETURN                                                            DUDB1     568
 1110 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     569
C                                                                       DUDB1     570
C-----------------------------------------------------------------------DUDB1     571
C                                                                       DUDB1     572
      ENTRY DUDB11(LORD,NLF1,KN,CID)                                    DUDB1     573
CD                                                                      DUDB1     574
CD    FOR BLOCK TYPE 11 (INITIAL VALUE BLOCK).                          DUDB1     575
CD                                                                      DUDB1     576
      LDEB=(JDEB(264).NE.0)                                             DUDB1     577
C                                                                       DUDB1     578
      IORD=IDDAT(JE4+LORD)                                              DUDB1     579
      VALOUT(IORD)=DDAT(JEB+3)                                          DUDB1     580
      IF(LDEB) WRITE(IUD6,1120) LORD,IORD,VALOUT(IORD)                  DUDB1     581
C                                                                       DUDB1     582
      RETURN                                                            DUDB1     583
 1120 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     584
C                                                                       DUDB1     585
C-----------------------------------------------------------------------DUDB1     586
C                                                                       DUDB1     587
      ENTRY DUDB12(LORD,KORD,NLF1,KN,CID)                               DUDB1     588
CD                                                                      DUDB1     589
CD    FOR BLOCK TYPE 12 (DELAY BLOCK).                                  DUDB1     590
CD                                                                      DUDB1     591
      LDEB=(JDEB(264).NE.0)                                             DUDB1     592
C                                                                       DUDB1     593
      VALI=0.0                                                          DUDB1     594
      IORD=IDDAT(JE4+LORD)                                              DUDB1     595
      JEI=JEB+2                                                         DUDB1     596
      KINT=KINPU                                                        DUDB1     597
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     598
      IF(KINT.LT.KINPU) THEN                                            DUDB1     599
         DO 350 J=KINT+1,KINPU                                          DUDB1     600
         XDAT=GAINS(J)                                                  DUDB1     601
         IOUT=INPUTS(J)                                                 DUDB1     602
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     603
  350    CONTINUE                                                       DUDB1     604
      ENDIF                                                             DUDB1     605
      KINP=KINPU                                                        DUDB1     606
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     607
      IF(KINP.LT.KINPU) THEN                                            DUDB1     608
         DO 360 J=KINP+1,KINPU                                          DUDB1     609
         XDAT=GAINS(J)                                                  DUDB1     610
         IIN=INPUTS(J)                                                  DUDB1     611
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     612
  360    CONTINUE                                                       DUDB1     613
      ENDIF                                                             DUDB1     614
      T1=TS-DDAT(JEI+2)                                                 DUDB1     615
      IDEL=IDDAT(JEI+3)                                                 DUDB1     616
      KDEL=IDDAT(JEI+4)                                                 DUDB1     617
      DIFF=TS-DELT(KDEL)                                                DUDB1     618
      IF(DIFF.GT.0.0) THEN                                              DUDB1     619
         KDEL=KDEL+1                                                    DUDB1     620
         IF(KDEL.GT.NDLEN) THEN                                         DUDB1     621
            KDEL=1                                                      DUDB1     622
            WRITE(MSG(1),2001) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN)   DUDB1     623
     *      ,CID                                                        DUDB1     624
            WRITE(MSG(2),2010) IORD,BLNAM1,BLNAM2                       DUDB1     625
            WRITE(MSG(3),2020) TS                                       DUDB1     626
            WRITE(MSG(4),2030) NDLEN                                    DUDB1     627
            CALL PRTMSG(4)                                              DUDB1     628
         ENDIF                                                          DUDB1     629
         DELH(IDEL,KDEL)=VALI*DDAT(JEI+1)                               DUDB1     630
         DELT(KDEL)=TS                                                  DUDB1     631
         IDDAT(JEI+4)=KDEL                                              DUDB1     632
      ENDIF                                                             DUDB1     633
      IF(T1.LE.0.0) THEN                                                DUDB1     634
         VALOUT(IORD)=DELH(IDEL,1)                                      DUDB1     635
      ELSE                                                              DUDB1     636
         NDEL=IDDAT(JEI+5)-1                                            DUDB1     637
  370    NDEL=NDEL+1                                                    DUDB1     638
         IF(NDEL.GT.NDLEN) NDEL=1                                       DUDB1     639
         IF(NDEL.EQ.NDLEN) THEN                                         DUDB1     640
            IF(DELT(1).LE.T1) GO TO 370                                 DUDB1     641
         ELSE                                                           DUDB1     642
            IF(DELT(NDEL+1).LE.T1) GO TO 370                            DUDB1     643
         ENDIF                                                          DUDB1     644
         VALOUT(IORD)=DELH(IDEL,NDEL)                                   DUDB1     645
         IDDAT(JEI+5)=NDEL                                              DUDB1     646
      ENDIF                                                             DUDB1     647
C                                                                       DUDB1     648
      IF (IDDAT(JEI+2).NE.0) THEN                                       DUDB1     649
         KORD=KORD+1                                                    DUDB1     650
         DSTATE(LSTATE+KORD)=(DDAT(JEI+1)*VALI-XSTATE(LSTATE+KORD))/    DUDB1     651
     *                       DDAT(JEI+2)                                DUDB1     652
      END IF                                                            DUDB1     653
C                                                                       DUDB1     654
      IF(LDEB) WRITE(IUD6,1130) LORD,IORD,VALOUT(IORD)                  DUDB1     655
C                                                                       DUDB1     656
      RETURN                                                            DUDB1     657
 1130 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     658
C                                                                       DUDB1     659
C-----------------------------------------------------------------------DUDB1     660
C                                                                       DUDB1     661
      ENTRY DUDB13(LORD,NLF1,KN,CID)                                    DUDB1     662
CD                                                                      DUDB1     663
CD    FOR BLOCK TYPE 13 (SINE BLOCK).                                   DUDB1     664
CD                                                                      DUDB1     665
      LDEB=(JDEB(264).NE.0)                                             DUDB1     666
C                                                                       DUDB1     667
      VALI=0.0                                                          DUDB1     668
      IORD=IDDAT(JE4+LORD)                                              DUDB1     669
      JEI=JEB+2                                                         DUDB1     670
      KINT=KINPU                                                        DUDB1     671
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     672
      IF(KINT.LT.KINPU) THEN                                            DUDB1     673
         DO 380 J=KINT+1,KINPU                                          DUDB1     674
         XDAT=GAINS(J)                                                  DUDB1     675
         IOUT=INPUTS(J)                                                 DUDB1     676
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     677
  380    CONTINUE                                                       DUDB1     678
      ENDIF                                                             DUDB1     679
      KINP=KINPU                                                        DUDB1     680
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     681
      IF(KINP.LT.KINPU) THEN                                            DUDB1     682
         DO 390 J=KINP+1,KINPU                                          DUDB1     683
         XDAT=GAINS(J)                                                  DUDB1     684
         IIN=INPUTS(J)                                                  DUDB1     685
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     686
  390    CONTINUE                                                       DUDB1     687
      ENDIF                                                             DUDB1     688
      VALI=VALI*PII/180.0                                               DUDB1     689
      VALOUT(IORD)=SIN(VALI)                                            DUDB1     690
      DDAT(JEI+1)=(PII/180.0)*COS(VALI)                                 DUDB1     691
      IF(LDEB) WRITE(IUD6,1140) LORD,IORD,VALOUT(IORD)                  DUDB1     692
C                                                                       DUDB1     693
      RETURN                                                            DUDB1     694
 1140 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     695
C                                                                       DUDB1     696
C-----------------------------------------------------------------------DUDB1     697
C                                                                       DUDB1     698
      ENTRY DUDB14(LORD,NLF1,KN,CID)                                    DUDB1     699
CD                                                                      DUDB1     700
CD    FOR BLOCK TYPE 14 (COSINE BLOCK).                                 DUDB1     701
CD                                                                      DUDB1     702
      LDEB=(JDEB(264).NE.0)                                             DUDB1     703
C                                                                       DUDB1     704
      VALI=0.0                                                          DUDB1     705
      IORD=IDDAT(JE4+LORD)                                              DUDB1     706
      JEI=JEB+2                                                         DUDB1     707
      KINT=KINPU                                                        DUDB1     708
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     709
      IF(KINT.LT.KINPU) THEN                                            DUDB1     710
         DO 400 J=KINT+1,KINPU                                          DUDB1     711
         XDAT=GAINS(J)                                                  DUDB1     712
         IOUT=INPUTS(J)                                                 DUDB1     713
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     714
  400    CONTINUE                                                       DUDB1     715
      ENDIF                                                             DUDB1     716
      KINP=KINPU                                                        DUDB1     717
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     718
      IF(KINP.LT.KINPU) THEN                                            DUDB1     719
         DO 410 J=KINP+1,KINPU                                          DUDB1     720
         XDAT=GAINS(J)                                                  DUDB1     721
         IIN=INPUTS(J)                                                  DUDB1     722
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     723
  410    CONTINUE                                                       DUDB1     724
      ENDIF                                                             DUDB1     725
      VALI=VALI*PII/180.0                                               DUDB1     726
      VALOUT(IORD)=COS(VALI)                                            DUDB1     727
      DDAT(JEI+1)=(-PII/180.0)*SIN(VALI)                                DUDB1     728
      IF(LDEB) WRITE(IUD6,1150) LORD,IORD,VALOUT(IORD)                  DUDB1     729
C                                                                       DUDB1     730
      RETURN                                                            DUDB1     731
 1150 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     732
C                                                                       DUDB1     733
C-----------------------------------------------------------------------DUDB1     734
C                                                                       DUDB1     735
      ENTRY DUDB15(LORD,NLF1,KN,CID)                                    DUDB1     736
CD                                                                      DUDB1     737
CD    FOR BLOCK TYPE 15 (TANGENT BLOCK).                                DUDB1     738
CD                                                                      DUDB1     739
      LDEB=(JDEB(264).NE.0)                                             DUDB1     740
C                                                                       DUDB1     741
      VALI=0.0                                                          DUDB1     742
      IORD=IDDAT(JE4+LORD)                                              DUDB1     743
      JEI=JEB+2                                                         DUDB1     744
      KINT=KINPU                                                        DUDB1     745
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     746
      IF(KINT.LT.KINPU) THEN                                            DUDB1     747
         DO 420 J=KINT+1,KINPU                                          DUDB1     748
         XDAT=GAINS(J)                                                  DUDB1     749
         IOUT=INPUTS(J)                                                 DUDB1     750
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     751
  420    CONTINUE                                                       DUDB1     752
      ENDIF                                                             DUDB1     753
      KINP=KINPU                                                        DUDB1     754
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     755
      IF(KINP.LT.KINPU) THEN                                            DUDB1     756
         DO 430 J=KINP+1,KINPU                                          DUDB1     757
         XDAT=GAINS(J)                                                  DUDB1     758
         IIN=INPUTS(J)                                                  DUDB1     759
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     760
  430    CONTINUE                                                       DUDB1     761
      ENDIF                                                             DUDB1     762
      VALI=VALI*PII/180.0                                               DUDB1     763
      VALOUT(IORD)=TAN(VALI)                                            DUDB1     764
      DDAT(JEI+1)=(PII/180.0)*(1.0+TAN(VALI)**2.0)                      DUDB1     765
      IF(LDEB) WRITE(IUD6,1160) LORD,IORD,VALOUT(IORD)                  DUDB1     766
C                                                                       DUDB1     767
      RETURN                                                            DUDB1     768
 1160 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     769
C                                                                       DUDB1     770
C-----------------------------------------------------------------------DUDB1     771
C                                                                       DUDB1     772
      ENTRY DUDB16(LORD,NLF1,KN,CID)                                    DUDB1     773
CD                                                                      DUDB1     774
CD    FOR BLOCK TYPE 16 (ARC SINE BLOCK).                               DUDB1     775
CD                                                                      DUDB1     776
      LDEB=(JDEB(264).NE.0)                                             DUDB1     777
C                                                                       DUDB1     778
      VALI=0.0                                                          DUDB1     779
      IORD=IDDAT(JE4+LORD)                                              DUDB1     780
      JEI=JEB+2                                                         DUDB1     781
      KINT=KINPU                                                        DUDB1     782
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     783
      IF(KINT.LT.KINPU) THEN                                            DUDB1     784
         DO 440 J=KINT+1,KINPU                                          DUDB1     785
         XDAT=GAINS(J)                                                  DUDB1     786
         IOUT=INPUTS(J)                                                 DUDB1     787
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     788
  440    CONTINUE                                                       DUDB1     789
      ENDIF                                                             DUDB1     790
      KINP=KINPU                                                        DUDB1     791
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     792
      IF(KINP.LT.KINPU) THEN                                            DUDB1     793
         DO 450 J=KINP+1,KINPU                                          DUDB1     794
         XDAT=GAINS(J)                                                  DUDB1     795
         IIN=INPUTS(J)                                                  DUDB1     796
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     797
  450    CONTINUE                                                       DUDB1     798
      ENDIF                                                             DUDB1     799
      IF(ABS(VALI).GT.1.0) THEN                                         DUDB1     800
C         WRITE(IU6,1180)IORD,BLNAM1,BLNAM2,VALI                        DUDB1     801
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB1     802
         WRITE(MSG(2),1180) IORD,BLNAM1,BLNAM2,VALI                     DUDB1     803
         CALL PRTMSG(2)                                                 DUDB1     804
         MSG(1)='DUDB16: UD ERROR'                                      DUDB1     805
         CALL ASTOP(MSG(1),16)                                          DUDB1     806
      ENDIF                                                             DUDB1     807
      WS1=PII/180.0                                                     DUDB1     808
      VALOUT(IORD)=ASIN(VALI)/WS1                                       DUDB1     809
      DDAT(JEI+1)=1.0/(WS1*COS(WS1*VALOUT(IORD)))                       DUDB1     810
      IF(LDEB) WRITE(IUD6,1170) LORD,IORD,VALOUT(IORD)                  DUDB1     811
C                                                                       DUDB1     812
      RETURN                                                            DUDB1     813
 1170 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     814
 1180 FORMAT(5X,'ARCSIN BLOCK: ',I3,'(',2A4                             DUDB1     815
     *,') HAS UNACCEPTABLE INPUT = ',F10.5)                             DUDB1     816
C                                                                       DUDB1     817
C-----------------------------------------------------------------------DUDB1     818
C                                                                       DUDB1     819
      ENTRY DUDB17(LORD,NLF1,KN,CID)                                    DUDB1     820
CD                                                                      DUDB1     821
CD    FOR BLOCK TYPE 17 (ARC COSINE BLOCK).                             DUDB1     822
CD                                                                      DUDB1     823
      LDEB=(JDEB(264).NE.0)                                             DUDB1     824
C                                                                       DUDB1     825
      VALI=0.0                                                          DUDB1     826
      IORD=IDDAT(JE4+LORD)                                              DUDB1     827
      JEI=JEB+2                                                         DUDB1     828
      KINT=KINPU                                                        DUDB1     829
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     830
      IF(KINT.LT.KINPU) THEN                                            DUDB1     831
         DO 460 J=KINT+1,KINPU                                          DUDB1     832
         XDAT=GAINS(J)                                                  DUDB1     833
         IOUT=INPUTS(J)                                                 DUDB1     834
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     835
  460    CONTINUE                                                       DUDB1     836
      ENDIF                                                             DUDB1     837
      KINP=KINPU                                                        DUDB1     838
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     839
      IF(KINP.LT.KINPU) THEN                                            DUDB1     840
         DO 470 J=KINP+1,KINPU                                          DUDB1     841
         XDAT=GAINS(J)                                                  DUDB1     842
         IIN=INPUTS(J)                                                  DUDB1     843
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     844
  470    CONTINUE                                                       DUDB1     845
      ENDIF                                                             DUDB1     846
      IF(ABS(VALI).GT.1.0) THEN                                         DUDB1     847
C         WRITE(IU6,1200)IORD,BLNAM1,BLNAM2,VALI                        DUDB1     848
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB1     849
         WRITE(MSG(2),1200)IORD,BLNAM1,BLNAM2,VALI                      DUDB1     850
         CALL PRTMSG(2)                                                 DUDB1     851
         MSG(1)='DUDB17: UD ERROR'                                      DUDB1     852
         CALL ASTOP(MSG(1),16)                                          DUDB1     853
      ENDIF                                                             DUDB1     854
      WS1=PII/180.0                                                     DUDB1     855
      VALOUT(IORD)=ACOS(VALI)/WS1                                       DUDB1     856
      DDAT(JEI+1)=-1.0/(WS1*SIN(WS1*VALOUT(IORD)))                      DUDB1     857
      IF(LDEB) WRITE(IUD6,1190) LORD,IORD,VALOUT(IORD)                  DUDB1     858
C                                                                       DUDB1     859
      RETURN                                                            DUDB1     860
 1190 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     861
 1200 FORMAT(5X,'ARCCOS BLOCK: ',I3,'(',2A4                             DUDB1     862
     *,') HAS UNACCEPTABLE INPUT = ',F10.5)                             DUDB1     863
C                                                                       DUDB1     864
C-----------------------------------------------------------------------DUDB1     865
C                                                                       DUDB1     866
      ENTRY DUDB18(LORD,NLF1,KN,CID)                                    DUDB1     867
CD                                                                      DUDB1     868
CD    FOR BLOCK TYPE 18 (ARC TANGENT BLOCK).                            DUDB1     869
CD                                                                      DUDB1     870
      LDEB=(JDEB(264).NE.0)                                             DUDB1     871
C                                                                       DUDB1     872
      VALI=0.0                                                          DUDB1     873
      IORD=IDDAT(JE4+LORD)                                              DUDB1     874
      JEI=JEB+2                                                         DUDB1     875
      KINT=KINPU                                                        DUDB1     876
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     877
      IF(KINT.LT.KINPU) THEN                                            DUDB1     878
         DO 480 J=KINT+1,KINPU                                          DUDB1     879
         XDAT=GAINS(J)                                                  DUDB1     880
         IOUT=INPUTS(J)                                                 DUDB1     881
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     882
  480    CONTINUE                                                       DUDB1     883
      ENDIF                                                             DUDB1     884
      KINP=KINPU                                                        DUDB1     885
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     886
      IF(KINP.LT.KINPU) THEN                                            DUDB1     887
         DO 490 J=KINP+1,KINPU                                          DUDB1     888
         XDAT=GAINS(J)                                                  DUDB1     889
         IIN=INPUTS(J)                                                  DUDB1     890
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     891
  490    CONTINUE                                                       DUDB1     892
      ENDIF                                                             DUDB1     893
      VALOUT(IORD)=ATAN(VALI)*180.0/PII                                 DUDB1     894
      DDAT(JEI+1)=180.0/(PII*(1.0+VALI**2.0))                           DUDB1     895
      IF(LDEB) WRITE(IUD6,1210) LORD,IORD,VALOUT(IORD)                  DUDB1     896
C                                                                       DUDB1     897
      RETURN                                                            DUDB1     898
 1210 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     899
C                                                                       DUDB1     900
C-----------------------------------------------------------------------DUDB1     901
C                                                                       DUDB1     902
      ENTRY DUDB19(LORD,NLF1,KN,CID)                                    DUDB1     903
CD                                                                      DUDB1     904
CD    FOR BLOCK TYPE 19 (EXPONENTIAL BLOCK).                            DUDB1     905
CD                                                                      DUDB1     906
      LDEB=(JDEB(264).NE.0)                                             DUDB1     907
C                                                                       DUDB1     908
      VALI=0.0                                                          DUDB1     909
      IORD=IDDAT(JE4+LORD)                                              DUDB1     910
      JEI=JEB+2                                                         DUDB1     911
      KINT=KINPU                                                        DUDB1     912
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     913
      IF(KINT.LT.KINPU) THEN                                            DUDB1     914
         DO 500 J=KINT+1,KINPU                                          DUDB1     915
         XDAT=GAINS(J)                                                  DUDB1     916
         IOUT=INPUTS(J)                                                 DUDB1     917
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     918
  500    CONTINUE                                                       DUDB1     919
      ENDIF                                                             DUDB1     920
      KINP=KINPU                                                        DUDB1     921
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     922
      IF(KINP.LT.KINPU) THEN                                            DUDB1     923
         DO 510 J=KINP+1,KINPU                                          DUDB1     924
         XDAT=GAINS(J)                                                  DUDB1     925
         IIN=INPUTS(J)                                                  DUDB1     926
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     927
  510    CONTINUE                                                       DUDB1     928
      ENDIF                                                             DUDB1     929
      VALOUT(IORD)=EXP(VALI)                                            DUDB1     930
      DDAT(JEI+1)=VALOUT(IORD)                                          DUDB1     931
      IF(LDEB) WRITE(IUD6,1220) LORD,IORD,VALOUT(IORD)                  DUDB1     932
C                                                                       DUDB1     933
      RETURN                                                            DUDB1     934
 1220 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     935
C                                                                       DUDB1     936
C-----------------------------------------------------------------------DUDB1     937
C                                                                       DUDB1     938
      ENTRY DUDB20(LORD,NLF1,KN,CID)                                    DUDB1     939
CD                                                                      DUDB1     940
CD    FOR BLOCK TYPE 20 (NATURAL LOG BLOCK).                            DUDB1     941
CD                                                                      DUDB1     942
      LDEB=(JDEB(264).NE.0)                                             DUDB1     943
C                                                                       DUDB1     944
      VALI=0.0                                                          DUDB1     945
      IORD=IDDAT(JE4+LORD)                                              DUDB1     946
      JEI=JEB+2                                                         DUDB1     947
      KINT=KINPU                                                        DUDB1     948
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     949
      IF(KINT.LT.KINPU) THEN                                            DUDB1     950
         DO 520 J=KINT+1,KINPU                                          DUDB1     951
         XDAT=GAINS(J)                                                  DUDB1     952
         IOUT=INPUTS(J)                                                 DUDB1     953
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1     954
  520    CONTINUE                                                       DUDB1     955
      ENDIF                                                             DUDB1     956
      KINP=KINPU                                                        DUDB1     957
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1     958
      IF(KINP.LT.KINPU) THEN                                            DUDB1     959
         DO 530 J=KINP+1,KINPU                                          DUDB1     960
         XDAT=GAINS(J)                                                  DUDB1     961
         IIN=INPUTS(J)                                                  DUDB1     962
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1     963
  530    CONTINUE                                                       DUDB1     964
      ENDIF                                                             DUDB1     965
      IF(VALI.LE.0.0) THEN                                              DUDB1     966
C         WRITE(IU6,1240)IORD,BLNAM1,BLNAM2,VALI                        DUDB1     967
         WRITE(MSG(1),2000) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB1     968
         WRITE(MSG(2),1240)IORD,BLNAM1,BLNAM2,VALI                      DUDB1     969
         CALL PRTMSG(2)                                                 DUDB1     970
         MSG(1)='DUDB20: UD ERROR'                                      DUDB1     971
         CALL ASTOP(MSG(1),16)                                          DUDB1     972
      ENDIF                                                             DUDB1     973
      VALOUT(IORD)=LOG(VALI)                                            DUDB1     974
      DDAT(JEI+1)=1.0/VALI                                              DUDB1     975
      IF(LDEB) WRITE(IUD6,1230) LORD,IORD,VALOUT(IORD)                  DUDB1     976
C                                                                       DUDB1     977
      RETURN                                                            DUDB1     978
 1230 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1     979
 1240 FORMAT(5X,'LOG BLOCK: ',I3,'(',2A4                                DUDB1     980
     *,') HAS UNACCEPTABLE INPUT = ',F10.5)                             DUDB1     981
C                                                                       DUDB1     982
C-----------------------------------------------------------------------DUDB1     983
C                                                                       DUDB1     984
      ENTRY DUDB21(LORD,NLF1,KN,CID)                                    DUDB1     985
CD                                                                      DUDB1     986
CD    FOR BLOCK TYPE 21 (ABSOLUTE VALUE BLOCK).                         DUDB1     987
CD                                                                      DUDB1     988
      LDEB=(JDEB(264).NE.0)                                             DUDB1     989
C                                                                       DUDB1     990
      VALI=0.0                                                          DUDB1     991
      IORD=IDDAT(JE4+LORD)                                              DUDB1     992
      JEI=JEB+2                                                         DUDB1     993
      KINT=KINPU                                                        DUDB1     994
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1     995
      IF(KINT.LT.KINPU) THEN                                            DUDB1     996
         DO 540 J=KINT+1,KINPU                                          DUDB1     997
         XDAT=GAINS(J)                                                  DUDB1     998
         IOUT=INPUTS(J)                                                 DUDB1     999
         VALI=VALI+VALOUT(IOUT)*XDAT                                    DUDB1    1000
  540    CONTINUE                                                       DUDB1    1001
      ENDIF                                                             DUDB1    1002
      KINP=KINPU                                                        DUDB1    1003
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1    1004
      IF(KINP.LT.KINPU) THEN                                            DUDB1    1005
         DO 550 J=KINP+1,KINPU                                          DUDB1    1006
         XDAT=GAINS(J)                                                  DUDB1    1007
         IIN=INPUTS(J)                                                  DUDB1    1008
         VALI=VALI+VALIN(IIN)*XDAT                                      DUDB1    1009
  550    CONTINUE                                                       DUDB1    1010
      ENDIF                                                             DUDB1    1011
      VALOUT(IORD)=ABS(VALI)                                            DUDB1    1012
      DDAT(JEI+1)=1.0                                                   DUDB1    1013
      IF(VALI.LT.0.0) DDAT(JEI+1)=-1.0                                  DUDB1    1014
      IF(LDEB) WRITE(IUD6,1250) LORD,IORD,VALOUT(IORD)                  DUDB1    1015
C                                                                       DUDB1    1016
      RETURN                                                            DUDB1    1017
 1250 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1    1018
C                                                                       DUDB1    1019
C-----------------------------------------------------------------------DUDB1    1020
C                                                                       DUDB1    1021
      ENTRY DUDB27(LORD,NLF1,KN,CID)                                    DUDB1    1022
CD                                                                      DUDB1    1023
CD    FOR BLOCK TYPE 27 (LOGIC SWITCH BLOCK).                           DUDB1    1024
CD                                                                      DUDB1    1025
      LDEB=(JDEB(264).NE.0)                                             DUDB1    1026
C                                                                       DUDB1    1027
      II=0                                                              DUDB1    1028
      IORD=IDDAT(JE4+LORD)                                              DUDB1    1029
      JEI=JEB+2                                                         DUDB1    1030
      KINT=KINPU                                                        DUDB1    1031
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1    1032
      IF(KINT.LT.KINPU) THEN                                            DUDB1    1033
         DO 560 J=KINT+1,KINPU                                          DUDB1    1034
         XDAT=GAINS(J)                                                  DUDB1    1035
         IOUT=INPUTS(J)                                                 DUDB1    1036
         II=II+1                                                        DUDB1    1037
         IF(II.EQ.1) THEN                                               DUDB1    1038
            VALI1=VALOUT(IOUT)*XDAT                                     DUDB1    1039
            GO TO 560                                                   DUDB1    1040
         ENDIF                                                          DUDB1    1041
         IF(II.EQ.2) THEN                                               DUDB1    1042
            VALI2=VALOUT(IOUT)*XDAT                                     DUDB1    1043
            GO TO 560                                                   DUDB1    1044
         ENDIF                                                          DUDB1    1045
         VALI3=VALOUT(IOUT)*XDAT                                        DUDB1    1046
  560    CONTINUE                                                       DUDB1    1047
      ENDIF                                                             DUDB1    1048
      KINP=KINPU                                                        DUDB1    1049
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1    1050
      IF(KINP.LT.KINPU) THEN                                            DUDB1    1051
         DO 570 J=KINP+1,KINPU                                          DUDB1    1052
         XDAT=GAINS(J)                                                  DUDB1    1053
         IIN=INPUTS(J)                                                  DUDB1    1054
         II=II+1                                                        DUDB1    1055
         IF(II.EQ.1) THEN                                               DUDB1    1056
            VALI1=VALIN(IIN)*XDAT                                       DUDB1    1057
            GO TO 570                                                   DUDB1    1058
         ENDIF                                                          DUDB1    1059
         IF(II.EQ.2) THEN                                               DUDB1    1060
            VALI2=VALIN(IIN)*XDAT                                       DUDB1    1061
            GO TO 570                                                   DUDB1    1062
         ENDIF                                                          DUDB1    1063
         VALI3=VALIN(IIN)*XDAT                                          DUDB1    1064
  570    CONTINUE                                                       DUDB1    1065
      ENDIF                                                             DUDB1    1066
      IF (VALI3.LE.DDAT(JEI+1)) THEN                                    DUDB1    1067
         VALO=VALI1                                                     DUDB1    1068
         IDDAT(JEI+2)=1                                                 DUDB1    1069
      ELSE                                                              DUDB1    1070
         VALO=VALI2                                                     DUDB1    1071
         IDDAT(JEI+2)=2                                                 DUDB1    1072
      END IF                                                            DUDB1    1073
      VALOUT(IORD)=VALO                                                 DUDB1    1074
      IF(LDEB) WRITE(IUD6,1260) LORD,IORD,VALOUT(IORD)                  DUDB1    1075
C                                                                       DUDB1    1076
      RETURN                                                            DUDB1    1077
 1260 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1    1078
C                                                                       DUDB1    1079
C-----------------------------------------------------------------------DUDB1    1080
C                                                                       DUDB1    1081
      ENTRY DUDB28(LORD,NLF1,KN,CID)                                    DUDB1    1082
CD                                                                      DUDB1    1083
CD    FOR BLOCK TYPE 28 (TIMER BLOCK).                                  DUDB1    1084
CD                                                                      DUDB1    1085
      LDEB=(JDEB(264).NE.0)                                             DUDB1    1086
C                                                                       DUDB1    1087
      VALI=0.0                                                          DUDB1    1088
      IORD=IDDAT(JE4+LORD)                                              DUDB1    1089
      JEI=JEB+2                                                         DUDB1    1090
      KINT=KINPU                                                        DUDB1    1091
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1    1092
      IF(KINT.LT.KINPU) THEN                                            DUDB1    1093
         J=KINT+1                                                       DUDB1    1094
         XDAT=GAINS(J)                                                  DUDB1    1095
         IOUT=INPUTS(J)                                                 DUDB1    1096
         VALI=VALOUT(IOUT)*XDAT                                         DUDB1    1097
         GO TO 580                                                      DUDB1    1098
      ENDIF                                                             DUDB1    1099
      KINP=KINPU                                                        DUDB1    1100
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1    1101
      IF(KINP.LT.KINPU) THEN                                            DUDB1    1102
         J=KINP+1                                                       DUDB1    1103
         XDAT=GAINS(J)                                                  DUDB1    1104
         IIN=INPUTS(J)                                                  DUDB1    1105
         VALI=VALIN(IIN)*XDAT                                           DUDB1    1106
      ENDIF                                                             DUDB1    1107
  580 CONTINUE                                                          DUDB1    1108
      IF(VALI.GT.DDAT(JEI+1)) THEN                                      DUDB1    1109
         VALOUT(IORD)=0.0                                               DUDB1    1110
         DDAT(JEI+2)=TS                                                 DUDB1    1111
      ELSE                                                              DUDB1    1112
         VALOUT(IORD)=TS-DDAT(JEI+2)                                    DUDB1    1113
      ENDIF                                                             DUDB1    1114
      IF(LDEB) WRITE(IUD6,1270) LORD,IORD,VALOUT(IORD)                  DUDB1    1115
C                                                                       DUDB1    1116
      RETURN                                                            DUDB1    1117
 1270 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1    1118
C                                                                       DUDB1    1119
C-----------------------------------------------------------------------DUDB1    1120
C                                                                       DUDB1    1121
      ENTRY DUDB30(LORD,NLF1,KN,CID)                                    DUDB1    1122
CD                                                                      DUDB1    1123
CD    FOR BLOCK TYPE 30 (COUNTER BLOCK).                                DUDB1    1124
CD                                                                      DUDB1    1125
      LDEB=(JDEB(264).NE.0)                                             DUDB1    1126
C                                                                       DUDB1    1127
      VALI=0.0                                                          DUDB1    1128
      IORD=IDDAT(JE4+LORD)                                              DUDB1    1129
      JEI=JEB+2                                                         DUDB1    1130
      KINT=KINPU                                                        DUDB1    1131
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1    1132
      IF(KINT.LT.KINPU) THEN                                            DUDB1    1133
         J=KINT+1                                                       DUDB1    1134
         XDAT=GAINS(J)                                                  DUDB1    1135
         IOUT=INPUTS(J)                                                 DUDB1    1136
         VALI=VALOUT(IOUT)*XDAT                                         DUDB1    1137
         GO TO 590                                                      DUDB1    1138
      ENDIF                                                             DUDB1    1139
      KINP=KINPU                                                        DUDB1    1140
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1    1141
      IF(KINP.LT.KINPU) THEN                                            DUDB1    1142
         J=KINP+1                                                       DUDB1    1143
         XDAT=GAINS(J)                                                  DUDB1    1144
         IIN=INPUTS(J)                                                  DUDB1    1145
         VALI=VALIN(IIN)*XDAT                                           DUDB1    1146
      ENDIF                                                             DUDB1    1147
  590 CONTINUE                                                          DUDB1    1148
C                                                                       DUDB1    1149
      IVALO=IDDAT(JEI+12)                                               DUDB1    1150
      DIFF=TS-DDAT(JEI+9)                                               DUDB1    1151
      IF(DIFF.LE.0.0) GO TO 600                                         DUDB1    1152
      IF(VALI.GT.DDAT(JEI+2)) THEN                                      DUDB1    1153
         DDAT(JEI+10)=DDAT(JEI+10)+DIFF                                 DUDB1    1154
         IF(DDAT(JEI+10).GE.DDAT(JEI+1)) THEN                           DUDB1    1155
            IF(IDDAT(JEI+12).LT.IDDAT(JEI+6)) THEN                      DUDB1    1156
               IDDAT(JEI+12)=IDDAT(JEI+12)+1                            DUDB1    1157
               DDAT(JEI+10)=0.0                                         DUDB1    1158
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB1    1159
         WRITE(MSG(1),2001) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB1    1160
                  WRITE(MSG(2),1290) IORD,TS                            DUDB1    1161
                  WRITE(MSG(3),1300) IVALO,IDDAT(JEI+12)                DUDB1    1162
                  CALL PRTMSG(3)                                        DUDB1    1163
               ENDIF                                                    DUDB1    1164
            ENDIF                                                       DUDB1    1165
         ENDIF                                                          DUDB1    1166
         GO TO 600                                                      DUDB1    1167
      ELSE                                                              DUDB1    1168
         DDAT(JEI+10)=0.0                                               DUDB1    1169
      ENDIF                                                             DUDB1    1170
      IF(VALI.LT.DDAT(JEI+3)) THEN                                      DUDB1    1171
         DDAT(JEI+11)=DDAT(JEI+11)+DIFF                                 DUDB1    1172
         IF(DDAT(JEI+11).GE.DDAT(JEI+1)) THEN                           DUDB1    1173
            IF(IDDAT(JEI+12).GT.IDDAT(JEI+7)) THEN                      DUDB1    1174
               IDDAT(JEI+12)=IDDAT(JEI+12)-1                            DUDB1    1175
               DDAT(JEI+11)=0.0                                         DUDB1    1176
               IF(BLNAM1(1:1).EQ.'P')THEN                               DUDB1    1177
         WRITE(MSG(1),2001) NLF1,INAME(KN-2),INAME(KN-1),INAME(KN),CID  DUDB1    1178
                  WRITE(MSG(2),1290) IORD,TS                            DUDB1    1179
                  WRITE(MSG(3),1300) IVALO,IDDAT(JEI+12)                DUDB1    1180
                  CALL PRTMSG(3)                                        DUDB1    1181
               ENDIF                                                    DUDB1    1182
            ENDIF                                                       DUDB1    1183
         ENDIF                                                          DUDB1    1184
      ELSE                                                              DUDB1    1185
         DDAT(JEI+11)=0.0                                               DUDB1    1186
      ENDIF                                                             DUDB1    1187
  600 VALOUT(IORD)=IDDAT(JEI+12)                                        DUDB1    1188
      DDAT(JEI+9)=TS                                                    DUDB1    1189
      IF(LDEB) WRITE(IUD6,1280) LORD,IORD,VALOUT(IORD)                  DUDB1    1190
C                                                                       DUDB1    1191
      RETURN                                                            DUDB1    1192
 1280 FORMAT(1X,'LORD,IORD,VALOUT(IORD): ',2I5,F10.3)                   DUDB1    1193
 1290 FORMAT(5X,'COUNTER BLOCK (BL#',I2,'): AT T=',F11.4,' SEC')        DUDB1    1194
 1300 FORMAT(5X,'THE OUTPUT IS CHANGED FROM',I6,' TO',I6)               DUDB1    1195
C                                                                       DUDB1    1196
C-----------------------------------------------------------------------DUDB1    1197
C                                                                       DUDB1    1198
      ENTRY DUDB69(LORD,NLF1,KN,CID)                                    DUDB1    1199
CD                                                                      DUDB1    1200
CD    FOR BLOCK TYPE 69 (POWER BLOCK).                                  DUDB1    1201
CD                                                                      DUDB1    1202
      LDEB=(JDEB(264).NE.0)                                             DUDB1    1203
C                                                                       DUDB1    1204
      VALI=0.0                                                          DUDB1    1205
      IORD=IDDAT(JE4+LORD)                                              DUDB1    1206
      JEI=JEB+2                                                         DUDB1    1207
      AX=DDAT(JEI+1)                                                    DUDB1    1208
      BX=DDAT(JEI+2)                                                    DUDB1    1209
      KINT=KINPU                                                        DUDB1    1210
      KINPU=KINPU+IDDAT(JEI+13)                                         DUDB1    1211
      IF(KINT.LT.KINPU) THEN                                            DUDB1    1212
         DO 610 J=KINT+1,KINPU                                          DUDB1    1213
         XDAT=GAINS(J)                                                  DUDB1    1214
         IOUT=INPUTS(J)                                                 DUDB1    1215
         VALIX=VALOUT(IOUT)*XDAT                                        DUDB1    1216
         VALIX=ABS(VALIX)                                               DUDB1    1217
         VALI=VALI+VALIX**AX                                            DUDB1    1218
  610    CONTINUE                                                       DUDB1    1219
      ENDIF                                                             DUDB1    1220
      KINP=KINPU                                                        DUDB1    1221
      KINPU=KINPU+IDDAT(JEI+14)                                         DUDB1    1222
      IF(KINP.LT.KINPU) THEN                                            DUDB1    1223
         DO 620 J=KINP+1,KINPU                                          DUDB1    1224
         XDAT=GAINS(J)                                                  DUDB1    1225
         IIN=INPUTS(J)                                                  DUDB1    1226
         VALIX=VALIN(IIN)*XDAT                                          DUDB1    1227
         VALIX=ABS(VALIX)                                               DUDB1    1228
         VALI=VALI+VALIX**AX                                            DUDB1    1229
  620    CONTINUE                                                       DUDB1    1230
      ENDIF                                                             DUDB1    1231
      VALOUT(IORD)=VALI**BX                                             DUDB1    1232
      BX1=BX-1.0                                                        DUDB1    1233
      DDAT(JEI+3)=AX*BX*(VALI**BX1)                                     DUDB1    1234
      IF(LDEB) WRITE(IUD6,1000) LORD,IORD,VALOUT(IORD)                  DUDB1    1235
C                                                                       DUDB1    1236
      RETURN                                                            DUDB1    1237
C                                                                       DUDB1    1238
C-----------------------------------------------------------------------DUDB1    1239
C                                                                       DUDB1    1240
      ENTRY DUDB70(LORD,NLF1,KN,CID)                                    DUDB1    1241
CD                                                                      DUDB1    1242
CD    FOR BLOCK TYPE 70 (COMPENSATION BLOCK).                           DUDB1    1243
CD                                                                      DUDB1    1244
      LDEB=(JDEB(264).NE.0)                                             DUDB1    1245
C                                                                       DUDB1    1246
      IORD=IDDAT(JE4+LORD)                                              DUDB1    1247
      JEI=JEB+2                                                         DUDB1    1248
      RBL=DDAT(JEI+1)                                                   DUDB1    1249
      XBL=DDAT(JEI+2)                                                   DUDB1    1250
      NBX=IDDAT(JEI+3)                                                  DUDB1    1251
      IF(NBX.GT.0.AND.NBX.LE.NRBUS) THEN                                DUDB1    1252
         VNB=VALIN(20+NBX)                                              DUDB1    1253
         ANB=VALIN(30+NBX)                                              DUDB1    1254
         VNBR=VNB*COS(ANB)                                              DUDB1    1255
         VNBI=VNB*SIN(ANB)                                              DUDB1    1256
      ELSE                                                              DUDB1    1257
         VNBR=0.0                                                       DUDB1    1258
         VNBI=0.0                                                       DUDB1    1259
      ENDIF                                                             DUDB1    1260
      NLX=IDDAT(JEI+4)                                                  DUDB1    1261
      IF(NLX.GT.0.AND.NLX.LE.NRLIN) THEN                                DUDB1    1262
         LOC=IDDAT(JE2+4*NLX)                                           DUDB1    1263
         CALL GETCUR(CURR,CURI,LOC)                                     DUDB1    1264
      ELSE                                                              DUDB1    1265
         CURR=0.0                                                       DUDB1    1266
         CURI=0.0                                                       DUDB1    1267
      ENDIF                                                             DUDB1    1268
      VALOR=VNBR+RBL*CURR-XBL*CURI                                      DUDB1    1269
      VALOI=VNBI+RBL*CURI+XBL*CURR                                      DUDB1    1270
      MODE=IDDAT(JEI+5)                                                 DUDB1    1271
      IF(MODE.EQ.0) THEN                                                DUDB1    1272
         VALOUT(IORD)=SQRT(VALOR**2+VALOI**2)                           DUDB1    1273
      ELSEIF(MODE.EQ.1) THEN                                            DUDB1    1274
         VMG2=VALOR**2+VALOI**2                                         DUDB1    1275
         IF(VMG2.GT.0.000001) THEN                                      DUDB1    1276
            VAG=ATAN2(VALOI,VALOR)                                      DUDB1    1277
            VAGD=DDAT(JEI+7)-VAG                                        DUDB1    1278
            DDAT(JEI+7)=VAG                                             DUDB1    1279
            IF(VAGD.GT.3.15) THEN                                       DUDB1    1280
               IDDAT(JEI+6)=IDDAT(JEI+6)+1                              DUDB1    1281
            ELSEIF(VAGD.LT.-3.15) THEN                                  DUDB1    1282
               IDDAT(JEI+6)=IDDAT(JEI+6)-1                              DUDB1    1283
            ENDIF                                                       DUDB1    1284
            VALOUT(IORD)=VAG+6.2831853*IDDAT(JEI+6)                     DUDB1    1285
         ELSE                                                           DUDB1    1286
            VALOUT(IORD)=DDAT(JEI+7)+6.2831853*IDDAT(JEI+6)             DUDB1    1287
         ENDIF                                                          DUDB1    1288
      ELSEIF(MODE.EQ.2) THEN                                            DUDB1    1289
         VALOUT(IORD)=VALOR                                             DUDB1    1290
      ELSEIF(MODE.EQ.3) THEN                                            DUDB1    1291
         VALOUT(IORD)=VALOI                                             DUDB1    1292
      ELSE                                                              DUDB1    1293
         VALOUT(IORD)=0.0                                               DUDB1    1294
      ENDIF                                                             DUDB1    1295
      IF(LDEB) WRITE(IUD6,1000) LORD,IORD,VALOUT(IORD)                  DUDB1    1296
C                                                                       DUDB1    1297
      RETURN                                                            DUDB1    1298
 2000 FORMAT(' *** ERROR USER DEFINED MODEL AT BUS:',I6,' STATION: '    DUDB1    1299
     *,3A4,' ID:',A4)                                                   DUDB1    1300
 2001 FORMAT(' *** MESSAGE USER DEFINED MODEL AT BUS:',I6,' STATION: '  DUDB1    1301
     *,3A4,' ID:',A4)                                                   DUDB1    1302
 2010 FORMAT(5X,'DELAY BLOCK: ',I3,'(',2A4,')')                         DUDB1    1303
 2020 FORMAT(5X,'HAS ITS HISTORY OVERWRITTEN AT TIME=',F11.4)           DUDB1    1304
 2030 FORMAT(5X,'MAKE SURE THE DELAY CONTAINS LESS TIME STEPS THAN',    DUDB1    1305
     *' NDLEN=',I5)                                                     DUDB1    1306
      END                                                               DUDB1    1307
