-
Notifications
You must be signed in to change notification settings - Fork 0
/
SM_Import_st_win_cell.m
209 lines (177 loc) · 4.38 KB
/
SM_Import_st_win_cell.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
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
function [grc,nx,ny,nz] = SM_Import_st_win(filename)
% SM_IMPORTGEOM Short description
% [GR,TOTAL] = SM_IMPORTSTRESS(FNAME)
%
% Imports data from Elfen seismic output files
%
% Created by Alan Baird on 2012-02-08.
% Copyright (c) . All rights reserved.
fid = fopen(filename,'r');
eof=0
% Search for number of cells
foundNUM = false;
while ~foundNUM
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
elseif ~isempty(regexp(currentLine,'^\s+Number_of_cells','match','once'))
foundNUM = true
end
end % looking for number of cells
% find number of gridpoints with X coords
data=textscan(fid,'%d%d%d',1);
nx=data{1}+1
ny=data{2}+1
nz=data{3}+1
% Search for X coordinates
foundX = false;
while ~foundX
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
elseif ~isempty(regexp(currentLine,'^\s+X Coordinate','match','once'))
foundX = true
end
end % looking for X coords
% find number of gridpoints with X coords
totalx = regexp(currentLine,'{\s+(?<total>\d+)\s+}','names');
totalx=str2num(totalx.total);
data=textscan(fid,'%f',totalx);
gr.x=data{1};
% Search for Y coordinates
foundY = false;
while ~foundY
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
elseif ~isempty(regexp(currentLine,'^\s+Y Coordinate','match','once'))
foundY = true
end
end % looking for Y coords
% find number of gridpoints with Y coords
totaly = regexp(currentLine,'{\s+(?<total>\d+)\s+}','names');
totaly=str2num(totaly.total);
data=textscan(fid,'%f',totaly);
gr.y=data{1};
% Search for Z coordinates
foundZ = false;
while ~foundZ
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
elseif ~isempty(regexp(currentLine,'^\s+Z Coordinate','match','once'))
foundZ = true
end
end % looking for Y coords
% find number of gridpoints with Y coords
totalz = regexp(currentLine,'{\s+(?<total>\d+)\s+}','names');
totalz=str2num(totalz.total);
data=textscan(fid,'%f',totalz);
gr.z=data{1};
% Found x, y, z coords, now find remaining attributes
while ~eof
%Look for next attribute name
foundatt = false;
while ~foundatt
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
foundatt = true;
break
elseif ~isempty(regexp(currentLine,'"[A-Za-z_]+"','match','once'))
foundatt = true
end
end % looking for attributes
if eof == true
break
end
att=regexp(currentLine,'"(?<name>[A-Za-z_]+)"','names');
att=att.name
% Look for attribute values
foundval = false;
while ~foundval
currentLine = fgetl(fid);
%check for eof, then
if currentLine == -1
eof = true;
elseif ~isempty(regexp(currentLine,'^\s+Values','match','once'))
foundval = true
end
end % looking for values
attnum=regexp(currentLine, '{\s+(?<val>\d+)\s+}','names');
if length(attnum)==1 % Scalar
attnum=str2num(attnum.val);
data=textscan(fid,'%f',attnum);
gr.(att)=data{1};
elseif length(attnum)==3 % tensor
compnum=str2num(attnum(2).val);
total=str2num(attnum(3).val);
if compnum == 21
data=textscan(fid,'%f%f%f%f%f%f\r\n%f%f%f%f%f%f\r\n%f%f%f%f%f%f\r\n%f%f%f',total);
gr.(att)=cell2mat(data);
elseif compnum == 6
data=textscan(fid,'%f %f %f %f %f %f',total);
gr.(att)=cell2mat(data);
end
else
break
end
end
fieldnam=fieldnames(gr)
for i=1:total
ix=1+mod(i-1,nx);
iy=1+idivide((i-(idivide(i-1,nx*ny))*(nx*ny)-ix),nx);
iz=1+idivide((i-1),(nx*ny));
for str = fieldnam'
grc(ix,iy,iz).(char(str))=gr.(char(str))(i,:);
end
end
end % function
%if false
%% xlin=linspace(min(gr.x),max(gr.x),50);
%% ylin=linspace(min(gr.y),max(gr.y),50);
%% zlin=linspace(min(gr.z),max(gr.z),50);
%% [X,Y,Z]=meshgrid(xlin,ylin,zlin);
%% C=griddata3(gr.x,gr.y,gr.z,gr.D_SOLID,X,Y,Z);
%% slice(C,290000,6080000,-2000);
%% slice(C,25,25,25);
%%
% xlin=min(gr.x):100:max(gr.x);
% ylin=min(gr.y):100:max(gr.y);
% zlin=min(gr.z):100:max(gr.z);
% [X,Y,Z]=meshgrid(xlin,ylin,zlin);
% F=TriScatteredInterp(gr.x,gr.y,gr.z,gr.PRESSURE);
% C=F(X,Y,Z);
% xslice=710000; yslice=6055000; zslice=-2000;
% slice(X,Y,Z,C,xslice,yslice,zslice);
% view(3);
% axis on;
% grid on;
% light;
% lighting phong;
% camlight('left');
% shading interp;
% axis tight;
% axis equal;
%
%
%end
%
%if false
%
%for i=1:total
%gr.CFS(i)=calcCFS(gr.STRESS(i,:),gr.PRESSURE(i,:),35.00,0.0);
%end
%gr.CFS=gr.CFS';
%
%
%end
%
%
%%end % function
%