// ======================================================
// Numerical Analysis package in java
// vplot class
// This class plot 2D data
// with two plot axis
// Dr. Turhan Coban
// =====================================================
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.print.PrinterJob;
import java.awt.print.*;

class f3 extends f_x
{
public double func(double x) 
{
//çözümü istenen fonksiyon	
double ff;
ff=Math.cos(x)*Math.exp(-(x-Math.PI)*(x-Math.PI));
return ff; //maksimum testi
}
}
class f4 extends f_x
{
public double func(double x) 
{
//çözümü istenen fonksiyon	
double ff;
ff=Math.sin(x);
return ff; //maksimum testi
}
}
public class vplot extends JPanel implements MouseListener,MouseMotionListener
{private static final long serialVersionUID =5675863L;
public double x1[][],y1[][];
public int plottype1[];
public Color plotcolor1[];
public double x2[][],y2[][];
public int plottype2[];
public Color plotcolor2[];
shapes ch,ch1;
public Color bgcolor=Color.white;
public Color fgcolor=Color.black;
public Color xaxiscolor=Color.black;
public Color yaxiscolor=Color.black;
public Color y1axiscolor=Color.blue;
public Color gridcolor=Color.lightGray;
public int gridtype=1;
public int grid_number=10;
public int tic_number=10;
public boolean gridon=true;
public int show_mouse=0;
//recorded mouse coordinates
public double xi1,yi1;
public double xi2,yi2;
public double xj1,yj1;
public double xj2,yj2;
public int plotstyle;

Dimension d; //Plot page dimension
int dx; //x axis dimension pixels
int dy; //y axis  dimension pixels
int dx1; //x axis  dimension pixels
int dy1; //y axis   dimension pixels
int dxmin; //x axis plot pixels
int dymin; //y axis plot pixels
double xratio=0.8;
double yratio=0.8;
double xmax,xmin,ymax,ymin,ymax2,ymin2;
BasicStroke stroke = new BasicStroke(1.0f);
BasicStroke stroke2 = new BasicStroke(2.0f);
String s1[]=new String[10];
String s2[]=new String[10];
String s3[]=new String[10];
String s4[]=new String[10];
public boolean strtype1=false;
public boolean strtype2=false;
public boolean strtype3=false;
public boolean strtype4=false;
double xstr1[]=new double[10];
double ystr1[]=new double[10];
double xstr2,ystr2;
double xstr3,ystr3; 
double xstr4,ystr4;
int istr1=0;
int istr2=0;
int istr3=0;
int istr4=0;
final static Color bg = Color.white;
final static Color fg = Color.black;
final static Color red = Color.red;
final static Color white = Color.white;
String label="y=f(x)";
String xlabel="x";
String ylabel="y";
String ylabel2="y1";
boolean secondaxis=false;    

//Constructor classes============
//read data from file
public vplot(int plottype[],Color plotcolor[],String filename)
{setPlot(plottype,plotcolor,filename);}
public vplot(int plottype[],Color plotcolor[],String filename,int x1array[],int y1array[]) 
{setPlot(plottype,plotcolor,filename,x1array,y1array);}
public vplot(int plottype[],Color plotcolor[],String filename,int x1array[],int y1array[],int plottypei[],Color plotcolori[],int x2array[],int y2array[]) 
{secondaxis=true;
 setPlot(plottype,plotcolor,filename,x1array,y1array,plottypei,plotcolori,x2array,y2array);}
//read data from arrays
public vplot(int plottype[],Color plotcolor[],double a[][])
{setPlot(plottype,plotcolor,a);}
public vplot(int plottype[],Color plotcolor[],double xi[][],double yi[][])
{setPlot(plottype,plotcolor,xi,yi);}
public vplot(int plottype[],Color plotcolor[],double xi[][],double yi[][],int plottypei[],Color plotcolori[],double x2i[][],double y2i[][])
{secondaxis=true;
 setPlot(plottype,plotcolor,xi,yi,plottypei,plotcolori,x2i,y2i);}
//read data from function(s)
public vplot(int plottype[],Color plotcolor[],f_x ff,double xmini,double xmaxi,int n)
{setPlot(plottype,plotcolor,ff,xmini,xmaxi,n);}
public vplot(int plottype[],Color plotcolor[],f_x ff[],double xmini,double xmaxi,int n)
{setPlot(plottype,plotcolor,ff,xmini,xmaxi,n);}
//===============================

//read plot data from function ff
public void setPlot(int plottype[],Color plotcolor[],f_x ff,double xmini,double xmaxi,int n)
{	double x[]=veri.setX(xmini,xmaxi,n);
    double y[]=veri.feval(ff,x);
    double xx[][]={x};
    double yy[][]={y};
    setPlot(plottype,plotcolor,xx,yy);
}
//read plot data from set functions ff[]
public void setPlot(int plottype[],Color plotcolor[],f_x ff[],double xmini,double xmaxi,int n)
{	int m=ff.length;
    double xx[][]=new double[m][n];
    double yy[][]=new double[m][n];
    for(int i=0;i<m;i++)
    {xx[i]=veri.setX(xmini,xmaxi,n);
     yy[i]=veri.feval(ff[i],xx[i]);
    }
    setPlot(plottype,plotcolor,xx,yy);
}

public void setPlot(int plottype[],Color plotcolor[],String filename)
{	double a[][]=new double[1][1];
	try{
	double b[][]=veri.inputdouble(filename);
	a=b;
    } catch(IOException e){}
    setPlot(plottype,plotcolor,a);
}
public void setPlot(int plottype[],Color plotcolor[],String filename,int x1array[],int y1array[]) 
{	double a[][]=new double[1][1];
	try{
	double b[][]=veri.inputdouble(filename);
	a=b;
    } catch(IOException e){}
    setPlot(plottype,plotcolor,a,x1array,y1array);
}

public void setPlot(int plottype[],Color plotcolor[],String filename,int x1array[],int y1array[],int plottypei[],Color plotcolori[],int x2array[],int y2array[]) 
{	double a[][]=new double[1][1];
	try{
	double b[][]=veri.inputdouble(filename);
	a=b;
    } catch(IOException e){}
    setPlot(plottype,plotcolor,a,x1array,plottypei,plotcolori,y1array,x2array,y2array);
}

public void setPlot(int plottype[],Color plotcolor[],double a[][],int x1array[],int plottypei[],Color plotcolori[],double b[][],int y1array[],int x2array[],int y2array[]) 
{	
    int nx=x1array.length;
    int ny=x1array.length;
    if(nx!=ny) System.out.println("array sizes of x and y data does not match");
    int m=a[0].length;
    
    x1=new double[nx][m];
    y1=new double[nx][m];
    
    for(int i=0;i<nx;i++)
    {for(int j=0;j<m;j++)
     {x1[i][j]=a[x1array[i]][j];
      y1[i][j]=a[y1array[i]][j];
     }
    }
    int nx2=x2array.length;
    int ny2=x2array.length;
    x2=new double[nx2][m];
    y2=new double[nx2][m];
    if(nx2!=ny2) System.out.println("array sizes of x and y data does not match");
    for(int i=0;i<nx2;i++)
    {for(int j=0;j<m;j++)
     {x2[i][j]=b[x2array[i]][j];
      y2[i][j]=b[y2array[i]][j];
     }
    }
   setPlot(plottype,plotcolor,x1,y1,plottypei,plotcolori,x2,y2);
}

public void setPlot(int plottype[],Color plotcolor[],double a[][],int x1array[],int plottypei[],Color plotcolori[],int y1array[],int x2array[],int y2array[]) 
{	
    int nx=x1array.length;
    int ny=x1array.length;
    if(nx!=ny) System.out.println("array sizes of x and y data does not match");
    int m=a[0].length;    
    x1=new double[nx][m];
    y1=new double[nx][m];
    for(int i=0;i<nx;i++)
    {for(int j=0;j<m;j++)
     {x1[i][j]=a[x1array[i]][j];
      y1[i][j]=a[y1array[i]][j];
     }
    }
    int nx2=x2array.length;
    int ny2=x2array.length;
    x2=new double[nx2][m];
    y2=new double[nx2][m];
    if(nx2!=ny2) System.out.println("array sizes of x and y data does not match");
    for(int i=0;i<nx2;i++)
    {for(int j=0;j<m;j++)
     {x2[i][j]=a[x2array[i]][j];
      y2[i][j]=a[y2array[i]][j];
     }
    }
   setPlot(plottype,plotcolor,x1,y1,plottypei,plotcolori,x2,y2);
}

public void setPlot(int plottype[],Color plotcolor[],double a[][],int x1array[],int y1array[]) 
{   int nx=x1array.length;
    int ny=x1array.length;
    if(nx!=ny) System.out.println("array sizes of x and y data does not match");
    int m=a[0].length;    
    x1=new double[nx][m];
    y1=new double[nx][m];
    for(int i=0;i<nx;i++)
    {for(int j=0;j<m;j++)
     {x1[i][j]=a[x1array[i]][j];
      y1[i][j]=a[y1array[i]][j];
     }
    }
    setPlot(plottype,plotcolor,x1,y1); 
}

public void setPlot(int plottype[],Color plotcolor[],double a[][])
{	int n=a.length-1;
    int m=a[0].length;    
    x1=new double[n][m];
    y1=new double[n][m];
    for(int i=0;i<n;i++)
    {for(int j=0;j<m;j++)
     {x1[i][j]=a[0][j];
      y1[i][j]=a[i+1][j];
     }
    }
    setPlot(plottype,plotcolor,x1,y1); 
}

public void setPlot(int plottype[],Color plotcolor[],double xi[][],double yi[][])
{	plottype1=plottype;
    plotcolor1=plotcolor;
	d=getSize();
	dx = d.width;
    dy = d.height;
    dx1=(int)(xratio*dx);
    dy1=(int)(yratio*dy);
    x1=xi;
    y1=yi;
    xmax=veri.max(x1);
    xmin= veri.min(x1); 
    ymax=veri.max(y1);
    ymin= veri.min(y1); 
    addMouseListener(this);
    addMouseMotionListener(this);   
}

public void setPlot(int plottype[],Color plotcolor[],double xi[][],double yi[][],int plottypei[],Color plotcolori[],double x2i[][],double y2i[][])
{	plottype1=plottype;
    plotcolor1=plotcolor;
    plottype2=plottypei;
    plotcolor2=plotcolori;
	//secondaxis=true;
	d=getSize();
	dx = d.width;
    dy = d.height;
    dx1=(int)(xratio*dx);
    dy1=(int)(yratio*dy);
    x1=xi;
    y1=yi;
    y2=y2i;
    x2=x2i;
    xmax=veri.max(x1);
    xmin= veri.min(x1); 
    ymax=veri.max(y1);
    ymin= veri.min(y1); 
    xmax=veri.max(xmax,x2);
    xmin= veri.min(xmin,x2); 
    ymax2=veri.max(y2);
    ymin2= veri.min(y2); 
    addMouseListener(this);
    addMouseMotionListener(this);   
}

public void addPlot(int plottype[],Color plotcolor[],double xi[][],double yi[][])
{	int n=x1.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
    for(int i=n;i<n2;i++)
    { m[i]=xi[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=xi[i-n][j];
          yy[i][j]=yi[i-n][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}

public void addPlot(int plottype[],Color plotcolor[],double xi[][],double yi[][],int plottype2[],Color plotcolor2[],double xi2[][],double yi2[][])
{	addPlot(plottype,plotcolor,xi,yi);
    addPlot2(plottype2,plotcolor2,xi2,yi2);
}

public void addPlot2(int plottype[],Color plotcolor[],double xi[][],double yi[][])
{	int nnn;
    if(secondaxis) nnn=x2.length;
    else nnn=0;
    int n1=xi.length;
    int n2=nnn+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<nnn;i++)
    { //System.out.println("n="+nnn+"i="+i+"mi="+x2[i].length+"plotcolor="+plotcolor2[i]+"plottype="+plottype2[i]);
	  m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor2[i];
      plottype3[i]=plottype2[i];
    }
    for(int i=nnn;i<n2;i++)
    { m[i]=xi[i-nnn].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-nnn];
      plottype3[i]=plottype[i-nnn];
    }
    //=====
    for(int i=0;i<nnn;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=nnn;i<n2;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=xi[i-nnn][j];
          yy[i][j]=yi[i-nnn][j];
      }
    }
    secondaxis=true;
    setPlot(plottype1,plotcolor1,x1,y1,plottype3,plotcolor3,xx,yy);
}
public void addPlot(int plottype[],Color plotcolor[],double a[][])
{	int n=a.length-1;
    int m=a[0].length;    
    double xx1[][]=new double[n][m];
    double yy1[][]=new double[n][m];
    for(int i=0;i<n;i++)
    {for(int j=0;j<m;j++)
     {xx1[i][j]=a[0][j];
      yy1[i][j]=a[i+1][j];
     }
    }
    addPlot(plottype,plotcolor,xx1,yy1); 
}
public void addPlot(int plottype[],Color plotcolor[],double a[][],int x1array[],int y1array[]) 
{   int nx=x1array.length;
    int ny=x1array.length;
    if(nx!=ny) System.out.println("array sizes of x and y data does not match");
    int m=a[0].length;    
    double xx1[][]=new double[nx][m];
    double yy1[][]=new double[nx][m];
    for(int i=0;i<nx;i++)
    {for(int j=0;j<m;j++)
     {xx1[i][j]=a[x1array[i]][j];
      yy1[i][j]=a[y1array[i]][j];
     }
    }
    addPlot(plottype,plotcolor,xx1,yy1); 
}

public void addPlot2(int plottype[],Color plotcolor[],double a[][])
{	int n=a.length-1;
    int m=a[0].length;    
    double xx1[][]=new double[n][m];
    double yy1[][]=new double[n][m];
    for(int i=0;i<n;i++)
    {for(int j=0;j<m;j++)
     {xx1[i][j]=a[0][j];
      yy1[i][j]=a[i+1][j];
     }
    }
    addPlot2(plottype,plotcolor,xx1,yy1); 
}
public void addPlot2(int plottype[],Color plotcolor[],double a[][],int x1array[],int y1array[]) 
{   int nx=x1array.length;
    int ny=x1array.length;
    if(nx!=ny) System.out.println("array sizes of x and y data does not match");
    int m=a[0].length;    
    double xx1[][]=new double[nx][m];
    double yy1[][]=new double[nx][m];
    for(int i=0;i<nx;i++)
    {for(int j=0;j<m;j++)
     {xx1[i][j]=a[x1array[i]][j];
      yy1[i][j]=a[y1array[i]][j];
     }
    }
    addPlot2(plottype,plotcolor,xx1,yy1); 
}

public void addPlot(int plottype[],Color plotcolor[],f_x ff,double xmini,double xmaxi,int n)
{	double x[]=veri.setX(xmini,xmaxi,n);
    double y[]=veri.feval(ff,x);
    double xx[][]={x};
    double yy[][]={y};
    addPlot(plottype,plotcolor,xx,yy);
}
//read plot data from set functions ff[]
public void addPlot(int plottype[],Color plotcolor[],f_x ff[],double xmini,double xmaxi,int n)
{	int m=ff.length;
    double xx[][]=new double[m][n];
    double yy[][]=new double[m][n];
    for(int i=0;i<m;i++)
    {xx[i]=veri.setX(xmini,xmaxi,n);
     yy[i]=veri.feval(ff[i],xx[i]);
    }
    addPlot(plottype,plotcolor,xx,yy);
}
public void addPlot2(int plottype[],Color plotcolor[],f_x ff,double xmini,double xmaxi,int n)
{	double x[]=veri.setX(xmini,xmaxi,n);
    double y[]=veri.feval(ff,x);
    double xx[][]={x};
    double yy[][]={y};
    addPlot2(plottype,plotcolor,xx,yy);
}
//read plot data from set functions ff[]
public void addPlot2(int plottype[],Color plotcolor[],f_x ff[],double xmini,double xmaxi,int n)
{	int m=ff.length;
    double xx[][]=new double[m][n];
    double yy[][]=new double[m][n];
    for(int i=0;i<m;i++)
    {xx[i]=veri.setX(xmini,xmaxi,n);
     yy[i]=veri.feval(ff[i],xx[i]);
    }
    addPlot2(plottype,plotcolor,xx,yy);
}
//Polynomial least square of degree npolynom
//==========================================
// "additionaldatanumber" additional data in between each two points
public void addPLSQR(int plottypei,Color plotcolori,int linenumberi,int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addPLSQR(plottype,plotcolor,linenumber,npolynom,additionaldatanumber);
}
public void addPLSQR2(int plottypei,Color plotcolori,int linenumberi,int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addPLSQR2(plottype,plotcolor,linenumber,npolynom,additionaldatanumber);
}
public void addPLSQR(int plottypei,Color plotcolori,double xi[],double yi[],int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addPLSQR(plottype,plotcolor,xii,yii,npolynom,additionaldatanumber);
}
public void addPLSQR2(int plottypei,Color plotcolori,double xi[],double yi[],int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addPLSQR2(plottype,plotcolor,xii,yii,npolynom,additionaldatanumber);
}
public void addPLSQR(int plottype[],Color plotcolor[],double xi[][],double yi[][],int npolynom,int additionaldatanumber)
{	int n=x1.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
        
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11B4.funcEKK(xi[i-n],yi[i-n],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addPLSQR2(int plottype[],Color plotcolor[],double xi[][],double yi[][],int npolynom,int additionaldatanumber)
{	int n=x2.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
    
    
    for(int i=n;i<n2;i++)
    { m[i]=x2[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11B4.funcEKK(xi[i-n],yi[i-n],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    setPlot(plottype1,plotcolor1,x1,y1,plottype3,plotcolor3,xx,yy); 
}
public void addPLSQR(int plottype[],Color plotcolor[],int linenumber[],int npolynom,int additionaldatanumber)
{	int n=x1.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }   
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11B4.funcEKK(x1[linenumber[i-n]],y1[linenumber[i-n]],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addPLSQR2(int plottype[],Color plotcolor[],int linenumber[],int npolynom,int additionaldatanumber)
{	int n=x2.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor2[i];
      plottype3[i]=plottype2[i];
    }   
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11B4.funcEKK(x2[linenumber[i-n]],y2[linenumber[i-n]],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    secondaxis=true;
    setPlot(plottype3,plotcolor3,x1,y1,plottype2,plotcolor2,xx,yy);
}
//Polynomial least square of degree npolynom
//==========================================
// "additionaldatanumber" additional data in between each two points
public void addOPLSQR(int plottypei,Color plotcolori,int linenumberi,int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addOPLSQR(plottype,plotcolor,linenumber,npolynom,additionaldatanumber);
}
public void addOPLSQR2(int plottypei,Color plotcolori,int linenumberi,int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addOPLSQR2(plottype,plotcolor,linenumber,npolynom,additionaldatanumber);
}
public void addOPLSQR(int plottypei,Color plotcolori,double xi[],double yi[],int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addOPLSQR(plottype,plotcolor,xii,yii,npolynom,additionaldatanumber);
}
public void addOPLSQR2(int plottypei,Color plotcolori,double xi[],double yi[],int npolynom,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addOPLSQR2(plottype,plotcolor,xii,yii,npolynom,additionaldatanumber);
}
public void addOPLSQR(int plottype[],Color plotcolor[],double xi[][],double yi[][],int npolynom,int additionaldatanumber)
{	int n=x1.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
        
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11A.funcOPEKK(xi[i-n],yi[i-n],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addOPLSQR2(int plottype[],Color plotcolor[],double xi[][],double yi[][],int npolynom,int additionaldatanumber)
{	int n=x2.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
    
    
    for(int i=n;i<n2;i++)
    { m[i]=x2[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11A.funcOPEKK(xi[i-n],yi[i-n],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    setPlot(plottype1,plotcolor1,x1,y1,plottype3,plotcolor3,xx,yy); 
}
public void addOPLSQR(int plottype[],Color plotcolor[],int linenumber[],int npolynom,int additionaldatanumber)
{	int n=x1.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }   
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11A.funcOPEKK(x1[linenumber[i-n]],y1[linenumber[i-n]],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addOPLSQR2(int plottype[],Color plotcolor[],int linenumber[],int npolynom,int additionaldatanumber)
{	int n=x2.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor2[i];
      plottype3[i]=plottype2[i];
    }   
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11A.funcOPEKK(x2[linenumber[i-n]],y2[linenumber[i-n]],npolynom,additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    secondaxis=true;
    setPlot(plottype3,plotcolor3,x1,y1,plottype2,plotcolor2,xx,yy);
}
//cubic spline curve fitting 
//==========================================
// "additionaldatanumber" additional data in between each two points
public void addCSpline(int plottypei,Color plotcolori,int linenumberi,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addCSpline(plottype,plotcolor,linenumber,additionaldatanumber);
}
public void addCSpline2(int plottypei,Color plotcolori,int linenumberi,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addCSpline2(plottype,plotcolor,linenumber,additionaldatanumber);
}
public void addCSpline(int plottypei,Color plotcolori,double xi[],double yi[],int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addCSpline(plottype,plotcolor,xii,yii,additionaldatanumber);
}
public void addCSpline2(int plottypei,Color plotcolori,double xi[],double yi[],int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addCSpline2(plottype,plotcolor,xii,yii,additionaldatanumber);
}
public void addCSpline(int plottype[],Color plotcolor[],double xi[][],double yi[][],int additionaldatanumber)
{	int n=x1.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
        
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11F.funcSpline(xi[i-n],yi[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addCSpline2(int plottype[],Color plotcolor[],double xi[][],double yi[][],int additionaldatanumber)
{	int n=x2.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
    
    
    for(int i=n;i<n2;i++)
    { m[i]=x2[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11F.funcSpline(xi[i-n],yi[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    setPlot(plottype1,plotcolor1,x1,y1,plottype3,plotcolor3,xx,yy); 
}
public void addCSpline(int plottype[],Color plotcolor[],int linenumber[],int additionaldatanumber)
{	int n=x1.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }   
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    {double S[][]=SCO11F.funcSpline(xx[i-n],yy[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addCSpline2(int plottype[],Color plotcolor[],int linenumber[],int additionaldatanumber)
{	int n=x2.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor2[i];
      plottype3[i]=plottype2[i];
    }   
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=SCO11F.funcSpline(x2[i-n],y2[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    secondaxis=true;
    setPlot(plottype3,plotcolor3,x1,y1,plottype2,plotcolor2,xx,yy);
}
//cubic B-spline curve fitting 
//==========================================
// "additionaldatanumber" additional data in between each two points
public void addBSpline(int plottypei,Color plotcolori,int linenumberi,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addBSpline(plottype,plotcolor,linenumber,additionaldatanumber);
}
public void addBSpline2(int plottypei,Color plotcolori,int linenumberi,int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 int linenumber[]={linenumberi};
 addBSpline2(plottype,plotcolor,linenumber,additionaldatanumber);
}
public void addBSpline(int plottypei,Color plotcolori,double xi[],double yi[],int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addBSpline(plottype,plotcolor,xii,yii,additionaldatanumber);
}
public void addBSpline2(int plottypei,Color plotcolori,double xi[],double yi[],int additionaldatanumber)
{int plottype[]={plottypei};
 Color plotcolor[]={plotcolori};
 double xii[][]={xi};
 double yii[][]={yi};
 addBSpline2(plottype,plotcolor,xii,yii,additionaldatanumber);
}
public void addBSpline(int plottype[],Color plotcolor[],double xi[][],double yi[][],int additionaldatanumber)
{	int n=x1.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
        
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=B_spline.funcB_Spline(xi[i-n],yi[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addBSpline2(int plottype[],Color plotcolor[],double xi[][],double yi[][],int additionaldatanumber)
{	int n=x2.length;
    int n1=xi.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }
    
    
    for(int i=n;i<n2;i++)
    { m[i]=x2[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=B_spline.funcB_Spline(xi[i-n],yi[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    setPlot(plottype1,plotcolor1,x1,y1,plottype3,plotcolor3,xx,yy); 
}
public void addBSpline(int plottype[],Color plotcolor[],int linenumber[],int additionaldatanumber)
{	int n=x1.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x1[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor1[i];
      plottype3[i]=plottype1[i];
    }   
    for(int i=n;i<n2;i++)
    { m[i]=x1[i-n].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor[i-n];
      plottype3[i]=plottype[i-n];
    }
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x1[i][j];
          yy[i][j]=y1[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    {double S[][]=B_spline.funcB_Spline(xx[i-n],yy[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    if(secondaxis)
    {setPlot(plottype3,plotcolor3,xx,yy,plottype2,plotcolor2,x2,y2);}
    else
    {setPlot(plottype3,plotcolor3,xx,yy);}
}
public void addBSpline2(int plottype[],Color plotcolor[],int linenumber[],int additionaldatanumber)
{	int n=x2.length;
    int n1=linenumber.length;
    int n2=n+n1;
    double xx[][],yy[][];
    int plottype3[]=new int[n2];
    Color plotcolor3[]=new Color[n2];
    xx=new double[n2][];
    yy=new double[n2][];
    int m[]=new int[n2];
    for(int i=0;i<n;i++)
    { m[i]=x2[i].length;
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
      plotcolor3[i]=plotcolor2[i];
      plottype3[i]=plottype2[i];
    }   
    //=====
    for(int i=0;i<n;i++)
    { 
	  for(int j=0;j<m[i];j++)
      {   xx[i][j]=x2[i][j];
          yy[i][j]=y2[i][j];
      }
    }
    for(int i=n;i<n2;i++)
    { double S[][]=B_spline.funcB_Spline(x2[i-n],y2[i-n],additionaldatanumber);
	  m[i]=S[i-n].length;  
	  xx[i]=new double[m[i]];
      yy[i]=new double[m[i]];
    for(int j=0;j<m[i];j++)
      {   xx[i][j]=S[0][j];
          yy[i][j]=S[1][j];
      }
    }
    secondaxis=true;
    setPlot(plottype3,plotcolor3,x1,y1,plottype2,plotcolor2,xx,yy);
}
// ======= set methods ========
public static Color setColor(int red,int green, int blue)
{Color c=new Color(red,green,blue);return c;}
public void setXaxiscolor(Color c)
{xaxiscolor=c;}
public void setYaxiscolor(Color c)
{yaxiscolor=c;}
public void setY1axiscolor(Color c)
{y1axiscolor=c;}
public void setGridOn()
{gridon=true;}
public void setGridOff()
{gridon=false;} 
public void setGridNumber(int gn)
{if(gn==0) gridon=false;
 else {gridon=true;grid_number=gn;}
}
public void setTicNumber(int gn)
{tic_number=gn;}    
public void setRatio(double xratioi,double yratioi)
{
xratio=xratioi;
yratio=yratioi;
}
public void setXaxis(double xmini,double xmaxi)
{
xmin=xmini;
xmax=xmaxi;
}
public void setYaxis(double ymini,double ymaxi)
{
ymin=ymini;
ymax=ymaxi;
}
public void setSecondYaxis(double ymini,double ymaxi)
{
ymin2=ymini;
ymax2=ymaxi;
}
public void setRatio(double ratioi)
{
xratio=ratioi;
yratio=ratioi;
}
  public void setPlabel(String ip) {label=ip;}
  public void setXlabel(String ix) {xlabel=ix;}
  public void setYlabel(String iy) {ylabel=iy;}
  public void setY2label(String iy) {ylabel2=iy;}
public void setAddionalLabel(String s,double xi,double yi)
{ s1[istr1]=s;
xstr1[istr1]=xi;
ystr1[istr1]=yi;
istr1++;
istr1=istr1%10;
strtype1=true;
}
public void setAddionalLabel(String s[],double xi,double yi)
{ s2=s;
  xstr2=xi;
  ystr2=yi;
  strtype2=true;
}
public void setAddionalLabel1(String s[],double xi,double yi)
{ s3=s;
  xstr3=xi;
  ystr3=yi;
  strtype3=true;
}
public void setAddionalLabel2(String s[],double xi,double yi)
{ s4=s;
xstr4=xi;
ystr4=yi;
strtype4=true;
}
    public void drawShapes(Graphics2D g2)
    {
        d=getSize();
        dx = d.width;
        dy = d.height;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        dx1=(int)(xratio*dx);
        dy1=(int)(yratio*dy);
        dxmin=(int)((1.0-xratio)/2.0*dx);
        dymin=(int)((1.0-yratio)/2.0*dy);
        g2.setStroke(stroke);
        g2.setColor(fg); 
        ch=new shapes(g2,dxmin,dymin,dx1,dy1,xmin,xmax,ymin,ymax);
        ch.drawXTic(tic_number,(ymax-ymin)/50,0);
        ch.drawYTic(tic_number,(xmax-xmin)/80,0);
        ch.drawXNumbers(tic_number);
        ch.drawYNumbers(tic_number);
        ch.drawLabel(label);
        ch.drawXLabel(xlabel);
        ch.drawYLabel(ylabel);
        if(gridon)
        {g2.setColor(gridcolor);
         ch.drawXGrid(grid_number);
         ch.drawYGrid(grid_number);         
         //g2.setStroke(new BasicStroke(1.0f));;
        }
        g2.setColor(fgcolor);
        g2.setStroke(stroke);
        if(strtype1)
        { for(int i=0;i<istr1;i++)
	        {ch.drawAdditionalLabel(s1[i],xstr1[i],ystr1[i]); }   
	    }
        if(strtype2)
        {  double dy1=(ymax-ymin)/30.0; 
	       ch.drawString(s2,xstr2,ystr2,dy1);   
	    }
	    if(strtype3)
        {   double dx1=(xmax-xmin)/30.0; 
	        double dy1=(ymax-ymin)/30.0; 
	        ch.drawString(s3,plottype1,xstr3,ystr3,dx1,dy1);   
	    }
        if(strtype4)
        {   double dx1=(xmax-xmin)/30.0; 
	        double dy1=(ymax-ymin)/30.0; 
	        ch.drawString(s4,plottype2,xstr4,ystr4,dx1,dy1);   
	    }
     if(secondaxis)
     {ch1=new shapes(g2,dxmin,dymin,dx1,dy1,xmin,xmax,ymin2,ymax2);

     g2.setColor(y1axiscolor);
     g2.setStroke(stroke);
     ch1.drawYTic1(10,(xmax-xmin)/80,0);
     ch1.drawYNumbers1(10);
     ch1.drawYLabel1(ylabel2);
     g2.setColor(fgcolor);   
     }
          g2.setColor(fgcolor);
          g2.setStroke(stroke2);
          Rectangle2D x=new Rectangle2D.Double(dxmin,dymin,dx1,dy1);
          g2.draw(x);
          g2.setStroke(stroke);
           for(int i=0;i<y1.length;i++)
           {  g2.setColor(plotcolor1[i]);
	           ch.drawPlotLines(i,plottype1,x1,y1);
	           g2.setColor(fgcolor);
           }//end of for(i=0
           if(show_mouse==0)
           {ch.drawMouse("y1",xj1,yj1);}
           else if(show_mouse==2)
           {ch1.drawMouse("y2",xj2,yj2);}
           else
           {String ss1[]={"   y1","   y2"};
            ch.drawMouse(ss1,xj1,yj1,xj2,yj2);
           } //end of if(show_mouse
            if(secondaxis)
            {           for(int i=0;i<y2.length;i++)
                        {   g2.setColor(plotcolor2[i]);
	                        ch1.drawPlotLines(i,plottype2,x2,y2);
	                        g2.setColor(fgcolor);
                        }//end of for(i=0
            } //end if(secondaxis       
    }       
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        drawShapes(g2);        
    } 
      public static void plot(f_x ff,double xmin,double xmax,int n)
      {
      double x1[]=veri.setX(xmin,xmax,n);
      double y1[]=veri.feval(ff,x1);
      double x2[][]={x1};
      double y2[][]={y1};
      int plottype1[]={0};
	  Color c1[]={Color.black};
      vplot p1=new vplot(plottype1,c1,x2,y2);
      FrameGrafigi.plot("plot penceresi",p1); 
      }          
      public static void plot(String function,double xmin,double xmax,int n)
      {
      double x1[]=veri.setX(xmin,xmax,n);
      double y1[]=veri.feval(function,x1);
      double x2[][]={x1};
      double y2[][]={y1};
      int plottype1[]={0};
	  Color c1[]={Color.black};
      vplot p1=new vplot(plottype1,c1,x2,y2);
      FrameGrafigi.plot("plot penceresi",p1); 
      }      
      public void plot()
      {FrameGrafigi.plot("plot penceresi",this);}
      public void plot(String s)
      {FrameGrafigi.plot(s,this);}     
      public static void plot(int plottype[],Color plotcolor[],double xi[][],double yi[][])
      {
      vplot p1=new vplot(plottype,plotcolor,xi,yi);
      FrameGrafigi.plot("plot penceresi",p1); 
      }
      public static void plot(int plottype[],Color plotcolor[],double xi[][],double yi[][],int plottypei[],Color plotcolori[],double x2i[][],double y2i[][])
      {
      vplot p1=new vplot(plottype,plotcolor,xi,yi,plottypei,plotcolori,x2i,y2i);
      FrameGrafigi.plot("plot penceresi",p1); 
      }
	  public void degerleriGir(int x,int y)
      {xi1=xmin+(double)(x-dxmin)/(double)dx1*(xmax-xmin);
       yi1=ymin-(double)(y-dymin-dy1)/(double)dy1*(ymax-ymin);
      }
      public void degerleriGir1(int x,int y)
      {xi2=xmin+(double)(x-dxmin)/(double)dx1*(xmax-xmin);
       yi2=ymin2-(double)(y-dymin-dy1)/(double)dy1*(ymax2-ymin2);
      }
      public void degerleriGir2(int x,int y)
      {xj1=xmin+(double)(x-dxmin)/(double)dx1*(xmax-xmin);
       yj1=ymin-(double)(y-dymin-dy1)/(double)dy1*(ymax-ymin);
      }
      public void degerleriGir3(int x,int y)
      {xj2=xmin+(double)(x-dxmin)/(double)dx1*(xmax-xmin);
       yj2=ymin2-(double)(y-dymin-dy1)/(double)dy1*(ymax2-ymin2);
      }
      public void mousePressed(MouseEvent e)
      {  if(e.isMetaDown()&& secondaxis) {show_mouse=2;degerleriGir1(e.getX(),e.getY());} //sağ tuş basıldığında
         else if(e.isAltDown() && secondaxis)             //orta tuş basıldığında
             {show_mouse=1;} 
         else {show_mouse=0;degerleriGir(e.getX(),e.getY()); }  //sol tuş basıldığında
       this.validate();
       this.repaint();
      }
      
      public void mouseClicked(MouseEvent e)
      {  }

      public void mouseReleased(MouseEvent e)
      {  }

      public void mouseEntered(MouseEvent e)
      {degerleriGir2(e.getX(),e.getY()); 
       if(secondaxis) degerleriGir3(e.getX(),e.getY()); 
       this.validate();
       this.repaint();
      }

      public void mouseExited(MouseEvent e)
      {
      }
      //MouseMotionListener (fare hareket dinleyicisi) metotlari
      public void mouseDragged(MouseEvent e)
      {  }
      public void mouseMoved(MouseEvent e)
      {degerleriGir2(e.getX(),e.getY()); 
       if(secondaxis) {degerleriGir3(e.getX(),e.getY());} 
       this.validate();
       this.repaint();
      } //sağ tuş basıldığında      
      public static void main(String arg[])
      {
	  double x[][]={{1,2,3,4,5,6,7,8,9},{1,2,3,4,5,6,7},{1,2,3}};
	  double y[][]={{1,2,3,4,5,6,7,8,9},{2,3,4,5,6,7,8},{10,11,12}};
	  double y1[][]={{11,12,13,14,15,16,17,18,19},{11,12,13,14,15,16,17,18,19}};
	  double x1[][]={{1,2,3,4,5,6,7,8,9},{1,2,3,4,5,6,7,8,9}};
	  double x2[][]={{1,2,3}};
	  double y2[][]={{1,4,9}};
	  int plottype1[]={4,17,6};
	  int plottype2[]={0,15};
	  int plottype3[]={0};
	  int plottype4[]={0};
	  Color c1[]={Color.black,Color.blue,Color.green};
	  Color c2[]={Color.blue,Color.blue};
	  Color c3[]={Color.blue};
	  Color c4[]={Color.blue};
	  vplot p1=new vplot(plottype1,c1,x,y);
	  p1.addPlot2(plottype2,c2,x1,y1);
	  int pp[]={0};	  
	  p1.setGridNumber(20);
	  f3 ff1=new f3();
	  p1.addPlot2(plottype4,c4,ff1,0.0,10.0,200);
	  p1.addOPLSQR(plottype3,c3,x2,y2,2,2);
	  p1.addBSpline(plottype3,c3,x2,y2,4);
	  f4 ff2=new f4();
	  f_x ff[]={ff1,ff2};
	  String s1[]={"Axis 1_PL1","Axis 1_PL2","Axis 1_PL3"};
	  String s2[]={"Axis 2_PL1","Axis 2_PL2"};
	   p1.setYlabel("y axis");   
	   p1.plot("pp");
      }	  
}