//====================================================== // Numerical Analysis package in java // Plot class to plot 2D data // Dr. Turhan Coban // EGE University, Engineering School, Mechanical Eng. Div. // turhan.coban@ege.edu.tr // ===================================================== import java.io.*; import java.awt.Color; //===== classes used by this class======= // PlotShapesSW // define shapes to draw in plot windows in real coordinate system // Plot2D // Plot and coordinates data // PLotW //defines actual graphic screens and pages //===== Example classes // PlotT0,PlotT01,PlotT02,PlotT03,PlotT1,PlotT2,PlotT3,PlotT4 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 Plot { // This class reads plot input variables // and sets relations between absolute scale and relative scale plot windows public String label="y=f(x)"; // Plot Label public String xlabel="x"; // X axis Label public String ylabel="y"; // 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 xgridon=0; // x axis grid line on public int ygridon=0; // y axis grid line on public int xlog=0; // x axis logaritmic scale public int ylog=0; // y axis logaritmic scale public int plottype[]; public String plotst[]={"0 _____________", "1 __ __ __ __ ", "2 . _ . _ . _ ", "3 . _ _ . . _ _ .", "4 - - - - - ", "5 kalın _____________", "6 kalın __ __ __ __ ", "7 kalın . _ . _ . _ ", "8 kalın . _ _ . . _ _ .", "9 kalın - - - - - ", "10 * " , "11 # ", "12 $ ", "13 % ", "14 & ", "15 - ", "16 ~ ", "17 + ", "18 x ", "19 = ", "20 kare", "21 dolu kare", "22 daire", "23 dolu daire", "24 üçken", "25 eşkenar dörtgen", "26 beşken", "27 altıgen", "28 dolu üçgen", "28 dolu eşkenar dörtken", "30 dolu beşgen", "31 dolu altıgen", "32 üç köşe yıldız", "33 dört köşe yıldız", "34 beş köşe yıldız", "35 altı köşe yıldız", "36 dolu üç köşe yıldız", "37 dolu dört köşe yıldız", "38 dolu beş köşe yıldız", "39 dolu altı köşe yıldız", "40 çubuk grafik", "41 dolu çubuk grafik"}; double xminmaxlog,yminmaxlog; // 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 ======================= public Plot() throws IOException : Read actual data from file Plot.txt and plot filenames listed in this file public Plot(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 file names from String fn[] and plot them public Plot(String fn[],int ipt[],int ir[],int ig[],int ib[]) throws IOException public Plot(String fn[]) throws IOException : Read file names from String fn[] and plot them public Plot(double xi[][],double yi[][],int ipt[],int ir[],int ig[],int ib[]) : read plot data from xi[][] and yi[][] public Plot(double xiyi[][]) : read plot data xi[] and yi[] from xiyi[][] string public Plot(double xi[][],double yi[][]) : read plot data from xi[][] and yi[][] public Plot(double xi[],double yi[]) : read plot data from xi[] and yi[] public Plot(f_x f,double xm,double xma,int N,int ipt,int ir,int ig,int ib) : create plot data from a simple function f_x f public Plot(f_x f,double xm,double xma,int N) : create plot data from a simple function f_x f public Plot(fi_x f,double xm,double xma,int Number_of_Data,int Number_of_Function) : create plot data from an array of simple functions fi_x f ======== Label settings ======================== public void setPlabel(String ip) {label=ip;} public void setXlabel(String ix) {xlabel=ix;} public void setYlabel(String iy) {ylabel=iy;} public void setXYlabel(String ix,String iy) {xlabel=ix;ylabel=iy;} ======== Setting additional data after initial construction ========= This groups's functions are similar to constructor classes public void addData(double xi[],double yi[]) public void addData(double xi[],double yi[],int iplottype) public void addData(double xi[],double yi[],int iplottype,int ir,int ig,int ib) public void addData(double xi[][],double yi[][]) public void addData(double xi[][],double yi[][],int ip[]) public void addData(double xi[][],double yi[][],int ip[],int ir[],int ig[],int ib[]) public void addFunction(f_x f,double xmi,double xma,int N,int ipt) public void addFunction(f_x f,double xmi,double xma,int N) public void addFunction(f_x f,double xmi,double xma,int N,int ipt,int ir,int ig,int ib) public void addFunction(fi_x f,double xmin,double xmax,int Number_of_Data,int Number_of_Function) public void addFunction(fi_x f,double xmin,double xmax,int Number_of_Data,int Number_of_Function,int ipt[]) public void addFunction(fi_x f,double xmin,double xmax,int Number_of_Data,int Number_of_Function, ================== Settings of additional plot information ================= ----------Plot Type ---------------------- public void setPlotType(int plot_type[]) public void setPlotType(int dataset,int plot_no) public void setPlotType(int dataset,char plot_char) ----------x y grid on-off ---------------- public void setXgrid(int igx) public void setYgrid(int igy) public void setGrid(int igx,int igy) public void setXtic(int ixt) public void setYtic(int iyt) public void setXYtic(int ixt,int iyt) ---------- Color setting for plot data -------- public void setColor(int dataset,int ired,int igreen,int iblue) public void setColor(int ired[],int igreen[],int iblue[]) ================ Setting of Minimum Maximum fuctions =================== public void setMinMax() public void setMinMax(double xi[][],double yi[][]) public void setMinMax(double iminx,double imaxx,double iminy,double imaxy) =============== Plot Window Formatting ================================== public void set_plotwindow(int width,int height,double xip,double yip,double dxp,double dyp) public void setabsMaxMin(int ixmin,int iymin,int idx,int idy) ================ Actual Plotting of constructed data public void plot() */ public Plot() throws IOException { //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 //========================== xmin=9.99e50; xmax=-9.99e50; ymin=9.99e50; ymax=-9.99e50; double xtemp,ytemp; try{ fini=new BufferedReader(new FileReader("Plot.txt")); } catch(IOException e) { System.err.println("Error Opening File \n"+e.toString()); System.exit(1); } label=Text.readStringLine(fini); xlabel=Text.readStringLine(fini); ylabel=Text.readStringLine(fini); nline=Text.readInt(fini); n=new int[100]; red=new int[100]; green=new int[100]; blue=new int[100]; plottype=new int[100]; ch=new char[100]; ch[10]='*'; ch[11]='#'; ch[12]='$'; ch[13]='%'; ch[14]='&'; ch[15]='@'; ch[16]='~'; ch[17]='+'; ch[18]='x'; ch[19]='='; //read all data to determine limit values String fn[]; fn=new String[nline]; int i,j; for(i=0;i= 10)&&(plottype[i] <= 19)) ch[i]=Text.readChar(fini); red[i]=Text.readInt(fini); green[i]=Text.readInt(fini); blue[i]=Text.readInt(fini); j=0; n[i]=0; //open ffile try{ ffile=new BufferedReader(new FileReader(fn[i])); } catch(IOException e) { System.err.println("Error Opening File \n"+e.toString()); System.exit(1); } try{ while(ffile!=null) { xtemp=Text.readDouble(ffile); ytemp=Text.readDouble(ffile); if(xtempxmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } } catch(EOFException e_eof) { //close ffile try{ ffile.close(); } catch(IOException e) { System.err.println("Error Closing File\n"+e.toString()); System.exit(1); } } //End of EOFException if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } //close ffile try{ ffile.close(); } catch(IOException e) { System.err.println("Error Closing File\n"+e.toString()); System.exit(1); } x=new double[nline][nmax]; y=new double[nline][nmax]; //re-read the data again to load it for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } } catch(EOFException e_eof) { //close ffile try{ ffile.close(); } catch(IOException e) { System.err.println("Error Closing File\n"+e.toString()); System.exit(1); } } //End of EOFException if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } //System.out.println("nline = "+nline+"nmax="+nmax); x=new double[nline][nmax]; y=new double[nline][nmax]; //re-read the data again to load it for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } } catch(EOFException e_eof) { //close ffile try{ ffile.close(); } catch(IOException e) { System.err.println("Error Closing File\n"+e.toString()); System.exit(1); } } //End of EOFException if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } x=new double[nline][nmax]; y=new double[nline][nmax]; //re-read the data again to load it for(i=0;ixmax) xmax=xtemp; if(ytempymax) ymax=ytemp; n[i]++; } } catch(EOFException e_eof) { //close ffile try{ ffile.close(); } catch(IOException e) { System.err.println("Error Closing File\n"+e.toString()); System.exit(1); } } //End of EOFException if(i==0) {nmax=n[i];ni=i;} else { if(n[i]>nmax) {nmax=n[i];ni=i;} } } x=new double[nline][nmax]; y=new double[nline][nmax]; //re-read the data again to load it 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;jnmax) { 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]