| 1 | function structure=MatlabProcessPatch(structure);
|
|---|
| 2 | %PROCESSPATCH - create a structure from a patch
|
|---|
| 3 | %
|
|---|
| 4 | % Usage:
|
|---|
| 5 | % Result=ProcessPatch(Result);
|
|---|
| 6 |
|
|---|
| 7 | %return if there is no fiel Patch
|
|---|
| 8 | if (~isfield(structure,'Patch')),
|
|---|
| 9 | return;
|
|---|
| 10 | end
|
|---|
| 11 |
|
|---|
| 12 | %loop over steps
|
|---|
| 13 | for i=1:length(structure),
|
|---|
| 14 |
|
|---|
| 15 | %Get Patch for current step
|
|---|
| 16 | Patch=structure(i).Patch;
|
|---|
| 17 | numvertices=structure(i).PatchVertices;
|
|---|
| 18 |
|
|---|
| 19 | %check that Patch is not empty
|
|---|
| 20 | if length(Patch)==0 continue; end
|
|---|
| 21 |
|
|---|
| 22 | %Get number of fields;
|
|---|
| 23 | fields=unique(Patch(:,1));
|
|---|
| 24 | steps=unique(Patch(:,2));
|
|---|
| 25 |
|
|---|
| 26 | %parse steps
|
|---|
| 27 | for j=1:length(steps),
|
|---|
| 28 |
|
|---|
| 29 | posstep=find(Patch(:,2)==steps(j));
|
|---|
| 30 |
|
|---|
| 31 | %Take all the lines of the Patch for this timestep
|
|---|
| 32 | temporarypatch=Patch(posstep,:);
|
|---|
| 33 | time=temporarypatch(1,3);
|
|---|
| 34 | step=temporarypatch(1,2);
|
|---|
| 35 |
|
|---|
| 36 | %parse fields
|
|---|
| 37 | for i=1:length(fields),
|
|---|
| 38 |
|
|---|
| 39 | %get name
|
|---|
| 40 | fieldname=EnumToString(fields(i));
|
|---|
| 41 |
|
|---|
| 42 | %get line positions
|
|---|
| 43 | pos=find(temporarypatch(:,1)==fields(i));
|
|---|
| 44 |
|
|---|
| 45 | %Fill Result structure
|
|---|
| 46 | structure(step).steps=step;
|
|---|
| 47 | structure(step).time=time;
|
|---|
| 48 | structure(step).(fieldname).element=temporarypatch(pos,4);
|
|---|
| 49 | structure(step).(fieldname).interpolation=temporarypatch(pos,5);
|
|---|
| 50 | structure(step).(fieldname).index=temporarypatch(pos,6:5+numvertices);
|
|---|
| 51 | if structure(step).(fieldname).interpolation==P1Enum,
|
|---|
| 52 | structure(step).(fieldname).value=temporarypatch(pos,6+numvertices:end);
|
|---|
| 53 | end
|
|---|
| 54 | if structure(step).(fieldname).interpolation==P0Enum,
|
|---|
| 55 | structure(step).(fieldname).value=temporarypatch(pos,6+numvertices);
|
|---|
| 56 | end
|
|---|
| 57 |
|
|---|
| 58 | end
|
|---|
| 59 | end
|
|---|
| 60 | end
|
|---|
| 61 |
|
|---|
| 62 | %remove fields
|
|---|
| 63 | structure=rmfield(structure,'Patch');
|
|---|
| 64 | structure=rmfield(structure,'PatchVertices');
|
|---|
| 65 | structure=rmfield(structure,'PatchNodes');
|
|---|