1% test segyline 2 3% preconditions 4filename = 'test-data/small.sgy'; 5assert(exist(filename,'file')==2); 6t0 = 1111.0; 7 8%% Spec is created 9try 10 spec = Segy.interpret_segycube(filename, 'Inline3D', 'Crossline3D', t0); 11 spec = Segy.interpret_segycube(filename, TraceField.Inline3D, 'Crossline3D', t0); 12 spec = Segy.interpret_segycube(filename, TraceField.Inline3D, 193, t0); 13 data = Segy.get_cube( spec ); 14 15 assert(all(size(data) == [50, 5, 5])); 16catch 17 %nothing should be caught 18 assert(false); 19end 20 21% fail when file doesn't exist 22 23try 24 Segy.get_header('does-not-exist', 193); 25 assert(false); 26catch 27 assert(true); 28end 29 30try 31 Segy.get_traces('does-not-exist', 189, 193 ); 32 assert(false); 33catch 34 assert(true); 35end 36 37try 38 Segy.get_ntraces('does-not-exist'); 39 assert(false); 40catch 41 assert(true); 42end 43 44try 45 Segy.interpret_segycube('does-not-exist'); 46 assert(false); 47catch 48 assert(true); 49end 50 51%% Segy.readInLine 4 52 53spec = Segy.interpret_segycube(filename, 'Inline3D', 'Crossline3D', t0); 54data = Segy.get_line(spec, 'iline', 4); 55sample_count = length(spec.sample_indexes); 56 57eps = 1e-6; 58% first trace along xline 59% first sample 60assert(abs(data(1, 1) - 4.2)<eps); 61% middle sample 62assert(abs(data(sample_count/2,1)-4.20024)<eps); 63% last sample 64assert(abs(data(sample_count,1)-4.20049)<eps); 65 66% middle trace along xline 67middle = 3; 68% first sample 69assert(abs(data(1, middle) - 4.22) < eps); 70% middle sample 71assert(abs(data(sample_count/2,middle)-4.22024)<eps); 72% last sample 73assert(abs(data(sample_count,middle)-4.22049)<eps); 74 75% middle trace along xline 76last = length(spec.crossline_indexes); 77% first sample 78assert(abs(data(1, last) - 4.24) < eps); 79% middle sample 80assert(abs(data(sample_count/2,last)-4.24024)<eps); 81% last sample 82assert(abs(data(sample_count,last)-4.24049)<eps); 83 84%% Segy.readCrossLine 1433 85 86spec = SegySpec(filename, TraceField.Inline3D, TraceField.Crossline3D, t0); 87data = Segy.readCrossLine(spec, 20); 88data = Segy.readCrossLine(spec, 21); 89data = Segy.readCrossLine(spec, 22); 90data = Segy.readCrossLine(spec, 23); 91data = Segy.readCrossLine(spec, 24); 92data = Segy.readCrossLine(spec, 22); 93sample_count = length(spec.sample_indexes); 94 95eps = 1e-4; 96% first trace along iline 97% first sample 98assert(abs(data(1, 1) - 1.22) < eps); 99% middle sample 100assert(abs(data(sample_count/2,1)-1.22024)<eps); 101% last sample 102assert(abs(data(sample_count,1)-1.22049)<eps); 103 104% middle trace along iline 105middle = 3; 106% first sample 107assert(abs(data(1, middle) - 3.22) < eps); 108% middle sample 109assert(abs(data(sample_count/2,middle)-3.22029)<eps); 110% last sample 111assert(abs(data(sample_count,middle)-3.22049)<eps); 112 113% middle trace along iline 114last = length(spec.inline_indexes); 115% first sample 116assert(abs(data(1, last) - 5.22) < eps); 117% middle sample 118assert(abs(data(sample_count/2,last)-5.22029)<eps); 119% last sample 120assert(abs(data(sample_count,last)-5.22049)<eps); 121 122filename_write = 'test-data/SEGY-3D_write_mex.sgy'; 123 124copyfile(filename, filename_write) 125 126spec = SegySpec(filename_write, TraceField.Inline3D, TraceField.Crossline3D, t0); 127data = Segy.get_line(spec, 'xline', 22); 128 129assert(abs(data(1, 1) - 1.22) < eps); 130 131data(1,1) = 100; 132 133Segy.writeCrossLine(spec, data, 22); 134 135data = Segy.readCrossLine(spec, 22); 136assert(data(1, 1) == 100); 137 138data = Segy.readInLine(spec, 4); 139 140assert(abs(data(1, 1) - 4.2) < eps); 141 142data(1,1) = 200; 143 144Segy.writeInLine(spec, data, 4); 145 146data = Segy.readInLine(spec, 4); 147assert(data(1, 1) == 200); 148 149[~, dt, nt] = Segy.get_traces(filename); 150assert(dt == 4000); 151assert(nt == 1); 152 153[headers, notraces] = Segy.get_header(filename, 'Inline3D'); 154assert(isequal((1:5), unique(headers))); 155assert(notraces == 25) 156 157assert(Segy.get_ntraces(filename) == 25); 158 159 160% Goal: 161% Fast writing of segy file 162% 163% Inputs: 164% filename Filename of segyfile to write 165% filename_orig Filename of segyfile to copy header 166% data: Data 167% nt: Number of time samples 168% nxl: Number of Xlines 169% nil: Number of Inlines 170% 171% function provided by Matteo Ravasi 172 173Segy_struct_orig = Segy.interpret_segycube(filename,'Inline3D','Crossline3D'); 174data = Segy.get_traces(filename); 175data = data + 1000; 176 177nt = 50; 178nxl = 5; 179nil = 5; 180 181if( ( nt == numel( Segy_struct_orig.t ) ) &&... 182 ( nxl == numel( Segy_struct_orig.xline ) ) &&... 183 ( nil == numel( Segy_struct_orig.iline ) ) ) 184 185 data = reshape( data, [nt, nxl*nil] ); 186 187 filename_copy = 'test-data/SEGY-3D_copy.sgy'; 188 copyfile( filename, filename_copy ); 189 190 Segy.put_traces( filename_copy, data, 1, nxl*nil ); 191 spec = Segy.interpret_segycube( filename_copy ); 192 data = Segy.get_line(spec, 'iline', 4); 193 194 assert(abs(data(1, 1) - 1004.2) < eps); 195 assert(abs(data(sample_count/2,1) - 1004.20024) < eps); 196 assert(abs(data(sample_count,1) - 1004.20049) < eps); 197 198 middle = 3; 199 assert(abs(data(1, middle) - 1004.22) < eps); 200 assert(abs(data(sample_count/2, middle) - 1004.22024) < eps); 201 assert(abs(data(sample_count, middle) - 1004.22049) < eps); 202 203 last = length(spec.crossline_indexes); 204 assert(abs(data(1, last) - 1004.24) < eps); 205 assert(abs(data(sample_count/2, last) - 1004.24024) < eps); 206 assert(abs(data(sample_count, last) - 1004.24049) < eps); 207else 208 assert(false); 209end 210 211% test put_line 212data = Segy.get_line(spec, 'iline', 4); 213data = data + 100; 214p1 = data(sample_count/2, 1); 215p2 = data(sample_count, 1); 216Segy.put_line(spec, data, 'iline', 4); 217data = Segy.get_line( spec, 'iline', 4); 218assert(all([p1, p2] == [data(sample_count/2, 1), data(sample_count, 1)])); 219 220% read trace headers and file headers 221dummy = Segy.get_segy_header( filename ); 222dummy = Segy.get_trace_header( filename, 0 ); 223dummy = Segy.get_trace_header( filename, 10 ); 224 225Segy.put_headers( filename, 10, 'cdp' ); 226Segy.get_header( filename, 'cdp' ); 227 228increasing = linspace( 1, notraces, notraces ); 229Segy.put_headers( filename_copy, increasing, 'offset' ); 230assert( all(increasing == Segy.get_header( filename_copy, 'offset' )) ); 231 232%% test_traces_offset 233prestack_filename = 'test-data/small-ps.sgy'; 234cube_with_offsets = Segy.parse_ps_segycube(prestack_filename); 235assert(isequal(cube_with_offsets.offset, [1 2])); 236 237try 238 ps_line1 = Segy.get_ps_line(cube_with_offsets, 'iline', 22); 239 % reading a line that doesn't exist should throw 240 assert(false); 241end 242ps_line1 = Segy.get_ps_line(cube_with_offsets, 'iline', 1); 243ps_line2 = Segy.get_ps_line(cube_with_offsets, 'xline', 1); 244 245% offset 1 246assert(abs(ps_line1(1,1,1) - 101.01) < eps); 247assert(abs(ps_line1(1,1,2) - 101.02) < eps); 248assert(abs(ps_line1(1,1,3) - 101.03) < eps); 249assert(abs(ps_line1(2,1,1) - 101.01001) < eps); 250assert(abs(ps_line1(3,1,1) - 101.01002) < eps); 251assert(abs(ps_line1(2,1,2) - 101.02001) < eps); 252 253% offset 2 254assert(abs(ps_line1(1,2,1) - 201.01) < eps); 255assert(abs(ps_line1(1,2,2) - 201.02) < eps); 256assert(abs(ps_line1(1,2,3) - 201.03) < eps); 257assert(abs(ps_line1(2,2,1) - 201.01001) < eps); 258assert(abs(ps_line1(3,2,1) - 201.01002) < eps); 259assert(abs(ps_line1(2,2,2) - 201.02001) < eps); 260 261%%%%% test writing of prestack lines 262prestack_dest = 'test-data/mex-tmp-small-ps.sgy'; 263assert(copyfile(prestack_filename, prestack_dest)); 264ps_cube_w = Segy.parse_ps_segycube(prestack_dest); 265Segy.put_ps_line( ps_cube_w, ps_line1 - 100.00, 'iline', 1 ); 266% offset 1 267wr_line1 = Segy.get_ps_line( ps_cube_w, 'iline', 1 ); 268assert(abs(wr_line1(1,1,1) - 001.01) < eps); 269assert(abs(wr_line1(1,1,2) - 001.02) < eps); 270assert(abs(wr_line1(1,1,3) - 001.03) < eps); 271assert(abs(wr_line1(2,1,1) - 001.01001) < eps); 272assert(abs(wr_line1(3,1,1) - 001.01002) < eps); 273assert(abs(wr_line1(2,1,2) - 001.02001) < eps); 274 275% offset 2 276assert(abs(wr_line1(1,2,1) - 101.01) < eps); 277assert(abs(wr_line1(1,2,2) - 101.02) < eps); 278assert(abs(wr_line1(1,2,3) - 101.03) < eps); 279assert(abs(wr_line1(2,2,1) - 101.01001) < eps); 280assert(abs(wr_line1(3,2,1) - 101.01002) < eps); 281assert(abs(wr_line1(2,2,2) - 101.02001) < eps); 282