CFPRIME DBXDOT                                                          DBXDOT      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 DBXDOT                                                 DBXDOT      3
CD                                                                      DBXDOT      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF SDB FOR USE IN THE  DBXDOT      5
CD    TRAPEZOIDAL METHOD. THIS SUBROUTINE IS SIMILAR TO SUBROUTINE      DBXDOT      6
CD    DESDB. THE DIFFERENCES ARE                                        DBXDOT      7
CD                                                                      DBXDOT      8
CD    1. THE PARTS RELATED TO THE RUNGE-KUTTA METHOD ARE DELETED        DBXDOT      9
CD                                                                      DBXDOT     10
CD    2. THE JACOBIAN CLACULATION PATH IS ADDED                         DBXDOT     11
CD                                                                      DBXDOT     12
CD    3. THE STATE DERIVATIVE ARRAY, XDOT, IS HERE A GLOBAL ARRAY       DBXDOT     13
CD                                                                      DBXDOT     14
      INCLUDE 'PARX.INS'                                                DBXDOT     15
      INCLUDE 'CNPT.INS'                                                DBXDOT     16
      INCLUDE 'CNIPTR.INS'                                              DBXDOT     17
      INCLUDE 'CNB4.INS'                                                DBXDOT     18
      INCLUDE 'CNB9.INS'                                                DBXDOT     19
      INCLUDE 'CNB91.INS'                                               DBXDOT     20
      INCLUDE 'CNSDB.INS'                                               DBXDOT     21
      INCLUDE 'CNUDM.INS'                                               DBXDOT     22
      INCLUDE 'CNUDMA.INS'                                              DBXDOT     23
      INCLUDE 'CNUDMB.INS'                                              DBXDOT     24
      INCLUDE 'CNUDMK.INS'                                              DBXDOT     25
C                                                                       DBXDOT     26
      INCLUDE 'CNXSTA.INS'                                              DBXDOT     27
      INCLUDE 'CNQSTA.INS'                                              DBXDOT     28
      INCLUDE 'CNZSTA.INS'                                              DBXDOT     29
      INCLUDE 'CNMDAT.INS'                                              DBXDOT     30
      INCLUDE 'CNVOLT.INS'                                              DBXDOT     31
      INCLUDE 'CNMYVA.INS'                                              DBXDOT     32
      INCLUDE 'CNYVAR.INS'                                              DBXDOT     33
      INCLUDE 'CNXDOT.INS'                                              DBXDOT     34
      INCLUDE 'CNIMPR.INS'                                              DBXDOT     35
      INCLUDE 'CNJCOB.INS'                                              DBXDOT     36
      INCLUDE 'CNGEAR.INS'                                              DBXDOT     37
      INCLUDE 'CNABAK.INS'                                              DBXDOT     38
C                                                                       DBXDOT     39
      CHARACTER*80 MSG                                                  DBXDOT     40
C                                                                       DBXDOT     41
      DIMENSION CDEV(4),YSEL(4,4)                                       DBXDOT     42
C                                                                       DBXDOT     43
      CHARACTER*2 LCKT                                                  DBXDOT     44
      DATA LCKT/'  '/                                                   DBXDOT     45
C                                                                       DBXDOT     46
      DO 500 N=1,NSDB                                                   DBXDOT     47
      JD=JDDAT(N)                                                       DBXDOT     48
      JSTATE=JXSDB(N)                                                   DBXDOT     49
      JY=JVSDB(N)                                                       DBXDOT     50
      NDTYPN=IDDAT(JD+2)                                                DBXDOT     51
      IF(NDTYPN.NE.50) GOTO 500                                         DBXDOT     52
C                                                                       DBXDOT     53
C     GET THE INPUT VALUES                                              DBXDOT     54
C                                                                       DBXDOT     55
      LSTATE=0                                                          DBXDOT     56
      JE0=JD+3                                                          DBXDOT     57
      JE1=JE0+3                                                         DBXDOT     58
      CALL RINUDM                                                       DBXDOT     59
