/* JRG, the Resource Geology Seismic Processing System for Java, and Viewmat for Java are Copyright 1998-2006 by John N. Louie The software and methods here are the subject of academic research, not commercial products. I would like to know what use you make of my methods, and have your feedback on their success or failure. Also, by letting me know who you are, I can inform you if bugs or errors are discovered. Please send me an email message with: your name and email address; whether you are a student or faculty member, consultant or employee; the name of your university or company, and department; and a sentence or two describing what use you intend to make of these methods. Send your message to louie@seismo.unr.edu */ import java.io.*; import java.util.Vector; import java.awt.*; import java.awt.event.*; public class ViewmatFrame extends Frame implements ActionListener/*, ItemListener*/ { static int nextx=0, nexty=0; static Vector framelist=null; Menu Windows; Viewmat vm; Viewmat vms[]; FileDialog fd; ViewmatProps props; ViewmatPicks picks; ViewmatGeom geom; String path; int plane; public void actionPerformed(ActionEvent e) { String label = e.getActionCommand(); String menuname; if (e.getSource() instanceof Menu) menuname = ((Menu)e.getSource()).getLabel(); else menuname = "Not a menu action."; if (menuname.equals("On Whole Data Set")) { FltVec.handleMethod(this, vm.inplace.getState(), label); vm.resetPropsPanel(props, props.pp); vm.setParameters(props, props.pp); redoWindowMenu(); System.gc(); return; } else if (menuname.equals("On Each Vector")) { FltPlane.handleMethod(this, vm.inplace.getState(), label); vm.resetPropsPanel(props, props.pp); vm.setParameters(props, props.pp); redoWindowMenu(); System.gc(); return; } else if (menuname.equals("On Each Plane")) { FltVol.handleMethod(this, vm.inplace.getState(), label); vm.resetPropsPanel(props, props.pp); vm.setParameters(props, props.pp); redoWindowMenu(); System.gc(); return; } else if (menuname.equals("Windows")) { for (int i=0; i 1) /* altered 4/10/06 JNL to workaround MacOS 10.4 bug thanks to Leiph Preston! new Thread (new readBinaryFileRun(fd.getDirectory(), path, vad.readtype, vad.iv0, vad.iv3, vad.iv2, vad.iv1, vad.oldrg)).start(); */ (new readBinaryFileRun(fd.getDirectory(), path, vad.readtype, vad.iv0, vad.iv3, vad.iv2, vad.iv1, vad.oldrg)).run(); else { if (vm.fvol == null && vm.inplace.getState()) { vm.fp = new FltPlane(vad.iv2, vad.iv1); /* if (vad.readtype == 1) * SEG-Y * vm.fp.readBinaryFile(path, vad.iv0); else*/ if (vad.readtype == 2) /* RG */ vm.fp.readRGFile(path, vad.oldrg); else /* Raw */ vm.fp.readBinaryFile(path, vad.iv0, vad.readtype); if (this.getTitle().equals("100x100 Zero Plane")) this.setTitle(path); else this.setTitle(this.getTitle() + " " + fd.getFile()); props.setTitle(this.getTitle() + " Properties"); this.vm.titletf.setText(this.getTitle()); vm.cvs.vmat.clip = vm.fp.max(); vm.cvs.vmat.title = new String(this.getTitle()); vm.fp.replotinFrame(this); vm.cvs.zoom(vm.fzoom); vm.cvs.vmat.resetPropsPanel(props, props.pp); vm.cvs.vmat.setParameters(props, props.pp); } else { /* altered 4/10/06 JNL to workaround MacOS 10.4 bug thanks to Leiph Preston! new Thread (new readBinaryFileRun(fd.getDirectory(), path, vad.readtype, vad.iv0, vad.iv2, vad.iv1, vad.oldrg)).start(); */ (new readBinaryFileRun(fd.getDirectory(), path, vad.readtype, vad.iv0, vad.iv2, vad.iv1, vad.oldrg)).run(); /*this.dispose();*/ } } vad.dispose(); } void handleWriteSound() { String name = null; short samp; ViewmatAction vad=null; float hz; fd.setMode(FileDialog.SAVE); if (vm.fvol == null) { fd.setTitle("Write Plane to Sound File..."); hz = 1F/vm.fp.getDUnitofDim(0); } else { fd.setTitle("Write Volume to Sound File..."); hz = 1F/vm.fvol.getDUnitofDim(0); } fd.setFile(titleforfile(this.getTitle()) + ".aif"); centerComp(fd); fd.show(); if (fd.getFile() != null) { path = fd.getDirectory() + fd.getFile(); vad = new ViewmatAction(this); vad.path = new String(path); name = new String(path); vad.beginPanel(); vad.setTitle("Creating AIFF Sound File " + path + " ..."); Label tlab1 = new Label("Apparent Samples per Second:"); vad.pp.add(tlab1); TextField tf1 = new TextField("" + hz, 8); vad.pp.add(tf1); Label tlab2 = new Label("Multiply SPS rate to speed up;"); vad.pp.add(tlab2); Label tlab3 = new Label("divide SPS rate to slow down."); vad.pp.add(tlab3); Button apply = new Button("Create Sound File"); vad.pp.add(apply); apply.addActionListener(vad); vad.finishPanel(); vad.height = 200; vad.setSize(300, vad.height); vad.center(); vad.show(); if (vad.done == false) { vad.dispose(); return; } float htemp; try {htemp = Float.valueOf(tf1.getText()).floatValue(); } catch (NumberFormatException nfe) {htemp = hz; } if (htemp == 0F && hz > 0F) htemp = hz; else if (htemp == 0F && hz == 0F) htemp = 8000F; else if (htemp < 0F) htemp = -htemp; hz = htemp; FltPlane sfp = null; if (vm.fvol == null) sfp = vm.fp; else sfp = vm.fvol; int ne = sfp.ne; int nv = sfp.vecs; float max = sfp.max(); int sampperchan; if (nv == 1) sampperchan = ne; else sampperchan = (nv/2)*ne; AifFileHead aifhead = new AifFileHead((int)(hz), sampperchan); int i, bytes; FileOutputStream fos = null; BufferedOutputStream bos = null; DataOutputStream dos = null; sfp.Notice("Writing " + (aifhead.AIFFILEHEADBYTES + 4*sampperchan) + "-byte AIFF sound file at " + ((int)(hz)) + "-Hz sampling to " + name + "... "); try {fos = new FileOutputStream(name); } catch(IOException ioe) { sfp.Errout("Can't create file " + name + ": " + ioe.toString()); return; } bos = new BufferedOutputStream(fos, 4*ne); dos = new DataOutputStream(bos); try { aifhead.write(dos); } catch(IOException ioe) { sfp.Errout("Could not write " + aifhead.AIFFILEHEADBYTES + " bytes to AIFF file " + name); return; } try { if (nv == 1) { for (i=0; i screen.width) p.x = screen.width - s.width; if ((p.y + s.height) > (screen.height - 28)) p.y = screen.height - s.height - 28; if (p.x < 0) p.x = 0; if (p.y < 20) p.y = 20; c.setLocation(p); } void resetLocation() { adjustScreenLocation(this, this.getLocation()); } void centerComp(Component c) { Point p = getLocation(); Dimension d = getSize(); Dimension s = c.getSize(); p.translate((d.width - s.width)/2 + 40, (d.height - s.height)/2); adjustScreenLocation(c, p); } void sideComp(Component c) { int left, right; Point p = getLocation(); Dimension d = getSize(); Dimension s = c.getSize(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); left = p.x; right = screen.width - p.x - d.width; if (left > right) p.translate(-(s.width), 0); else p.translate(d.width, 0); adjustScreenLocation(c, p); } void setNextLocation() { Point p = new Point(nextx, nexty); p.translate(40, 40); adjustScreenLocation(this, p); nextx = p.x; nexty = p.y; } /* End of ViewmatFrame class */ } class createPSFileRun /* implements java.lang.Runnable removed 4/10/06 to work around MacOS 10.4 bug */ { Viewmat vm; String path; int plane; public void run() { if (plane > -1) vm.createPSFile(path, plane); else vm.createPSFile(path); } createPSFileRun(Viewmat vm, String path) { this.vm = vm; this.path = path; this.plane = -1; } createPSFileRun(Viewmat vm, String path, int plane) { this.vm = vm; this.path = path; this.plane = plane; } } class createBinaryFileRun /* implements java.lang.Runnable removed 4/10/06 to work around MacOS 10.4 bug */ { FltPlane fp; String path; int readtype; int samptype; boolean oldrg; public void run() { fp.createBinaryFile(readtype, samptype, oldrg, path); } createBinaryFileRun(FltPlane fp, int readtype, int samptype, boolean oldrg, String path) { this.fp = fp; this.readtype = readtype; this.samptype = samptype; this.oldrg = oldrg; this.path = path; } } class appendBinaryFileRun /* implements java.lang.Runnable removed 4/10/06 to work around MacOS 10.4 bug */ { FltPlane fp; String path; int readtype; int samptype; boolean oldrg; public void run() { fp.appendBinaryFile(readtype, samptype, oldrg, path); } appendBinaryFileRun(FltPlane fp, int readtype, int samptype, boolean oldrg, String path) { this.fp = fp; this.readtype = readtype; this.samptype = samptype; this.oldrg = oldrg; this.path = path; } } class readBinaryFileRun /* implements java.lang.Runnable removed 4/10/06 to work around MacOS 10.4 bug */ { FltPlane fp; FltVol fvol; String path; String dir; int skip, filetype; boolean oldrg; public void run() { if (fvol == null) { if (filetype == 2) /* RG */ fp.readRGFile(path, oldrg); else /* Raw */ fp.readBinaryFile(path, skip, filetype); fp.viewinFrame(dir, path, false, 1F, RgCtab.vagray, false, -1F); } else { if (filetype == 2) /* RG */ fvol.readRGFile(path, oldrg); else /* Raw */ fvol.readBinaryFile(path, skip, filetype); fvol.viewinFrame(dir, path, false, 1F, RgCtab.vagray, false, -1F); } } readBinaryFileRun(String dir, String path, int filetype, int skip, int nv, int ne, boolean oldrg) { this.dir = new String(dir); this.path = new String(path); this.filetype = filetype; this.oldrg = oldrg; this.skip = skip; this.fp = new FltPlane(nv, ne); this.fvol = null; } readBinaryFileRun(String dir, String path, int filetype, int skip, int np, int nv, int ne, boolean oldrg) { this.dir = new String(dir); this.path = new String(path); this.filetype = filetype; this.oldrg = oldrg; this.skip = skip; this.fp = null; this.fvol = new FltVol(np, nv, ne); } } class readSEGYFileRun /*implements java.lang.Runnable removed 3/1/06 to work around MacOS 10.4 bug */ { FltPlane fp; FltVol fvol; String path; String dir; SEGYFileHead sfhd; RgHead rghd[]; long addresses[]; RgFileHead fhd; int np, nv, ne, samptype; public void run() { if (np > 1) { this.fp = null; this.fvol = new FltVol(np, nv, ne); this.fvol.headers = rghd; this.fvol.geogr = sfhd.geogr; } else { this.fp = new FltPlane(nv, ne); this.fp.headers = rghd; this.fp.geogr = sfhd.geogr; this.fvol = null; } if (fvol == null) { fp.setUnit0ofDim(0, fhd.starttime); fp.setDUnitofDim(0, fhd.dt); fp.setUnitsofDim(0, "Time, sec"); fp.setUnit0ofDim(1, 0); fp.setUnitsofDim(1, "Trace Sequence"); fp.setDUnitofDim(1, 1); fp.readSEGYFile(path, addresses, samptype); fp.viewinFrame(dir, path, true, 0.04F, RgCtab.vagray, false, fp.rms()); } else { fvol.setUnit0ofDim(0, fhd.starttime); fvol.setDUnitofDim(0, fhd.dt); fvol.setUnitsofDim(0, "Time, sec"); fvol.setUnit0ofDim(1, 0); fvol.setUnitsofDim(1, "Trace Sequence"); fvol.setDUnitofDim(1, 1); fvol.setUnit0ofDim(2, 0); fvol.setUnitsofDim(2, "Record Index"); fvol.setDUnitofDim(2, 1); fvol.readSEGYFile(path, addresses, samptype); fvol.viewinFrame(dir, path, true, 0.04F, RgCtab.vagray, false, fvol.rms()); } } /* Constructor */ readSEGYFileRun(String dir, String path, SEGYFileHead sfhd, int np, int samptype) { this.dir = new String(dir); this.path = new String(path); this.np = np; this.samptype = samptype; this.nv = sfhd.ntrace; this.ne = sfhd.getnt(); this.sfhd = sfhd; this.addresses = new long[sfhd.addresses.size()]; Long temp; for (int i=0; i 1) { this.fp = null; this.fvol = new FltVol(np, nv, ne); } else { this.fp = new FltPlane(nv, ne); this.fvol = null; } if (fvol == null) { SACTraceHead.readSACFiletoFP(fp, path, fhd, isIntel); fp.viewinFrame(dir, path, false, 100F, RgCtab.vagray, false, fp.max()); } else { SACTraceHead.readSACFiletoFV(fvol, path, fhd, np, isIntel); fvol.viewinFrame(dir, path, false, 100F, RgCtab.vagray, false, fvol.max()); } } /* Constructor */ readSACFileRun(String dir, String path, int np, boolean isIntel) { this.dir = new String(dir); this.path = new String(path); this.np = np; this.isIntel = isIntel; this.fhd = SACTraceHead.scanSACFile(path, np, isIntel); if (fhd.ntrace < 1) { this.nv = 0; this.ne = 0; this.dt = 0F; fhd = null; } else { if (np > 1) this.nv = fhd.ntrace/np; else this.nv = fhd.ntrace; this.ne = fhd.nt; this.dt = fhd.dt; } } }