/* JRG, the Resource Geology Seismic Processing System for Java, and Viewmat for Java are Copyright 1998-2007 by John N. Louie License is hereby granted for anyone to make any use of this software and its associated source and compiled binary codes, including free re-distribution, and incorporation into commercial products, provided this copyright notice is retained within all files, versions, and distribution media substantially incorporating John Louie's original work. 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.awt.*; import java.awt.event.*; public class ViewmatAction extends Dialog implements ActionListener, ItemListener { ViewmatFrame f; FltPlane fp; FltVol fvol; Panel pp; boolean done, noticeonly, oldrg, geogr; TextArea expl, picks; Button checkhead, getfile; Checkbox cb0, cb1, cb2, cb3, cb4, rgtype, geogrcb; Choice bintype, ch0, ch1, ch2, ch3, ch4; Label lab0, lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10; Label lab11, lab12, lab13, lab14, lab15; TextField tf0, tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9, tf10; TextField tf11, tf12, tf13, tf14, tf15; Label namelab, skiplab, nelab, nvlab, nplab; TextField nametf, skiptf, netf, nvtf, nptf; String path; int readtype, iv0, iv1, iv2, iv3, iv4, iv5, iv6, iv7, iv8; float fv0, fv1, fv2, fv3, fv4, fv6, fv7, fv8; int height; Choice samptypech; Checkbox tapeheadcb, swabheadcb; TextField firstrectf, lastrectf; Label samptypelab, firstreclab, lastreclab; int samptype, firstrec, lastrec; boolean tapehead, swabhead; SEGYFileHead sfhd; RgFileHead fhd; public void actionPerformed(ActionEvent e) { String label = e.getActionCommand(); if (label.equals("Cancel")) { this.setVisible(false); this.done = false; return; } else if (label.equals("Create Binary File")) { prepWriteBinary(false); this.done = true; this.setVisible(false); return; } else if (label.equals("Append Binary File")) { prepWriteBinary(true); this.done = true; this.setVisible(false); return; } else if (label.equals("Read Binary File")) { prepReadBinary(); this.done = true; this.setVisible(false); return; } else if (label.equals("Get File...")) { f.fd.setMode(FileDialog.LOAD); f.fd.setTitle("Get Binary File..."); f.fd.setFile(this.nametf.getText()); f.centerComp(f.fd); f.fd.show(); if (f.fd.getFile() == null) return; f.path = f.fd.getDirectory() + f.fd.getFile(); this.nametf.setText(f.path); this.done = false; return; } else if (label.equals("Check Header")) { FltPlane.checkHeader(this); this.done = false; return; } this.setVisible(false); this.done = true; return; } public Choice makeBintype(boolean Reading) { Choice btype = new Choice(); btype.add("Raw Float"); btype.add("SEG-Y"); btype.add("RG"); if (Reading) { btype.add("32-Bit Int"); btype.add("32-Bit Intel Int"); btype.add("16-Bit Int"); btype.add("16-Bit Intel Int"); btype.add("8-Bit Int"); btype.add("Plain Ascii Text"); btype.add("16-Bit Unsigned"); btype.add("8-Bit Unsigned"); btype.add("32-Bit Intel Float"); btype.add("SAC (IEEE)"); btype.add("SAC (Intel)"); } return btype; } public void itemStateChanged(ItemEvent e) { if (bintype.getSelectedIndex() == 1) { /* enable SEG-Y file parameters */ if (skiplab != null) { skiplab.setEnabled(false); skiptf.setEnabled(false); /*skiptf.setText("3600");*/ } if (nelab != null) { nelab.setEnabled(false); netf.setEnabled(false); nvlab.setEnabled(false); nvtf.setEnabled(false); nplab.setEnabled(false); nptf.setEnabled(false); } rgtype.setEnabled(false); samptypech.setEnabled(true); samptypelab.setEnabled(true); if (tapeheadcb != null) { tapeheadcb.setEnabled(true); /*swabheadcb.setEnabled(true);*/ firstrectf.setEnabled(true); lastrectf.setEnabled(true); firstreclab.setEnabled(true); lastreclab.setEnabled(true); } if (geogrcb != null) geogrcb.setEnabled(true); } else if (bintype.getSelectedIndex() == 2) { /* enable RG file parameters */ if (skiplab != null) { skiplab.setEnabled(false); skiptf.setEnabled(false); skiptf.setText("0"); } if (nelab != null) { nelab.setEnabled(false); netf.setEnabled(false); nvlab.setEnabled(false); nvtf.setEnabled(false); nplab.setEnabled(true); nptf.setEnabled(true); } rgtype.setEnabled(true); samptypech.setEnabled(false); samptypelab.setEnabled(false); if (tapeheadcb != null) { tapeheadcb.setEnabled(false); /*swabheadcb.setEnabled(false);*/ firstrectf.setEnabled(false); lastrectf.setEnabled(false); firstreclab.setEnabled(false); lastreclab.setEnabled(false); } if (geogrcb != null) geogrcb.setEnabled(false); } else if (bintype.getSelectedIndex() == 12 || bintype.getSelectedIndex() == 13) { /* enable SAC file parameters */ if (skiplab != null) { skiplab.setEnabled(false); skiptf.setEnabled(false); skiptf.setText("0"); } if (nelab != null) { nelab.setEnabled(false); netf.setEnabled(false); nvlab.setEnabled(false); nvtf.setEnabled(false); nplab.setEnabled(true); nptf.setEnabled(true); } rgtype.setEnabled(false); samptypech.setEnabled(false); samptypelab.setEnabled(false); if (tapeheadcb != null) { tapeheadcb.setEnabled(false); /*swabheadcb.setEnabled(false);*/ firstrectf.setEnabled(false); lastrectf.setEnabled(false); firstreclab.setEnabled(false); lastreclab.setEnabled(false); } if (geogrcb != null) geogrcb.setEnabled(false); } else { /* enable Raw file parameters */ if (skiplab != null) { skiplab.setEnabled(true); skiptf.setEnabled(true); skiptf.setText("0"); } if (nelab != null) { nelab.setEnabled(true); netf.setEnabled(true); nvlab.setEnabled(true); nvtf.setEnabled(true); nplab.setEnabled(true); nptf.setEnabled(true); } rgtype.setEnabled(false); samptypech.setEnabled(false); samptypelab.setEnabled(false); if (tapeheadcb != null) { tapeheadcb.setEnabled(false); /*swabheadcb.setEnabled(false);*/ firstrectf.setEnabled(false); lastrectf.setEnabled(false); firstreclab.setEnabled(false); lastreclab.setEnabled(false); } if (geogrcb != null) geogrcb.setEnabled(false); } } /* Constructor */ ViewmatAction(ViewmatFrame f) { super(f); this.f = f; this.fp = f.vm.fp; this.fvol = f.vm.fvol; this.done = false; this.noticeonly = false; namelab = null; skiplab = null; nelab = null; nvlab = null; nplab = null; nametf = null; skiptf = null; netf = null; nvtf = null; nptf = null; samptypech = null; tapeheadcb = null; swabheadcb = null; firstrectf = null; lastrectf = null; samptypelab = null; firstreclab = null; lastreclab = null; geogrcb = null; if (fvol == null) this.geogr = f.vm.fp.geogr; else this.geogr = f.vm.fvol.geogr; sfhd = null; fhd = null; height = 300; } public void prepWriteBinary(boolean appending) { int temp; float ftemp; readtype = bintype.getSelectedIndex(); oldrg = rgtype.getState(); tapehead = true; swabhead = false; samptype = samptypech.getSelectedIndex(); geogr = geogrcb.getState(); if (readtype == 2 && appending) /* RG */ { OldRGFileHead ofhd = new OldRGFileHead(); fhd = new RgFileHead(); iv0 = 0; if (oldrg) { ofhd.readOldRGFileHead(path); fhd.copyOldRGFileHead(ofhd); } else fhd.readRgFileHead(path); if (fhd.isValid()) { if (fvol != null) temp = fvol.ne; else temp = fp.ne; if (temp != fhd.nt) { this.f.Errout("RG file " + path + "\nhas " + fhd.nt + " samples per trace; cannot append" + "\nthe current data, which has " + temp + " samples per trace."); readtype = -1; } /* Filter on starttime? */ } else { this.f.Errout("File " + path + "\ndoes not appear to have an RG file header:\n" + fhd + "\nCannot append RG traces."); readtype = -1; } } else if (readtype == 1 && appending) /* SEG-Y */ { /*this.f.setCursor(Cursor.WAIT_CURSOR); this.setCursor(Cursor.WAIT_CURSOR);*/ sfhd = new SEGYFileHead(); iv3 = sfhd.scanSEGYFile(path, tapehead, swabhead, -1, -1, samptype, f); /*this.f.setCursor(Cursor.DEFAULT_CURSOR); this.setCursor(Cursor.DEFAULT_CURSOR);*/ if (sfhd.isValid() && iv3 > 0) { if (fvol != null) temp = fvol.ne; else temp = fp.ne; if (temp != sfhd.getnt()) { this.f.Errout("SEG-Y file " + path + "\nhas " + sfhd.getnt() + " samples per trace; cannot append" + "\nthe current data, which has " + temp + " samples per trace."); readtype = -1; } } else { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file with a reel header," + "\ncannot append SEG-Y traces."); readtype = -1; } } } public void prepReadBinary() { int temp; readtype = bintype.getSelectedIndex(); oldrg = rgtype.getState(); try {iv0 = Integer.valueOf(skiptf.getText()).intValue(); } catch (NumberFormatException nfe) {iv0 = 0; } if (iv0 < 0) iv0 = 0; int ne, nv, np; try {ne = Integer.valueOf(netf.getText()).intValue(); } catch (NumberFormatException nfe) {ne = fvol==null ? fp.getNMembofDim(0) : fvol.getNMembofDim(0); } if (ne <= 0) ne = fvol==null ? fp.getNMembofDim(0) : fvol.getNMembofDim(0); try {nv = Integer.valueOf(nvtf.getText()).intValue(); } catch (NumberFormatException nfe) {nv = fvol==null ? fp.getNMembofDim(1) : fvol.getNMembofDim(1); } if (nv <= 0) nv = fvol==null ? fp.getNMembofDim(1) : fvol.getNMembofDim(1); try {np = Integer.valueOf(nptf.getText()).intValue(); } catch (NumberFormatException nfe) {np = fvol==null ? fp.getNMembofDim(2) : fvol.getNMembofDim(2); } if (np <= 0) np = fvol==null ? fp.getNMembofDim(2) : fvol.getNMembofDim(2); iv1 = ne; iv2 = nv; iv3 = np; if (readtype == 2) /* RG */ { OldRGFileHead ofhd = new OldRGFileHead(); fhd = new RgFileHead(); iv0 = 0; if (oldrg) { ofhd.readOldRGFileHead(path); fhd.copyOldRGFileHead(ofhd); } else fhd.readRgFileHead(path); if (fhd.isValid()) { iv1 = fhd.nt; iv2 = fhd.ntrace/iv3; } else { this.f.Errout("File " + path + "\ndoes not appear to have an RG file header:\n" + fhd); iv1 = 0; iv2 = 0; iv3 = 0; } } else if (readtype == 1) /* SEG-Y */ { /*this.f.setCursor(Cursor.WAIT_CURSOR); this.setCursor(Cursor.WAIT_CURSOR);*/ tapehead = tapeheadcb.getState(); swabhead = false /*swabheadcb.getState()*/; samptype = samptypech.getSelectedIndex(); if (firstrectf.getText().equalsIgnoreCase("all")) firstrec = -1; else { try {firstrec = Integer.valueOf(firstrectf.getText()).intValue(); } catch (NumberFormatException nfe) {firstrec = -1; } if (firstrec < 0) firstrec = -1; } if (lastrectf.getText().equalsIgnoreCase("all")) lastrec = -1; else { try {lastrec = Integer.valueOf(lastrectf.getText()).intValue(); } catch (NumberFormatException nfe) {lastrec = -1; } if (lastrec < 0) lastrec = -1; } if (firstrec > -1 && lastrec > -1 && firstrec > lastrec) { temp = firstrec; firstrec = lastrec; lastrec = temp; } sfhd = new SEGYFileHead(); iv0 = 0; iv3 = sfhd.scanSEGYFile(path, tapehead, swabhead, firstrec, lastrec, samptype, f); /*this.f.setCursor(Cursor.DEFAULT_CURSOR); this.setCursor(Cursor.DEFAULT_CURSOR);*/ if (sfhd.isValid() && iv3 > 0) { iv1 = sfhd.getnt(); iv2 = sfhd.ntrace; geogr = sfhd.geogr; } else if (firstrec < 0 && lastrec < 0) { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file:\n" + sfhd); iv1 = 0; iv2 = 0; iv3 = 0; } else if (firstrec < 0 && lastrec > -1) { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers <= " + lastrec + ":\n" + sfhd); iv1 = 0; iv2 = 0; iv3 = 0; } else if (firstrec > -1 && lastrec < 0) { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers >= " + firstrec + ":\n" + sfhd); iv1 = 0; iv2 = 0; iv3 = 0; } else { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers " + firstrec + " through " + lastrec + ":\n" + sfhd); iv1 = 0; iv2 = 0; iv3 = 0; } /*f.Errout("SEG-Y header for " + iv3 + " records: " + sfhd.toString());*/ } } public RgFileHead checkReadBinary(String path) { int temp; readtype = bintype.getSelectedIndex(); oldrg = rgtype.getState(); fhd = new RgFileHead(); if (readtype == 2) /* RG */ { OldRGFileHead ofhd = new OldRGFileHead(); if (oldrg) { ofhd.readOldRGFileHead(path); fhd.copyOldRGFileHead(ofhd); } else fhd.readRgFileHead(path); } else if (readtype == 1) /* SEG-Y */ { this.f.setCursor(Cursor.WAIT_CURSOR); tapehead = tapeheadcb.getState(); swabhead = false /*swabheadcb.getState()*/; samptype = samptypech.getSelectedIndex(); if (firstrectf.getText().equalsIgnoreCase("all")) firstrec = -1; else { try {firstrec = Integer.valueOf(firstrectf.getText()).intValue(); } catch (NumberFormatException nfe) {firstrec = -1; } if (firstrec < 0) firstrec = -1; } if (lastrectf.getText().equalsIgnoreCase("all")) lastrec = -1; else { try {lastrec = Integer.valueOf(lastrectf.getText()).intValue(); } catch (NumberFormatException nfe) {lastrec = -1; } if (lastrec < 0) lastrec = -1; } if (firstrec > lastrec) { temp = firstrec; firstrec = lastrec; lastrec = temp; } sfhd = new SEGYFileHead(); iv0 = 0; iv3 = sfhd.scanSEGYFile(path, tapehead, swabhead, firstrec, lastrec, samptype, f); fhd = new RgFileHead(sfhd.fhd); geogr = sfhd.geogr; this.f.setCursor(Cursor.DEFAULT_CURSOR); /*f.Errout("SEG-Y header for " + iv3 + " records: " + sfhd.toString());*/ } else if (readtype == 12 || readtype == 13) /* SAC */ { this.f.setCursor(Cursor.WAIT_CURSOR); iv0 = 0; fhd = SACTraceHead.scanSACFile(path, iv3, (readtype==13 ? true : false)); if (iv3 > 1) iv2 = fhd.ntrace/iv3; else iv2 = fhd.ntrace; this.f.setCursor(Cursor.DEFAULT_CURSOR); } return fhd; } void makeWriteBinary(String path, boolean appending) { this.path = new String(path); beginPanel(); if (appending) this.setTitle("Appending to Binary File " + path + " ..."); else this.setTitle("Creating Binary File " + path + " ..."); Label tlab1 = new Label("Binary File Type:"); pp.add(tlab1); bintype = makeBintype(false); pp.add(bintype); bintype.select(2); bintype.addItemListener(this); samptypelab = new Label("Trace Data Type:"); pp.add(samptypelab); samptypech = new Choice(); samptypech.add("IEEE/Java Float"); samptypech.add("IBM Float"); samptypech.add("32-bit Integer"); pp.add(samptypech); samptypech.select(0); geogrcb = new Checkbox("Coords will be lat/lon degrees."); pp.add(geogrcb); if (fvol == null) geogrcb.setState(fp.geogr); else geogrcb.setState(fvol.geogr); rgtype = new Checkbox("Old RG headers without source coords."); pp.add(rgtype); rgtype.setState(false); Button apply; if (appending) apply = new Button("Append Binary File"); else apply = new Button("Create Binary File"); pp.add(apply); apply.addActionListener(this); finishPanel(); height = 200; this.setSize(350, height); samptypech.setEnabled(false); rgtype.setEnabled(true); } void makeReadBinary(String path) { this.path = new String(path); beginPanel(); this.setTitle("Open Binary File..."); expl = new TextArea("Binary file " + path + "\n" + (f.vm.inplace.getState() && f.vm.fvol==null ? "will replace the current data (if one Plane)\n" + f.getTitle() + "\n" : "will open in a new window\n") + "(controlled by Methods->In Place).\n", 3, 35); pp.add(expl); Label tlab1 = new Label("Binary File Type:"); pp.add(tlab1); bintype = makeBintype(true); pp.add(bintype); bintype.select(1); bintype.addItemListener(this); firstreclab = new Label("First Field Record No. to Read:"); pp.add(firstreclab); firstrectf = new TextField("", 4); pp.add(firstrectf); lastreclab = new Label("Last:"); pp.add(lastreclab); lastrectf = new TextField("", 4); pp.add(lastrectf); tapeheadcb = new Checkbox("3600-byte Reel Header Block Present"); pp.add(tapeheadcb); tapeheadcb.setState(true); samptypelab = new Label("Trace Data Type:"); pp.add(samptypelab); samptypech = new Choice(); samptypech.add("IEEE/Java Float"); samptypech.add("IBM Float"); samptypech.add("32-bit Integer"); samptypech.add("16-bit Integer"); samptypech.add("32-bit Int w/ Gain"); pp.add(samptypech); samptypech.select(0); /* swabheadcb = new Checkbox("Must Byte-Swap Binary in Headers"); pp.add(swabheadcb); swabheadcb.setState(false); */ skiplab = new Label("Bytes to Skip:"); pp.add(skiplab); skiptf = new TextField("0", 8); pp.add(skiptf); nelab = new Label("Elements per Vector:"); pp.add(nelab); if (fvol == null) netf = new TextField("" + fp.getNMembofDim(0), 5); else netf = new TextField("" + fvol.getNMembofDim(0), 5); pp.add(netf); nvlab = new Label("Vectors per Plane:"); pp.add(nvlab); if (fvol == null) nvtf = new TextField("" + fp.getNMembofDim(1), 5); else nvtf = new TextField("" + fvol.getNMembofDim(1), 5); pp.add(nvtf); nplab = new Label("Number of Planes:"); pp.add(nplab); if (fvol == null) nptf = new TextField("1", 5); else nptf = new TextField("" + fvol.getNMembofDim(2), 5); pp.add(nptf); rgtype = new Checkbox("Old RG headers without source coords."); pp.add(rgtype); rgtype.setState(true); Button apply = new Button("Read Binary File"); pp.add(apply); apply.addActionListener(this); finishPanel(); height = 500; this.setSize(350, height); skiplab.setEnabled(false); skiptf.setEnabled(false); if (nelab != null) { nelab.setEnabled(false); netf.setEnabled(false); nvlab.setEnabled(false); nvtf.setEnabled(false); nplab.setEnabled(false); nptf.setEnabled(false); } rgtype.setEnabled(false); } void beginPanel() { this.setVisible(false); this.setModal(true); pp = new Panel(new FlowLayout()); pp.setSize(350, height); } void finishPanel() { Button cancel = new Button("Cancel"); pp.add(cancel); cancel.addActionListener(this); pp.validate(); this.setSize(350, height); this.add(pp); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); } void center() { Point p = f.getLocation(); Dimension d = f.getSize(); Dimension s = getSize(); p.translate((d.width - s.width)/2 + 40, (d.height - s.height)/2); f.adjustScreenLocation(this, p); } }