C                                                                       DBXDOT     60
      K1=IDDAT(JD+1)                                                    DBXDOT     61
      NLF1=NOLD(K1)                                                     DBXDOT     62
      K13=K1*3                                                          DBXDOT     63
      VRE=REAL(VOLT(K1))                                                DBXDOT     64
      VIM=AIMAG(VOLT(K1))                                               DBXDOT     65
      VMG=SQRT(VRE*VRE+VIM*VIM)                                         DBXDOT     66
      VALIN(7)=VMG                                                      DBXDOT     67
      IF(VMG.GT.0.05)THEN                                               DBXDOT     68
         VAG=ATAN2(VIM,VRE)                                             DBXDOT     69
         VAGD=DDAT(JE0+2)-VAG                                           DBXDOT     70
         DDAT(JE0+2)=VAG                                                DBXDOT     71
         IF(VAGD.GT.3.15) THEN                                          DBXDOT     72
            IDDAT(JE0+1)=IDDAT(JE0+1)+1                                 DBXDOT     73
         ELSEIF(VAGD.LT.-3.15) THEN                                     DBXDOT     74
            IDDAT(JE0+1)=IDDAT(JE0+1)-1                                 DBXDOT     75
         ENDIF                                                          DBXDOT     76
         VALIN(9)=VAG+6.2831853*IDDAT(JE0+1)                            DBXDOT     77
      ELSE                                                              DBXDOT     78
         VALIN(9)=DDAT(JE0+2)+6.2831853*IDDAT(JE0+1)                    DBXDOT     79
      ENDIF                                                             DBXDOT     80
      VALIN(1)=VMG*YDEV(JY+2)                                           DBXDOT     81
      VALIN(3)=VMG*VALIN(1)                                             DBXDOT     82
C                                                                       DBXDOT     83
      VALIN(5)=YDEV(JY+2)                                               DBXDOT     84
      VALIN(12)=SSDB(JY+3)                                              DBXDOT     85
C                                                                       DBXDOT     86
      KORD=0                                                            DBXDOT     87
      CALL DEUDM(H,KORD,NLF1,K13,LCKT)                                  DBXDOT     88
      JE0=1                                                             DBXDOT     89
C                                                                       DBXDOT     90
      DO 100 J=1,KORD                                                   DBXDOT     91
         XDOT(JSTATE+J)=DSTATE(J)                                       DBXDOT     92
  100 CONTINUE                                                          DBXDOT     93
C                                                                       DBXDOT     94
      IOUT=IDDAT(JE7+1)                                                 DBXDOT     95
      BASERT=BASER(JY+4)                                                DBXDOT     96
      YSDB(JY+1)=VALOUT(IOUT)*BASERT                                    DBXDOT     97
      YDEV(JY+2)=VALOUT(IOUT)                                           DBXDOT     98
      SSDB(JY+3)=VALIN(12)                                              DBXDOT     99
C                                                                       DBXDOT    100
      JYUDM=JY+4                                                        DBXDOT    101
      DO 110 J=1,NUDB                                                   DBXDOT    102
         YVAR(JYUDM+J)=VALOUT(J)                                        DBXDOT    103
  110 CONTINUE                                                          DBXDOT    104
C                                                                       DBXDOT    105
C     UPDATE JACOBIAN MATRICES                                          DBXDOT    106
C                                                                       DBXDOT    107
      IF (NITER.GT.0) GOTO 120                                          DBXDOT    108
C                                                                       DBXDOT    109
      YSDBN=YSDB(JY+1)                                                  DBXDOT    110
C                                                                       DBXDOT    111
      CALL MOVE(0,MBUSR,MBUSR,70)                                       DBXDOT    112
      CALL FMOVE(0,UDAT,UDAT,NXUDB**2)                                  DBXDOT    113
      MBUSR(1)=K1                                                       DBXDOT    114
C                                                                       DBXDOT    115
      JEU=JE7-JE1+2                                                     DBXDOT    116
      DO 130 I=1,JEU                                                    DBXDOT    117
         UDAT(I)=DDAT(I+JE1-1)                                          DBXDOT    118
  130 CONTINUE                                                          DBXDOT    119
      IWS1=JD+5                                                         DBXDOT    120
      JE1=JE1-IWS1                                                      DBXDOT    121
      JE2=JE2-IWS1                                                      DBXDOT    122
      JE3=JE3-IWS1                                                      DBXDOT    123
      JE4=JE4-IWS1                                                      DBXDOT    124
      JE5=JE5-IWS1                                                      DBXDOT    125
      JE6=JE6-IWS1                                                      DBXDOT    126
      JE7=JE7-IWS1                                                      DBXDOT    127
