[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 |
|
---|
[10284] | 44 | %Process NaN if any (do not now before mask is applied)
|
---|
| 45 | if exist(options,'nan')
|
---|
| 46 | data(find(isnan(data)))=getfieldvalue(options,'nan',0);
|
---|
| 47 | end
|
---|
[4330] | 48 | %non patch processing
|
---|
[7098] | 49 | if datatype~=4 & datatype~=5,
|
---|
[2700] | 50 |
|
---|
[4330] | 51 | %transpose data if necessary
|
---|
| 52 | if (size(data,2) > size(data,1)),
|
---|
| 53 | data=data';
|
---|
| 54 | end
|
---|
| 55 | datasize=size(data);
|
---|
[1] | 56 |
|
---|
[4330] | 57 | %convert to double if necessary
|
---|
| 58 | if ~isnumeric(data);
|
---|
| 59 | disp('processdata info message: data is not numeric (logical?). Converted to double');
|
---|
| 60 | data=double(data);
|
---|
| 61 | end
|
---|
[1740] | 62 |
|
---|
[4330] | 63 | %check length
|
---|
[9725] | 64 | if datasize(1)~=md.mesh.numberofvertices & datasize(1)~=md.mesh.numberofelements & datasize(1)~=md.mesh.numberofvertices*6 & (md.mesh.dimension==3 & ~(datasize(1)==md.mesh.numberofelements2d | datasize(1)==md.mesh.numberofvertices2d))
|
---|
[4330] | 65 | error('plotmodel error message: data not supported yet');
|
---|
| 66 | end
|
---|
| 67 |
|
---|
| 68 | %quiver?
|
---|
| 69 | if datasize(2)>1,
|
---|
| 70 | datatype=3;
|
---|
| 71 |
|
---|
| 72 | %check number of columns, add zeros if necessary,
|
---|
[9719] | 73 | if (md.mesh.dimension==3)
|
---|
[4330] | 74 | if datasize(2)==2,
|
---|
| 75 | data=[data, zeros(datasize(1),1)];
|
---|
| 76 | elseif datasize(2)~=3,
|
---|
| 77 | error('plotmodel error message: data provided should have 2 or 3 columns for quiver plot, and 1 for regular plot');
|
---|
| 78 | end
|
---|
[9719] | 79 | %elseif ((md.mesh.dimension==2) & datasize(2)~=2),
|
---|
[5867] | 80 | % error('plotmodel error message: data provided should have 2 columns for quiver plot, and 1 for regular plot');
|
---|
[1740] | 81 | end
|
---|
| 82 | end
|
---|
| 83 |
|
---|
[8298] | 84 | %treat the case datasize(1)=6*nodes
|
---|
[9725] | 85 | if datasize(1)==6*md.mesh.numberofvertices
|
---|
[4330] | 86 | %keep the only norm of data
|
---|
[9725] | 87 | data1=data(1:6:md.mesh.numberofvertices*6,:);
|
---|
| 88 | data2=data(2:6:md.mesh.numberofvertices*6,:);
|
---|
[4330] | 89 | data=sqrt(data1.^2+data2.^2);
|
---|
[9725] | 90 | datasize(1)=md.mesh.numberofvertices;
|
---|
[8298] | 91 | %---> go to node data
|
---|
[4330] | 92 | end
|
---|
[1740] | 93 |
|
---|
[8298] | 94 | %treat the case datasize(1)=nodes2d
|
---|
[9725] | 95 | if (md.mesh.dimension==3 & datasize(1)==md.mesh.numberofvertices2d),
|
---|
[4330] | 96 | data=project3d(md,data,'node');
|
---|
[9725] | 97 | datasize(1)=md.mesh.numberofvertices;
|
---|
[8298] | 98 | %---> go to node data
|
---|
[4330] | 99 | end
|
---|
[1] | 100 |
|
---|
[8298] | 101 | %treat the case datasize(1)=nodes2d
|
---|
[9725] | 102 | if (md.mesh.dimension==3 & datasize(1)==md.mesh.numberofelements2d),
|
---|
[4330] | 103 | data=project3d(md,data,'element');
|
---|
[9725] | 104 | datasize(1)=md.mesh.numberofelements;
|
---|
[8298] | 105 | %---> go to node data
|
---|
[4330] | 106 | end
|
---|
[27] | 107 |
|
---|
[4330] | 108 | %smoothing?
|
---|
| 109 | if exist(options,'smooth')
|
---|
| 110 | data=averaging(md,data,getfieldvalue(options,'smooth'));
|
---|
[9725] | 111 | datasize(1)=md.mesh.numberofvertices;
|
---|
[8298] | 112 | %---> go to node data
|
---|
[4330] | 113 | end
|
---|
[2426] | 114 | end
|
---|
| 115 |
|
---|
[1] | 116 | %element data
|
---|
[9725] | 117 | if (datasize(1)==md.mesh.numberofelements & datasize(2)==1),
|
---|
[1] | 118 |
|
---|
[4330] | 119 | %Initialize datatype if non patch
|
---|
[7098] | 120 | if datatype~=4 & datatype~=5,
|
---|
[4330] | 121 | datatype=1;
|
---|
| 122 | end
|
---|
| 123 |
|
---|
[7244] | 124 | %Mask?
|
---|
| 125 | if exist(options,'mask'),
|
---|
| 126 | flags=getfieldvalue(options,'mask');
|
---|
| 127 | pos=find(~flags);
|
---|
[9725] | 128 | if length(flags)==md.mesh.numberofvertices,
|
---|
[9733] | 129 | [pos2 dummy]=find(ismember(md.mesh.elements,pos));
|
---|
[7244] | 130 | data(pos2,:)=NaN;
|
---|
[9725] | 131 | elseif length(flags)==md.mesh.numberofelements
|
---|
[7244] | 132 | data(pos,:)=NaN;
|
---|
| 133 | else
|
---|
[9725] | 134 | disp('plotmodel warning: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements');
|
---|
[7244] | 135 | end
|
---|
[1] | 136 | end
|
---|
[7244] | 137 |
|
---|
[1124] | 138 | %log?
|
---|
[2439] | 139 | if exist(options,'log'),
|
---|
[6497] | 140 | bounds=getfieldvalue(options,'caxis',[min(data(:)) max(data(:))]);
|
---|
[6708] | 141 | data(find(data<bounds(1)))=bounds(1);
|
---|
| 142 | if any(data<=0),
|
---|
[6497] | 143 | error('Log option cannot be applied on negative values. Use caxis option (Rignot''s settings: [1.5 max(data)])');
|
---|
| 144 | end
|
---|
[1218] | 145 | pos=find(~isnan(data));
|
---|
[2439] | 146 | data(pos)=log(data(pos))/log(getfieldvalue(options,'log'));
|
---|
[1124] | 147 | end
|
---|
[1] | 148 | end
|
---|
| 149 |
|
---|
[8298] | 150 | %node data
|
---|
[9725] | 151 | if (datasize(1)==md.mesh.numberofvertices & datasize(2)==1),
|
---|
[4411] | 152 | datatype=2;
|
---|
[7244] | 153 |
|
---|
| 154 | %Mask?
|
---|
| 155 | if exist(options,'mask'),
|
---|
| 156 | flags=getfieldvalue(options,'mask');
|
---|
| 157 | pos=find(~flags);
|
---|
[9725] | 158 | if length(flags)==md.mesh.numberofvertices,
|
---|
[7244] | 159 | data(pos,:)=NaN;
|
---|
[9725] | 160 | elseif length(flags)==md.mesh.numberofelements
|
---|
[9733] | 161 | data(md.mesh.elements(pos,:),:)=NaN;
|
---|
[7244] | 162 | else
|
---|
[9725] | 163 | disp('plotmodel warning: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements');
|
---|
[7244] | 164 | end
|
---|
[1] | 165 | end
|
---|
[7244] | 166 |
|
---|
[1124] | 167 | %log?
|
---|
[2439] | 168 | if exist(options,'log'),
|
---|
[6911] | 169 | %if any(data<=0),
|
---|
| 170 | % error('Log option cannot be applied on negative values. Use caxis option (Rignot''s settings: [1.5 max(data)])');
|
---|
| 171 | %end
|
---|
[2439] | 172 | data=log(data)/log(getfieldvalue(options,'log'));
|
---|
[1124] | 173 | end
|
---|
[1] | 174 | end
|
---|
| 175 |
|
---|
| 176 | %layer projection?
|
---|
[2439] | 177 | if getfieldvalue(options,'layer',0)>=1,
|
---|
| 178 | data=project2d(md,data,getfieldvalue(options,'layer')); %project onto 2d mesh
|
---|
[1] | 179 | end
|
---|
[1744] | 180 |
|
---|
| 181 | %control arrow density if quiverplot
|
---|
[4330] | 182 | if datatype==3 & exist(options,'density')
|
---|
[1744] | 183 | databak=data;
|
---|
| 184 | data=NaN*ones(datasize);
|
---|
[2439] | 185 | density=getfieldvalue(options,'density');
|
---|
| 186 | data(1:density:end,:)=databak(1:density:end,:);
|
---|
[1744] | 187 | clear databak
|
---|
| 188 | end
|
---|
[8577] | 189 |
|
---|
| 190 | %OK, if datatype=0 error out
|
---|
| 191 | if datatype==0,
|
---|
| 192 | error(['data provided not recognized or not supported']);
|
---|
| 193 | end
|
---|