-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathreadSCISIM.m
72 lines (66 loc) · 2.1 KB
/
readSCISIM.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
function [iter,dt,t,x,R,v,omega,M,I,fixed] = readSCISIM(h5_filename)
path_to_print_meshes = ...
'/Users/ajx/Dropbox/scisim/post_processing/print_meshes.py';
path_to_python = '/usr/local/bin/python';
out_filename = tempname;
cmd = sprintf('%s %s %s >%s', ...
path_to_python,path_to_print_meshes,h5_filename,out_filename);
[status,r] = system(cmd);
if status ~= 0
error(sprintf('\n%s\n\n%s',cmd,r));
end
fp = fopen(out_filename,'r');
hash = fscanf(fp,'Git hash: %s\n',1);
iter = fscanf(fp,'Iteration: %d\n',1);
dt = fscanf(fp,'Timestep: %f\n',1);
t = fscanf(fp,'Time: %f\n',1);
x = zeros(100,3);
R = zeros(100,9);
v = zeros(100,3);
omega = zeros(100,3);
M = zeros(100,1);
I = zeros(100,9);
fixed = zeros(100,1);
mesh_name = cell(1,100);
count = 0;
while true
id = fscanf(fp,'Body: %d\n',1);
if isempty(id)
break;
else
count = count+1;
assert(count == id+1);
end
x(count,:) = fscanf(fp,' x: [ %f %f %f ]\n');
R(count,1:3) = fscanf(fp,' R: [%f %f %f]\n',3);
R(count,4:6) = fscanf(fp,' [%f %f %f]\n',3);
R(count,7:9) = fscanf(fp,' [%f %f %f]\n',3);
v(count,:) = fscanf(fp,' v: [ %f %f %f ]\n');
omega(count,:) = fscanf(fp,' omega: [ %f %f %f ]\n');
M(count) = fscanf(fp,' M: %f\n',1);
I(count,1:3) = fscanf(fp,' I: [%f %f %f]\n',3);
I(count,4:6) = fscanf(fp,' [%f %f %f]\n',3);
I(count,7:9) = fscanf(fp,' [%f %f %f]\n',3);
fixed(count) = fscanf(fp,' fixed: %f\n',1);
mesh_name{count} = fscanf(fp,' mesh_name: %s\n',1);
if count==size(x,1)
x = [x ;zeros(count,3)];
R = [R ;zeros(count,9)];
v = [v ;zeros(count,3)];
omega = [omega;zeros(count,3)];
M = [M ;zeros(count,1)];
I = [I ;zeros(count,9)];
fixed = [fixed;zeros(count,1)];
mesh_name = {mesh_name{:} cell(1,count)};
end
end
x = x(1:count,:);
R = R(1:count,:);
v = v(1:count,:);
omega = omega(1:count,:);
M = M(1:count,:);
I = I(1:count,:);
fixed = fixed(1:count,:);
fclose(fp);
delete(out_filename);
end