/* 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.util.*; import java.io.*; import java.lang.Math; import java.awt.*; class testvec { public static void main(String args[]) { int i; System.out.println("Starting construction and reading."); FltVec fltvec = new FltVec(210*1000); /* read and write file test */ fltvec.readBinaryFile("test.flt", 0); System.out.println("max=" + fltvec.max() + " rms=" + fltvec.rms() + " dot=" + fltvec.dot(fltvec)); /* dimensioning test System.out.println("" + fltvec.getNDims() + " dimensions of "); for (i=0; i -1) { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers <= " + vad.lastrec + ":\n" + fhd); return null; } else if (vad.firstrec > -1 && vad.lastrec < 0) { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers >= " + vad.firstrec + ":\n" + fhd); return null; } else { this.f.Errout("File " + path + "\ndoes not appear to be a SEG-Y file,\n" + "or does not include record numbers " + vad.firstrec + " through " + vad.lastrec + ":\n" + fhd); return null; } if (Equal && (this.vec.length != fhd.ntrace*fhd.nt)) { Errout("Selected records in SEG-Y file " + vad.nametf.getText() + "\nhave " + (fhd.ntrace*fhd.nt) + " samples total but " + "current data has " + this.vec.length + ",\n" + "cannot use the records as a size equivalent."); return null; } for (int i=0; i NElem) window = NElem; int dwind = DetectWindow; int nt = NElem; float thresh = Threshold; float vy[] = new float[NElem]; int x = Elem0; int y = 0; xp = x; yp = y; /* detect first significant energy by comparing short moving window with an initial average */ if (Detect) { xp = this.agcdetects(Elem0, NElem, Window, Detect, DetectWindow, Threshold, vy); yp = xp - x; if (xp < 0) { vy = null; return; } } /* untaper beginning of trace */ for (start = xp, l1norm = 0F, end = xp + window; xp0F) l1norm += this.vec[xp]; else l1norm -= this.vec[xp]; xp++; } if (l1norm == 0) { xp = this.agcdetects(Elem0, NElem, Window, Detect, DetectWindow, Threshold, vy); yp = xp - x; if (xp < 0) { vy = null; return; } for (start = xp, l1norm = 0F, end = xp + window; xp0F) l1norm += this.vec[xp]; else l1norm -= this.vec[xp]; xp++; } } if (l1norm == 0) { vy = null; return; } for (xp = start, end = start + window / 2; xp0F) l1norm += this.vec[head]; else l1norm -= this.vec[head]; head++; if (this.vec[tail]>0F) l1norm -= this.vec[tail]; else l1norm += this.vec[tail]; tail++; if (oldnorm == 0F) l1norm = oldnorm; oldnorm = l1norm; vy[yp] = this.vec[xp] / l1norm; yp++; xp++; } /* untaper end of trace */ for (end = x + nt; xp 0F) initaver += this.vec[xp]; else initaver -= this.vec[xp]; xp++; } for (xp = x + dwind / 2, yp = y + dwind / 2, tail = x, head = x + dwind, end = x + nt - dwind / 2, probe = initaver; ((probe<=(initaver*thresh)) && (xp0F) probe += this.vec[head]; else probe -= this.vec[head]; head++; if (this.vec[tail]>0F) probe -= this.vec[tail]; else probe += this.vec[tail]; tail++; } if ((xp == end)||(probe == 0F)) return -1; return xp; } public void clip(float lim1, float lim2) { int i; float hold; if (lim1 > lim2) { hold = lim1; lim1 = lim2; lim2 = hold; } Notice("clip: clipping " + vec.length + " elements to between " + lim1 + " and " + lim2 + "... "); for (i=0; i lim2) vec[i] = lim2; else if (hold < lim1) vec[i] = lim1; } Noticeln("done."); } public void clip(double lim1, double lim2) { this.clip((float)(lim1), (float)(lim2)); } static void clipPanel(ViewmatAction vad, ViewmatFrame f, boolean inplace, String label) { vad.expl = new TextArea(label + " of " + f.getTitle() + (inplace ? " in-place\n" : " in new window\n") + "\n" + "The " + label + " method on class FltVec data\n" + "irreversibly replaces amplitudes less than the\n" + "first limit below with with the limit, and\n" + "those above the second limit below with that\n" + "limit. (Default limits that appear below are the\n" + "signed minimum and maximum.) Plots can be\n" + "clipped temoprarily using the Clip value in\n" + "the Edit->Plot Parameters dialogue.", 5, 35); vad.pp.add(vad.expl); vad.lab0 = new Label("Low Clip (positive or negative):"); vad.lab1 = new Label("High Clip (positive or negative):"); if (f.vm.fvol == null) { vad.tf0 = new TextField("" + f.vm.fp.smin(), 8); vad.tf1 = new TextField("" + f.vm.fp.max(), 8); } else { vad.tf0 = new TextField("" + f.vm.fvol.smin(), 8); vad.tf1 = new TextField("" + f.vm.fvol.max(), 8); } vad.pp.add(vad.lab0); vad.pp.add(vad.tf0); vad.pp.add(vad.lab1); vad.pp.add(vad.tf1); } public void doclip(ViewmatAction vad) { float ltemp=Float.MAX_VALUE; try {ltemp = Float.valueOf(vad.tf0.getText()).floatValue(); } catch (NumberFormatException nfe) { Errout("Cannot clip with entered low of " + vad.tf0.getText()); return; } float htemp=Float.MAX_VALUE; try {htemp = Float.valueOf(vad.tf1.getText()).floatValue(); } catch (NumberFormatException nfe) { Errout("Cannot clip with entered high of " + vad.tf1.getText()); return; } this.clip(ltemp, htemp); } public void ctr() { float avg; int i; avg = 0.0F; Notice("FltVec.ctr: removing average "); for (i=0; i 0) Errout("cull: " + count + " elements over " + limit + " found"); Noticeln("done."); } public void cull() {this.cull(Float.MAX_VALUE); } static void cullPanel(ViewmatAction vad, ViewmatFrame f, boolean inplace, String label) { vad.expl = new TextArea(label + " of " + f.getTitle() + (inplace ? " in-place\n" : " in new window\n") + "\n" + "The " + label + " method on class FltVec data\n" + "replaces positive or negative amplitudes greater\n" + "than or equal to the limit below with zero.\n" + "Values of NaN and Inf are also zeroed.", 5, 35); vad.pp.add(vad.expl); vad.lab0 = new Label("Cull Limit Value (positive):"); vad.pp.add(vad.lab0); vad.tf0 = new TextField("" + Float.MAX_VALUE, 8); vad.pp.add(vad.tf0); } public void docull(ViewmatAction vad) { float temp=Float.MAX_VALUE; try {temp = Float.valueOf(vad.tf0.getText()).floatValue(); } catch (NumberFormatException nfe) { Errout("Cannot cull with entered limit of " + vad.tf0.getText()); return; } this.cull(temp); } public double dot(FltVec f1) { int i; double sum; sum = 0.0; Notice("dot: finding product of two arrays of " + this.vec.length + " elements... "); for (i=0; i0.0, <=1.0):"); vad.pp.add(vad.lab0); vad.tf0 = new TextField("1.0", 4); vad.pp.add(vad.tf0); vad.lab1 = new Label("Rise (float, >=0.0, <0.5):"); vad.pp.add(vad.lab1); vad.tf1 = new TextField("0.05", 4); vad.pp.add(vad.tf1); } public void dohann(ViewmatAction vad) { float temp, portion, rise; portion = 1F; rise = 0.05F; try {temp = Float.valueOf(vad.tf0.getText()).floatValue(); } catch (NumberFormatException nfe) { Errout("hann: Cannot taper with portion of " + vad.tf0.getText() + " - must be a positive float <= 1.0."); return; } if (temp <= 0F || temp > 1F) { Errout("hann: Cannot taper with portion of " + vad.tf0.getText() + " - must be a positive float <= 1.0."); return; } portion = temp; try {temp = Float.valueOf(vad.tf1.getText()).floatValue(); } catch (NumberFormatException nfe) { Errout("hann: Cannot taper with rise of " + vad.tf1.getText() + " - must be a positive float < 0.5."); return; } if (temp < 0F || temp >= 0.5F) { Errout("hann: Cannot taper with rise of " + vad.tf1.getText() + " - must be a positive float < 0.5."); return; } rise = temp; this.hann(portion, rise); } public void inv() { int i; float hold; Notice("FltVec.inv: inverting amplitudes of " + vec.length + " elements... "); for (i=0; i xk) j--; if(i <= j) { temp = x[i]; x[i] = x[j]; x[j] = temp; i++; j--; } } if(j < iq) low = i; if(i > iq) hi = j; } return (x[iq]<0 ? -x[iq] : x[iq]); } public void sqrt(boolean PreserveNegative) { int i; float hold; Notice("FltVec.sqrt: square root of " + vec.length + " elements... "); for (i=0; i 0F) index = (int)(254*val/pclip) + 1; else index = 0; if (index > 255) index = 255; else if (index < 0) index = 0; Array[i] = (255 << 24) | (ColorTable[index].R << 16) | (ColorTable[index].G << 8) | ColorTable[index].B; } /* Noticeln("done."); */ } public float max() { int i; float max, val; max = 0.0F; Notice("max: finding maximum value of " + vec.length + " elements... "); for (i=0; i max) max = val; } Noticeln("done."); return max; } public float min() { int i; float min, val; Notice("min: finding minimum absolute value of " + vec.length + " elements... "); min = vec[0] < 0.0F ? -vec[0] : vec[0]; for (i=1; i2 ? (readtype>3 ? (readtype>4 ? (readtype>5 ? (readtype>6 ? (readtype>7 ? " plain ascii text" : " 8-bit integer") : " 16-bit Intel integer") : " 16-bit integer") : " 32-bit Intel integer") : " 32-bit integer") : " raw IEEE float")*/ + " elements from file " + name + " after skipping " + SkipBytes + " bytes... "); if (readtype == 8) { bytes = readASCIIFile(name, (long)(SkipBytes)); return; } try {fis = new FileInputStream(name); } catch(FileNotFoundException fnf) { Errout(fnf.toString()); return; } bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); if (SkipBytes > 0) { try {bytes = dis.skipBytes(SkipBytes); } catch(IOException ioe) { Errout("Could not seek " + SkipBytes + " bytes into file " + name); return; } } if (readtype == 3) { for (i=0; i 0) in.skip(skip); for (i=0; i= NDims) return 1; else return 0; } public String getAmpUnits() { return AmpUnits; } public void setAmpUnits(String Ampunits) { AmpUnits = new String(Ampunits); } public float getAmp0() { return Amp0; } public void setAmp0(float Amp0) { this.Amp0 = Amp0; } public float getAmpFac() { return AmpFac; } public void setAmpFac(float Ampfac) { this.AmpFac = Ampfac; } public String getUnitsofDim(int Dim) { if (Dim == 0) return ElemUnits; return ""; } public void setUnitsofDim(int Dim, String Dimunits) { if (Dim == 0) ElemUnits = new String(Dimunits); } public float getUnit0ofDim(int Dim) { if (Dim == 0) return Elem0; return 0F; } public void setUnit0ofDim(int Dim, float Unit0) { if (Dim == 0) Elem0 = Unit0; } public float getDUnitofDim(int Dim) { if (Dim == 0) return DElem; return 1F; } public void setDUnitofDim(int Dim, float DUnit) { if (Dim == 0) DElem = DUnit; } public void Errout(String Error) { System.out.println(); System.out.println(Error); System.out.println(); System.out.flush(); if (this.f != null) { ViewmatNotice vn = new ViewmatNotice(this.f, "Error on " + this.f.getTitle(), Error); vn.show(); } } public void Noticeln(String Note) { if (noticeon) { System.out.println(Note); System.out.flush(); } } public void Notice(String Note) { if (noticeon) { System.out.print(Note); System.out.flush(); } } public void setNoticeOn(boolean on) { this.noticeon = on; } }