[4330] | 1 | function [data datatype]=processdata(md,data,options);
|
---|
[1] | 2 | %PROCESSDATA - process data to be plotted
|
---|
| 3 | %
|
---|
[4330] | 4 | % datatype = 1 -> elements
|
---|
| 5 | % datatype = 2 -> nodes
|
---|
| 6 | % datatype = 3 -> node quivers
|
---|
| 7 | % datatype = 4 -> patch
|
---|
| 8 | %
|
---|
[1] | 9 | % Usage:
|
---|
[4330] | 10 | % [data datatype]=processdata(md,data,options);
|
---|
[1] | 11 | %
|
---|
| 12 | % See also: PLOTMODEL, PROCESSMESH
|
---|
| 13 |
|
---|
[27] | 14 | %check format
|
---|
[5123] | 15 | if (iscell(data) | isempty(data) | length(data)==0 | (length(data)==1 & ~isstruct(data) & isnan(data))),
|
---|
[27] | 16 | error('plotmodel error message: data provided is empty');
|
---|
| 17 | end
|
---|
| 18 |
|
---|
[4330] | 19 | %Process Patch
|
---|
| 20 | if isstruct(data)
|
---|
| 21 | if (isfield(data,'index') & isfield(data,'value')),
|
---|
[7098] | 22 | if data.interpolation(1)==P1Enum(),
|
---|
| 23 | data=data.value;
|
---|
| 24 | data=data';
|
---|
| 25 | data=data(:);
|
---|
| 26 | datatype=4;
|
---|
| 27 | elseif data.interpolation(1)==P0Enum(),
|
---|
| 28 | data=data.value;
|
---|
| 29 | datatype=5;
|
---|
| 30 | else
|
---|
| 31 | error(['interpolation ' data.interpolation(1) ' not supported yet']);
|
---|
[7081] | 32 | end
|
---|
[4330] | 33 | else
|
---|
| 34 | error('structure other than Patch not supported yet');
|
---|
| 35 | end
|
---|
| 36 | else
|
---|
| 37 | %initialize datatype
|
---|
| 38 | datatype=0;
|
---|
[1740] | 39 | end
|
---|
[4330] | 40 |
|
---|
| 41 | %get datatype
|
---|
[1740] | 42 | datasize=size(data);
|
---|
[1171] | 43 |
|
---|
[4330] | 44 | %non patch processing
|
---|
[7098] | 45 | if datatype~=4 & datatype~=5,
|
---|
[2700] | 46 |
|
---|
[4330] | 47 | %transpose data if necessary
|
---|
| 48 | if (size(data,2) > size(data,1)),
|
---|
| 49 | data=data';
|
---|
| 50 | end
|
---|
| 51 | datasize=size(data);
|
---|
[1] | 52 |
|
---|
[4330] | 53 | %convert to double if necessary
|
---|
| 54 | if ~isnumeric(data);
|
---|
| 55 | disp('processdata info message: data is not numeric (logical?). Converted to double');
|
---|
| 56 | data=double(data);
|
---|
| 57 | end
|
---|
[1740] | 58 |
|
---|
[4330] | 59 | %check length
|
---|
[9719] | 60 | if datasize(1)~=md.numberofnodes & datasize(1)~=md.numberofelements & datasize(1)~=md.numberofnodes*6 & (md.mesh.dimension==3 & ~(datasize(1)==md.numberofelements2d | datasize(1)==md.numberofnodes2d))
|
---|
[4330] | 61 | error('plotmodel error message: data not supported yet');
|
---|
| 62 | end
|
---|
| 63 |
|
---|
| 64 | %quiver?
|
---|
| 65 | if datasize(2)>1,
|
---|
| 66 | datatype=3;
|
---|
| 67 |
|
---|
| 68 | %check number of columns, add zeros if necessary,
|
---|
[9719] | 69 | if (md.mesh.dimension==3)
|
---|
[4330] | 70 | if datasize(2)==2,
|
---|
| 71 | data=[data, zeros(datasize(1),1)];
|
---|
| 72 | elseif datasize(2)~=3,
|
---|
| 73 | error('plotmodel error message: data provided should have 2 or 3 columns for quiver plot, and 1 for regular plot');
|
---|
| 74 | end
|
---|
[9719] | 75 | %elseif ((md.mesh.dimension==2) & datasize(2)~=2),
|
---|
[5867] | 76 | % error('plotmodel error message: data provided should have 2 columns for quiver plot, and 1 for regular plot');
|
---|
[1740] | 77 | end
|
---|
| 78 | end
|
---|
| 79 |
|
---|
[8298] | 80 | %treat the case datasize(1)=6*nodes
|
---|
| 81 | if datasize(1)==6*md.numberofnodes
|
---|
[4330] | 82 | %keep the only norm of data
|
---|
[8298] | 83 | data1=data(1:6:md.numberofnodes*6,:);
|
---|
| 84 | data2=data(2:6:md.numberofnodes*6,:);
|
---|
[4330] | 85 | data=sqrt(data1.^2+data2.^2);
|
---|
[8298] | 86 | datasize(1)=md.numberofnodes;
|
---|
| 87 | %---> go to node data
|
---|
[4330] | 88 | end
|
---|
[1740] | 89 |
|
---|
[8298] | 90 | %treat the case datasize(1)=nodes2d
|
---|
[9719] | 91 | if (md.mesh.dimension==3 & datasize(1)==md.numberofnodes2d),
|
---|
[4330] | 92 | data=project3d(md,data,'node');
|
---|
[8298] | 93 | datasize(1)=md.numberofnodes;
|
---|
| 94 | %---> go to node data
|
---|
[4330] | 95 | end
|
---|
[1] | 96 |
|
---|
[8298] | 97 | %treat the case datasize(1)=nodes2d
|
---|
[9719] | 98 | if (md.mesh.dimension==3 & datasize(1)==md.numberofelements2d),
|
---|
[4330] | 99 | data=project3d(md,data,'element');
|
---|
| 100 | datasize(1)=md.numberofelements;
|
---|
[8298] | 101 | %---> go to node data
|
---|
[4330] | 102 | end
|
---|
[27] | 103 |
|
---|
[4330] | 104 | %smoothing?
|
---|
| 105 | if exist(options,'smooth')
|
---|
| 106 | data=averaging(md,data,getfieldvalue(options,'smooth'));
|
---|
[8298] | 107 | datasize(1)=md.numberofnodes;
|
---|
| 108 | %---> go to node data
|
---|
[4330] | 109 | end
|
---|
[2426] | 110 | end
|
---|
| 111 |
|
---|
[1] | 112 | %element data
|
---|
[5428] | 113 | if (datasize(1)==md.numberofelements & datasize(2)==1),
|
---|
[1] | 114 |
|
---|
[4330] | 115 | %Initialize datatype if non patch
|
---|
[7098] | 116 | if datatype~=4 & datatype~=5,
|
---|
[4330] | 117 | datatype=1;
|
---|
| 118 | end
|
---|
| 119 |
|
---|
[7244] | 120 | %Mask?
|
---|
| 121 | if exist(options,'mask'),
|
---|
| 122 | flags=getfieldvalue(options,'mask');
|
---|
| 123 | pos=find(~flags);
|
---|
[8298] | 124 | if length(flags)==md.numberofnodes,
|
---|
[7244] | 125 | [pos2 dummy]=find(ismember(md.elements,pos));
|
---|
| 126 | data(pos2,:)=NaN;
|
---|
| 127 | elseif length(flags)==md.numberofelements
|
---|
| 128 | data(pos,:)=NaN;
|
---|
| 129 | else
|
---|
[8298] | 130 | disp('plotmodel warning: mask length not supported yet (supported length are md.numberofnodes and md.numberofelements');
|
---|
[7244] | 131 | end
|
---|
[1] | 132 | end
|
---|
[7244] | 133 |
|
---|
[1124] | 134 | %log?
|
---|
[2439] | 135 | if exist(options,'log'),
|
---|
[6497] | 136 | bounds=getfieldvalue(options,'caxis',[min(data(:)) max(data(:))]);
|
---|
[6708] | 137 | data(find(data<bounds(1)))=bounds(1);
|
---|
| 138 | if any(data<=0),
|
---|
[6497] | 139 | error('Log option cannot be applied on negative values. Use caxis option (Rignot''s settings: [1.5 max(data)])');
|
---|
| 140 | end
|
---|
[1218] | 141 | pos=find(~isnan(data));
|
---|
[2439] | 142 | data(pos)=log(data(pos))/log(getfieldvalue(options,'log'));
|
---|
[1124] | 143 | end
|
---|
[1] | 144 | end
|
---|
| 145 |
|
---|
[8298] | 146 | %node data
|
---|
| 147 | if (datasize(1)==md.numberofnodes & datasize(2)==1),
|
---|
[4411] | 148 | datatype=2;
|
---|
[7244] | 149 |
|
---|
| 150 | %Mask?
|
---|
| 151 | if exist(options,'mask'),
|
---|
| 152 | flags=getfieldvalue(options,'mask');
|
---|
| 153 | pos=find(~flags);
|
---|
[8298] | 154 | if length(flags)==md.numberofnodes,
|
---|
[7244] | 155 | data(pos,:)=NaN;
|
---|
| 156 | elseif length(flags)==md.numberofelements
|
---|
| 157 | data(md.elements(pos,:),:)=NaN;
|
---|
| 158 | else
|
---|
[8298] | 159 | disp('plotmodel warning: mask length not supported yet (supported length are md.numberofnodes and md.numberofelements');
|
---|
[7244] | 160 | end
|
---|
[1] | 161 | end
|
---|
[7244] | 162 |
|
---|
[1124] | 163 | %log?
|
---|
[2439] | 164 | if exist(options,'log'),
|
---|
[6911] | 165 | %if any(data<=0),
|
---|
| 166 | % error('Log option cannot be applied on negative values. Use caxis option (Rignot''s settings: [1.5 max(data)])');
|
---|
| 167 | %end
|
---|
[2439] | 168 | data=log(data)/log(getfieldvalue(options,'log'));
|
---|
[1124] | 169 | end
|
---|
[1] | 170 | end
|
---|
| 171 |
|
---|
| 172 | %layer projection?
|
---|
[2439] | 173 | if getfieldvalue(options,'layer',0)>=1,
|
---|
| 174 | data=project2d(md,data,getfieldvalue(options,'layer')); %project onto 2d mesh
|
---|
[1] | 175 | end
|
---|
[1744] | 176 |
|
---|
| 177 | %control arrow density if quiverplot
|
---|
[4330] | 178 | if datatype==3 & exist(options,'density')
|
---|
[1744] | 179 | databak=data;
|
---|
| 180 | data=NaN*ones(datasize);
|
---|
[2439] | 181 | density=getfieldvalue(options,'density');
|
---|
| 182 | data(1:density:end,:)=databak(1:density:end,:);
|
---|
[1744] | 183 | clear databak
|
---|
| 184 | end
|
---|
[8577] | 185 |
|
---|
| 186 | %OK, if datatype=0 error out
|
---|
| 187 | if datatype==0,
|
---|
| 188 | error(['data provided not recognized or not supported']);
|
---|
| 189 | end
|
---|