// plot8d.java plot 8d data // reads from stdin, first line 8 nx ny nz nt nu nv nw np // many lines x y z t u v w p U // sorted x first, y next, ... // one space separator // java -cp . plot8d < file.dat > file.out // converted from plot6d.java import java.io.*; import java.awt.*; import java.awt.event.*; public class plot8d extends Frame { // mouse and display variables int xm, ym, bm; // mouse position int height = 800; // was 800 int width = 1000; // was 1000 double gfct = 0.575; // percent size of plot volume double xmin = 0.0; // scaled for plotting double xmax = 1.0; double ymin = 0.0; double ymax = 1.0; double zmin = 0.0; double zmax = 1.0; double tmin = 0.0; double tmax = 1.0; double umin = 0.0; double umax = 1.0; double vmin = 0.0; double vmax = 1.0; double wmin = 0.0; double wmax = 1.0; double pmin = 0.0; double pmax = 1.0; double Umin = 0.0; double Umax = 1.0; double dxmin, dxmax, dymin, dymax, dzmin, dzmax, dtmin, dtmax; double dumin, dumax, dvmin, dvmax, dwmin, dwmax, dpmin, dpmax, dUmin, dUmax; double v1min = 0.0; // variable samples, computed based on mouse click double v1max = 1.0; double v2min = 0.0; double v2max = 1.0; double v3min = 0.0; double v3max = 1.0; double v4min = 0.0; double v4max = 1.0; double v5min = 0.0; double v5max = 1.0; double v6min = 0.0; double v6max = 1.0; double v7min = 0.0; double v7max = 1.0; double v8min = 0.0; double v8max = 1.0; double xw, yh, xoff, yoff; int dim = 8; // should be read in int nn[] = new int[dim]; // nx, ny, nz, nt, nu, nv, nw, np // in var order int var1 = 0; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 front axis // under mouse change int var2 = 1; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 side axis int var3 = 2; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 scan-run int var4 = 3; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 other-run int var5 = 4; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 other-run int var6 = 5; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 other-run int var7 = 6; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 other-run int var8 = 7; // x=0, y=1, z=2, t=3, u=4, v=5, w=6, p=7 other-run double v1, v2, v3, v4, v5, v6, v7, v8; int v3step = 1; int v4step = 1; int v5step = 1; int v6step = 1; int v7step = 1; int v8step = 1; int nx; // computed based on data int ny; int nz; int nt; int nu; int nv; int nw; int np; int nv1; // nx, ny, nz, nt, nu, nv, nw, np based on // var1, var2, var3, var4, var5, var6, var7, var8 int nv2; int nv3; int nv4; int nv5; int nv6; int nv7; int nv8; int nxyztuvwp; double pt[][]; // = new double[nxyztuvwp][dim+1]; double ya = 0.5; // orthographic typ 0.2 to 0.7, must fix text double xs = (gfct*(width-150)); double ys = (gfct*(height-100)); int xp, yp; // for passing back ortho point boolean debug = true; int n_input; boolean run345678 = false; boolean stop = false; int speed = 100; // millisecond delay // set up double buffering for smooth "run" Image dbImage; Graphics dbg; // double buffered graphics public plot8d() { System.out.println("plot8d.java running."); setTitle("plot8d x,y,z,t,u,v,w,p value U"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); try { read_data(); nn[0] = nx; nn[1] = ny; nn[2] = nz; nn[3] = nt; nn[4] = nu; nn[5] = nv; nn[6] = nw; nn[7] = np; nv1 = nn[0]; nv2 = nn[1]; nv3 = nn[2]; nv4 = nn[3]; nv5 = nn[4]; nv6 = nn[5]; nv7 = nn[6]; nv8 = nn[7]; v3step = nn[var3]-1; v4step = nn[var4]-1; v5step = nn[var5]-1; v6step = nn[var6]-1; v7step = nn[var7]-1; v8step = nn[var8]-1; } // end try catch(IOException exception) { System.out.println(exception); } // repaint(); } // plot8d constructor // this is the key to double buffering, repaint() calls update, not paint public void update(Graphics g) { // initialize Double Buffers if(dbImage==null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } // only first time // clear Image in RAM, dbg is off screen buffer dbg.setColor(Color.white); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); paint(dbg); // now call paint to render in dbg g.drawImage(dbImage, 0, 0, this); // display rendered image, very fast } // end update public class do_scan extends Thread // var1, var2, var3, var4, var5, var6, var7, var8 // v3step, v4step, v5step, v6step, v7step, v8step can be changed { do_scan() { if(debug) System.out.println("do_scan on var3="+var3+" with nv3="+nv3); if(debug) System.out.println("do_scan on var4="+var4+" with nv4="+nv4); if(debug) System.out.println("do_scan on var5="+var5+" with nv5="+nv5); if(debug) System.out.println("do_scan on var6="+var6+" with nv6="+nv6); if(debug) System.out.println("do_scan on var7="+var7+" with nv7="+nv7); if(debug) System.out.println("do_scan on var8="+var8+" with nv8="+nv8); } public void run() { for(int iii=0; iii11) fstring = fstring.substring(0,10); g.drawString(fstring, 80, 242); for(int i=1; i11) fstring = fstring.substring(0,10); g.drawString(fstring, 80, 62+20*i); } // draw box, bottom nv1 = nn[var1]; nv2 = nn[var2]; nv3 = nn[var3]; nv4 = nn[var4]; nv5 = nn[var5]; nv6 = nn[var6]; nv7 = nn[var7]; nv8 = nn[var8]; if(var1==0) { v1min = xmin; v1max = xmax; } if(var1==1) { v1min = ymin; v1max = ymax; } if(var1==2) { v1min = zmin; v1max = zmax; } if(var1==3) { v1min = tmin; v1max = tmax; } if(var1==4) { v1min = umin; v1max = umax; } if(var1==5) { v1min = vmin; v1max = vmax; } if(var1==6) { v1min = wmin; v1max = wmax; } if(var1==7) { v1min = pmin; v1max = pmax; } if(var2==0) { v2min = xmin; v1max = xmax; } if(var2==1) { v2min = ymin; v1max = ymax; } if(var2==2) { v2min = zmin; v1max = zmax; } if(var2==3) { v2min = tmin; v1max = tmax; } if(var2==4) { v2min = umin; v1max = umax; } if(var2==5) { v2min = vmin; v1max = vmax; } if(var2==6) { v2min = wmin; v1max = wmax; } if(var2==7) { v2min = pmin; v1max = pmax; } if(var3==0) { v3min = xmin; v1max = xmax; } if(var3==1) { v3min = ymin; v1max = ymax; } if(var3==2) { v3min = zmin; v1max = zmax; } if(var3==3) { v3min = tmin; v1max = tmax; } if(var3==4) { v3min = umin; v1max = umax; } if(var3==5) { v3min = vmin; v1max = vmax; } if(var3==6) { v3min = wmin; v1max = wmax; } if(var3==7) { v3min = pmin; v1max = pmax; } if(var4==0) { v4min = xmin; v1max = xmax; } if(var4==1) { v4min = ymin; v1max = ymax; } if(var4==2) { v4min = zmin; v1max = zmax; } if(var4==3) { v4min = tmin; v1max = tmax; } if(var4==4) { v4min = umin; v1max = umax; } if(var4==5) { v4min = vmin; v1max = vmax; } if(var4==6) { v4min = wmin; v1max = wmax; } if(var4==7) { v4min = pmin; v1max = pmax; } if(var5==0) { v5min = xmin; v1max = xmax; } if(var5==1) { v5min = ymin; v1max = ymax; } if(var5==2) { v5min = zmin; v1max = zmax; } if(var5==3) { v5min = tmin; v1max = tmax; } if(var5==4) { v5min = umin; v1max = umax; } if(var5==5) { v5min = vmin; v1max = vmax; } if(var5==6) { v5min = wmin; v1max = wmax; } if(var5==7) { v5min = pmin; v1max = pmax; } if(var6==0) { v6min = xmin; v1max = xmax; } if(var6==1) { v6min = ymin; v1max = ymax; } if(var6==2) { v6min = zmin; v1max = zmax; } if(var6==3) { v6min = tmin; v1max = tmax; } if(var6==4) { v6min = umin; v1max = umax; } if(var6==5) { v6min = vmin; v1max = vmax; } if(var6==6) { v6min = wmin; v1max = wmax; } if(var6==7) { v6min = pmin; v1max = pmax; } if(var7==0) { v7min = xmin; v1max = xmax; } if(var7==1) { v7min = ymin; v1max = ymax; } if(var7==2) { v7min = zmin; v1max = zmax; } if(var7==3) { v7min = tmin; v1max = tmax; } if(var7==4) { v7min = umin; v1max = umax; } if(var7==5) { v7min = vmin; v1max = vmax; } if(var7==6) { v7min = wmin; v1max = wmax; } if(var7==7) { v7min = pmin; v1max = pmax; } if(var8==0) { v8min = xmin; v1max = xmax; } if(var8==1) { v8min = ymin; v1max = ymax; } if(var8==2) { v8min = zmin; v1max = zmax; } if(var8==3) { v8min = tmin; v1max = tmax; } if(var8==4) { v8min = umin; v1max = umax; } if(var8==5) { v8min = vmin; v1max = vmax; } if(var8==6) { v8min = wmin; v1max = wmax; } if(var8==7) { v8min = pmin; v1max = pmax; } set_color(0, g); ortho(v1min, v2min, Umin); xp1=xp; yp1=yp; ortho(v1max, v2min, Umin); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1max, v2max, Umin); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); ortho(v1min, v2max, Umin); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1min, v2min, Umin); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); set_color(ncol-1, g); // top ortho(v1min, v2min, Umax); xp1=xp; yp1=yp; ortho(v1max, v2min, Umax); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1max, v2max, Umax); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); ortho(v1min, v2max, Umax); xp2=xp; yp2=yp; g.drawLine(xp1, yp1, xp2, yp2); ortho(v1min, v2min, Umax); xp1=xp; yp1=yp; g.drawLine(xp2, yp2, xp1, yp1); // draw box edges with z value colors U1 = Umin; hU = (Umax-Umin)/(ncol); for(int i=0; i= "+nxyztuvwp); System.out.println("var1="+var1+", var2="+var2+", var3="+var3+ ", var4="+var4+", var5="+var5+", var6="+var6+ ", var7="+var7+", var8="+var8); lin = nxyztuvwp-1; } return lin; } // end i4x // orthographic projection, sets xp,yp void ortho(double x, double y, double U) { double x1, y1, U1, x2, y2, x3, y3; x1 = (x-xmin)/(xmax-xmin); // zero base, normalized y1 = (y-ymin)/(ymax-ymin); U1 = (U-Umin)/(Umax-Umin); // U-Umin; x2 = x1+y1*ya; // ortho z is up, y is back y2 = U1+y1*ya; x3 = x2*xs; // scale y3 = y2*ys; x3 = x3+25; // away from boarder y3 = height-y3-25; // away from boarder xp = (int)x3; yp = (int)y3; //System.out.println("ortho xp="+xp+", yp="+yp); //System.out.println("x1="+x1+", y1="+y1+", U1="+U1); //System.out.println(" "); } // end ortho void set_color(int i, Graphics g) { if(i<0) {g.setColor(Color.black); return;} if(i>9) {g.setColor(Color.gray); return; } switch(i) { case 0: g.setColor(Color.black); break; case 1: g.setColor(new Color(188,143,143)); break; // Color.pink); brown case 2: g.setColor(Color.red); break; case 3: g.setColor(Color.orange); break; case 4: g.setColor(Color.yellow); break; case 5: g.setColor(Color.green); break; case 6: g.setColor(Color.blue); break; case 7: g.setColor(Color.magenta); break; case 8: g.setColor(Color.cyan); break; case 9: g.setColor(Color.gray); break; } } // end set_color void read_data() throws IOException // big ugly input method { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input_line; double amount; int len; int index; int last; System.out.println("read_data running"); input_line = in.readLine(); // dim nx ny nz nt nu nv nw np // one space between each, dim should be 8 System.out.println("input: "+input_line); len = input_line.length(); index = 0; while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index,last)+ "| len="+(input_line.substring(index,last).length())); dim = Integer.parseInt(input_line.substring(index,last)); System.out.println("dim="+dim); index = last; // nx while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); nx = Integer.parseInt(input_line.substring(index,last)); System.out.println("nx="+nx); index = last; // ny while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); ny = Integer.parseInt(input_line.substring(index,last)); System.out.println("ny="+ny); index = last; // nz while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); if(debug) System.out.println(input_line.substring(index+1,last)); nz = Integer.parseInt(input_line.substring(index,last)); System.out.println("nz="+nz); index = last; // nt while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); nt = Integer.parseInt(input_line.substring(index,last)); System.out.println("nt="+nt); index = last; // nu while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); nu = Integer.parseInt(input_line.substring(index,last)); System.out.println("nu="+nu); index = last; // nv while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug) System.out.println("last="+last); nv = Integer.parseInt(input_line.substring(index,last)); System.out.println("nv="+nv); index = last; // nw while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(last==-1) last = len; if(debug) System.out.println("last="+last); nw = Integer.parseInt(input_line.substring(index,last)); System.out.println("nw="+nw); index = last; // np while(input_line.charAt(index)==' ') index++; if(debug) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(last==-1) last = len; if(debug) System.out.println("last="+last); np = Integer.parseInt(input_line.substring(index,last)); System.out.println("np="+np); nxyztuvwp = nx*ny*nz*nt*nu*nv*nw*np; System.out.println("about to allocate "+(nxyztuvwp*(dim+1))+" doubles"); pt = new double[nxyztuvwp][dim+1]; n_input = 0; // read data points, last index varies by 1 input_line = in.readLine(); // tested for short in 'while' while(input_line.length()>8) // exit on blank or short line { if(debug && n_input==0) System.out.println("input: "+input_line); len = input_line.length(); index = 0; // first x while(input_line.charAt(index)==' ') index++; if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][0] = amount; index = input_line.indexOf(' ',last); // second y if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][1] = amount; index = input_line.indexOf(' ',last); // third z if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][2] = amount; index = input_line.indexOf(' ',last); // fourth t if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][3] = amount; index = input_line.indexOf(' ',last); // fifth u if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][4] = amount; index = input_line.indexOf(' ',last); // sixth v if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][5] = amount; index = input_line.indexOf(' ',last); // seventh w if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][6] = amount; index = input_line.indexOf(' ',last); // eighth p if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][7] = amount; index = input_line.indexOf(' ',last); // U if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(last==-1) last = len; if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index+1,last)); if(debug && n_input==0) System.out.println("amount="+amount); pt[n_input][8] = amount; if(n_input==0) { dxmin = pt[n_input][0]; dxmax = pt[n_input][0]; dymin = pt[n_input][1]; dymax = pt[n_input][1]; dzmin = pt[n_input][2]; dzmax = pt[n_input][2]; dtmin = pt[n_input][3]; dtmax = pt[n_input][3]; dumin = pt[n_input][4]; dumax = pt[n_input][4]; dvmin = pt[n_input][5]; dvmax = pt[n_input][5]; dwmin = pt[n_input][6]; dwmax = pt[n_input][6]; dpmin = pt[n_input][7]; dpmax = pt[n_input][7]; dUmin = pt[n_input][8]; dUmax = pt[n_input][8]; System.out.println("first x="+dxmin+", y="+dymin+", z="+dzmin); System.out.println("first t="+dtmin+", u="+dumin+", v="+dvmin); System.out.println("first w="+dwmin+", d="+dpmin+", U="+dUmin); } else { dxmin = Math.min(dxmin,pt[n_input][0]); dxmax = Math.max(dxmax,pt[n_input][0]); dymin = Math.min(dymin,pt[n_input][1]); dymax = Math.max(dymax,pt[n_input][1]); dzmin = Math.min(dzmin,pt[n_input][2]); dzmax = Math.max(dzmax,pt[n_input][2]); dtmin = Math.min(dtmin,pt[n_input][3]); dtmax = Math.max(dtmax,pt[n_input][3]); dumin = Math.min(dumin,pt[n_input][4]); dumax = Math.max(dumax,pt[n_input][4]); dvmin = Math.min(dvmin,pt[n_input][5]); dvmax = Math.max(dvmax,pt[n_input][5]); dwmin = Math.min(dwmin,pt[n_input][6]); dwmax = Math.max(dwmax,pt[n_input][6]); dpmin = Math.min(dpmin,pt[n_input][7]); dpmax = Math.max(dpmax,pt[n_input][7]); dUmin = Math.min(dUmin,pt[n_input][8]); dUmax = Math.max(dUmax,pt[n_input][8]); } n_input++; if(n_input>=nxyztuvwp) break; input_line = in.readLine(); // done with this line, read next } // end while } // end try catch(IOException exception) { System.out.println(exception); } System.out.println("read_data finished, n_input="+n_input); System.out.println("xmin="+dxmin+", xmax="+dxmax+", last="+pt[nxyztuvwp-1][0]); System.out.println("ymin="+dymin+", ymax="+dymax+", last="+pt[nxyztuvwp-1][1]); System.out.println("zmin="+dzmin+", zmax="+dzmax+", last="+pt[nxyztuvwp-1][2]); System.out.println("tmin="+dtmin+", tmax="+dtmax+", last="+pt[nxyztuvwp-1][3]); System.out.println("umin="+dumin+", umax="+dumax+", last="+pt[nxyztuvwp-1][4]); System.out.println("vmin="+dvmin+", vmax="+dvmax+", last="+pt[nxyztuvwp-1][5]); System.out.println("wmin="+dwmin+", wmax="+dwmax+", last="+pt[nxyztuvwp-1][6]); System.out.println("pmin="+dpmin+", pmax="+dpmax+", last="+pt[nxyztuvwp-1][7]); System.out.println("Umin="+dUmin+", Umax="+dUmax+", last="+pt[nxyztuvwp-1][8]); for(int i=0; i