Index: ../trunk-jpl/src/m/solve/parseresultsfromdisk.m =================================================================== --- ../trunk-jpl/src/m/solve/parseresultsfromdisk.m (revision 25560) +++ ../trunk-jpl/src/m/solve/parseresultsfromdisk.m (revision 25561) @@ -6,7 +6,6 @@ results=parseresultsfromdiskioserial(md,filename); end - function results=parseresultsfromdiskioserial(md,filename) % {{{ %Open file @@ -14,58 +13,58 @@ if(fid==-1), error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']); end -results=struct(); -%Read fields until the end of the file. -result = ReadData(fid,md); -if isempty(result), error(['no results found in binary file ' filename]); end -check_nomoresteps=0; -counter = 1; -step = result.step; -while ~isempty(result), +%Collect all results in a cell array +allresults = {}; +counter = 1; +while(true) - if check_nomoresteps, - %check that the new result does not add a step, which would be an error: - if result.step>=1, - error('parsing results for a steady-state core, which incorporates transient results!'); - end - end - - %Check step, increase counter if this is a new step - if(step~=result.step & result.step>1) - counter = counter + 1; - step = result.step; - end - - %Add result - if(result.step==0), - %if we have a step = 0, this is a steady state solution, don't expect more steps. - index = 1; - check_nomoresteps=1; - elseif(result.step==1), - index = 1; - else - index = counter; - end - if(result.step~=-9999), - results(index).step=result.step; - end - if(result.time~=-9999), - results(index).time=result.time; - end - results(index).(result.fieldname)=result.field; - %read next result try, result = ReadData(fid,md); catch me, disp('WARNING: file corrupted, trying partial recovery'); - result=[]; + continue; end + %Have we reached the end of the file? + if isempty(result), + if counter==1 + error(['no results found in binary file ' filename]); + else + break; + end + end + + %Add result to cell array + allresults{counter} = result; + counter = counter+1; end +fclose(fid); -fclose(fid); +%Now, process all results and find how many steps we have +numresults = numel(allresults); +allsteps = zeros(numresults,1); +for i=1:numresults + allsteps(i) = allresults{i}.step; +end +pos = find(allsteps~=-9999); +allsteps = sort(unique(allsteps(pos))); + +%Ok, now construct structure +results=struct(); +for i=1:numresults + result = allresults{i}; + + index = 1; + if result.step ~= -9999 + index = find(result.step == allsteps); + end + + if(result.step~=-9999) results(index).step=result.step; end + if(result.time~=-9999) results(index).time=result.time; end + results(index).(result.fieldname)=result.field; +end % }}} function results=parseresultsfromdiskiosplit(md,filename) % {{{