1 | function Struct=meshread(filename)
|
---|
2 |
|
---|
3 | %some checks
|
---|
4 | if ~exist(filename),
|
---|
5 | error(['meshread error message: file ' filename ' not found!']);
|
---|
6 | end
|
---|
7 |
|
---|
8 | fid=fopen(filename,'r');
|
---|
9 |
|
---|
10 | while (~feof(fid)),
|
---|
11 |
|
---|
12 | A=fscanf(fid,'%s',1);
|
---|
13 |
|
---|
14 | if strcmp(A,'MeshVersionFormatted');
|
---|
15 | Struct.Version=fscanf(fid,'%s',1);
|
---|
16 |
|
---|
17 | elseif strcmp(A,'Dimension'),
|
---|
18 | Struct.Dimension=fscanf(fid,'%i',1);
|
---|
19 |
|
---|
20 | elseif strcmp(A,'Vertices'),
|
---|
21 | Struct.nods=fscanf(fid,'%i',1);
|
---|
22 | A=fscanf(fid,'%f %f %f',[3 Struct.nods]);
|
---|
23 | Struct.x=A(1,:)';
|
---|
24 | Struct.y=A(2,:)';
|
---|
25 |
|
---|
26 | elseif strcmp(A,'Triangles'),
|
---|
27 | Struct.nels=fscanf(fid,'%i',1);
|
---|
28 | A=fscanf(fid,'%i %i %i',[4 Struct.nels]);
|
---|
29 | Struct.index=A(1:3,:)';
|
---|
30 |
|
---|
31 | elseif strcmp(A,'Quadrilaterals'),
|
---|
32 | Struct.nels=fscanf(fid,'%i',1);
|
---|
33 | A=fscanf(fid,'%i %i %i %i',[5 Struct.nels]);
|
---|
34 | Struct.index=A(1:4,:)';
|
---|
35 | else
|
---|
36 | %do nothing
|
---|
37 |
|
---|
38 | end
|
---|
39 | end
|
---|
40 |
|
---|
41 | fclose(fid);
|
---|