-
Notifications
You must be signed in to change notification settings - Fork 4
/
neut_tesr_fscanf.m
74 lines (69 loc) · 2.01 KB
/
neut_tesr_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
% Ran Ma
% 7/4/2018
% read Neper .tesr file
if(~exist('fname','var'))
fname = 'n10-id1.tesr';
end
fid = fopen(fname,'r');
if(fid==-1)
error(strcat('>>>Error: ',fname,' does not exist ...'));
end
while (1)
currLine = fgetl(fid);
if(strcmp(currLine,'***tesr'))
continue;
elseif(strcmp(currLine,' **format'))
currLine = fgetl(fid);
if(strcmp(currLine(end-4:end),'ascii'))
format = 1;
elseif(strcmp(currLine(end-6:end),'binary8'))
format = 2;
elseif(strcmp(currLine(end-6:end),'binary16'))
format = 3;
elseif(strcmp(currLine(end-6:end),'binary32'))
format = 4;
else
fclose(fid);
error(strcat('>>>Error: unknown option ',currLine));
end
elseif(strcmp(currLine,' **general'))
currLine = fgetl(fid);
ndim = sscanf(currLine,'%f');
currLine = fgetl(fid);
numgrid = sscanf(currLine,'%f%f%f');
numel = prod(numgrid);
fgetl(fid);
elseif(strcmp(currLine,' **cell'))
currLine = fgetl(fid);
numCry = sscanf(currLine,'%f');
while(~strcmp(currLine,' *ori'))
currLine = fgetl(fid);
end
for temp = 1:(numCry+1)
fgetl(fid);
end
elseif(strcmp(currLine,' **data'))
if(format == 1)
temp = textscan(fid,'%f');
RegionOnElement = cell2mat(temp);
elseif(format == 2)
temp = fread(fid,numel,'*ubit8');
RegionOnElement = double(temp);
fgetl(fid);
elseif(format == 3)
temp = fread(fid,numel,'*ubit16');
RegionOnElement = double(temp);
fgetl(fid);
elseif(format == 4)
temp = fread(fid,numel,'*ubit32');
RegionOnElement = double(temp);
fgetl(fid);
end
elseif(strcmp(currLine,'***end'))
break;
else
fclose(fid);
error(strcat('>>>Error: unknown command ',currLine));
end
end
fclose(fid);