-
Notifications
You must be signed in to change notification settings - Fork 4
/
neut_tess_fscanf.m
105 lines (94 loc) · 3.04 KB
/
neut_tess_fscanf.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
% Ran Ma
% 3/8/2019
% read Neper .tess file
if(~exist('fname','var'))
fname = 'n10-id1.tess';
end
fid = fopen(fname,'r');
if(fid==-1)
error(strcat('>>>Error: ',fname,' does not exist ...'));
end
currLine = fgetl(fid);
if(~strcmp(currLine,'***tess'))
error('>>> Error: This is not a tess file ...');
end
while (1)
currLine = fgetl(fid);
currLine = strtrim(currLine);
if(strcmp(currLine,'***tess'))
continue;
elseif(strcmp(currLine,'**format'))
currLine = fgetl(fid);
if(~strcmp(currLine(end-2:end),'2.0'))
error(strcat('>>>Error: unknown input file format ',currLine));
end
elseif(strcmp(currLine,'**general'))
currLine = fgetl(fid);
ndim = sscanf(currLine,'%f');
elseif(strcmp(currLine,'**cell'))
currLine = fgetl(fid);
numCry = sscanf(currLine,'%f');
for temp = 1:(2*numCry+9)
currLine = fgetl(fid);
end
elseif(strcmp(currLine,'**vertex'))
currLine = fgetl(fid);
num_vertex = sscanf(currLine,'%f');
temp = textscan(fid,'%f%f%f%f%f');
vertex = cell2mat(temp);
if(size(vertex,1) ~= num_vertex)
error('>>> Error: Invalid number of vertex');
end
elseif(strcmp(currLine,'**edge'))
currLine = fgetl(fid);
num_edge = sscanf(currLine,'%f');
temp = textscan(fid,'%f%f%f%f');
NodeOnEdge = cell2mat(temp);
if(size(NodeOnEdge,1) ~= num_edge)
error('>>> Error: Invalid number of edge');
end
elseif(strcmp(currLine,'**face'))
currLine = fgetl(fid);
num_face = sscanf(currLine,'%f');
NodeOnFace = zeros(num_face,10);
EdgeOnFace = zeros(num_face,10);
face_direction = zeros(num_face,4);
for ii = 1:num_face
% read vertex
currLine = fgetl(fid);
temp = sscanf(currLine,'%f');
NodeOnFace(ii,1:length(temp)) = temp;
% read edge
currLine = fgetl(fid);
temp = sscanf(currLine,'%f');
EdgeOnFace(ii,1:length(temp)) = temp;
% read normal direction
currLine = fgetl(fid);
temp = sscanf(currLine,'%f');
face_direction(ii,1:4) = temp;
% garbage
fgetl(fid);
end
elseif(strcmp(currLine,'**polyhedron'))
currLine = fgetl(fid);
num_cell = sscanf(currLine,'%f');
FaceOnRegion = zeros(num_cell,20);
if(num_cell ~= numCry)
error('>>> Error: polyhedron ~= crystal');
end
for ii = 1:num_cell
currLine = fgetl(fid);
temp = sscanf(currLine,'%f');
FaceOnRegion(ii,1:length(temp)) = temp;
end
elseif(strcmp(currLine,'**domain'))
warning(strcat('skipping domain part of ',fname));
break;
elseif(strcmp(currLine,'***end'))
break;
else
fclose(fid);
error(strcat('>>>Error: unknown command ',currLine));
end
end
fclose(fid);