- Timestamp:
- May 21, 2018, 7:06:45 PM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/find_field_cells.m
r1041 r1045 18 18 % _vector_x,_y,_z: indices of variables giving the vector components x, y, z 19 19 % _warnflag: index of warnflag 20 % .DimIndex 20 21 % .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation or derivatives (tps) is needed to calculate the requested field 21 22 % .FieldName = operation to be performed to finalise the field cell after projection … … 64 65 65 66 function [CellInfo,NbDim,errormsg]=find_field_cells(Data) 66 CellInfo={}; 67 CellInfo={};%default output 67 68 NbDim=0; 68 69 errormsg=''; … … 87 88 FieldName=cell(size(Role)); % fieldRequest set to {} by default 88 89 CheckSub=zeros(size(Role));% =1 for fields to substract 89 Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default90 %Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default 90 91 if isfield(Data,'VarAttribute') 91 92 for ivar=1:numel(Data.VarAttribute) … … 105 106 end 106 107 107 %% find scattered (unstructured) coordinates 108 ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x' 109 check_select=false(1,nbvar); 110 check_coord=false(1,nbvar); 111 CellInfo=cell(1,numel(ivar_coord_x)); 112 NbDim=zeros(1,numel(ivar_coord_x)); 113 % loop on unstructured coordinate x -> different field cells 114 for icell=1:numel(ivar_coord_x) 115 DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell) 116 if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension 117 % look for variables sharing dimension(s) with ivar_coord_x(icell) 118 check_cell=zeros(numel(DimCell),nbvar); 119 for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension 120 for ivar=1:nbvar 121 check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar})); 122 end 123 end 124 check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell 125 VarIndex=find(check_cell);% list of detected variable indices 126 if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later) 127 if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate 128 CellInfo{icell}.CoordIndex=ivar_coord_x(icell); 129 % size of coordinate var 108 %% detect fields with different roles 109 ind_scalar=find(strcmp('scalar',Role)); 110 ind_errorflag=find(strcmp('errorflag',Role)); 111 ind_image=find(strcmp('image',Role)); 112 ind_vector_x=[find(strcmp('vector_x',Role)) find(strcmp('vector_x_tps',Role))]; 113 if ~isempty(ind_vector_x) 114 ind_vector_y=[find(strcmp('vector_y',Role)) find(strcmp('vector_y_tps',Role))]; 115 ind_vector_z=find(strcmp('vector_z',Role)); 116 ind_warnflag=find(strcmp('warnflag',Role)); 117 ind_ancillary=find(strcmp('ancillary',Role)); 118 end 119 ind_discrete=find(strcmp('discrete',Role)); 120 ind_coord_x=find(strcmp('coord_x',Role)); 121 ind_coord_y=find(strcmp('coord_y',Role)); 122 ind_coord_z=find(strcmp('coord_z',Role)); 123 ind_coord_tps=find(strcmp('coord_tps',Role)); 124 check_string=cellfun(@ischar,Data.VarDimName)==1; 125 index_string=find(check_string); 126 for ivar=index_string 127 Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char strings into cells 128 end 129 check_coord_names= cellfun(@numel,Data.VarDimName)==1; 130 check_coord_raster=false(size(check_coord_names));% check variables describing regular mesh (raster coordinates), from two values, min and max. 131 if check_var 132 for ivar=find(check_coord_names) 133 if numel(Data.(Data.ListVarName{ivar}))==2 134 check_coord_raster(ivar)=true; 135 end 136 end 137 else 138 for ivar=find(check_coord_names) 139 DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName)); 140 if Data.DimValue(DimIndex)==2 141 check_coord_raster(ivar)=true; 142 end 143 end 144 end 145 146 147 %% initate cells around each scalar field 148 index_remove=[]; 149 cell_nbre=numel(ind_scalar)+numel(ind_vector_x); 150 flag_remove=false(1,cell_nbre); 151 NbDim=zeros(1,cell_nbre); 152 index_coord_x=zeros(size(ind_coord_x)); 153 for icell=1:numel(ind_scalar) 154 CellInfo{icell}.VarType='scalar'; 155 CellInfo{icell}.VarIndex_scalar=ind_scalar(icell); 156 CellInfo{icell}.VarIndex=ind_scalar(icell); 157 DimCell_var=Data.VarDimName{ind_scalar(icell)};% cell of dimension names for ivar_coord_x(icell) 158 %look for errorflag 159 for ivar=ind_errorflag 160 DimCell=Data.VarDimName{ivar}; 161 if isequal(DimCell,DimCell_var) 162 CellInfo{icell}.VarIndex(2)=ivar; 163 CellInfo{icell}.VarIndex_errorflag=ivar; 164 break 165 end 166 end 167 end 168 169 %% initate cells around each vector field 170 for icell=numel(ind_scalar)+1:cell_nbre 171 CellInfo{icell}.VarType='vector'; 172 CellInfo{icell}.VarIndex(1)=ind_vector_x(icell-numel(ind_scalar)); 173 CellInfo{icell}.VarIndex_vector_x=ind_vector_x(icell-numel(ind_scalar)); 174 DimCell_var=Data.VarDimName{ind_vector_x(icell-numel(ind_scalar))};% cell of dimension names for ivar_coord_x(icell) 175 % look for the associated y vector component 176 nbvar=1; 177 for ivar=ind_vector_y 178 DimCell=Data.VarDimName{ivar}; 179 if isequal(DimCell,DimCell_var) 180 CellInfo{icell}.VarIndex(2)=ivar; 181 nbvar=2; 182 CellInfo{icell}.VarIndex_vector_y=ivar; 183 break 184 end 185 end 186 if ~isfield(CellInfo{icell},'VarIndex_vector_y') 187 flag_remove(icell)=true;% no vector_y found , mark cell to remove 188 end 189 % look for the associated z vector component 190 for ivar=ind_vector_z 191 DimCell=Data.VarDimName{ivar}; 192 if isequal(DimCell,DimCell_var) 193 CellInfo{icell}.VarIndex(3)=ivar; 194 nbvar=3; 195 break 196 end 197 end 198 %look for the vector color scalar (ancillary) 199 for ivar=ind_ancillary 200 DimCell=Data.VarDimName{ivar}; 201 if isequal(DimCell,DimCell_var) 202 nbvar=nbvar+1; 203 CellInfo{icell}.VarIndex(nbvar)=ivar; 204 CellInfo{icell}.VarIndex_ancillary=ivar; 205 break 206 end 207 end 208 %look for warnflag 209 for ivar=ind_warnflag 210 DimCell=Data.VarDimName{ivar}; 211 if isequal(DimCell,DimCell_var) 212 nbvar=nbvar+1; 213 CellInfo{icell}.VarIndex(nbvar)=ivar; 214 CellInfo{icell}.VarIndex_warnflag=ivar; 215 break 216 end 217 end 218 %look for errorflag 219 for ivar=ind_errorflag 220 DimCell=Data.VarDimName{ivar}; 221 if isequal(DimCell,DimCell_var) 222 nbvar=nbvar+1; 223 CellInfo{icell}.VarIndex(nbvar)=ivar; 224 CellInfo{icell}.VarIndex_errorflag=ivar; 225 break 226 end 227 end 228 end 229 230 %% find coordinates for each cell around field variables, scalars or vectors 231 for icell=1:cell_nbre 232 CellInfo{icell}.CoordType=''; 233 ind_var=CellInfo{icell}.VarIndex(1); 234 DimCell_var=Data.VarDimName{ind_var};% cell of dimension names for ivar_coord_x(icell) 235 if ~check_var 236 for idim=1:numel(DimCell_var) 237 CellInfo{icell}.DimIndex(idim)=find(strcmp(DimCell_var{idim},Data.ListDimName)); 238 end 239 end 240 %look for z scattered coordinates 241 if isempty(ind_coord_z) 242 NbDim(icell)=2; 243 CellInfo{icell}.CoordIndex=[0 0]; 244 else 245 NbDim(icell)=3; 246 CellInfo{icell}.CoordIndex=[0 0 0]; 247 for ivar=ind_coord_z 248 DimCell=Data.VarDimName{ivar}; 249 if isequal(DimCell,DimCell_var) 250 CellInfo{icell}.CoordType='scattered'; 251 CellInfo{icell}.CoordIndex(1)=ivar; 252 CellInfo{icell}.ZName=Data.ListVarName{ivar}; 253 CellInfo{icell}.ZIndex=ivar; 254 break 255 end 256 end 257 end 258 % look for y coordinate 259 for ivar=ind_coord_y 260 % detect scattered y coordinates, variable with the same dimension(s) as the field variable considered 261 DimCell=Data.VarDimName{ivar}; 262 if isequal(DimCell,DimCell_var) 263 CellInfo{icell}.CoordType='scattered'; 264 CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar; 265 CellInfo{icell}.YName=Data.ListVarName{ivar}; 266 CellInfo{icell}.YIndex=ivar; 267 break 268 end 269 end 270 271 %look for x coordinates 272 if strcmp(CellInfo{icell}.CoordType,'scattered') 273 for ivar=ind_coord_x 274 DimCell=Data.VarDimName{ivar}; 275 if isequal(DimCell,DimCell_var) 276 CellInfo{icell}.CoordIndex(NbDim(icell))=ivar; 277 CellInfo{icell}.XName=Data.ListVarName{ivar}; 278 CellInfo{icell}.XIndex=ivar; 279 break 280 end 281 end 282 end 283 if isfield(CellInfo{icell},'ZName') 284 if isfield(CellInfo{icell},'YName')&& isfield(CellInfo{icell},'XName') 285 continue %scattered coordinates OK 286 end 287 else 288 if isfield(CellInfo{icell},'YName') 289 if isfield(CellInfo{icell},'XName') 290 NbDim(icell)=2; 291 continue %scattered coordinates OK 292 end 293 else 294 if isfield(CellInfo{icell},'XName'); % only one coordinate x, switch vector field to 1D plot 295 for ind=1:numel(CellInfo{icell}.VarIndex) 296 Role{CellInfo{icell}.VarIndex(ind)}='coord_y'; 297 end 298 continue 299 end 300 end 301 end 302 303 %look for grid coordinates 304 if isempty(CellInfo{icell}.CoordType) 305 NbDim(icell)=numel(DimCell_var); 306 CellInfo{icell}.DimOrder=[]; 307 if NbDim(icell)==3 308 %coord z 309 for ivar=ind_coord_z 310 if check_coord_names(ivar) 311 DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); 312 check_coord=~isempty(DimRank); 313 elseif check_coord_raster(ivar) 314 DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); 315 check_coord=~isempty(DimRank); 316 end 317 % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{1}))||...% coord varbable 318 % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{1})); % rasrewr coord defined by min and max 319 if check_coord 320 CellInfo{icell}.CoordType='grid'; 321 CellInfo{icell}.CoordIndex(1)=ivar; 322 CellInfo{icell}.ZName=Data.ListVarName{ivar}; 323 CellInfo{icell}.ZIndex=ivar; 324 CellInfo{icell}.DimOrder=DimRank; 325 break 326 end 327 end 328 end 329 for ivar=ind_coord_y 330 if check_coord_names(ivar) 331 DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); 332 check_coord=~isempty(DimRank); 333 elseif check_coord_raster(ivar) 334 DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); 335 check_coord=~isempty(DimRank); 336 end 337 % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)-1}))||...% coord variable 338 % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)-1})); % rasrewr coord defined by min and max 339 if check_coord 340 CellInfo{icell}.CoordType='grid'; 341 CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar; 342 CellInfo{icell}.YName=Data.ListVarName{ivar}; 343 CellInfo{icell}.YIndex=ivar; 344 CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank]; 345 break 346 end 347 end 348 for ivar=ind_coord_x 349 if check_coord_names(ivar) 350 DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); 351 check_coord=~isempty(DimRank); 352 elseif check_coord_raster(ivar) 353 DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); 354 check_coord=~isempty(DimRank); 355 end 356 % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)}))||...% coord variable 357 % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)})); % raster coord defined by min and max 358 if check_coord 359 CellInfo{icell}.CoordIndex(NbDim(icell))=ivar; 360 CellInfo{icell}.XName=Data.ListVarName{ivar}; 361 CellInfo{icell}.XIndex=ivar; 362 CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank]; 363 break 364 end 365 end 366 end 367 %look for tps coordinates 368 for ivar=ind_coord_tps 369 DimCell=Data.VarDimName{ivar}; 370 if numel(DimCell)==3 && strcmp(DimCell{1},DimCell_var{1}) 371 CellInfo{icell}.CoordType='tps'; 372 CellInfo{icell}.CoordIndex=ivar; 130 373 if check_var 131 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));374 NbDim(icell)=size(Data.(Data.ListVarName{ivar}),2); 132 375 else 133 for idim=1:numel(DimCell) 134 check_index= strcmp(DimCell{idim},Data.ListDimName); 135 CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index); 376 DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName)); 377 NbDim(icell)= Data.DimValue(DimIndex); 378 end 379 for ivardim=1:numel(Data.VarDimName) 380 if strcmp(Data.VarDimName{ivardim},DimCell{3}) 381 CellInfo{icell}.NbCentres_tps= ivardim;% nbre of sites for each tps subdomain 382 elseif strcmp(Data.VarDimName{ivardim}{1},DimCell{2}) && numel(Data.VarDimName{ivardim})>=3 && strcmp(Data.VarDimName{ivardim}{3},DimCell{3}) 383 CellInfo{icell}.SubRange_tps=ivardim;% subrange definiton for tps 136 384 end 137 CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);138 139 ind_scalar=find(strcmp('scalar',Role(VarIndex)));140 ind_vector_x=find(strcmp('vector_x',Role(VarIndex)));141 ind_vector_y=find(strcmp('vector_y',Role(VarIndex))); 142 ind_y=find(strcmp('coord_y',Role(VarIndex))); 143 if numel([ind_scalar ind_vector_x ind_vector_y])==0 144 % if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y 145 NbDim(icell)=1;146 else147 CellInfo{icell}.CoordType='scattered';148 ind_z=find(strcmp('coord_z',Role(VarIndex)));149 if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y)150 CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex];151 NbDim(icell)=2;385 end 386 end 387 break 388 end 389 end 390 391 %% get number of coordinate points for each cell 392 if check_var 393 for icell=1:numel(CellInfo) 394 switch CellInfo{icell}.CoordType 395 case 'scattered' 396 CellInfo{icell}.CoordSize=numel(Data.(CellInfo{icell}.XName)); 397 case 'grid' 398 if NbDim(icell)==3 399 CellInfo{icell}.CoordSize=[numel(Data.(CellInfo{icell}.XName)) numel(Data.(CellInfo{icell}.YName)) numel(Data.(CellInfo{icell}.YName))]; 152 400 else 153 CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex]; 154 NbDim(icell)=3; 401 CellInfo{icell}.CoordSize=[numel(Data.(CellInfo{icell}.XName)) numel(Data.(CellInfo{icell}.YName))]; 155 402 end 156 end 157 end 158 CellInfo{icell}.VarIndex=VarIndex; 159 check_select=check_select|check_cell; 160 end 161 end 162 163 %% look for tps coordinates 164 ivar_remain=find(~check_select);% indices of remaining variables (not already selected) 165 check_coord_tps= strcmp('coord_tps',Role(~check_select)); 166 ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates 167 168 % loop on the tps coordinate sets 169 for icell_tps=1:numel(ivar_tps) 170 check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell 171 check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected 172 DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable 173 icell=numel(CellInfo)+icell_tps; % new field cell index 174 CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable 175 if numel(DimCell)==3 176 VarDimName=Data.VarDimName(~check_select); 177 for ivardim=1:numel(VarDimName) 178 if strcmp(VarDimName{ivardim},DimCell{3}) 179 CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain 180 check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 181 elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3}) 182 CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps 183 check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 184 elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable 185 check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 186 end 187 end 188 end 189 CellInfo{icell}.CoordType='tps'; 190 CellInfo{icell}.VarIndex=find(check_cell); 191 if check_var 192 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); 193 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); 194 else 195 check_index_1= strcmp(DimCell{1},Data.ListDimName); 196 check_index_2= strcmp(DimCell{2},Data.ListDimName); 197 NbDim(icell)=Data.DimValue(check_index_2); 198 if numel(DimCell)>=3 199 check_index_3= strcmp(DimCell{3},Data.ListDimName); 200 CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); 201 end 202 end 203 check_select=check_select|check_cell; 204 end 205 206 %% look for coordinate variables and corresponding gridded data: 207 % coordinate variables are variables associated with a single dimension, defining the coordinate values 208 % two cases: 1)the coordiante variable represents the set of coordiante values 209 % 2)the coordinate variable contains only two elements, representing the coordinate bounds for the dimension with the same name as the cordinate 210 ivar_remain=find(~check_select);% indices of remaining variables, not already taken into account 211 ListVarName=Data.ListVarName(~check_select);%list of names of remaining variables 212 VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables 213 check_coord_select= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension 214 check_coord_select=check_coord_select & ~strcmp('ancillary',Role(~check_select));% do not select ancillary variables as coordinates 215 ListCoordIndex=ivar_remain(check_coord_select);% indices of remaining variables with a single dimension 216 ListCoordName=ListVarName(check_coord_select);% corresponding names of remaining variables with a single dimension 217 ListDimName=VarDimName(check_coord_select);% dimension names of remaining variables with a single dimension 218 219 %remove redondant variables -> keep only one variable per dimension 220 check_keep=true(size(ListDimName)); 221 for idim=1:numel(ListDimName) 222 prev_ind=find(strcmp(ListDimName{idim},ListDimName(1:idim-1)));% check whether the dimension is already taken into account 223 if ~isempty(prev_ind)% in case of multiple coord variable 224 if strcmp(ListCoordName{idim},ListDimName{idim}) %variable with the same name as the coordinate taken in priority 225 check_keep(prev_ind)=0;% choose a variable with the same name as coordinate in priority 226 else 227 check_keep(idim)=0; %keep the first coordiante variable found 228 end 229 end 230 end 231 ListCoordIndex=ListCoordIndex(check_keep);% list of coordinate variable indices 232 ListCoordName=ListCoordName(check_keep);% list of coordinate variable names 233 ListDimName=ListDimName(check_keep);% list of coordinate dimension names 234 235 % determine dimension sizes 236 CoordSize=zeros(size(ListCoordIndex)); 237 for ilist=1:numel(ListCoordIndex) 238 if iscell(ListDimName{ilist}) 239 ListDimName(ilist)=ListDimName{ilist};%transform cell to string 240 end 241 if check_var% if the list of dimensions has been directly defined, no variable data available 242 CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist 243 else 244 check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the index in the list of dimensions 245 CoordSize(ilist)=Data.DimValue(check_index);% find the corresponding dimension value 246 end 247 if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only 248 ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name 249 end 250 end 251 252 %% group the remaining variables in cells sharing the same coordinate variables 253 NewCellInfo={}; 254 NewCellDimIndex={}; 255 NewNbDim=[]; 256 for ivardim=1:numel(VarDimName) % loop at the list of dimensions for the remaining variables 257 DimCell=VarDimName{ivardim};% dimension names of the current variable 258 if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed 259 DimIndices=[]; 260 for idim=1:numel(DimCell) 261 ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of dimensions ListDimName 262 if ~isempty(ind_dim) 263 DimIndices=[DimIndices ind_dim]; %update the list of dim indices included in DimCell 264 if check_var & CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordinate definition limited to lower and upper bounds 265 if isvector(Data.(ListVarName{ivardim})) 266 if numel(Data.(ListVarName{ivardim}))>2 267 CoordSize(ind_dim)=numel(Data.(ListVarName{ivardim})); 268 end 269 else 270 CoordSize(ind_dim)=size(Data.(ListVarName{ivardim}),idim); 271 end 272 end 273 end 274 end 275 % look for cells of variables with the same coordinate variables 276 check_previous=0; 277 for iprev=1:numel(NewCellInfo) 278 if isequal(DimIndices,NewCellDimIndex{iprev}) 279 check_previous=1; 280 NewCellInfo{iprev}.VarIndex=[NewCellInfo{iprev}.VarIndex ivar_remain(ivardim)];%append the current variable index to the found field cell 281 break 282 end 283 end 284 % create a new cell if no previous one contains the coordinate variables 285 if ~check_previous 286 nbcell=numel(NewCellInfo)+1; 287 NewCellDimIndex{nbcell}=DimIndices; 288 NewCellInfo{nbcell}.VarIndex=ivar_remain(ivardim);% create a new field cell with the current variable index 289 NewNbDim(nbcell)=numel(DimIndices); 290 NewCellInfo{nbcell}.CoordType='grid'; 291 NewCellInfo{nbcell}.CoordSize=CoordSize(DimIndices); 292 NewCellInfo{nbcell}.CoordIndex=ListCoordIndex(DimIndices); 293 end 294 end 295 NbDim=[NbDim NewNbDim]; 296 CellInfo=[CellInfo NewCellInfo]; 297 298 %% suppress empty cells or cells with a single coordinate variable 299 check_remove=false(size(CellInfo)); 300 for icell=1:numel(check_remove) 301 if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell)) 302 check_remove(icell)=1; 303 end 304 end 305 CellInfo(check_remove)=[]; 306 NbDim(check_remove)=[]; 403 case 'tps' 404 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); 405 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1); 406 end 407 end 408 else 409 for icell=1:numel(CellInfo) 410 CellInfo{icell}.CoordSize=size(Data.DimValue(CellInfo{icell}.DimIndex)); 411 end 412 end 413 % 414 % %% loop on the tps coordinate sets 415 % 416 % for icell_tps=1:numel(ind_coord_tps) 417 % check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell 418 % check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected 419 % DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable 420 % icell=numel(CellInfo)+icell_tps; % new field cell index 421 % CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable 422 % if numel(DimCell)==3 423 % VarDimName=Data.VarDimName(~check_select); 424 % for ivardim=1:numel(VarDimName) 425 % if strcmp(VarDimName{ivardim},DimCell{3}) 426 % CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain 427 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 428 % elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3}) 429 % CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps 430 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 431 % elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable 432 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 433 % end 434 % end 435 % end 436 % CellInfo{icell}.CoordType='tps'; 437 % CellInfo{icell}.VarIndex=find(check_cell); 438 % if check_var 439 % NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); 440 % CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); 441 % else 442 % check_index_1= strcmp(DimCell{1},Data.ListDimName); 443 % check_index_2= strcmp(DimCell{2},Data.ListDimName); 444 % NbDim(icell)=Data.DimValue(check_index_2); 445 % if numel(DimCell)>=3 446 % check_index_3= strcmp(DimCell{3},Data.ListDimName); 447 % CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); 448 % end 449 % end 450 % check_select=check_select|check_cell; 451 % end 452 453 454 %% cell for ordinary plots 455 iremove=false(1,numel(ind_coord_y)); 456 for ilist=1:numel(ind_coord_y)% remove the y coordinates which have been used yet in scalar or vector fields 457 for icell=1:numel(CellInfo) 458 if isfield(CellInfo{icell},'YIndex')&& isequal(CellInfo{icell}.YIndex,ind_coord_y(ilist)) 459 iremove(ilist)=true; 460 continue 461 end 462 end 463 end 464 ind_coord_y(iremove)=[]; 465 if ~isempty(ind_coord_x) 466 y_nbre=zeros(1,numel(ind_coord_x)); 467 for icell=1:numel(ind_coord_x) 468 Cell1DPlot{icell}.VarType='1DPlot'; 469 Cell1DPlot{icell}.XIndex=ind_coord_x(icell); 470 Cell1DPlot{icell}.XName=Data.ListVarName{ind_coord_x(icell)}; 471 DimCell_x=Data.VarDimName{ind_coord_x(icell)}; 472 for ivar=[ind_coord_y ind_discrete] 473 DimCell=Data.VarDimName{ivar}; 474 if numel(DimCell)==1 && strcmp(DimCell_x{1},DimCell{1}) 475 y_nbre(icell)=y_nbre(icell)+1; 476 Cell1DPlot{icell}.YIndex(y_nbre(icell))=ivar; 477 break 478 end 479 end 480 end 481 Cell1DPlot(find(y_nbre==0))=[]; 482 CellInfo=[CellInfo Cell1DPlot]; 483 NbDim=[NbDim ones(1,numel(Cell1DPlot))]; 484 end 307 485 308 486 %% document roles of non-coordinate variables 309 487 for icell=1:numel(CellInfo) 310 VarIndex=CellInfo{icell}.VarIndex; 311 for ivar=VarIndex 312 if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) 313 CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; 314 else 315 CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; 316 end 317 if ~isempty(ProjModeRequest{ivar}) 318 CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar}; 319 end 320 if ~isempty(FieldName{ivar}) 321 CellInfo{icell}.FieldName=FieldName{ivar}; 322 end 323 if CheckSub(ivar)==1 324 CellInfo{icell}.CheckSub=1; 325 end 326 end 327 end 488 if isfield(CellInfo{icell},'VarIndex') 489 VarIndex=CellInfo{icell}.VarIndex; 490 for ivar=VarIndex 491 % if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) 492 % CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; 493 % else 494 % CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; 495 % end 496 if ~isempty(ProjModeRequest{ivar}) 497 CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar}; 498 end 499 if ~isempty(FieldName{ivar}) 500 CellInfo{icell}.FieldName=FieldName{ivar}; 501 end 502 if CheckSub(ivar)==1 503 CellInfo{icell}.CheckSub=1; 504 end 505 end 506 end 507 end 508 % for icell=ind_coord_tps 509 % VarIndex=CellInfo{icell}.VarIndex; 510 % for ivar=VarIndex 511 % if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) 512 % CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; 513 % else 514 % CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; 515 % end 516 % if ~isempty(ProjModeRequest{ivar}) 517 % CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar}; 518 % end 519 % if ~isempty(FieldName{ivar}) 520 % CellInfo{icell}.FieldName=FieldName{ivar}; 521 % end 522 % if CheckSub(ivar)==1 523 % CellInfo{icell}.CheckSub=1; 524 % end 525 % end 526 % end 527 528 529 530 % 531 % %% analyse vector fields 532 % if ~isempty(ind_vector_x) && ~isempty(ind_vector_y) 533 % if numel(ind_vector_x)>1 534 % errormsg='multiply defined vector x component' 535 % return 536 % end 537 % DimCell_vec=Data.VarDimName{ind_vector_x};% cell of dimension names for ivar_coord_x(icell) 538 % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension 539 % DimCell_y=Data.VarDimName{ind_vector_y};% cell of dimension names for ivar_coord_x(icell) 540 % if ischar(DimCell_y),DimCell_y={DimCell_y};end % transform char to cell for a single dimension 541 % if ~isequal(DimCell,DimCell_y) 542 % errormsg='inconsistent x and y vector components'; 543 % return 544 % end 545 % %look for coordinates 546 % for ivar=ind_coord_y 547 % DimCell=Data.VarDimName{ivar}; 548 % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension 549 % if isequal(DimCell,DimCell_vec) 550 % CoordType='scattered'; 551 % coordy=ivar; 552 % else 553 % if isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{1}) 554 % CoordType='grid'; 555 % coordy=ivar; 556 % elseif ~isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{2}) 557 % CoordType='grid'; 558 % coordy=ivar; 559 % coordz=ind_coord_z; 560 % end 561 % end 562 % 563 % %% find scattered (unstructured) coordinates 564 % ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x' 565 % check_select=false(1,nbvar); 566 % check_coord=false(1,nbvar); 567 % CellInfo=cell(1,numel(ivar_coord_x)); 568 % NbDim=zeros(1,numel(ivar_coord_x)); 569 % % loop on unstructured coordinate x -> different field cells 570 % for icell=1:numel(ivar_coord_x) 571 % DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell) 572 % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension 573 % % look for variables sharing dimension(s) with ivar_coord_x(icell) 574 % check_cell=zeros(numel(DimCell),nbvar); 575 % for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension 576 % for ivar=1:nbvar 577 % check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar})); 578 % end 579 % end 580 % check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell 581 % VarIndex=find(check_cell);% list of detected variable indices 582 % if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later) 583 % if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate 584 % CellInfo{icell}.CoordIndex=ivar_coord_x(icell); 585 % % size of coordinate var 586 % if check_var 587 % CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)})); 588 % else 589 % for idim=1:numel(DimCell) 590 % check_index= strcmp(DimCell{idim},Data.ListDimName); 591 % CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index); 592 % end 593 % CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize); 594 % end 595 % % ind_scalar=find(strcmp('scalar',Role(VarIndex))); 596 % % ind_vector_x=find(strcmp('vector_x',Role(VarIndex))); 597 % % ind_vector_y=find(strcmp('vector_y',Role(VarIndex))); 598 % ind_y=find(strcmp('coord_y',Role(VarIndex))); 599 % if numel([ind_scalar ind_vector_x ind_vector_y])==0 600 % % if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y 601 % NbDim(icell)=1; 602 % else 603 % CellInfo{icell}.CoordType='scattered'; 604 % ind_z=find(strcmp('coord_z',Role(VarIndex))); 605 % if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y) 606 % CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex]; 607 % NbDim(icell)=2; 608 % else 609 % CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex]; 610 % NbDim(icell)=3; 611 % end 612 % end 613 % end 614 % CellInfo{icell}.VarIndex=VarIndex; 615 % check_select=check_select|check_cell; 616 % end 617 % end 618 % 619 % %% look for tps coordinates 620 % ivar_remain=find(~check_select);% indices of remaining variables (not already selected) 621 % check_coord_tps= strcmp('coord_tps',Role(~check_select)); 622 % ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates 623 % 624 % % loop on the tps coordinate sets 625 % for icell_tps=1:numel(ivar_tps) 626 % check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell 627 % check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected 628 % DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable 629 % icell=numel(CellInfo)+icell_tps; % new field cell index 630 % CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable 631 % if numel(DimCell)==3 632 % VarDimName=Data.VarDimName(~check_select); 633 % for ivardim=1:numel(VarDimName) 634 % if strcmp(VarDimName{ivardim},DimCell{3}) 635 % CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain 636 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 637 % elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3}) 638 % CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps 639 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 640 % elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable 641 % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected 642 % end 643 % end 644 % end 645 % CellInfo{icell}.CoordType='tps'; 646 % CellInfo{icell}.VarIndex=find(check_cell); 647 % if check_var 648 % NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); 649 % CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); 650 % else 651 % check_index_1= strcmp(DimCell{1},Data.ListDimName); 652 % check_index_2= strcmp(DimCell{2},Data.ListDimName); 653 % NbDim(icell)=Data.DimValue(check_index_2); 654 % if numel(DimCell)>=3 655 % check_index_3= strcmp(DimCell{3},Data.ListDimName); 656 % CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); 657 % end 658 % end 659 % check_select=check_select|check_cell; 660 % end 661 % 662 % 663 % 664 % % determine dimension sizes 665 % CoordSize=zeros(size(ListCoordIndex)); 666 % for ilist=1:numel(ListCoordIndex) 667 % if iscell(ListDimName{ilist}) 668 % ListDimName(ilist)=ListDimName{ilist};%transform cell to string 669 % end 670 % if check_var% if the list of dimensions has been directly defined, no variable data available 671 % CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist 672 % else 673 % check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the index in the list of dimensions 674 % CoordSize(ilist)=Data.DimValue(check_index);% find the corresponding dimension value 675 % end 676 % if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only 677 % ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name 678 % end 679 % end 680 % end 681 % end 682 % 683 % 684 % 685 % %% suppress empty cells or cells with a single coordinate variable 686 % check_remove=false(size(CellInfo)); 687 % for icell=1:numel(check_remove) 688 % if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell)) 689 % check_remove(icell)=1; 690 % end 691 % end 692 % CellInfo(check_remove)=[]; 693 % NbDim(check_remove)=[]; 694 % 695 % -
trunk/src/get_field.m
r1040 r1045 135 135 return 136 136 end 137 [Field.MaxDim,imax]=max(NbDim); 137 if isempty(CellInfo) 138 Field.MaxDim=max(cellfun(@numel,Field.Display.VarDimName)); 139 check_cellinfo=false; 140 else 141 [Field.MaxDim,imax]=max(NbDim); 142 check_cellinfo=true; 143 end 138 144 139 145 %% set time mode … … 210 216 %% set default field options 211 217 checknbdim=cellfun('size',Field.Display.VarDimName,2); 212 if max(checknbdim)<=1213 Field.MaxDim=1;% only 1D fields, considered as a time series by default214 end218 % if max(checknbdim)<=1 219 % Field.MaxDim=1;% only 1D fields, considered as a time series by default 220 % end 215 221 if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields 216 222 check_vec_input=0; 223 % case of vector initially selected from uvmat input 217 224 if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y') 218 225 ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1); … … 224 231 end 225 232 end 226 if ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') 233 % otherwise select vectors marked as attributes in the input field 234 if check_cellinfo && ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') 227 235 set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1)) 228 236 set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1)) … … 252 260 253 261 %% Make choices of coordinates from input 254 if isfield(CellInfo{imax},'CoordIndex') 255 CoordIndex=CellInfo{imax}.CoordIndex; 256 if numel(CoordIndex)==2 257 if isfield(ParamIn,'Coord_x')&& isfield(ParamIn,'Coord_y') 258 YName=ParamIn.Coord_y; 259 XName=ParamIn.Coord_x; 260 else 261 YName=Field.ListVarName{CoordIndex(1)}; 262 XName=Field.ListVarName{CoordIndex(2)}; 263 end 264 ListCoord=get(handles.Coord_x,'String'); 265 XIndex=find(strcmp(XName,ListCoord)); 266 if ~isempty(XIndex) 267 set(handles.Coord_x,'Value',XIndex) 268 end 269 YIndex=find(strcmp(YName,ListCoord)); 270 if ~isempty(YIndex) 271 set(handles.Coord_y,'Value',YIndex) 272 end 273 end 274 end 262 % check_menu=false(1,numel(Data.ListVarName)); 263 % ListCoordMenu=1:numel(Data.ListVarName); 264 % CoordIndex=CellInfo{icell}.CoordIndex(CellInfo{icell}.CoordIndex~=0); 265 % 266 % for ivar=find(check_coord_names) 267 % check_dim=strcmp(Data.VarDimName{ivar},DimCell_var); 268 % if ~isempty(find(check_dim)) 269 % check_menu(ivar)=true; 270 % end 271 % end 272 % CellInfo{icell}.CoordMenu=[CoordIndex find(check_menu)]; 273 % ListCoordMenu(CoordIndex)=[]; 274 % for ivar=ListCoordMenu 275 % DimCell=Data.VarDimName{ivar}; 276 % if isequal(DimCell,DimCell_var) 277 % check_menu(ivar)=true; 278 % end 279 % end 280 % CellInfo{icell}.CoordMenu=[CellInfo{icell}.CoordMenu find(check_menu)]; 281 % 282 % if isfield(CellInfo{imax},'CoordIndex') 283 % CoordIndex=CellInfo{imax}.CoordIndex; 284 % if numel(CoordIndex)==2 285 % if isfield(ParamIn,'Coord_x')&& isfield(ParamIn,'Coord_y') 286 % YName=ParamIn.Coord_y; 287 % XName=ParamIn.Coord_x; 288 % else 289 % YName=Field.ListVarName{CoordIndex(1)}; 290 % XName=Field.ListVarName{CoordIndex(2)}; 291 % end 292 % ListCoord=get(handles.Coord_x,'String'); 293 % XIndex=find(strcmp(XName,ListCoord)); 294 % if ~isempty(XIndex) 295 % set(handles.Coord_x,'Value',XIndex) 296 % end 297 % YIndex=find(strcmp(YName,ListCoord)); 298 % if ~isempty(YIndex) 299 % set(handles.Coord_y,'Value',YIndex) 300 % end 301 % end 302 % end 275 303 276 304 %% put the GUI on the lower right of the sceen … … 304 332 % --- Activated by selection in the list of variables 305 333 % ---------------------------------------------------------------------- 306 function variables_Callback(hObject, eventdata, handles)334 function variables_Callback(hObject, VarName, handles) 307 335 308 336 Tabchar={''};%default … … 388 416 end 389 417 390 %% propose a plot by default if a variable has been selected391 if ~is equal(index,1)418 %% propose a plot by default if variables_Callback has not been already called by FieldOption_Callback (VarName is not a char string) 419 if ~ischar(VarName) && ~isequal(index,1) 392 420 if numel(DimCell)==1 393 421 set(handles.FieldOption,'Value',1)%propose 1D plot … … 412 440 FieldOption=FieldList{get(handles.FieldOption,'Value')}; 413 441 switch FieldOption 414 415 442 case '1D plot' 416 443 set(handles.Coordinates,'Visible','on') … … 423 450 set(handles.PanelScalar,'Visible','off') 424 451 set(handles.PanelVectors,'Visible','off') 425 set(handles.Coord_y,'Visible','o ff')426 set(handles.Y_title,'Visible','o ff')452 set(handles.Coord_y,'Visible','on') 453 set(handles.Y_title,'Visible','on') 427 454 set(handles.Coord_z,'Visible','off') 428 455 set(handles.Z_title,'Visible','off') 429 ordinate_Callback(hObject, VarName, handles) 430 456 %ordinate_Callback(hObject, VarName, handles) 431 457 case {'scalar'} 432 458 set(handles.Coordinates,'Visible','on') … … 440 466 set(handles.PanelScalar,'Position',pos) 441 467 set(handles.Coord_y,'Visible','on') 442 set(handles.Y_title,'Visible','on') 443 444 if ~ischar(VarName) 445 446 %default scalar selection 447 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante 448 for ilist=1:numel(Field.Display.VarDimName) 449 if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') 450 Role=Field.Display.VarAttribute{ilist}.Role; 451 if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') 468 set(handles.Y_title,'Visible','on') 469 if ~ischar(VarName) 470 %default scalar selection 471 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante 472 for ilist=1:numel(Field.Display.VarDimName) 473 if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') 474 Role=Field.Display.VarAttribute{ilist}.Role; 475 if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') 476 test_coord(ilist)=1; 477 end 478 end 479 dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist 480 if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable 452 481 test_coord(ilist)=1; 453 482 end 454 483 end 455 dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist 456 if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable 457 test_coord(ilist)=1; 458 end 459 end 460 scalar_index=find(~test_coord,1);%get the first variable not a coordinate 461 if isempty(scalar_index) 462 set(handles.scalar,'Value',1) 463 else 464 set(handles.scalar,'Value',scalar_index) 465 end 466 end 467 scalar_Callback(hObject,VarName, handles) 468 469 484 scalar_index=find(~test_coord,1);%get the first variable not a coordinate 485 if isempty(scalar_index) 486 set(handles.scalar,'Value',1) 487 else 488 set(handles.scalar,'Value',scalar_index) 489 end 490 end 491 scalar_Callback(hObject,VarName, handles) 470 492 case 'vectors' 471 493 set(handles.PanelVectors,'Visible','on') … … 509 531 end 510 532 end 511 vector_Callback(handles) 512 533 vector_Callback(handles) 513 534 case 'civdata...' 514 535 set(handles.PanelOrdinate,'Visible','off') … … 576 597 end 577 598 end 578 set(handles.Coord_x,'Value',coord_val )579 end 580 set(handles.Coord_x,'String', ListCoord)599 set(handles.Coord_x,'Value',coord_val+1) 600 end 601 set(handles.Coord_x,'String',[{''}; ListCoord]) 581 602 582 603 … … 611 632 function scalar_Callback(hObject, VarName, handles) 612 633 613 Field=get(handles.get_field,'UserData'); 614 scalar_menu=get(handles.scalar,'String'); 615 if ischar(VarName) 634 Field=get(handles.get_field,'UserData');% get the input field info stored in UserData of the GUI 635 scalar_menu=get(handles.scalar,'String');% read the menu for scalar selection 636 if ischar(VarName)% case of a call with input variable 616 637 ScalarName=VarName; 617 638 scalar_index=find(strcmp(VarName,scalar_menu)); 618 set(handles.scalar,'Value',scalar_index) 619 else 639 set(handles.scalar,'Value',scalar_index)% select the input variable field in the menu 640 else % no input variable, the variable ScalarName is selected from the menu 620 641 scalar_index=get(handles.scalar,'Value'); 621 642 ScalarName=scalar_menu{scalar_index}; … … 626 647 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante 627 648 dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable 628 if ~get(handles.CheckDimensionX,'Value')649 %if ~get(handles.CheckDimensionX,'Value') 629 650 %look for coordinate variables among the other variables 630 651 for ilist=1:numel(Field.Display.VarDimName) … … 636 657 end 637 658 end 638 end659 %end 639 660 var_component=find(test_component);% list of variable indices elligible as unstructured coordinates 640 var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates661 var_coord=find(test_coord);% % list of variable indices elligible as gridded coordinates 641 662 var_coord(var_coord==scalar_index)=[]; 642 663 var_component(var_component==scalar_index)=[]; … … 664 685 elseif strcmp(Role,'coord_y') 665 686 coord_val(2)=ilist; 666 687 elseif strcmp(Role,'coord_z') 667 688 coord_val(3)=ilist; 689 Check3D=1; 668 690 end 669 691 end … … 679 701 end 680 702 end 681 if get(handles.CheckDimensionX,'Value')682 set(handles.Coord_x,'Value',2)683 set(handles.Coord_x,'String',dim_var')684 else703 % if get(handles.CheckDimensionX,'Value') 704 % set(handles.Coord_x,'Value',2) 705 % set(handles.Coord_x,'String',dim_var') 706 % else 685 707 set(handles.Coord_x,'Value',coord_val(1)) 686 708 set(handles.Coord_x,'String',ListCoord) 687 end688 if get(handles.CheckDimensionX,'Value')689 set(handles.Coord_y,'Value',1)690 set(handles.Coord_y,'String',dim_var')691 else709 % end 710 % if get(handles.CheckDimensionX,'Value') 711 % set(handles.Coord_y,'Value',1) 712 % set(handles.Coord_y,'String',dim_var') 713 % else 692 714 set(handles.Coord_y,'Value',coord_val(2)) 693 715 set(handles.Coord_y,'String',ListCoord) 694 end 695 if get(handles.CheckDimensionX,'Value') 696 set(handles.Coord_z,'Value',1) 697 set(handles.Coord_z,'String',dim_var') 698 else 716 % end 717 % if get(handles.CheckDimensionX,'Value') 718 % set(handles.Coord_z,'Value',1) 719 % set(handles.Coord_z,'String',dim_var') 720 % else 721 if numel(test_coord)>=3 699 722 set(handles.Coord_z,'Value',coord_val(2)) 700 723 set(handles.Coord_z,'String',ListCoord) 724 set(handles.Coord_z,'Visible','on') 725 set(handles.Check3D,'Value', 1) 701 726 end 702 727 … … 911 936 string=get(handles.Coord_y,'String'); 912 937 VarName=string{index}; 938 913 939 if ~ischar(DimCell) 914 940 update_field(handles,VarName) … … 992 1018 if ~isempty(index) 993 1019 set(handles.variables,'Value',index+1) 994 variables_Callback(handles.variables, [], handles)1020 variables_Callback(handles.variables, VarName, handles) 995 1021 end 996 1022 … … 1022 1048 1023 1049 % --- Executes on button press in CheckDimensionY. 1024 function CheckDimensionX_Callback(hObject, eventdata, handles)1025 CheckDimensionX=get(handles.CheckDimensionX,'value')1026 if CheckDimensionX1027 set(handles.Coordinates,'visible','off')1028 else1029 set(handles.Coordinates,'visible','on')1030 end1050 % function CheckDimensionX_Callback(hObject, eventdata, handles) 1051 % CheckDimensionX=get(handles.CheckDimensionX,'value') 1052 % if CheckDimensionX 1053 % set(handles.Coordinates,'visible','off') 1054 % else 1055 % set(handles.Coordinates,'visible','on') 1056 % end 1031 1057 % FieldList=get(handles.FieldOption,'String'); 1032 1058 % FieldOption=FieldList{get(handles.FieldOption,'Value')}; -
trunk/src/plot_field.m
r1031 r1045 115 115 %% check input structure 116 116 % check the cells of fields : 117 [CellInfo,NbDimArray,errormsg]=find_field_cells(Data); 118 if ~isempty(errormsg) 119 msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]); 120 return 121 end 122 123 index_3D=find(NbDimArray>2,1); 124 if ~isempty(index_3D) 125 msgbox_uvmat('ERROR','volume plot not implemented yet'); 126 return 127 end 128 index_2D=find(NbDimArray==2);%find 2D fields 129 index_1D=find(NbDimArray==1); 130 index_0D=find(NbDimArray==0); 117 118 % if ~isfield(PlotParam,'FieldName') 119 % index_0D=[]; 120 % index_1D=1; 121 % index_2D=[];%find 2D fields 122 % index_3D=[]; 123 % else 124 [CellInfo,NbDimArray,errormsg]=find_field_cells(Data); 125 if ~isempty(errormsg) 126 msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]); 127 return 128 end 129 index_0D=find(NbDimArray==0); 130 index_1D=find(NbDimArray==1); 131 index_2D=find(NbDimArray==2);%find 2D fields 132 index_3D=find(NbDimArray>2,1); 133 if ~isempty(index_3D) 134 msgbox_uvmat('ERROR','volume plot not implemented yet'); 135 return 136 end 137 % end 131 138 132 139 %% test axes and figure … … 228 235 if ~isempty(htext)%&&~isempty(hchecktable) 229 236 if isempty(index_0D) 230 % set(htext,'Data',{})231 % set(htext,'visible','off')232 % set(hchecktable,'visible','off')233 % set(hchecktable,'Value',0)234 237 else 235 238 errormsg=plot_text(Data,CellInfo(index_0D),htext); 236 239 set(htext,'visible','on') 237 % set(hchecktable,'visible','on')238 % set(hchecktable,'Value',1)239 240 end 240 241 set(hfig,'Unit','pixels'); … … 409 410 %loop on input fields 410 411 for icell=1:numel(CellInfo) 411 VarIndex=CellInfo{icell}. VarIndex;% indices of the selected variables in the list data.ListVarName412 coord_x_index=CellInfo{icell}. CoordIndex;412 VarIndex=CellInfo{icell}.YIndex;% indices of the selected variables in the list data.ListVarName 413 coord_x_index=CellInfo{icell}.XIndex; 413 414 coord_x_name{icell}=data.ListVarName{coord_x_index}; 414 415 coord_x{icell}=data.(data.ListVarName{coord_x_index});%coordinate variable set as coord_x -
trunk/src/proj_field.m
r1027 r1045 554 554 return 555 555 end 556 CellInfo=CellInfo(NbDim>=2); %keep only the 2D cells 557 %%%%%% TODO: treat 1D fields: project as identity so that P o P=P for projection operation 556 CellInfo=CellInfo(NbDim>=2); %keep only the 2D or 3D cells 558 557 cell_select=true(size(CellInfo)); 559 558 560 559 for icell=1:length(CellInfo) 561 560 if isfield(CellInfo{icell},'ProjModeRequest') 562 if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode)563 cell_select(icell)=0;564 end561 % if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode) 562 % cell_select(icell)=0; 563 % end 565 564 if strcmp(ProjMode,'interp_tps')&& ~strcmp(CellInfo{icell}.CoordType,'tps') 566 565 cell_select(icell)=0; … … 851 850 end 852 851 853 854 855 856 857 852 else 858 853 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; … … 929 924 ProjData.ListVarName=[ProjData.ListVarName {AXName}]; 930 925 ProjData.VarDimName=[ProjData.VarDimName {AXName}]; 926 nbvar=numel(ProjData.VarDimName); 927 ProjData.VarAttribute{nbvar}.Role='coord_x'; 931 928 for ivar=VarIndex 932 929 %VarName{ivar}=FieldData.ListVarName{ivar}; … … 950 947 ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName{ivar}]; 951 948 ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate 952 ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line 949 nbvar=nbvar+1; 950 ProjData.VarAttribute{nbvar}.Role='coord_y';% for plot with continuous line 953 951 end 954 952 if nbcolor==3 … … 1122 1120 1123 1121 check_grid=zeros(size(CellInfo));% =1 if a grid is needed , =0 otherwise, for each field cell 1124 ProjMode=cell(size(CellInfo)); 1125 for icell=1:numel(CellInfo) 1126 ProjMode{icell}=ObjectData.ProjMode;% projection mode of the plane object 1127 end 1122 ProjMode=num2cell(blanks(numel(CellInfo))); 1123 ProjMode=regexprep(ProjMode,' ',ObjectData.ProjMode); 1124 %ProjMode=cell(size(CellInfo)); 1125 % for icell=1:numel(CellInfo) 1126 % ProjMode{icell}=ObjectData.ProjMode;% projection mode of the plane object 1127 % end 1128 1128 icell_grid=[];% field cell index which defines the grid 1129 1129 if ~strcmp(ObjectData.ProjMode,'projection')&& ~strcmp(ObjectData.Type,'plane_z')% TODO:rationalize … … 1202 1202 ProjData.ListVarName={AYName,AXName}; 1203 1203 1204 ProjData.VarAttribute={[],[]}; 1204 ProjData.VarAttribute{1}.Role='coord_y'; 1205 ProjData.VarAttribute{2}.Role='coord_x'; 1205 1206 end 1206 1207 … … 1219 1220 continue % only cells represnting 2D or 3D fields are involved 1220 1221 end 1221 VarIndex= CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName1222 VarIndex= CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 1222 1223 %dimensions 1223 1224 DimCell=FieldData.VarDimName{VarIndex(1)}; … … 1237 1238 continue %skip for next cell (needs tps field cell) 1238 1239 end 1239 coord_x=FieldData.( FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates1240 coord_y=FieldData.( FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates1240 coord_x=FieldData.(CellInfo{icell}.XName);% initial x coordinates 1241 coord_y=FieldData.(CellInfo{icell}.YName);% initial y coordinates 1241 1242 check3D=(numel(CellInfo{icell}.CoordIndex)==3); 1242 1243 if check3D 1243 coord_z=FieldData.( FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});1244 coord_z=FieldData.(CellInfo{icell}.ZName); 1244 1245 end 1245 1246 … … 1256 1257 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane 1257 1258 indcut=find(abs(fieldZ) <= width); 1258 for ivar= VarIndex1259 for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex] 1259 1260 VarName=FieldData.ListVarName{ivar}; 1260 1261 FieldData.(VarName)=FieldData.(VarName)(indcut); … … 1305 1306 return 1306 1307 end 1307 for ivar= VarIndex1308 for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex] 1308 1309 VarName=FieldData.ListVarName{ivar}; 1309 1310 FieldData.(VarName)=FieldData.(VarName)(indcut); … … 1321 1322 nbvar=0; 1322 1323 %nbvar=numel(ProjData.ListVarName); 1323 for ivar= VarIndex%transfer variables to the projection plane1324 for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex] %transfer variables to the projection plane 1324 1325 VarName=FieldData.ListVarName{ivar}; 1325 1326 if ivar==CellInfo{icell}.CoordIndex(end) … … 1401 1402 SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps}); 1402 1403 checkUV=0; 1403 if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')1404 FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x _tps}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y_tps}));1404 if strcmp(CellInfo{icell}.VarType,'vector') 1405 FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y})); 1405 1406 checkUV=1; 1406 1407 end -
trunk/src/read_field.m
r1041 r1045 8 8 % .FieldName; field name 9 9 % .VelType 10 % .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2 (fix1).... 10 % .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2 (fix1).... 11 11 % .Npx,.Npy: for images, nbre of pixels in x and y 12 12 % errormsg: error message, ='' by default … … 20 20 % .ColorVar: variable used for vector color 21 21 % .Npx, .Npy: nbre of pixels along x and y (used for .vol input files) 22 % .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num' 22 % .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num' 23 23 % num: frame number for movies 24 24 % … … 94 94 ParamOut.CivStage=Field.CivStage; 95 95 case 'netcdf'% general netcdf file (not recognized as civ) 96 ListVar ={};96 ListVarName={}; 97 97 Role={}; 98 98 ProjModeRequest={}; 99 ListInputField={}; 100 ListOperator={}; 101 checkU=0; 102 checkV=0; 99 %ListInputField={}; 100 %checkU=0; 101 %checkV=0; 103 102 % scan the list InputField 103 Operator=cell(1,numel(InputField)); 104 InputVar=cell(1,numel(InputField)); 104 105 for ilist=1:numel(InputField) 105 106 % look for input variables to read 106 107 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 107 108 if isempty(r)% no operator used 108 if isempty(find(strcmp(InputField{ilist},ListVar),1)) 109 ListVar=[ListVar InputField(ilist)];%append the variable name if not already in the list 110 ListInputField=[ListInputField InputField(ilist)]; 111 ListOperator=[ListOperator {''}]; 112 end 113 if check_colorvar(ilist) 114 if isempty(find(strcmp(InputField{ilist},ListVar),1)) 115 Role{numel(ListVar)}='ancillary';% not projected with interpolation 116 ProjModeRequest{numel(ListVar)}=''; 109 ListVarName=[ListVarName InputField(ilist)];%append the variable name 110 %InputVar{ilist}=InputField(ilist); 111 %ListInputField=[ListInputField InputField(ilist)]; 112 if check_colorvar(ilist)% case of field used for vector color 113 Role{numel(ListVarName)}='ancillary';% not projected with interpolation 114 ProjModeRequest{numel(ListVarName)}=''; 115 else 116 Role{numel(ListVarName)}='scalar'; 117 ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot) 118 end 119 Operator{numel(ListVarName)}=''; 120 else % an operator 'vec' or 'norm' is used 121 ListVarName=[ListVarName {r.UName}]; % append the variable in the list if not previously listed 122 if strcmp(r.Operator,'norm') 123 if check_colorvar(ilist) 124 Role=[Role {'ancillary'}]; 125 else 126 Role=[Role {'scalar'}]; 117 127 end 118 128 else 119 Role{numel(ListVar)}='scalar'; 120 ProjModeRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 121 end 122 if isfield(ParamIn,'Coord_y') 123 if ~isempty(strcmp(InputField{ilist},ParamIn.Coord_y)) 124 Role{numel(ListVar)}='coord_y'; 125 end 126 end 127 else % an operator 'vec' or 'norm' is used 129 Role=[Role {'vector_x'}]; 130 end 131 %ListInputField=[ListInputField InputField(ilist)]; 132 ListVarName=[ListVarName {r.VName}];% append the variable in the list if not previously listed 133 Role=[Role {'vector_y'}]; 134 %ListInputField=[ListInputField InputField(ilist)]; 135 Operator{numel(ListVarName)-1}=r.Operator; 136 Operator{numel(ListVarName)}=''; 128 137 if ~check_colorvar(ilist) && strcmp(r.Operator,'norm') 129 ProjModeRequestVar='interp_lin';%scalar field (requires interpolation for plot) 138 ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot) 139 ProjModeRequest{numel(ListVarName)-1}='interp_lin';%scalar field (requires interpolation for plot) 130 140 else 131 ProjModeRequestVar=''; 132 end 133 ind_var_U=find(strcmp(r.UName,ListVar));%check previous listing of variable r.UName 134 ind_var_V=find(strcmp(r.VName,ListVar));%check previous listing of variable r.VName 135 if isempty(ind_var_U) 136 ListVar=[ListVar {r.UName}]; % append the variable in the list if not previously listed 137 Role=[Role {'vector_x'}]; 138 ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}]; 139 ListInputField=[ListInputField InputField(ilist)]; 140 else 141 checkU=1; 142 end 143 if isempty(ind_var_V) 144 ListVar=[ListVar {r.VName}];% append the variable in the list if not previously listed 145 Role=[Role {'vector_y'}]; 146 ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}]; 147 ListInputField=[ListInputField InputField(ilist)]; 148 else 149 checkV=1; 141 ProjModeRequest{numel(ListVarName)}=''; 142 ProjModeRequest{numel(ListVarName)-1}=''; 150 143 end 151 144 end … … 156 149 NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z); 157 150 if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array 158 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);151 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 159 152 elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time in a multidimensional array 160 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);153 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 161 154 if numel(num)~=1 162 155 NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected 163 156 end 164 157 else 165 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);158 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 166 159 end 167 160 if ~isempty(errormsg) … … 169 162 end 170 163 CheckStructured=1; 171 %scan all the variables beyond the two first NbCoord ones describing the coordinates. 172 for ilist=NbCoord+1:numel(Field.VarDimName) 173 if isequal(Field.VarDimName{1},Field.VarDimName{ilist}) % if a variable has the same dimension as the coordinate, it denotes a field with unstructured coordinates 174 Field.VarAttribute{1}.Role='coord_x';%unstructured coordinates 175 Field.VarAttribute{2}.Role='coord_y'; 176 if NbCoord>=3 177 Field.VarAttribute{3}.Role='coord_z'; 178 end 179 CheckUnstructured=0; 180 break 181 end 182 end 183 if CheckStructured 184 for ilist=NbCoord+1:numel(Field.VarDimName) 185 if numel(Field.VarDimName{ilist})==NbCoord 186 rank(1)=find(strcmp(ParamIn.Coord_x,Field.VarDimName{ilist})); 187 rank(2)=find(strcmp(ParamIn.Coord_y,Field.VarDimName{ilist})); 188 if NbCoord==3 189 rank(3)=find(strcmp(ParamIn.Coord_z,Field.VarDimName{ilist})); 190 end 191 rank=rank(end:-1:1); 192 VarName=Field.ListVarName{ilist}; 193 Field.(VarName)=permute(Field.(VarName),rank); 194 Field.VarDimName{ilist}=Field.VarDimName{ilist}(rank);% permute the order of dimensions 195 end 196 end 164 %scan all the variables 165 NbCoord=0; 166 if ~isempty(ParamIn.Coord_x) 167 index_Coord_x=find(strcmp(ParamIn.Coord_x,Field.ListVarName)); 168 Field.VarAttribute{index_Coord_x}.Role='coord_x';% 169 NbCoord=NbCoord+1; 170 end 171 if ~isempty(ParamIn.Coord_y) 172 if ischar(ParamIn.Coord_y) 173 index_Coord_y=find(strcmp(ParamIn.Coord_y,Field.ListVarName)); 174 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 175 NbCoord=NbCoord+1; 176 else 177 for icoord_y=1:numel(ParamIn.Coord_y) 178 index_Coord_y=find(strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName)); 179 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 180 NbCoord=NbCoord+1; 181 end 182 end 183 end 184 NbDim=1; 185 if ~isempty(ParamIn.Coord_z) 186 index_Coord_z=find(strcmp(ParamIn.Coord_z,Field.ListVarName)); 187 Field.VarAttribute{index_Coord_z}.Role='coord_z';% 188 NbCoord=NbCoord+1; 189 NbDim=3; 190 elseif ~isempty(ParamIn.FieldName) 191 NbDim=2; 197 192 end 198 193 NormName=''; 199 194 UName=''; 200 195 VName=''; 201 if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (1 D plots) 202 for ilist=1:numel(ListVar) 203 Field.VarAttribute{ilist+NbCoord}.Role=Role{ilist}; 204 Field.VarAttribute{ilist+NbCoord}.ProjModeRequest=ProjModeRequest{ilist}; 196 if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (exclude 1 D plots) 197 VarAttribute=cell(1,numel(ListVarName)); 198 for ilist=1:numel(ListVarName) 199 index_var=find(strcmp(ListVarName{ilist},Field.ListVarName),1); 200 VarDimName{ilist}=Field.VarDimName{index_var}; 201 DimOrder=[]; 202 if NbDim ==2 203 DimOrder=[find(strcmp(ParamIn.Coord_y,VarDimName{ilist})) find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))]; 204 elseif NbDim ==3 205 DimOrder=[find(strcmp(ParamIn.Coord_z,VarDimName{ilist}))... 206 find(strcmp(ParamIn.Coord_y,VarDimName{ilist}))... 207 find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))]; 208 end 209 if ~isempty(DimOrder) 210 Field.(ListVarName{ilist})=permute(Field.(ListVarName{ilist}),DimOrder); 211 VarDimName{ilist}=VarDimName{ilist}(DimOrder); 212 end 213 if numel(Field.VarAttribute)>=index_var 214 VarAttribute{ilist}=Field.VarAttribute{index_var};% read var attributes from input if exist 215 end 216 end 217 check_remove=false(1,numel(Field.ListVarName)); 218 for ilist=1:numel(ListVarName) 219 VarAttribute{ilist}.Role=Role{ilist}; 220 VarAttribute{ilist}.ProjModeRequest=ProjModeRequest{ilist}; 205 221 if isfield(ParamIn,'FieldName') 206 Field.VarAttribute{ilist+NbCoord}.FieldName=ListInputField{ilist}; 207 end 208 r=regexp(ListInputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 209 if ~isempty(r)&& strcmp(r.Operator,'norm') 210 NormName='norm'; 211 if ~isempty(find(strcmp(ListVar,'norm'))) 212 NormName='norm_1'; 213 end 214 Field.ListVarName=[Field.ListVarName {NormName}]; 215 ilistmax=numel(Field.ListVarName); 216 Field.VarDimName{ilistmax}=Field.VarDimName{ilist+2}; 217 Field.VarAttribute{ilistmax}.Role='scalar'; 218 Field.(NormName)=Field.(r.UName).*Field.(r.UName)+Field.(r.VName).*Field.(r.VName); 219 Field.(NormName)=sqrt(Field.(NormName)); 220 UName=r.UName; 221 VName=r.VName; 222 end 223 end 224 225 if ~isempty(NormName)% remove U and V if norm has been calculated and U and V are not needed as variables 226 ind_var_U=find(strcmp(UName,ListVar));%check previous listing of variable r.UName 227 ind_var_V=find(strcmp(VName,ListVar));%check previous listing of variable r.VName 228 if ~checkU && ~checkV 229 Field.ListVarName([ind_var_U+2 ind_var_V+2])=[]; 230 Field.VarDimName([ind_var_U+2 ind_var_V+2])=[]; 231 Field.VarAttribute([ind_var_U+2 ind_var_V+2])=[]; 232 elseif ~checkU 233 Field.ListVarName(ind_var_U+2)=[]; 234 Field.VarDimName(ind_var_U+2)=[]; 235 Field.VarAttribute(ind_var_U+2 )=[]; 236 elseif ~checkV 237 Field.ListVarName(ind_var_V+2)=[]; 238 Field.VarDimName(ind_var_V+2)=[]; 239 Field.VarAttribute(ind_var_V+2 )=[]; 240 end 241 end 242 % insert coordinates as indices in case of plots vs matrix index 243 if isfield(ParamIn,'CheckCoordIndex') && ParamIn.CheckCoordIndex 244 Field.ListVarName=[Field.ListDimName Field.ListVarName]; 245 Field.VarDimName=[Field.ListDimName Field.VarDimName]; 246 for idim=1:numel(Field.ListDimName) 247 CoordName=Field.ListDimName{idim}; 248 Field.(CoordName)=1:Field.DimValue(idim); 249 end 250 Field.VarAttribute=[cell(1,numel(Field.ListDimName)) Field.VarAttribute]; 251 end 252 253 end 222 VarAttribute{ilist}.Operator=Operator{ilist}; 223 end 224 if strcmp(Operator{ilist},'norm') 225 UName=ListVarName{ilist}; 226 VName=ListVarName{ilist+1}; 227 ListVarName{ilist}='norm'; 228 Field.norm=Field.(UName).*Field.(UName)+Field.(VName).*Field.(VName); 229 Field.norm=sqrt(Field.norm); 230 check_remove(ilist+1)=true; 231 VarAttribute{ilist}.Operator=''; 232 end 233 end 234 ListVarName(check_remove)=[]; 235 VarDimName(check_remove)=[]; 236 VarAttribute(check_remove)=[]; 237 Field.ListVarName=[Field.ListVarName(1:NbCoord) ListVarName];% complement the list of vqriables, which may be listed twice 238 Field.VarDimName=[Field.VarDimName(1:NbCoord) VarDimName]; 239 Field.VarAttribute=[Field.VarAttribute(1:NbCoord) VarAttribute]; 240 end 241 254 242 case 'video' 255 243 if strcmp(class(ParamIn),'VideoReader') … … 286 274 for ilist=1:numel(Input.Frames{1}.Attributes) 287 275 if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries') 288 timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000;289 break276 timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000; 277 break 290 278 end 291 279 end … … 294 282 otherwise 295 283 errormsg=[ FileType ': invalid input file type for uvmat']; 284 296 285 end 297 286 … … 311 300 Field.VarAttribute{1}.Unit='pixel'; 312 301 Field.VarAttribute{2}.Unit='pixel'; 302 Field.VarAttribute{1}.Role='coord_y'; 303 Field.VarAttribute{2}.Role='coord_x'; 313 304 Field.VarAttribute{3}.Role='scalar'; 314 305 if ndims(A)==3 -
trunk/src/uvmat.m
r1041 r1045 1748 1748 set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch' 1749 1749 drawnow 1750 % readthe current input file name:1750 % get the current input file name: 1751 1751 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); 1752 1752 % detect the file type, get the movie object if relevant, and look for the corresponding file series: … … 2002 2002 UvData.NewSeries=1; %flag for REFRESH: begin a new series 2003 2003 UvData.FileName_1='';% name of the current second field (used to detect a constant field during file scanning) 2004 UvData.FileType{index}=FileInfo.FileType;2004 %UvData.FileType{index}=FileInfo.FileType; 2005 2005 UvData.FileInfo{index}=FileInfo; 2006 2006 UvData.MovieObject{index}=VideoObject; … … 2196 2196 UvData.XmlData{index}=XmlData; 2197 2197 UvData.NewSeries=1; 2198 set(handles.uvmat,'UserData',UvData) 2198 2199 2199 2200 %display warning message … … 2233 2234 set(handles.Coord_y,'String','Coord_y'); 2234 2235 end 2235 set(handles.uvmat,'UserData',UvData) 2236 2236 2237 2237 2238 %% set index navigation options … … 3157 3158 if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used 3158 3159 if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used 3159 % if strcmp(get(handles.NomType,'String'),'level')3160 % jindex=str2num(get(handles.j1,'String'));3161 % filename=[fullfile(RootPath,SubDir,['level' num2str(jindex)],RootFile) FileIndex FileExt];% build the input file name (first line)3162 % else3163 3160 if isempty(regexp(RootPath,'^http://')) 3164 filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)3161 filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line) 3165 3162 else 3166 3163 filename=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];% … … 3250 3247 for iobj=1:numel(UvData.ProjObject) 3251 3248 if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps') 3252 check_proj_tps=1; 3249 check_proj_tps=1;% tps projection proposed 3253 3250 break 3254 3251 end … … 3285 3282 end 3286 3283 end 3287 switch UvData.FileInfo{1}.Fi leType3288 case {'civ x','civdata','netcdf','pivdata_fluidimage'};3284 switch UvData.FileInfo{1}.FieldType 3285 case {'civdata','netcdf'}; 3289 3286 list_fields=get(handles.FieldName,'String');% list menu fields 3290 3287 FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field … … 3775 3772 set(handles.ListObject_1,'String',{'plane'}) 3776 3773 if UvData.Field.NbDim==3 %3D case 3777 % ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider3778 % ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider3779 3774 UvData.ProjObject{1}.NbDim=3;%test for 3D objects 3780 3775 UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane 3781 3776 UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen 3782 3777 UvData.ProjObject{1}.Angle=[0 0]; 3778 if isfield(UvData.Field,'CoordUnit') 3779 UvData.ProjObject{1}.CoordUnit=CoordUnit; 3780 end 3783 3781 elseif isfield(UvData,'Z') 3784 3782 %multilevel case (single menuplane in a 3D space) … … 3846 3844 UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects 3847 3845 if ~isfield(UvData.ProjObject{iobj},'RangeZ') 3848 UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane3846 UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane 3849 3847 end 3850 3848 if iobj==1 && ~(isfield(UvData.ProjObject{iobj},'Coord') && size(UvData.ProjObject{iobj}.Coord,2)>=3 && UvData.ProjObject{iobj}.Coord(1,3)<UvData.Field.ZMax && UvData.ProjObject{iobj}.Coord(1,3)>UvData.Field.ZMin) 3851 3849 UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen 3852 3850 end 3853 3851 end … … 3979 3977 % display menus and plot histograms 3980 3978 test_v=0; 3981 if ~isempty(menu_histo) 3982 set(handles.HistoMenu,'Value',1) 3983 set(handles.HistoMenu,'String',menu_histo) 3984 set(handles.Histogram,'Visible','on') 3985 set(handles.HistoMenu,'Visible','on') 3986 set(handles.HistoAxes,'Visible','on') 3987 HistoMenu_Callback(handles.HistoMenu, [], handles)% plot first histogram 3988 end 3989 end 3990 3979 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A REMETTRE 3980 % if ~isempty(menu_histo) 3981 % set(handles.HistoMenu,'Value',1) 3982 % set(handles.HistoMenu,'String',menu_histo) 3983 % set(handles.Histogram,'Visible','on') 3984 % set(handles.HistoMenu,'Visible','on') 3985 % set(handles.HistoAxes,'Visible','on') 3986 % HistoMenu_Callback(handles.HistoMenu, [], handles)% plot first histogram 3987 % end 3988 end 3989 % open the set_object for interactive plane projection in 3D case 3991 3990 if UvData.Field.NbDim==3 3992 3991 set(handles.CheckEditObject,'Value',1) 3993 3992 CheckEditObject_Callback(handles.uvmat, [], handles) 3994 3993 end 3995 %ResizeFcn(handles.uvmat,[],handles) 3994 3996 3995 set(handles.uvmat,'Pointer',pointer) 3997 3996 … … 4359 4358 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); 4360 4359 if isempty(regexp(RootPath,'^http://')) 4361 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];4360 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; 4362 4361 else 4363 4362 FileName=[RootPath '/' SubDir '/' RootFile FileIndices FileExt]; … … 4452 4451 set(handles.Coord_y,'Max',2) 4453 4452 %set(huvmat, 4454 case 'civdata...'%reinitiate input, return to automatic civ data reading 4453 case 'civdata...'%reinitiate input, return to automatic civ data readingget_field 4455 4454 display_file_name(handles,FileName,1) 4456 4455 end … … 4459 4458 if isfield(GetFieldData,'Coordinates') 4460 4459 XName=GetFieldData.Coordinates.Coord_x; 4461 % set(handles.SwitchCoordIndex,'String','var'); % variable used as coordinate4462 % else4463 % set(handles.SwitchCoordIndex,'String','dim'); % matrix index used a coordinate4464 4460 end 4465 4461 TimeNameStr=GetFieldData.Time.SwitchVarIndexTime; … … 4477 4473 MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension); 4478 4474 set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit 4479 UvData=get(handles.uvmat,'UserData');4480 4475 UvData.TimeUnit=GetFieldData.Time.TimeUnit; 4481 4476 set(handles.uvmat,'UserData',UvData); … … 4490 4485 MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension); 4491 4486 set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit 4492 UvData=get(handles.uvmat,'UserData');4493 4487 UvData.TimeUnit=GetFieldData.Time.TimeUnit; 4494 4488 set(handles.uvmat,'UserData',UvData); … … 4497 4491 end 4498 4492 set(handles.Coord_x,'String',XName) 4499 % if ischar(YName)4500 % YName={YName};4501 % end4502 4493 set(handles.Coord_y,'String',YName) 4503 4494 set(handles.Coord_z,'String',ZName) … … 4506 4497 set(handles.ColorScalar,'Value',1) 4507 4498 set(handles.ColorScalar,'String',VecColorList); 4508 UvData.FileInfo{1}.FileType='netcdf';4499 % UvData.FileInfo{1}.FileType='netcdf'; 4509 4500 set(handles.uvmat,'UserData',UvData) 4510 4501 REFRESH_Callback(hObject, eventdata, handles) … … 4672 4663 set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]); 4673 4664 4674 UvData.File Type{2}='netcdf';4665 UvData.FileInfo{2}.FileType='netcdf'; 4675 4666 set(handles.uvmat,'UserData',UvData) 4676 4667 REFRESH_Callback(hObject, eventdata, handles) … … 4804 4795 else% we introduce the same file (with a different field) for the second series 4805 4796 FileName_1=FileName;% we compare two fields in the same file 4806 UvData.File Type{2}=UvData.FileInfo{1}.FileType;4797 UvData.FileInfo{2}.FileType=UvData.FileInfo{1}.FileType; 4807 4798 UvData.XmlData{2}= UvData.XmlData{1}; 4808 4799 set(handles.SubField,'Value',1) … … 5721 5712 %------------------------------------------------------------------------ 5722 5713 check_view=get(handles.CheckViewObject,'Value'); 5723 5724 5725 5726 5714 hset_object=findobj(allchild(0),'tag','set_object'); 5715 if ~isempty(hset_object) 5716 delete(hset_object)% delete existing version of set_object 5717 end 5727 5718 if check_view %activate set_object 5728 5719 IndexObj=get(handles.ListObject,'Value'); … … 5747 5738 data.Type='plane'; 5748 5739 end 5749 5740 5750 5741 %% initiate the new projection object 5751 5742 hset_object=set_object(data,[],ZBounds); … … 5758 5749 set(hhset_object.SAVE,'Enable','on') 5759 5750 end 5760 else5761 % hset_object=findobj(allchild(0),'tag','set_object');5762 % if ~isempty(hset_object)5763 % delete(hset_object)% delete existing version of set_object5764 % end5765 5751 end 5766 5752
Note: See TracChangeset
for help on using the changeset viewer.