source: issm/oecreview/Archive/24684-25833/ISSM-25560-25561.diff@ 25834

Last change on this file since 25834 was 25834, checked in by Mathieu Morlighem, 4 years ago

CHG: added 24684-25833

File size: 2.8 KB
RevLine 
[25834]1Index: ../trunk-jpl/src/m/solve/parseresultsfromdisk.m
2===================================================================
3--- ../trunk-jpl/src/m/solve/parseresultsfromdisk.m (revision 25560)
4+++ ../trunk-jpl/src/m/solve/parseresultsfromdisk.m (revision 25561)
5@@ -6,7 +6,6 @@
6 results=parseresultsfromdiskioserial(md,filename);
7 end
8
9-
10 function results=parseresultsfromdiskioserial(md,filename) % {{{
11
12 %Open file
13@@ -14,58 +13,58 @@
14 if(fid==-1),
15 error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']);
16 end
17-results=struct();
18
19-%Read fields until the end of the file.
20-result = ReadData(fid,md);
21-if isempty(result), error(['no results found in binary file ' filename]); end
22-check_nomoresteps=0;
23-counter = 1;
24-step = result.step;
25-while ~isempty(result),
26+%Collect all results in a cell array
27+allresults = {};
28+counter = 1;
29+while(true)
30
31- if check_nomoresteps,
32- %check that the new result does not add a step, which would be an error:
33- if result.step>=1,
34- error('parsing results for a steady-state core, which incorporates transient results!');
35- end
36- end
37-
38- %Check step, increase counter if this is a new step
39- if(step~=result.step & result.step>1)
40- counter = counter + 1;
41- step = result.step;
42- end
43-
44- %Add result
45- if(result.step==0),
46- %if we have a step = 0, this is a steady state solution, don't expect more steps.
47- index = 1;
48- check_nomoresteps=1;
49- elseif(result.step==1),
50- index = 1;
51- else
52- index = counter;
53- end
54- if(result.step~=-9999),
55- results(index).step=result.step;
56- end
57- if(result.time~=-9999),
58- results(index).time=result.time;
59- end
60- results(index).(result.fieldname)=result.field;
61-
62 %read next result
63 try,
64 result = ReadData(fid,md);
65 catch me,
66 disp('WARNING: file corrupted, trying partial recovery');
67- result=[];
68+ continue;
69 end
70
71+ %Have we reached the end of the file?
72+ if isempty(result),
73+ if counter==1
74+ error(['no results found in binary file ' filename]);
75+ else
76+ break;
77+ end
78+ end
79+
80+ %Add result to cell array
81+ allresults{counter} = result;
82+ counter = counter+1;
83 end
84+fclose(fid);
85
86-fclose(fid);
87+%Now, process all results and find how many steps we have
88+numresults = numel(allresults);
89+allsteps = zeros(numresults,1);
90+for i=1:numresults
91+ allsteps(i) = allresults{i}.step;
92+end
93+pos = find(allsteps~=-9999);
94+allsteps = sort(unique(allsteps(pos)));
95+
96+%Ok, now construct structure
97+results=struct();
98+for i=1:numresults
99+ result = allresults{i};
100+
101+ index = 1;
102+ if result.step ~= -9999
103+ index = find(result.step == allsteps);
104+ end
105+
106+ if(result.step~=-9999) results(index).step=result.step; end
107+ if(result.time~=-9999) results(index).time=result.time; end
108+ results(index).(result.fieldname)=result.field;
109+end
110 % }}}
111 function results=parseresultsfromdiskiosplit(md,filename) % {{{
112
Note: See TracBrowser for help on using the repository browser.