-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathread_eas_matrix.m
58 lines (49 loc) · 1.45 KB
/
read_eas_matrix.m
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
% read_eas : reads an 3D array stored as a 1D array in EAS format
%
% Call [D,header,title]=read_eas_matrix(filename);
%
% TMH ([email protected])
%
% See also write_eas_matrix, write_eas
%
function [D,header,txt_title,dim,txtdata,txtheader]=read_eas_matrix(filename,nx,ny,nz);
nanVal=-997799;
%% GET COLUMN DATA
[d,header,txt_title,txtheader]=read_eas(filename);
ncols=length(header);
if nargin == 1
% GET NX,NY,NZ
% SGeMS header info
dim=[];
try
id1=strfind(txt_title,'(');
id2=strfind(txt_title,')');
dims=txt_title( (id1+1):(id2-1) );
j=findstr(dims,'x');
dim.nx=str2num(dims(1:(j(1)-1)));
dim.ny=str2num(dims((j(1)+1):(j(2)-1)));
dim.nz=str2num(dims((j(2)+1):length(dims)));
end
% MPS header info 'nx ny nz'
try
d_header=str2num(txt_title);
dim.nx=d_header(1);
dim.ny=d_header(2);
dim.nz=d_header(3);
end
if isempty(dim)
disp(sprintf('%s: Could not find dimension info %s. Please specify as input parameters',filename));
return;
end
else
dim.nx=1;
dim.ny=1;
dim.nz=1;
try;dim.nx=nx;end
try;dim.ny=ny;end
try;dim.nz=nz;end
end
d(find(d==nanVal))=NaN;
%% RESHAPE TO MATRIX 3D ARRAY
D=reshape(d,dim.nx,dim.ny,dim.nz,ncols);
D=permute(D,[2 1 3 4]);