C                                                                       DBXDOT    128
C     FORM: DEL I = CDEV*DEL YC+YDEV*DEL V                              DBXDOT    129
C                   (-YSEL*DEL V, AFTER INTERCONNECTION)                DBXDOT    130
C                                                                       DBXDOT    131
C          DEL U0 = XUI*DEL I+XUV*DEL V+XUY*DEL YB+XUREF*DEL VREF       DBXDOT    132
C                                                                       DBXDOT    133
      DO 50 I=1,20                                                      DBXDOT    134
      DO 40 J=1,NXUDB                                                   DBXDOT    135
      XUY(I,J)=0.0                                                      DBXDOT    136
  40  CONTINUE                                                          DBXDOT    137
      DO 50 J=1,LOUTP                                                   DBXDOT    138
      XUI(I,J)=0.0                                                      DBXDOT    139
      XUV(I,J)=0.0                                                      DBXDOT    140
  50  CONTINUE                                                          DBXDOT    141
C      CALL FMOVE(0,XUI,XUI,20*LOUTP)                                   DBXDOT    142
C      CALL FMOVE(0,XUV,XUV,20*LOUTP)                                   DBXDOT    143
C      CALL FMOVE(0,XUY,XUY,20*NXUDB)                                   DBXDOT    144
C                                                                       DBXDOT    145
      IBEND=IUDAT(JE7+1)                                                DBXDOT    146
C                                                                       DBXDOT    147
      IF(YSDBN.GT.0.0) THEN                                             DBXDOT    148
         CDEV(1)=VRE                                                    DBXDOT    149
         CDEV(2)=VIM                                                    DBXDOT    150
C                                                                       DBXDOT    151
         YSEL(1,1)=YSDBN                                                DBXDOT    152
         YSEL(1,2)=0.0                                                  DBXDOT    153
         YSEL(2,1)=0.0                                                  DBXDOT    154
         YSEL(2,2)=YSDBN                                                DBXDOT    155
C                                                                       DBXDOT    156
         YDEVS(1,1)=YSDBN                                               DBXDOT    157
         YDEVS(1,2)=0.0                                                 DBXDOT    158
         YDEVS(2,1)=0.0                                                 DBXDOT    159
         YDEVS(2,2)=YSDBN                                               DBXDOT    160
      ELSE                                                              DBXDOT    161
         CDEV(1)=VIM                                                    DBXDOT    162
         CDEV(2)=-VRE                                                   DBXDOT    163
C                                                                       DBXDOT    164
         YSEL(1,1)=0.0                                                  DBXDOT    165
         YSEL(1,2)=YSDBN                                                DBXDOT    166
         YSEL(2,1)=-YSDBN                                               DBXDOT    167
         YSEL(2,2)=0.0                                                  DBXDOT    168
C                                                                       DBXDOT    169
         YDEVS(1,1)=0.0                                                 DBXDOT    170
         YDEVS(1,2)=YSDBN                                               DBXDOT    171
         YDEVS(2,1)=-YSDBN                                              DBXDOT    172
         YDEVS(2,2)=0.0                                                 DBXDOT    173
         YSDBN=-YSDBN                                                   DBXDOT    174
      ENDIF                                                             DBXDOT    175
C                                                                       DBXDOT    176
      XUV(1,1)=YSDBN*VRE/VMG                                            DBXDOT    177
      XUV(1,2)=YSDBN*VIM/VMG                                            DBXDOT    178
      XUV(3,1)=2.0*YSDBN*VRE                                            DBXDOT    179
      XUV(3,2)=2.0*YSDBN*VIM                                            DBXDOT    180
      XUV(7,1)=VRE/VMG                                                  DBXDOT    181
      XUV(7,2)=VIM/VMG                                                  DBXDOT    182
      XUV(9,1)=-VIM/VMG/VMG                                             DBXDOT    183
      XUV(9,2)=VRE/VMG/VMG                                              DBXDOT    184
C                                                                       DBXDOT    185
      XUY(1,IBEND)=VMG                                                  DBXDOT    186
      XUY(3,IBEND)=VMG*VMG                                              DBXDOT    187
      XUY(5,IBEND)=1.0                                                  DBXDOT    188
