-
Notifications
You must be signed in to change notification settings - Fork 17
/
read_dot_dyn.m
88 lines (74 loc) · 2.62 KB
/
read_dot_dyn.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
function [node_loc,X,Y,Z] = read_dot_dyn(fname);
% function [nodes,X,Y,Z] = read_dot_dyn(fname);
%
% read_dot_dyn reads a .dyn file that contain information about node IDs and
% their x,y,z locations and returns 4 3D matricies nodes is matrix of node
% numbers
%
% X,Y,Z are matricies of X, Y, and Z node locations (initial)
%
% These matricies are part of the input to scat_and_disp.m
%
% fname is the name of your .dyn file that has comma-delimited node information
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Builds upon read_dyna_nodes.m
% Last modified 10/18/04 Stephen McAleavey, U. Rochester BME
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modified to use comma delimiters, not spaces.
% Mark 04/01/08
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
endofline=sprintf('\n');
% Load grid data
% Open file
fid=fopen(fname,'r');
if (fid == -1),
disp(['Can''t open ' fname]);
return;
end;
% find last word just before data...
s=fscanf(fid,'%s',1);
while (~strcmp(s,'*NODE')),
s=fscanf(fid,'%s',1);
end;
% Find start of next line...
c=fscanf(fid,'%c',1);
while(c~=endofline);
c=fscanf(fid,'%c',1);
end;
% Suck in data...
[node_loc,count]=fscanf(fid,'%d,%f,%f,%f',[4,inf]);
node_loc=node_loc';
fclose(fid);
% All beyond here is new to rdn2 vs read_dyna_nodes
% Sort data in prepartion for formation of plaid 3D matricies
%
% This step generates matrix n2 which a "defuzzed" nodeloc
% the X,Y,Z components of X,Y,Z are truncated to TOL places after the
% decimal. The reason for this operation is to eliminate the
% roundoff error differences between node coordinates (e.g. 1.499999
% is really 1.50000). The "numerical fuzz" left behind by the float to
% ascii conversion fouls up sorting and confounds the creation of plaid
% 3D matricies
%
TOL=3; % One might calculate TOL from the data by finding the range of
% X,Y,Z and selecting a thousandth of that, & TOL is log10 of 1/that
n2=node_loc;
n2(:,2:4)=round((10^TOL)*n2(:,2:4))/(10^TOL);
[n2,I]=sortrows(n2,[4 3 2]);
% node_loc now is sorted into the same order, preserving the orginal
% (unrounded) values.
node_loc=node_loc(I,:);
node_loc=n2;
% figure out dimensions
zsum=sum(n2(:,4)==n2(1,4));
zdim=size(n2,1)/zsum;
ysum=sum(n2(1:zsum,3)==n2(1,3));
ydim=zsum/ysum;
xsum=sum(n2(1:ysum,2)==n2(1,2));
xdim=ysum/xsum;
% create outputs by reshaping node_loc
X=reshape(node_loc(:,2),xdim,ydim,zdim);
Y=reshape(node_loc(:,3),xdim,ydim,zdim);
Z=reshape(node_loc(:,4),xdim,ydim,zdim);
node_loc=reshape(node_loc(:,1),xdim,ydim,zdim);