Changeset 25561


Ignore:
Timestamp:
09/11/20 09:57:40 (5 years ago)
Author:
Mathieu Morlighem
Message:

NEW: better handling of results if they are not properly sorted in the first place

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/solve/parseresultsfromdisk.m

    r25303 r25561  
    77end
    88
    9 
    109function results=parseresultsfromdiskioserial(md,filename) % {{{
    1110
     
    1514        error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']);
    1615end
    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
     18allresults = {};
     19counter    = 1;
     20while(true)
    5721
    5822        %read next result
     
    6125        catch me,
    6226                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;
     42end
    6843fclose(fid);
     44
     45%Now, process all results and find how many steps we have
     46numresults = numel(allresults);
     47allsteps   = zeros(numresults,1);
     48for i=1:numresults
     49        allsteps(i) = allresults{i}.step;
     50end
     51pos = find(allsteps~=-9999);
     52allsteps = sort(unique(allsteps(pos)));
     53
     54%Ok, now construct structure
     55results=struct();
     56for 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;
     67end
    6968% }}}
    7069function results=parseresultsfromdiskiosplit(md,filename) % {{{
Note: See TracChangeset for help on using the changeset viewer.