void RungeKutta(double t2){
  if (klast == kmax - 1)   throw new RuntimeException("storage space is exceeded");
  if (klast == -1) {
    setInit();
    T[0]=0;
    ++klast;
  }
  if (t2 == 0.0)   return;
  int i, nstp;
  double t1=T[klast];
  double t=t1;
  double tsav=t1;
  for (i=0; i < nvar; i++)   y[i]=Y[i][klast];
  double h=hinit;
  for (nstp=0; nstp < MAXSTP; nstp++) {
    double tmp=nstp;
    if (nstp > MAXSTP / 2) {
      tmp=tmp + 3;
    }
    derivs(t,y,dydt);
    for (i=0; i < nvar; i++)     yscal[i]=Math.abs(y[i]) + Math.abs(dydt[i] * h) + TINY;
    if (klast < kmax - 2 && Math.abs(t - tsav) > Math.abs(dtsav)) {
      ++klast;
      for (i=0; i < nvar; i++)       Y[i][klast]=y[i];
      T[klast]=t;
      tsav=t;
    }
    if ((t + h - t2) * (t + h - t1) > 0.0)     h=t2 - t;
    t=rkqs(y,dydt,t,h,yscal);
    if (hdid == h)     ++nok;
 else     ++nbad;
    if ((t - t2) * (t2 - t1) >= 0.0) {
      if (klast < kmax - 1) {
        ++klast;
        for (i=0; i < nvar; i++)         Y[i][klast]=y[i];
        T[klast]=t;
      }
      return;
    }
    if (Math.abs(hnext) <= hmin) {
      throw new RuntimeException("Step size too small in odeint");
    }
    h=hnext;
  }
  throw new RuntimeException("Too many steps in routine odeint");
}

void RungeKutta ( double t2 ) { if ( klast == kmax - 1 ) throw new RuntimeException ( "storage space is exceeded" ) ; if ( klast == - 1 ) { setInit ( ) ; T [ 0 ] = 0 ; ++ klast ; } if ( t2 == 0.0 ) return ; int i , nstp ; double t1 = T [ klast ] ; double t = t1 ; double tsav = t1 ; for ( i = 0 ; i < nvar ; i ++ ) y [ i ] = Y [ i ] [ klast ] ; double h = hinit ; for ( nstp = 0 ; nstp < MAXSTP ; nstp ++ ) { double tmp = nstp ; if ( nstp > MAXSTP / 2 ) { tmp = tmp + 3 ; } derivs ( t , y , dydt ) ; for ( i = 0 ; i < nvar ; i ++ ) yscal [ i ] = Math . abs ( y [ i ] ) + Math . abs ( dydt [ i ] * h ) + TINY ; if ( klast < kmax - 2 && Math . abs ( t - tsav ) > Math . abs ( dtsav ) ) { ++ klast ; for ( i = 0 ; i < nvar ; i ++ ) Y [ i ] [ klast ] = y [ i ] ; T [ klast ] = t ; tsav = t ; } if ( ( t + h - t2 ) * ( t + h - t1 ) > 0.0 ) h = t2 - t ; t = rkqs ( y , dydt , t , h , yscal ) ; if ( hdid == h ) ++ nok ; else ++ nbad ; if ( ( t - t2 ) * ( t2 - t1 ) >= 0.0 ) { if ( klast < kmax - 1 ) { ++ klast ; for ( i = 0 ; i < nvar ; i ++ ) Y [ i ] [ klast ] = y [ i ] ; T [ klast ] = t ; } return ; } if ( Math . abs ( hnext ) <= hmin ) { throw new RuntimeException ( "Step size too small in odeint" ) ; } h = hnext ; } throw new RuntimeException ( "Too many steps in routine odeint" ) ; }
driving routine for rungekutta integration
