source:
issm/oecreview/Archive/24684-25833/ISSM-25560-25561.diff
Last change on this file was 25834, checked in by , 4 years ago | |
---|---|
File size: 2.8 KB |
-
../trunk-jpl/src/m/solve/parseresultsfromdisk.m
6 6 results=parseresultsfromdiskioserial(md,filename); 7 7 end 8 8 9 10 9 function results=parseresultsfromdiskioserial(md,filename) % {{{ 11 10 12 11 %Open file … … 14 13 if(fid==-1), 15 14 error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']); 16 15 end 17 results=struct();18 16 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), 17 %Collect all results in a cell array 18 allresults = {}; 19 counter = 1; 20 while(true) 26 21 27 if check_nomoresteps,28 %check that the new result does not add a step, which would be an error:29 if result.step>=1,30 error('parsing results for a steady-state core, which incorporates transient results!');31 end32 end33 34 %Check step, increase counter if this is a new step35 if(step~=result.step & result.step>1)36 counter = counter + 1;37 step = result.step;38 end39 40 %Add result41 if(result.step==0),42 %if we have a step = 0, this is a steady state solution, don't expect more steps.43 index = 1;44 check_nomoresteps=1;45 elseif(result.step==1),46 index = 1;47 else48 index = counter;49 end50 if(result.step~=-9999),51 results(index).step=result.step;52 end53 if(result.time~=-9999),54 results(index).time=result.time;55 end56 results(index).(result.fieldname)=result.field;57 58 22 %read next result 59 23 try, 60 24 result = ReadData(fid,md); 61 25 catch me, 62 26 disp('WARNING: file corrupted, trying partial recovery'); 63 result=[];27 continue; 64 28 end 65 29 30 %Have we reached the end of the file? 31 if isempty(result), 32 if counter==1 33 error(['no results found in binary file ' filename]); 34 else 35 break; 36 end 37 end 38 39 %Add result to cell array 40 allresults{counter} = result; 41 counter = counter+1; 66 42 end 43 fclose(fid); 67 44 68 fclose(fid); 45 %Now, process all results and find how many steps we have 46 numresults = numel(allresults); 47 allsteps = zeros(numresults,1); 48 for i=1:numresults 49 allsteps(i) = allresults{i}.step; 50 end 51 pos = find(allsteps~=-9999); 52 allsteps = sort(unique(allsteps(pos))); 53 54 %Ok, now construct structure 55 results=struct(); 56 for i=1:numresults 57 result = allresults{i}; 58 59 index = 1; 60 if result.step ~= -9999 61 index = find(result.step == allsteps); 62 end 63 64 if(result.step~=-9999) results(index).step=result.step; end 65 if(result.time~=-9999) results(index).time=result.time; end 66 results(index).(result.fieldname)=result.field; 67 end 69 68 % }}} 70 69 function results=parseresultsfromdiskiosplit(md,filename) % {{{ 71 70
Note:
See TracBrowser
for help on using the repository browser.