Changeset 25561
- Timestamp:
- 09/11/20 09:57:40 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/solve/parseresultsfromdisk.m
r25303 r25561 7 7 end 8 8 9 10 9 function results=parseresultsfromdiskioserial(md,filename) % {{{ 11 10 … … 15 14 error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']); 16 15 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 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 end 32 end 33 34 %Check step, increase counter if this is a new step 35 if(step~=result.step & result.step>1) 36 counter = counter + 1; 37 step = result.step; 38 end 39 40 %Add result 41 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 else 48 index = counter; 49 end 50 if(result.step~=-9999), 51 results(index).step=result.step; 52 end 53 if(result.time~=-9999), 54 results(index).time=result.time; 55 end 56 results(index).(result.fieldname)=result.field; 16 17 %Collect all results in a cell array 18 allresults = {}; 19 counter = 1; 20 while(true) 57 21 58 22 %read next result … … 61 25 catch me, 62 26 disp('WARNING: file corrupted, trying partial recovery'); 63 result=[]; 64 end 65 66 end 67 27 continue; 28 end 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; 42 end 68 43 fclose(fid); 44 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) % {{{
Note:
See TracChangeset
for help on using the changeset viewer.