Changeset 535
 Timestamp:
 Sep 3, 2012, 2:02:13 PM (11 years ago)
 Location:
 trunk/src
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/find_field_cells.m
r530 r535 55 55 56 56 function [CellInfo,NbDim,errormsg]=find_field_cells(Data) 57 % CellVarIndex={}; 58 % CellInfo={} 57 59 58 NbDim=0; 60 % CellVarType=[]; 61 errormsg=[]; 59 errormsg=''; 62 60 if ~isfield(Data,'ListVarName'), errormsg='the list of variables .ListVarName is missing';return;end 63 61 if ~isfield(Data,'VarDimName'), errormsg='the list of dimensions .VarDimName is missing';return;end 64 62 nbvar=numel(Data.ListVarName);%number of field variables 65 63 if ~isequal(numel(Data.VarDimName),nbvar), errormsg='.ListVarName and .VarDimName have unequal length';return;end 66 if isfield(Data,'ListDimName')&& isfield(Data,'DimValue')&&isequal(numel(Data.ListDimName),numel(Data.DimValue)) 67 check_dim=1;% dimensions of data defined, data not needed for this function 68 else 69 check_dim=0; 70 for ilist=1:numel(Data.ListVarName) 71 if ~isfield(Data,Data.ListVarName{ilist}) 72 errormsg=['missing variable ' Data.ListVarName{ilist}]; 73 return 74 end 75 end 76 end 77 icell=0; 78 79 % NbDim=[]; 80 % VarDimIndex=[]; 81 % VarDimName={}; 64 % check the existence of variable data 65 check_var=1; 66 for ilist=1:numel(Data.ListVarName) 67 if ~isfield(Data,Data.ListVarName{ilist}) 68 check_var=0;% dimensions of data defined, data not needed for this function 69 break 70 end 71 end 72 if ~check_var && ~(isfield(Data,'ListDimName')&& isfield(Data,'DimValue')&&isequal(numel(Data.ListDimName),numel(Data.DimValue))) 73 errormsg=['missing variable or values of dimensions' Data.ListVarName{ilist}]; 74 return 75 end 76 82 77 83 78 %% role of variables and list of requested operations … … 127 122 CellInfo{icell}.CoordIndex=ivar_coord_x(icell); 128 123 % size of coordinate var 129 if check_dim 124 if check_var 125 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)})); 126 else 130 127 for idim=1:numel(DimCell) 131 128 check_index= strcmp(DimCell{idim},Data.ListDimName); … … 133 130 end 134 131 CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize); 135 else136 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));137 132 end 138 133 ind_y=find(strcmp('coord_y',Role(VarIndex))); … … 157 152 158 153 %% look for tps coordinates 159 ivar_remain=find(~check_select); 154 ivar_remain=find(~check_select);% indices of remaining variables (not already selected) 160 155 check_coord_tps= strcmp('coord_tps',Role(~check_select)); 161 ivar_tps=ivar_remain(check_coord_tps); 156 ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates 162 157 for icell_tps=1:numel(ivar_tps) 163 DimCell=Data.VarDimName{ivar_tps(icell_tps)}; 164 icell=numel(CellInfo)+icell_tps; 165 CellInfo{icell}.CoordIndex=ivar_tps(icell );158 DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable 159 icell=numel(CellInfo)+icell_tps; % new field cell index 160 CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable 166 161 CellInfo{icell}.VarIndex_subrange_tps=[]; 167 162 CellInfo{icell}.VarIndex_nbsites_tps=[]; … … 182 177 CellInfo{icell}.CoordType='tps'; 183 178 CellInfo{icell}.VarIndex=find(check_cell); 184 if check_dim 179 if check_var 180 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); 181 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); 182 else 185 183 check_index_1= strcmp(DimCell{1},Data.ListDimName); 186 184 check_index_2= strcmp(DimCell{2},Data.ListDimName); … … 188 186 NbDim(icell)=Data.DimValue(check_index_2); 189 187 CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); 190 else191 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);192 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);193 188 end 194 189 check_select=check_selectcheck_cell; 195 190 end 196 191 197 %% look for dimension variables and corresponding gridded data 198 ivar_remain=find(~check_select); 192 %% look for coordinate variables and corresponding gridded data: 193 % coordinate variables are variables associated with a single dimension, defining the coordinate values 194 % two cases: 1)the coordiante variable represents the set of coordiante values 195 % 2)the coordinate variable contains only two elements, representing the coordinate bounds for the dimension with the same name as the cordinate 196 ivar_remain=find(~check_select);% indices of remaining variables, not already taken into account 197 ListVarName=Data.ListVarName(~check_select);%list of remaining variables 199 198 VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables 200 check_coord= cellfun(@numel,VarDimName)==1cellfun(@ischar,VarDimName)==1;% find variables with a single dimension 201 ListCoordIndex=ivar_remain(check_coord); 202 ListCoordName=Data.ListVarName(ListCoordIndex); 203 ListDimName=Data.VarDimName(ListCoordIndex); 204 %remove redondant values 199 check_coord= cellfun(@numel,VarDimName)==1cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension 200 ListCoordIndex=ivar_remain(check_coord);% indices of remaining variables with a single dimension 201 ListCoordName=Data.ListVarName(ListCoordIndex);% corresponding names of remaining variables with a single dimension 202 ListDimName=Data.VarDimName(ListCoordIndex);% dimension names of remaining variables with a single dimension 203 204 %remove redondant variables > keep only one variable per dimension 205 205 check_keep=logical(ones(size(ListDimName))); 206 206 for idim=1:numel(ListDimName) 207 prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim1)); 207 prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim1));% check whether the dimension is already taken into account 208 208 if ~isempty(prev_ind) 209 if strcmp(ListCoordName{idim},ListDimName{idim}) % coordinate variable209 if strcmp(ListCoordName{idim},ListDimName{idim}) %variable with the same name as the coordinate taken in priority 210 210 check_keep(prev_ind)=0; 211 211 else … … 214 214 end 215 215 end 216 ListCoordIndex=ListCoordIndex(check_keep); 217 ListCoordName=ListCoordName(check_keep); 218 ListDimName=ListDimName(check_keep); 219 220 CoordSize=[]; 216 ListCoordIndex=ListCoordIndex(check_keep);% list of coordinate variable indices 217 ListCoordName=ListCoordName(check_keep);% list of coordinate variable names 218 ListDimName=ListDimName(check_keep);% list of coordinate dimension names 219 220 % determine dimension sizes 221 CoordSize=zeros(size(ListCoordIndex)); 221 222 for ilist=1:numel(ListCoordIndex) 222 223 if iscell(ListDimName{ilist}) 223 224 ListDimName(ilist)=ListDimName{ilist};%transform cell to string 224 225 end 225 if check_dim% if the list of dimensions is directly defined 226 check_index= strcmp(ListDimName{ilist},Data.ListDimName); 227 DimValue=Data.DimValue(check_index); 226 if check_var% if the list of dimensions has been directly defined, no variable data available 227 CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist 228 228 else 229 DimValue=numel(Data.(ListCoordName{ilist})); 230 end 231 if DimValue==2% case of uniform grid coordinate defined by lower and upper bounds only 232 ListDimName{ilist}=ListCoordName{ilist};% look for dimensions with name equal to coordinate for 233 if check_dim 234 check_index= strcmp(ListCoordName{ilist},Data.ListDimName); 235 CoordSize(ilist)=Data.DimValue(check_index); 236 else 237 CoordSize(ilist)=numel(Data.(ListCoordName{ilist})); 238 end 239 else 240 CoordSize(ilist)=DimValue; 241 end 242 end 229 check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the index in the list of dimensions 230 CoordSize(ilist)=Data.DimValue(check_index);% find the corresponding dimension value 231 end 232 if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only 233 ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name 234 % if check_var 235 % check_index= strcmp(ListCoordName{ilist},Data.ListDimName); 236 % CoordSize(ilist)=Data.DimValue(check_index); 237 % else 238 % CoordSize(ilist)=numel(Data.(ListCoordName{ilist})); 239 % % end 240 % else 241 % CoordSize(ilist)=DimValue; 242 end 243 end 244 245 % group the remaining variables in cells sharing the same coordinate variables 243 246 NewCellInfo={}; 244 247 NewCellDimIndex={}; 245 248 NewNbDim=[]; 246 for ivardim=1:numel(VarDimName) % loop onthe list of remaining variables247 DimCell=VarDimName{ivardim};% dimension names of the current variable 249 for ivardim=1:numel(VarDimName) % loop at the list of remaining variables 250 DimCell=VarDimName{ivardim};% dimension names of the current variable 248 251 if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed 249 252 DimIndices=[]; 250 253 for idim=1:numel(DimCell) 251 ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coord dimensions254 ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coordinate variables 252 255 if ~isempty(ind_dim) 253 256 DimIndices=[DimIndices ind_dim]; %update the list of coord dimensions included in DimCell 254 end 255 end 257 if check_var && CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordiante variable limited to lower and upper bounds 258 if isvector(Data.(ListVarName{ivardim}))  iscolumn(Data.(ListVarName{ivardim})) 259 if numel(Data.(ListVarName{ivardim}))>2 260 CoordSize(ind_dim)=numel(Data.(ListVarName{ivardim})); 261 end 262 else 263 CoordSize(ind_dim)=size(Data.(ListVarName{ivardim}),idim); 264 end 265 end 266 end 267 end 268 % look for cells of variables with the same coordinate variables 256 269 check_previous=0; 257 270 for iprev=1:numel(NewCellInfo) … … 262 275 end 263 276 end 277 % create a new cell if no previous one contains the coordinate variables 264 278 if ~check_previous 265 279 nbcell=numel(NewCellInfo)+1; 
trunk/src/plot_field.m
r530 r535 270 270 Data={}; 271 271 for icell=1:length(CellInfo) 272 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 272 273 % select types of variables to be projected 274 ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 275 check_proj=false(size(FieldData.ListVarName)); 276 for ilist=1:numel(ListProj) 277 if isfield(CellInfo{icell},ListProj{ilist}) 278 check_proj(CellInfo{icell}.(ListProj{ilist}))=1; 279 end 280 end 281 VarIndex=find(check_proj); 282 % 283 % VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 284 % for ivar=1:length(VarIndex) 285 % checkancillary=0; 286 % if length(FieldData.VarAttribute)>=VarIndex(ivar) 287 % VarAttribute=FieldData.VarAttribute{VarIndex(ivar)}; 288 % if isfield(VarAttribute,'Role')&&(strcmp(VarAttribute.Role,'ancillary')strcmp(VarAttribute.Role,'coord_tps')... 289 % strcmp(VarAttribute.Role,'vector_x_tps')strcmp(VarAttribute.Role,'vector_y_tps')) 290 % checkancillary=1; 291 % end 292 % end 293 % if ~checkancillary% does not display variables with attribute '.Role=ancillary' 273 294 for ivar=1:length(VarIndex) 274 checkancillary=0; 275 if length(FieldData.VarAttribute)>=VarIndex(ivar) 276 VarAttribute=FieldData.VarAttribute{VarIndex(ivar)}; 277 if isfield(VarAttribute,'Role')&&(strcmp(VarAttribute.Role,'ancillary')strcmp(VarAttribute.Role,'coord_tps')... 278 strcmp(VarAttribute.Role,'vector_x_tps')strcmp(VarAttribute.Role,'vector_y_tps')) 279 checkancillary=1; 280 end 281 end 282 % if ~checkancillary% does not display variables with attribute '.Role=ancillary' 283 VarName=FieldData.ListVarName{VarIndex(ivar)}; 284 VarValue=FieldData.(VarName); 285 Data =[Data [{VarName}; num2cell(VarValue)]]; 286 if size(VarValue,1)~=1 287 VarValue=VarValue';% put the different values on a line 288 end 289 if size(VarValue,1)==1 290 txt=[VarName '=' num2str(VarValue)]; 291 txt_cell=[txt_cell;{txt}]; 292 end 293 % end 295 VarName=FieldData.ListVarName{VarIndex(ivar)}; 296 VarValue=FieldData.(VarName); 297 if iscolumn(VarValue) 298 VarValue=VarValue';% put the different values on a line 299 end 300 if numel(VarValue)>1 && numel(VarValue)<10 301 for ind=1:numel(VarValue) 302 VarNameCell{1,ind}=[VarName '_' num2str(ilist)]; 303 end 304 else 305 VarNameCell={VarName}; 306 end 307 if numel(VarValue)<10 308 Data =[Data [VarNameCell; num2cell(VarValue)]]; 309 else 310 Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]]; 311 end 312 if size(VarValue,1)==1 313 txt=[VarName '=' num2str(VarValue)]; 314 txt_cell=[txt_cell;{txt}]; 315 end 294 316 end 295 317 end 
trunk/src/uvmat.m
r534 r535 293 293 display_file_name(handles,inputfile) 294 294 %%%%%%% 295 testinputfield=1;296 295 end 297 296 … … 2404 2403 %% get bounds and mesh (needed to propose default options for projection objects) 2405 2404 if NbDim>1 2406 CoordMax=zeros(1,numel(imax)); 2407 CoordMin=zeros(1,numel(imax)); 2405 CoordMax=zeros(numel(imax),NbDim); 2406 CoordMin=zeros(numel(imax),NbDim); 2407 Mesh=zeros(numel(imax),NbDim); 2408 2408 for ind=1:numel(imax) 2409 2409 XName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)}; 2410 2410 YName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end1)}; 2411 CoordMax(ind, 1)=max(max(UvData.Field.(XName)));2412 CoordMin(ind, 1)=min(min(UvData.Field.(XName)));2413 CoordMax(ind, 2)=max(max(UvData.Field.(YName)));2414 CoordMin(ind, 2)=min(min(UvData.Field.(YName)));2411 CoordMax(ind,NbDim)=max(max(UvData.Field.(XName))); 2412 CoordMin(ind,NbDim)=min(min(UvData.Field.(XName))); 2413 CoordMax(ind,NbDim1)=max(max(UvData.Field.(YName))); 2414 CoordMin(ind,NbDim1)=min(min(UvData.Field.(YName))); 2415 2415 % test_x=1;%test for unstructured coordinates 2416 2416 if NbDim==3 2417 2417 ZName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)}; 2418 CoordMax(imax(ind), 3)=max(max(UvData.Field.(ZName)));2419 CoordMin(ind, 3)=min(min(UvData.Field.(ZName)));2418 CoordMax(imax(ind),1)=max(max(UvData.Field.(ZName))); 2419 CoordMin(ind,1)=min(min(UvData.Field.(ZName))); 2420 2420 end 2421 2421 … … 2423 2423 2424 2424 case 'scattered' %unstructured coordinates 2425 NbPoints (ind)=CellInfo{imax(ind)}.CoordSize;% nbre of points2426 Mesh(ind )=(prod(CoordMax(ind,:)CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)2425 NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points 2426 Mesh(ind,:)=(prod(CoordMax(ind,:)CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim) 2427 2427 case 'grid'%structured coordinate 2428 NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points 2429 Mesh(ind)=min((CoordMax(ind,:)CoordMin(ind,:))./NbPoints); 2430 2428 NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction 2429 Mesh(ind,:)=min((CoordMax(ind,:)CoordMin(ind,:))./(NbPoints1)); 2431 2430 end 2432 2431 end … … 2525 2524 % main projection object (uvmat display) 2526 2525 list_object=get(handles.ListObject_1,'String'); 2527 if isequal(list_object,{''}) %refresh list of objects if the menu is empty2526 if isequal(list_object,{''})isequal(list_object,' ')%refresh list of objects if the menu is empty 2528 2527 set(handles.ListObject,'Value',1) 2529 2528 set(handles.ListObject,'String',{'plane'})
Note: See TracChangeset
for help on using the changeset viewer.