//====================================================== // Numerical Analysis package in java // Plot class to plot 2D data // Dr. Turhan Coban // EGE University, Engineering School, Mechanical Eng. Div. // ===================================================== import java.io.*; abstract class f_x { //single function single independent variable // example f=x*x abstract double func(double x); } abstract class fi_x { // multifunction single independent variable // vector of dependent variables are returned // example f[0]=x+sin(x) // f[1]=x*x-x // func(x) returns the value of f[0] and f[1] // as a two dimensional vector abstract double[] func(double x); } public class Plot2 { // This class reads plot input variables // and sets relations between absolute scale and relative scale plot windows public String label=" "; // Plot Label public String xlabel=" "; // X axis Label public String ylabel=" "; // Y axis Label public String filename; // file name public double xmin,ymin,xmax,ymax; // real max,min scale public int xabsmin,yabsmin,abswidth,absheight; // absolute max,min scale in Pixel dimension public int nmax; // max number of data points public int ni; // data set number with nmax data public int nline; // max number of data sets public double x[][]; // x data public double y[][]; // y=f(x) data public int n[]; // n : number of data in each line public int red[],green[],blue[]; // color code 0-255 public int plottype[]; public int xgridon=0; public int ygridon=0; // plottype = 0 continuous line // plottype = 1 dashed line // plottype = 2 // plottype = 3 // plottype = 10 variable character plot type // plottype = 20 rectangle // plottype = 21 filled rectangle // plottype = 22 circle // plottype = 23 filled circle // plottype = 24 triangle // plottype = 25 diamond // plottype = 26 pentagon // plottype = 27 hexagon // plottype = 28 filled triangle // plottype = 29 filled diamond // plottype = 30 filled pentagon // plottype = 31 filled hexagon // plottype = 32 tri sided star // plottype = 33 four sided star // plottype = 34 five sided star // plottype = 35 six sided star // plottype = 36 filled tri sided star // plottype = 37 filled four sided star // plottype = 38 filled five sided star // plottype = 39 filled six sided star // plottype = 40 bar plot // plottype = 41 filled bar plot public char ch[]; // plot character (used with plottype 10) public int xntic=10; // number of tics in x axis public int yntic=10; // number of tics in y axis BufferedReader fini; BufferedReader ffile; File plotFile; File lineDataFile; String fn[]; //constructors //1. public Plot2() throws IOException : read data from Plot.txt (actual datafiles are listed in Plot.txt) //2. public Plot2(String pl,String xl,String yl,int xnt,int ynt // ,int xgo,int ygo,String fn[],int ipt[],int ir[],int ig[] // ,int ib[]) throws IOException : read data file names from String fn[] //3. public Plot2(String fn[],int ipt[],int ir[],int ig[],int ib[]) throws IOException // : read data file names from String fn[] //4. public Plot2(String fn[]) throws IOException : read data file names from String fn[] //5. public Plot2(double xi[][],double yi[][],int ipt[],int ir[],int ig[],int ib[]) // : read data from xi yi arrays //6. public Plot2(f_x f,double xm,double xma,int N,int ipt,int ir,int ig,int ib) // : read data from a simple function f_x f f(x) //7. public Plot2(f_x f,double xm,double xma,int N) : read data from a simple function f_x f f(x) //8. public Plot2(fi_x f,double xm,double xma,int Number_of_Data,int Number_of_Function, // int ipt[],int ir[],int ig[],int ib[]) : : read data from a series of functions fi_x f fi(x) // // //read input variables from Plot.txt //adding max-min prompts and input fields //initial values of max and mins // Structure of input file // filename // xlabel // ylabel // nline // datafilename plottype redcolor greencolor bluecolor // ........ // datafilename plottype redcolor greencolor bluecolor // // A sample data file input : // filename // xaxislabel // yaxislabel // 4 // b.dat 22 0 0 0 // a.dat 21 0 255 0 // a.dat 0 0 255 0 // b.dat 0 0 0 255 // // see above for meaning of plot types public Plot2(double xi[][],double yi[][],int ipt[],int ir[],int ig[],int ib[]) { // reading data from initial array xmin=9.99e50; xmax=-9.99e50; ymin=9.99e50; ymax=-9.99e50; double xtemp,ytemp; n=new int[100]; red=new int[100]; green=new int[100]; blue=new int[100]; plottype=new int[100]; ch=new char[100]; //read all data to determine limit values int i,j; nline=xi.length; for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } //end of for x=new double[nline][nmax]; y=new double[nline][nmax]; for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } //end of for x=new double[nline][nmax]; y=new double[nline][nmax]; for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[0]++; } nmax=n[0];ni=0; x=new double[nline][nmax]; y=new double[nline][nmax]; i=0; for(j=0;jxmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[0]++; } nmax=n[0];ni=0; x=new double[1][nmax]; y=new double[1][nmax]; for(j=0;jxmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[0]++; } nmax=n[0];ni=0; x=new double[1][nmax]; y=new double[1][nmax]; for(j=0;jxmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } //end of for x=new double[nline][nmax]; y=new double[nline][nmax]; for(int i=0;inmax) { nmax=xi.length; ni=nline; } double xa[][]=new double[nline][nmax]; double ya[][]=new double[nline][nmax]; for(int i=0;inmax) { nmax=xi[i-oldnline].length; ni=i; } } double xa[][]=new double[nline][nmax]; double ya[][]=new double[nline][nmax]; for(int i=0;ixmax) xmax=x[i][j]; if(x[i][j]ymax) ymax=y[i][j]; if(y[i][j]nmax) {nmax=xi[i].length;ni=i;} for(int j=0;jxmax) xmax=xi[i][j]; if(xi[i][j]ymax) ymax=yi[i][j]; if(yi[i][j]