C                                                                       DBXDOT    189
C     FORM THE REMOTE BUS ARRAY AND CONTROL A B C D MATRICES            DBXDOT    190
C                                                                       DBXDOT    191
      LCYO=1                                                            DBXDOT    192
      LWIF=0                                                            DBXDOT    193
      NBUSS=1                                                           DBXDOT    194
      NBUSR=0                                                           DBXDOT    195
      CALL AUDMB(LCYO,LWIF,NBUSR,NBUSS)                                 DBXDOT    196
      IF (KERUDM.NE.0) GO TO 900                                        DBXDOT    197
C                                                                       DBXDOT    198
      IROWAK=2                                                          DBXDOT    199
      ICOLBV=1                                                          DBXDOT    200
      NBR(1)=K1                                                         DBXDOT    201
      IF (NBUSR.NE.0) THEN                                              DBXDOT    202
         DO 210 I=1,NBUSR                                               DBXDOT    203
            ICOLBV=ICOLBV+1                                             DBXDOT    204
            NBR(ICOLBV)=MBUSR(NBUSS+I)                                  DBXDOT    205
  210    CONTINUE                                                       DBXDOT    206
      END IF                                                            DBXDOT    207
C                                                                       DBXDOT    208
C     SOLVE THE CONTROL EQUATIONS                                       DBXDOT    209
C                                                                       DBXDOT    210
      LREM=2*NBUSR                                                      DBXDOT    211
      CALL AUDMC(IROWAK,LCYO,LWIF,LREM)                                 DBXDOT    212
      IF (KERUDM.NE.0) GO TO 900                                        DBXDOT    213
C                                                                       DBXDOT    214
C     FORM: DEL XDOT = AX*X+BXI*DEL I+BXV*DEL V(S&R)                    DBXDOT    215
C              DEL I = CX*X+ADEV*DEL I+YDEV*DEL V+YDEVR*DEL VR          DBXDOT    216
C                                                                       DBXDOT    217
      DO 220 I=1,KORD                                                   DBXDOT    218
         DO 230 J=1,KORD                                                DBXDOT    219
            AX(I,J)=AXB(I,J)                                            DBXDOT    220
  230    CONTINUE                                                       DBXDOT    221
  220 CONTINUE                                                          DBXDOT    222
C                                                                       DBXDOT    223
      DO 240 I=1,KORD                                                   DBXDOT    224
      BXV(I,1)=BUV(I,1)                                                 DBXDOT    225
      BXV(I,2)=BUV(I,2)                                                 DBXDOT    226
      BXI(I,1)=BUI(I,1)                                                 DBXDOT    227
      BXI(I,2)=BUI(I,2)                                                 DBXDOT    228
      CX(1,I)=CDEV(1)*CYX(1,I)                                          DBXDOT    229
      CX(2,I)=CDEV(2)*CYX(1,I)                                          DBXDOT    230
  240 CONTINUE                                                          DBXDOT    231
C                                                                       DBXDOT    232
      ADEV(1,1)=CDEV(1)*CYI(1,1)                                        DBXDOT    233
      ADEV(2,1)=CDEV(2)*CYI(1,1)                                        DBXDOT    234
      ADEV(1,2)=CDEV(1)*CYI(1,2)                                        DBXDOT    235
      ADEV(2,2)=CDEV(2)*CYI(1,2)                                        DBXDOT    236
      YDEVS(1,1)=YDEVS(1,1)+CDEV(1)*CYV(1,1)                            DBXDOT    237
      YDEVS(2,1)=YDEVS(2,1)+CDEV(2)*CYV(1,1)                            DBXDOT    238
      YDEVS(1,2)=YDEVS(1,2)+CDEV(1)*CYV(1,2)                            DBXDOT    239
      YDEVS(2,2)=YDEVS(2,2)+CDEV(2)*CYV(1,2)                            DBXDOT    240
C                                                                       DBXDOT    241
      IF (NBUSR.NE.0) THEN                                              DBXDOT    242
         DO 280 I=1,KORD                                                DBXDOT    243
            DO 290 J=1,2*NBUSR                                          DBXDOT    244
               BXV(I,J+4)=BUVR(I,J)                                     DBXDOT    245
  290       CONTINUE                                                    DBXDOT    246
  280    CONTINUE                                                       DBXDOT    247
         DO 300 I=1,2*NBUSR                                             DBXDOT    248
         YDEVR(1,I)=CDEV(1)*CYVR(1,I)                                   DBXDOT    249
         YDEVR(2,I)=CDEV(2)*CYVR(1,I)                                   DBXDOT    250
  300    CONTINUE                                                       DBXDOT    251
      END IF                                                            DBXDOT    252
