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

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

CHG: added 24684-25833

File size: 2.8 KB
  • ../trunk-jpl/src/m/solve/parseresultsfromdisk.m

     
    66        results=parseresultsfromdiskioserial(md,filename);
    77end
    88
    9 
    109function results=parseresultsfromdiskioserial(md,filename) % {{{
    1110
    1211%Open file
     
    1413if(fid==-1),
    1514        error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']);
    1615end
    17 results=struct();
    1816
    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
     18allresults = {};
     19counter    = 1;
     20while(true)
    2621
    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;
    57 
    5822        %read next result
    5923        try,
    6024                result  = ReadData(fid,md);
    6125        catch me,
    6226                disp('WARNING: file corrupted, trying partial recovery');
    63                 result=[];
     27                continue;
    6428        end
    6529
     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;
    6642end
     43fclose(fid);
    6744
    68 fclose(fid);
     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) % {{{
    7170
Note: See TracBrowser for help on using the repository browser.