[6736] | 1 | function results=parseresultsfromdisk(filename,iosplit)
|
---|
[1] | 2 | %PARSERESULTSFROMDISK - ...
|
---|
| 3 | %
|
---|
| 4 | % Usage:
|
---|
[6736] | 5 | % results=parseresultsfromdisk(filename,iosplit)
|
---|
[1] | 6 |
|
---|
[6736] | 7 | if iosplit,
|
---|
| 8 | results=parseresultsfromdiskiosplit(filename);
|
---|
| 9 | else
|
---|
| 10 | results=parseresultsfromdiskioserial(filename);
|
---|
[1] | 11 | end
|
---|
[1591] | 12 |
|
---|
[4319] | 13 | %process patch if necessary
|
---|
[4439] | 14 | results=MatlabProcessPatch(results);
|
---|
[9373] | 15 |
|
---|
| 16 | function results=parseresultsfromdiskioserial(filename) % {{{
|
---|
| 17 | %PARSERESULTSFROMDISK - ...
|
---|
| 18 | %
|
---|
| 19 | % Usage:
|
---|
| 20 | % results=parseresultsfromdiskioserial(filename)
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | %Open file
|
---|
| 24 | fid=fopen(filename,'rb');
|
---|
| 25 | if(fid==-1),
|
---|
| 26 | error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']);
|
---|
| 27 | end
|
---|
| 28 | results=struct();
|
---|
| 29 |
|
---|
| 30 | %Read fields until the end of the file.
|
---|
| 31 | result=ReadData(fid);
|
---|
| 32 | while ~isempty(result),
|
---|
| 33 | %Get time and step
|
---|
| 34 | results(result.step).step=result.step;
|
---|
| 35 | results(result.step).time=result.time;
|
---|
| 36 |
|
---|
| 37 | %Add result
|
---|
| 38 | if (length(results)>=result.step & isfield(results,result.fieldname) & ~strcmp(result.fieldname,'SolutionType')),
|
---|
| 39 | results(result.step).(result.fieldname)=[ results(result.step).(result.fieldname); result.field];
|
---|
| 40 | else
|
---|
| 41 | results(result.step).(result.fieldname)=result.field;
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | %read next result
|
---|
| 45 | result=ReadData(fid);
|
---|
| 46 |
|
---|
| 47 | end
|
---|
| 48 |
|
---|
| 49 | fclose(fid);
|
---|
| 50 | % }}}
|
---|
| 51 | function results=parseresultsfromdisk(filename) % {{{
|
---|
| 52 | %PARSERESULTSFROMDISKIOSPLIT - ...
|
---|
| 53 | %
|
---|
| 54 | % Usage:
|
---|
| 55 | % results=parseresultsfromdiskiosplit(filename)
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | %Open file
|
---|
| 59 | fid=fopen(filename,'rb');
|
---|
| 60 | if(fid==-1),
|
---|
| 61 | error(['loadresultsfromdisk error message: could not open ',filename,' for binary reading']);
|
---|
| 62 | end
|
---|
| 63 | results=struct();
|
---|
| 64 |
|
---|
| 65 | %if we have done split I/O, ie, we have results that are fragmented across patches,
|
---|
| 66 | %do a first pass, and figure out the structure of results
|
---|
| 67 | result=ReadDataDimensions(fid);
|
---|
| 68 | while ~isempty(result),
|
---|
| 69 |
|
---|
| 70 | %Get time and step
|
---|
| 71 | results(result.step).step=result.step;
|
---|
| 72 | results(result.step).time=result.time;
|
---|
| 73 |
|
---|
| 74 | %Add result
|
---|
| 75 | if strcmpi(result.fieldname,'Patch'),
|
---|
| 76 | results(result.step).(result.fieldname)=[0 result.N];
|
---|
| 77 | else
|
---|
| 78 | results(result.step).(result.fieldname)=NaN;
|
---|
| 79 | end
|
---|
| 80 |
|
---|
| 81 | %read next result
|
---|
| 82 | result=ReadDataDimensions(fid);
|
---|
| 83 | end
|
---|
| 84 |
|
---|
| 85 | %do a second pass, and figure out the size of the patches
|
---|
| 86 | fseek(fid,0,-1); %rewind
|
---|
| 87 | result=ReadDataDimensions(fid);
|
---|
| 88 | while ~isempty(result),
|
---|
| 89 |
|
---|
| 90 | %Add result
|
---|
| 91 | if strcmpi(result.fieldname,'Patch'),
|
---|
| 92 | patchdimensions=results(result.step).(result.fieldname);
|
---|
| 93 | results(result.step).(result.fieldname)=[patchdimensions(1)+result.M result.N];
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | %read next result
|
---|
| 97 | result=ReadDataDimensions(fid);
|
---|
| 98 | end
|
---|
| 99 |
|
---|
| 100 | %allocate patches
|
---|
| 101 | for i=1:length(results),
|
---|
| 102 | results(i).Patch=zeros(results(i).Patch(1),results(i).Patch(2));
|
---|
| 103 | results(i).counter=1; %use to index into the patch
|
---|
| 104 | end
|
---|
| 105 |
|
---|
| 106 | %third pass, this time to read the real information
|
---|
| 107 | fseek(fid,0,-1); %rewind
|
---|
| 108 | result=ReadData(fid);
|
---|
| 109 | while ~isempty(result),
|
---|
| 110 |
|
---|
| 111 | %Get time and step
|
---|
| 112 | results(result.step).step=result.step;
|
---|
| 113 | results(result.step).time=result.time;
|
---|
| 114 |
|
---|
| 115 | %Add result
|
---|
| 116 | if strcmpi(result.fieldname,'Patch'),
|
---|
| 117 | counter=results(result.step).counter;
|
---|
| 118 | counter2=counter+size(result.field,1)-1;
|
---|
| 119 | results(result.step).(result.fieldname)(counter:counter2,:)=result.field;
|
---|
| 120 |
|
---|
| 121 | %increment counter:
|
---|
| 122 | results(result.step).counter=counter2+1;
|
---|
| 123 | else
|
---|
| 124 | results(result.step).(result.fieldname)=result.field;
|
---|
| 125 | end
|
---|
| 126 |
|
---|
| 127 | %read next result
|
---|
| 128 | result=ReadData(fid);
|
---|
| 129 |
|
---|
| 130 | end
|
---|
| 131 |
|
---|
| 132 | %close file
|
---|
| 133 | fclose(fid);
|
---|
| 134 | % }}}
|
---|
| 135 | function result=ReadData(fid) % {{{
|
---|
| 136 | %READDATA - ...
|
---|
| 137 | %
|
---|
| 138 | % Usage:
|
---|
| 139 | % field=ReadData(fid)
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | %read field
|
---|
| 143 | [length,count]=fread(fid,1,'int');
|
---|
| 144 |
|
---|
| 145 | if count==0,
|
---|
| 146 | result=struct([]);
|
---|
| 147 | else
|
---|
| 148 | fieldname=fread(fid,length,'char');
|
---|
| 149 | fieldname=fieldname(1:end-1)';
|
---|
| 150 | fieldname=char(fieldname);
|
---|
| 151 | time=fread(fid,1,'double');
|
---|
| 152 | step=fread(fid,1,'int');
|
---|
| 153 |
|
---|
| 154 | type=fread(fid,1,'int');
|
---|
| 155 | M=fread(fid,1,'int');
|
---|
| 156 | if type==1,
|
---|
| 157 | field=fread(fid,M,'double');
|
---|
| 158 | elseif type==2,
|
---|
| 159 | field=fread(fid,M,'char');
|
---|
| 160 | field=char(field(1:end-1)');
|
---|
| 161 | elseif type==3,
|
---|
| 162 | N=fread(fid,1,'int');
|
---|
| 163 | field=transpose(fread(fid,[N M],'double'));
|
---|
| 164 | else
|
---|
| 165 | error(['cannot read data of type ' num2str(type) ]);
|
---|
| 166 | end
|
---|
| 167 |
|
---|
| 168 | result.fieldname=fieldname;
|
---|
| 169 | result.time=time;
|
---|
| 170 | result.step=step;
|
---|
| 171 | result.field=field;
|
---|
| 172 | end
|
---|
| 173 | % }}}
|
---|
| 174 | function result=ReadDataDimensions(fid) % {{{
|
---|
| 175 | %READDATA - read data dimensions, step and time, but not the data itself.
|
---|
| 176 | %
|
---|
| 177 | % Usage:
|
---|
| 178 | % field=ReadDataDimensions(fid)
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | %read field
|
---|
| 182 | [length,count]=fread(fid,1,'int');
|
---|
| 183 |
|
---|
| 184 | if count==0,
|
---|
| 185 | result=struct([]);
|
---|
| 186 | else
|
---|
| 187 | fieldname=fread(fid,length,'char');
|
---|
| 188 | fieldname=fieldname(1:end-1)';
|
---|
| 189 | fieldname=char(fieldname);
|
---|
| 190 | time=fread(fid,1,'double');
|
---|
| 191 | step=fread(fid,1,'int');
|
---|
| 192 |
|
---|
| 193 | type=fread(fid,1,'int');
|
---|
| 194 | M=fread(fid,1,'int');
|
---|
| 195 | N=1; %default
|
---|
| 196 | if type==1,
|
---|
| 197 | fseek(fid,M*8,0);
|
---|
| 198 | elseif type==2,
|
---|
| 199 | fseek(fid,M,0);
|
---|
| 200 | elseif type==3,
|
---|
| 201 | N=fread(fid,1,'int');
|
---|
| 202 | fseek(fid,N*M*8,0);
|
---|
| 203 | else
|
---|
| 204 | error(['cannot read data of type ' num2str(type) ]);
|
---|
| 205 | end
|
---|
| 206 |
|
---|
| 207 | result.fieldname=fieldname;
|
---|
| 208 | result.time=time;
|
---|
| 209 | result.step=step;
|
---|
| 210 | result.M=M;
|
---|
| 211 | result.N=N;
|
---|
| 212 | end
|
---|
| 213 | % }}}
|
---|