abstract class f_xt extends Mathd
{
  // single function  two independent variable : x,t
  // a single value is returned 
  abstract double func(double x,double t);
}

 class timevplot extends Thread
 {int nx,nt;
 double x[][];
 double y[][];
 double dt;
 double dt_real;
 double xmin,xmax,ymin,ymax;

 public timeplot(double xi[][],double yi[][],double dti,double dt_reali)
 {nx=xi[0].length;nt=xi.length;dt=dti;
 dt_real=dt_reali;
 xmin=9.99e50;
 xmax=-9.99e50;
 ymin=9.99e50;
 ymax=-9.99e50;
 x=new double[nt][nx];
 y=new double[nt][nx];
 for(int i=0;i<nt;i++)
 {for(int j=0;j<nx;j++)
   {x[i][j]=xi[i][j];
   y[i][j]=yi[i][j];
   if(x[i][j]<xmin) xmin=x[i][j];
   if(x[i][j]>xmax) xmax=x[i][j];
   if(y[i][j]<ymin) ymin=y[i][j];
   if(y[i][j]>ymax) ymax=y[i][j];
   }
 }
 }
 
 public timeplot(f_xt f,double x0,double xn,double dx,double t0,double tn,double dt_reali,double dti)
 {dt=dti;
  dt_real=dt_reali;
  nx=(int)((xn-x0)/dx+1);
  nt=(int)((tn-t0)/dt_real+1);
 
 xmin=x0;
 xmax=xn;
 ymin=9.99e50;
 ymax=-9.99e50;
 x=new double[nt][nx];
 y=new double[nt][nx];
 double t;
 for(int i=0;i<nt;i++)
 {for(int j=0;j<nx;j++)
   {x[i][j]=x0+dx*j;
    t=t0+dt_real*i;
    y[i][j]=f.func(x[i][j],t);
    if(y[i][j]<ymin) ymin=y[i][j];
    if(y[i][j]>ymax) ymax=y[i][j];
    //System.out.println( x[i][j]+" "+y[i][j]);
    }
   
 }
 }
 
 public timeplot(double yi[][],double x0,double xn,double dti,double dt_reali)
 {nx=yi[0].length;nt=yi.length;
 dt=dti;
 dt_real=dt_reali;
 xmin=x0;
 xmax=xn;
 ymin=9.99e50;
 ymax=-9.99e50;
 x=new double[nt][nx];
 y=new double[nt][nx];
 double dx=(xn-x0)/(nx-1);
 for(int i=0;i<nt;i++)
 {for(int j=0;j<nx;j++)
   {x[i][j]=x0+dx*j;
    y[i][j]=yi[i][j];
    if(y[i][j]<ymin) ymin=y[i][j];
    if(y[i][j]>ymax) ymax=y[i][j];
    }
 }
 }
 
 public void run()
 {
 Plot1 pp=new Plot1(x[0],y[0]); 
 pp.setMinMax(xmin,xmax,ymin,ymax);
 
 for(int i=0;i<nt;i++)
 try {
 pp.ppA(x[i],y[i],0,0,0,255);
 pp.setPlabel("t = "+i*dt_real+" s");
 int t=(int)(1000*dt);
 pp.setPlotType(0,5);
 pp.plot();
 Thread.sleep(t);
 pp.dispose();
     }
 catch(InterruptedException e)
 {System.err.println(e.toString());}
 }
 }