C                                                                       DBXDOT    253
C     SOLVE THE DEVICE EQUATIONS                                        DBXDOT    254
C                                                                       DBXDOT    255
      LREF=1                                                            DBXDOT    256
      CALL AUDMD(KORD,IROWAK,LREM,LREF)                                 DBXDOT    257
      IF (KERUDM.NE.0) GO TO 900                                        DBXDOT    258
C                                                                       DBXDOT    259
C     LOAD A, B, C, D MATRICES TO WORKING ARRAYS                        DBXDOT    260
C                                                                       DBXDOT    261
      DO 340 I=1,KORD                                                   DBXDOT    262
         DO 350 J=1,KORD                                                DBXDOT    263
            A(I,J)=AX(I,J)                                              DBXDOT    264
  350    CONTINUE                                                       DBXDOT    265
         DO 360 J=1,2*ICOLBV                                            DBXDOT    266
            B(I,J)=BXV(I,J)                                             DBXDOT    267
  360    CONTINUE                                                       DBXDOT    268
         AK(1,I)=CX(1,I)                                                DBXDOT    269
         AK(2,I)=CX(2,I)                                                DBXDOT    270
  340 CONTINUE                                                          DBXDOT    271
C                                                                       DBXDOT    272
         YD(1,1)=YDEVS(1,1)                                             DBXDOT    273
         YD(1,2)=YDEVS(1,2)                                             DBXDOT    274
         YD(2,1)=YDEVS(2,1)                                             DBXDOT    275
         YD(2,2)=YDEVS(2,2)                                             DBXDOT    276
C                                                                       DBXDOT    277
      GOTO 370                                                          DBXDOT    278
C                                                                       DBXDOT    279
  900 CONTINUE                                                          DBXDOT    280
      MSG='DBXDOT: ERROR IN USER DEFINED SDB'                           DBXDOT    281
      CALL ASTOP(MSG,33)                                                DBXDOT    282
C                                                                       DBXDOT    283
  370 CONTINUE                                                          DBXDOT    284
C                                                                       DBXDOT    285
C     FINALLY FORM AG, BG, CG MATRICES (JACOBIAN MATRICES)              DBXDOT    286
C                                                                       DBXDOT    287
      NAIDEX=IAIDEX                                                     DBXDOT    288
      NBIDEX=IBIDEX                                                     DBXDOT    289
      NCIDEX=ICIDEX                                                     DBXDOT    290
C                                                                       DBXDOT    291
      IPATH=1                                                           DBXDOT    292
      IF (IPATH.EQ.1) THEN                                              DBXDOT    293
C                                                                       DBXDOT    294
C     FOR USE IN THE NORMAL TRAPEZOIDAL INTEGRATION METHOD              DBXDOT    295
C                                                                       DBXDOT    296
      DO 380 I=1,KORD                                                   DBXDOT    297
         DO 390 J=1,KORD                                                DBXDOT    298
            IF (IA(I,J).EQ.0) GOTO 390                                  DBXDOT    299
            A(I,J)=-CEFJM*A(I,J)                                        DBXDOT    300
 390     CONTINUE                                                       DBXDOT    301
         A(I,I)=A(I,I)+1.0                                              DBXDOT    302
         DO 400 J=1,2*ICOLBV                                            DBXDOT    303
            IF (IB(I,J).EQ.0) GOTO 400                                  DBXDOT    304
            B(I,J)=-CEFJM*B(I,J)                                        DBXDOT    305
 400     CONTINUE                                                       DBXDOT    306
 380  CONTINUE                                                          DBXDOT    307
C                                                                       DBXDOT    308
C     PERFORM LU FACTORIZATION FOR A                                    DBXDOT    309
C                                                                       DBXDOT    310
      CALL LUDCM(KORD)                                                  DBXDOT    311
C                                                                       DBXDOT    312
C     COMPUTE INVERSE(A)*B                                              DBXDOT    313
C                                                                       DBXDOT    314
      CALL FBSUBA(KORD)                                                 DBXDOT    315
