-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegyLoader.java
executable file
·447 lines (378 loc) · 17.8 KB
/
segyLoader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/**
* segy Loader based on java
*
* Author: Rong Tao
* Time: 2017.03
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.BasicStroke;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JEditorPane;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JProgressBar;
import javax.swing.JToolBar;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JDialog;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.UIManager;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Timer;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.AttributeSet;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.file.Path;
import javax.imageio.ImageIO;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import net.java.dev.designgridlayout.DesignGridLayout;
class cjbsegy{
/* reference: cjbsegy.h */
int tracl, tracr, fldr, tracf, ep, cdp, cdpt;/* int (0-6) */
short trid, nvs, nhs, duse;/* short (7-10) */
int offset, gelev, selev, sdepth, gdel, sdel, swdep, gwdep;/* int (11-18) */
short scalel, scalco;/* short (19-20) */
int sx, sy, gx, gy;/* int (21-24) */
short counit, wevel, swevel, sut, gut;/* short (25-70) */
short sstat, gstat, tstat, laga, lagb;
short delrt, muts, mute, ns, dt;
short gain, igc, igi, corr, sfs;
short sfe, slen, styp, stas, stae;
short tatyp, afilf, afils, nofilf, nofils;
short lcf, hcf, lcs, hcs, year;
short day, hour, minute, sec, timbas;
short trwf, grnors, grnofr, grnlof, gaps;
short otrav;
float d1, f1, d2, f2, ungpow, unscale;/* float (71-76) */
int ntr; /* int (77) */
short mark, shortpad;/* short (78-79) */
int line3d, cdp3d;/* int (80-81) */
short unass0,unass1,unass2,unass3,unass4 ;
short unass5,unass6,unass7,unass8,unass9 ;
String[] segy = {"tracl", "tracr", "fldr", "tracf", "ep",
"cdp", "cdpt", "trid", "nvs", "nhs",
"duse", "offset", "gelev", "selev", "sdepth",
"gdel", "sdel", "swdep", "gwdep", "scalel",
"scalco", "sx", "sy", "gx", "gy",
"counit", "wevel", "swevel", "sut", "gut",
"sstat", "gstat", "tstat", "laga", "lagb",
"delrt", "muts", "mute", "ns", "dt",
"gain", "igc", "igi", "corr", "sfs",
"sfe", "slen", "styp", "stas", "stae",
"tatyp", "afilf", "afils", "nofilf", "nofils",
"lcf", "hcf", "lcs", "hcs", "year",
"day", "hour", "minute", "sec", "timbas",
"trwf", "grnors", "grnofr", "grnlof", "gaps",
"otrav", "d1", "f1", "d2", "f2",
"ungpow", "unscale", "ntr", "mark", "shortpad",
"line3d", "cdp3d",
"unass0", "unass1", "unass2", "unass3", "unass4",
"unass5", "unass6", "unass7", "unass8", "unass9"};
}
class Swap{
/* float */
public static float swap (float value){
int intValue = Float.floatToRawIntBits (value);
intValue = swap (intValue);
return Float.intBitsToFloat (intValue);
}
/* int */
public static int swap (int value){
int b1 = (value >> 0) & 0xff;
int b2 = (value >> 8) & 0xff;
int b3 = (value >> 16) & 0xff;
int b4 = (value >> 24) & 0xff;
return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
}
/* short */
public static short swap (short value){
int b1 = value & 0xff;
int b2 = (value >> 8) & 0xff;
return (short) (b1 << 8 | b2 << 0);
}
/* long */
public static long swap (long value){
long b1 = (value >> 0) & 0xff;
long b2 = (value >> 8) & 0xff;
long b3 = (value >> 16) & 0xff;
long b4 = (value >> 24) & 0xff;
long b5 = (value >> 32) & 0xff;
long b6 = (value >> 40) & 0xff;
long b7 = (value >> 48) & 0xff;
long b8 = (value >> 56) & 0xff;
return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 |
b5 << 24 | b6 << 16 | b7 << 8 | b8 << 0;
}
/* double */
public static double swap (double value){
long longValue = Double.doubleToLongBits (value);
longValue = swap (longValue);
return Double.longBitsToDouble (longValue);
}
/* short array */
public static void swap (short[] array){
for (int i = 0; i < array.length; i++)
array[i] = swap (array[i]);
}
/* int array */
public static void swap (int[] array){
for (int i = 0; i < array.length; i++)
array[i] = swap (array[i]);
}
/* long array */
public static void swap (long[] array){
for (int i = 0; i < array.length; i++)
array[i] = swap (array[i]);
}
/* float array */
public static void swap (float[] array){
for (int i = 0; i < array.length; i++)
array[i] = swap (array[i]);
}
/* double array */
public static void swap (double[] array){
for (int i = 0; i < array.length; i++)
array[i] = swap (array[i]);
}
}
class mySEGYJFrame extends JFrame {
private String filename;
private static JLabel countlabel = new JLabel();
private Object[] columnNames = new Object[]{"Trace # "};
private DefaultTableModel model;
private ArrayList<cjbsegy> hdrlist;
private JTable hdrtable;
private JScrollPane hdrscrollpane;
private String[] segy = {"tracl", "tracr", "fldr", "tracf", "ep",
"cdp", "cdpt", "trid", "nvs", "nhs",
"duse", "offset", "gelev", "selev", "sdepth",
"gdel", "sdel", "swdep", "gwdep", "scalel",
"scalco", "sx", "sy", "gx", "gy",
"counit", "wevel", "swevel", "sut", "gut",
"sstat", "gstat", "tstat", "laga", "lagb",
"delrt", "muts", "mute", "ns", "dt",
"gain", "igc", "igi", "corr", "sfs",
"sfe", "slen", "styp", "stas", "stae",
"tatyp", "afilf", "afils", "nofilf", "nofils",
"lcf", "hcf", "lcs", "hcs", "year",
"day", "hour", "minute", "sec", "timbas",
"trwf", "grnors", "grnofr", "grnlof", "gaps",
"otrav", "d1", "f1", "d2", "f2",
"ungpow", "unscale", "ntr", "mark", "shortpad",
"line3d", "cdp3d",
"unass0", "unass1", "unass2", "unass3", "unass4",
"unass5", "unass6", "unass7", "unass8", "unass9"};
mySEGYJFrame(String filename)throws IOException,
NoSuchFieldException,
IllegalAccessException{
this.filename = filename;
setTitle("rongtao's segy header show");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
setLocation(size.width/10 , size.height/7 );
hdrlist = ReadSEGY.readSegy(this.filename);
model = new DefaultTableModel(columnNames, hdrlist.size());
hdrtable = new JTable(model){
@Override
public boolean isCellEditable(int row, int column){
return false;
}
};
hdrtable.getColumnModel().getColumn(0).setWidth(10);
hdrtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for(int itrace = 0;itrace<hdrlist.size();itrace++){
hdrtable.setValueAt(Integer.toString(itrace+1),itrace,0);
}
hdrscrollpane = new JScrollPane(hdrtable);
JComboBox info = new JComboBox<String>(segy);
info.setSelectedIndex(0);
info.addItemListener(new itemlistener());
JPanel panel1 = new JPanel();
JLabel titlelabel = new JLabel("SEGY header info");
DesignGridLayout layout1 = new DesignGridLayout(panel1);
layout1.row().left().add(new JSeparator()).fill().withOwnRowWidth();
layout1.row().center().add(titlelabel);
layout1.row().left().add(new JSeparator()).fill().withOwnRowWidth();
layout1.row().left().add(info);
layout1.row().left().add(new JSeparator()).fill().withOwnRowWidth();
layout1.row().left().add(hdrscrollpane);
layout1.row().left().add(new JSeparator()).fill().withOwnRowWidth();
JInternalFrame internalFrame = new JInternalFrame("SEGY header",true,true, true, true);
DesignGridLayout mainLayout = new DesignGridLayout(internalFrame.getContentPane());
mainLayout.row().grid().add(panel1);
internalFrame.pack();
internalFrame.setVisible(true);
getContentPane().add(internalFrame);
setVisible(true);
pack();
}
class itemlistener implements ItemListener{
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
JComboBox combo = (JComboBox) e.getSource();
String item = (combo.getSelectedItem()).toString();
DefaultTableModel temp =(DefaultTableModel)hdrtable.getModel();
int row = hdrtable.getRowCount();
int col = hdrtable.getColumnCount();
Vector<Object> newCol = new Vector<Object>();
newCol.add(item);
temp.addColumn(newCol);
try{
Field h = cjbsegy.class.getDeclaredField(item);
h.setAccessible(true);
for(int itrace = 0;itrace<hdrlist.size();itrace++){
hdrtable.setValueAt(h.get(hdrlist.get(itrace)),itrace,col);
}
}catch(Exception ee){ee.printStackTrace();}
}
}
}
static class ReadSEGY{
static int counttrace = 0;
public static ArrayList<cjbsegy> readSegy(String filename)
throws java.io.IOException,
NoSuchFieldException,
IllegalAccessException{
DataInputStream fp = null;
if(!new File(filename).exists()){
System.out.println("The "+filename +" file dont't exists");
return null;
}
fp = new DataInputStream(new FileInputStream(new File(filename)));
countlabel.setText(Integer.toString(++counttrace));
cjbsegy hdr = readCjbsegy(fp);
fp.skip(hdr.ns*4);
ArrayList<cjbsegy> list = new ArrayList<cjbsegy>();
list.add(hdr);
do{
countlabel.setText(Integer.toString(++counttrace));
if(fp.available()<=0)break;
list.add(readCjbsegy(fp));
fp.skip(hdr.ns*4);
} while(fp.available()>0);
return list;
}//read file
private static cjbsegy readCjbsegy(DataInputStream fp)
throws java.io.IOException,
NoSuchFieldException,
IllegalAccessException{
cjbsegy hdr = new cjbsegy();
for(int i = 0; i<92; i++){
Field strs = cjbsegy.class.getDeclaredField(hdr.segy[i]);
strs.setAccessible(true);
if( ( i>=0 && i<=6 )
|| ( i>=11 && i<=18 )
|| ( i>=21 && i<=24 )
|| i==77
|| ( i>=80 && i<=81 ) )
strs.set(hdr,fp.readInt());
else if( ( i>=7 && i<=10 )
|| ( i>=19 && i<=20 )
|| ( i>=25 && i<=70 )
|| ( i>=78 && i<=79 )
|| ( i>=82 && i<=91 ) )
strs.set(hdr,fp.readShort());
else
strs.set(hdr,fp.readFloat());
}
return hdr;
}
}
public static void main(String[]args)
throws java.io.IOException,
NoSuchFieldException,
IllegalAccessException{
new mySEGYJFrame("v.su");
}
}
class mySEGYParasJFrame extends JFrame{
mySEGYParasJFrame(){}
}