C                                                                       DBXDOT    316
C     STORE AK IN CJCOB ARRAY                                           DBXDOT    317
C                                                                       DBXDOT    318
         DO 420 J=1,KORD                                                DBXDOT    319
         NCIDEX=NCIDEX+1                                                DBXDOT    320
         CJCOB(NCIDEX)=-AK(1,J)                                         DBXDOT    321
         CJCOB(NCIDEX+KORD)=-AK(2,J)                                    DBXDOT    322
 420     CONTINUE                                                       DBXDOT    323
C                                                                       DBXDOT    324
C     STORE A AND B IN AJCOB AND BJCOB ARRAY                            DBXDOT    325
C                                                                       DBXDOT    326
      DO 430 I=1,KORD                                                   DBXDOT    327
         DO 440 J=1,KORD                                                DBXDOT    328
            NAIDEX=NAIDEX+1                                             DBXDOT    329
            AJCOB(NAIDEX)=A(I,J)                                        DBXDOT    330
  440    CONTINUE                                                       DBXDOT    331
  430 CONTINUE                                                          DBXDOT    332
C                                                                       DBXDOT    333
      DO 450 I=1,ICOLBV                                                 DBXDOT    334
         NBIDEX=NBIDEX+1                                                DBXDOT    335
         IBJCOB(NBIDEX)=NBR(I)                                          DBXDOT    336
         IWS1=2*I                                                       DBXDOT    337
         DO 460 J=1,KORD                                                DBXDOT    338
            NBIDEX=NBIDEX+2                                             DBXDOT    339
            BJCOB(NBIDEX-1)=B(J,IWS1-1)                                 DBXDOT    340
            BJCOB(NBIDEX)=B(J,IWS1)                                     DBXDOT    341
  460    CONTINUE                                                       DBXDOT    342
  450 CONTINUE                                                          DBXDOT    343
      NBIDEX=NBIDEX+1                                                   DBXDOT    344
      IBJCOB(NBIDEX)=0                                                  DBXDOT    345
C                                                                       DBXDOT    346
      ELSE                                                              DBXDOT    347
C                                                                       DBXDOT    348
C     FOR USE IN GEAR'S METHOD TO CALCULATE THE SECOND ORDER DERIVATIVESDBXDOT    349
C                                                                       DBXDOT    350
C      DO 470 ILR=1,ISTATE                                              DBXDOT    351
C         DO 480 ILC=1,ISTATE                                           DBXDOT    352
C            ADGEN(ILR,ILC,N)=A(ILR,ILC)                                DBXDOT    353
C 480     CONTINUE                                                      DBXDOT    354
C         DO 490 ILC=1,ICOLBV                                           DBXDOT    355
C            BDGEN(ILR,ILC,N)=B(ILR,ILC)                                DBXDOT    356
C 490     CONTINUE                                                      DBXDOT    357
C         DO 495 ILC=1,IROWAK                                           DBXDOT    358
C            AKDGEN(ILC,ILR,N)=-AK(ILC,ILR)                             DBXDOT    359
C 495     CONTINUE                                                      DBXDOT    360
C 470  CONTINUE                                                         DBXDOT    361
C                                                                       DBXDOT    362
      END IF                                                            DBXDOT    363
C                                                                       DBXDOT    364
  120 CONTINUE                                                          DBXDOT    365
C                                                                       DBXDOT    366
C     UPDATE COUNTERS                                                   DBXDOT    367
C                                                                       DBXDOT    368
      IAIDEX=IAIDEX+KORD*KORD                                           DBXDOT    369
      ICIDEX=ICIDEX+4*KORD                                              DBXDOT    370
C                                                                       DBXDOT    371
  200 IBIDEX=IBIDEX+1                                                   DBXDOT    372
      KS=IBJCOB(IBIDEX)                                                 DBXDOT    373
      IF (KS.EQ.0) GOTO 500                                             DBXDOT    374
      IBIDEX=IBIDEX+2*KORD                                              DBXDOT    375
      GOTO 200                                                          DBXDOT    376
C                                                                       DBXDOT    377
  500 CONTINUE                                                          DBXDOT    378
C                                                                       DBXDOT    379
      RETURN                                                            DBXDOT    380
      END                                                               DBXDOT    381
