Changeset 530
- Timestamp:
- Aug 27, 2012, 4:38:41 PM (12 years ago)
- Location:
- trunk/src
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/calc_tps.m
r516 r530 5 5 SubDomain=DataIn.SubDomain;% 6 6 end 7 [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(DataIn); 7 %[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(DataIn); 8 [CellInfo,NbDimArray,errormsg]=find_field_cells(DataIn); 8 9 nbtps=0; 9 for icell=1:numel(Cell VarIndex);10 VarType=VarTypeCell{icell};11 if NbDim Vec(icell)>=2&& ~isempty(VarType.coord_x)10 for icell=1:numel(CellInfo); 11 %VarType=VarTypeCell{icell}; 12 if NbDimArray(icell)>=2 && strcmp(CellInfo{icell}.CoordType,'scattered')%'&& ~isempty(VarType.coord_x) 12 13 nbtps=nbtps+1; 13 X=DataIn.(DataIn.ListVarName{ VarType.coord_x});14 Y=DataIn.(DataIn.ListVarName{ VarType.coord_y});15 if ~isempty(VarType.vector_x)&&~isempty(VarType.vector_y)16 Attr=DataIn.VarAttribute{ VarType.vector_x};14 X=DataIn.(DataIn.ListVarName{CellInfo{icell}.CoordIndex(end)}); 15 Y=DataIn.(DataIn.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 16 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') 17 Attr=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x}; 17 18 if ~isfield(Attr,'VarIndex_tps')&& (checkall || (isfield(Attr,'FieldRequest')&&strcmp(Attr.FieldRequest,'interp_tps'))) 18 U=DataIn.(DataIn.ListVarName{ VarType.vector_x});19 V=DataIn.(DataIn.ListVarName{ VarType.vector_y});19 U=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 20 V=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 20 21 else 21 22 continue 22 23 end 23 24 end 24 if ~isempty(VarType.errorflag)25 FF=DataIn.(DataIn.ListVarName{ VarType.errorflag});25 if isfield(CellInfo{icell},'VarIndex_errorflag') 26 FF=DataIn.(DataIn.ListVarName{CellInfo{icell}.VarIndex_errorflag}); 26 27 X=X(FF==0); 27 28 Y=Y(FF==0); … … 47 48 48 49 DataOut.VarAttribute{nbvar+3}.Role='coord_tps'; 49 DataOut.VarAttribute{nbvar+4}=DataIn.VarAttribute{ VarType.vector_x};%reproduce attributes of velocity50 DataOut.VarAttribute{nbvar+4}=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x};%reproduce attributes of velocity 50 51 DataOut.VarAttribute{nbvar+4}.Role='vector_x_tps'; 51 DataIn.VarAttribute{ VarType.vector_x}.VarIndex_tps=nbvar+4;% indicte the correspondance with initial data52 DataOut.VarAttribute{nbvar+5}=DataIn.VarAttribute{ VarType.vector_y};%reproduce attributes of velocity52 DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_x}.VarIndex_tps=nbvar+4;% indicte the correspondance with initial data 53 DataOut.VarAttribute{nbvar+5}=DataIn.VarAttribute{CellInfo{icell}.VarIndex_vector_y};%reproduce attributes of velocity 53 54 DataOut.VarAttribute{nbvar+5}.Role='vector_y_tps'; 54 55 if isfield(DataOut,'ListDimName')%cleaning' -
trunk/src/check_files.m
r515 r530 35 35 'calc_field_tps';...% defines fields (velocity, vort, div...) and calculate them 36 36 'cell2tab';... %transform a Matlab cell in a character array suitable for display in a table 37 'check_field_structure';...% check the validity of the field struture representation consistant with the netcdf format38 37 'check_files';... 39 38 'civ';... %function associated with the interface 'civ.fig' for PIV and spline interpolation -
trunk/src/displ_uvmat.m
r473 r530 1 %'displ_uvmat': display a message using msgbox_uvmat or on the log file in batch mode 2 %-------------------------------------------------------------------------- 3 % function displ_uvmat(title,display_str,Position) 4 % 1 5 function displ_uvmat(title,display_str,Position) 2 6 if isequal(Position,0) -
trunk/src/find_field_cells.m
r527 r530 2 2 % group the variables into 'fields' with common dimensions 3 3 %------------------------------------------------------------------------ 4 % function [Cell VarIndex,NbDim,CellVarType,errormsg]=find_field_cells(Data)4 % function [CellInfo,NbDim,errormsg]=find_field_cells(Data) 5 5 % 6 6 % OUTPUT: 7 % CellVaxIndex: cell whose elements are arrays of indices in the list data.ListVarName 8 % CellvarIndex{i} represents a set of variables with the same dimensions 9 % NbDim: array with the length of CellVarIndex, giving its space dimension 10 % CellVarType: cell array of structures with fields 11 % .coord_x, y, z: indices (in .ListVarname) of variables representing unstructured coordinates x, y, z 12 % .vector_x,_y,_z: indices of variables giving the vector components x, y, z 13 % .warnflag: index of warnflag 14 % .errorflag: index of error flag 15 % .ancillary: indices of ancillary variables 16 % .image : B/W image, (behaves like scalar) 17 % .color : color image, the last index, which is not a coordinate variable, represent the 3 color components rgb 18 % .discrete: like scalar, but set of data points without continuity, represented as dots in a usual plot, instead of continuous lines otherwise 19 % .scalar: scalar field (default) 20 % .coord: vector of indices of coordinate variables corresponding to matrix dimensions 21 % 7 % CellInfo: cell of structures describing field cells 8 % .CoordType: type of coordinates for each field cell = 'scattered','grid','tps'; 9 % .CoordIndex: array of the indices of the variables representing the coordinates (in the order z,y,x) 10 % .CoordSize: array of the nbre of values for each coordinate in a grid, nbre of points in the unstructured case 11 % .NbSite_tps: 12 % .SubRange_tps 13 % .VarIndex: arrays of the variable indices in the field cell 14 % .VarIndex_ancillary: indices of ancillary variables 15 % _color : color image, the last index, which is not a coordinate variable, represent the 3 color components rgb 16 % _discrete: like scalar, but set of data points without continuity, represented as dots in a usual plot, instead of continuous lines otherwise 17 % _errorflag: index of error flag 18 % _image : B/W image, (behaves like scalar) 19 % _vector_x,_y,_z: indices of variables giving the vector components x, y, z 20 % _warnflag: index of warnflag 22 21 % .FieldRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation or derivatives (tps) is needed to calculate the requested field 23 % .FieldNames = cell of fields to calculate from the fied cell 24 % 22 % .Operation = operation to be performed to finalise the field cell after projection 23 % .SubCheck=0 /1 indicate that the field must be substracted (second entry in uvmat) 24 % NbDim: array with the length of CellVarIndex, giving the space dimension of each field cell 25 25 % errormsg: error message 26 26 % … … 54 54 % group the variables into 'fields' with common dimensions 55 55 56 function [CellVarIndex,NbDim,CellVarType,errormsg]=find_field_cells(Data) 57 CellVarIndex={}; 58 59 CellVarType=[]; 56 function [CellInfo,NbDim,errormsg]=find_field_cells(Data) 57 % CellVarIndex={}; 58 % CellInfo={} 59 NbDim=0; 60 % CellVarType=[]; 60 61 errormsg=[]; 62 if ~isfield(Data,'ListVarName'), errormsg='the list of variables .ListVarName is missing';return;end 63 if ~isfield(Data,'VarDimName'), errormsg='the list of dimensions .VarDimName is missing';return;end 61 64 nbvar=numel(Data.ListVarName);%number of field variables 65 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 62 77 icell=0; 63 78 64 NbDim=[]; 65 VarDimIndex=[]; 66 VarDimName={}; 67 if ~isfield(Data,'VarDimName') 68 errormsg='missing .VarDimName'; 69 return 70 end 79 % NbDim=[]; 80 % VarDimIndex=[]; 81 % VarDimName={}; 71 82 72 83 %% role of variables and list of requested operations 84 %ListRole={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','vector_x_tps','vector_y_tps','warnflag','errorflag',... 85 % 'ancillary','image','color','discrete','scalar','coord_tps'};% rmq vector_x_tps and vector_y_tps to be replaced by vector_x and vector_y 73 86 Role=num2cell(blanks(nbvar));%initialize a cell array of nbvar blanks 74 87 FieldRequest=regexprep(Role,' ',''); % fieldRequest set to '' by default … … 93 106 end 94 107 95 %% loop on the list of variables, group them by common dimensions 96 CellVarType=cell(1,length(CellVarIndex)); 97 for ivar=1:nbvar 98 if ischar(Data.VarDimName{ivar}) 99 Data.VarDimName{ivar}=Data.VarDimName(ivar);%transform char chain into cell 100 end 101 DimCell=Data.VarDimName{ivar}; %dimensions associated with the variable #ivar 102 testnewcell=1; 103 for icell_prev=1:numel(CellVarIndex)%detect whether the dimensions of ivar fit with an existing cell 104 PrevVarIndex=CellVarIndex{icell_prev};%list of variable indices in cell # icell_prev 105 PrevDimCell=Data.VarDimName{PrevVarIndex(1)};%list of corresponding variable names 106 if isequal(PrevDimCell,DimCell) 107 CellVarIndex{icell_prev}=[CellVarIndex{icell_prev} ivar];% add variable index #ivar to the cell #icell_prev 108 testnewcell=0; %existing cell detected 109 break 110 end 111 end 112 if testnewcell 113 icell=icell+1; 114 CellVarIndex{icell}=ivar;%put the current variable index in the new cell 115 NbDim(icell)=numel(DimCell);%default 116 CellVarType{icell}=[]; 117 end 118 if ~isempty(FieldRequest{ivar}) 119 CellVarType{icell}.FieldRequest=FieldRequest{ivar}; 120 end 121 if ~isempty(Operation{ivar}) 122 CellVarType{icell}.Operation=Operation{ivar}; 123 end 124 if CheckSub(ivar) 125 CellVarType{icell}.CheckSub=1; 126 end 127 end 128 129 %% find dimension variables 130 checksinglecell=cellfun(@numel,CellVarIndex)==1 & NbDim==1;% find isolated cells with a single dimension 131 ind_dim_var_cell=find(checksinglecell); 132 %CoordType(ind_dim_var_cell)='dim_var';% to be used in output 133 %VarDimIndex=cell(size(ind_dim_var_cell)); 134 VarDimName=cell(size(ind_dim_var_cell)); 135 for icoord=1:numel(ind_dim_var_cell) 136 VarDimIndex(icoord)=CellVarIndex{ind_dim_var_cell(icoord)}; 137 VarDimName{icoord}=Data.VarDimName{VarDimIndex(icoord)}{1}; 138 end 139 140 %% find the spatial dimensions and vector components 141 ListRole={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','vector_x_tps','vector_y_tps','warnflag','errorflag',... 142 'ancillary','image','color','discrete','scalar','coord_tps'};% rmq vector_x_tps and vector_y_tps to be replaced by vector_x and vector_y 143 144 for ilist=1:numel(ListRole) 145 VarType.(ListRole{ilist})=find(strcmp(ListRole{ilist},Role)); 146 end 147 %look for tps coordinates 148 if ~isempty(VarType.coord_tps) 149 VarType.subrange_tps=[]; 150 VarType.nbsites_tps=[]; 151 select=zeros(1,numel(VarType.coord_tps)); 152 for ifield=1:numel(VarType.coord_tps) 153 DimCell=Data.VarDimName{VarType.coord_tps(ifield)}; 154 if numel(DimCell)==3 155 for ivardim=1:numel(Data.VarDimName) 156 if strcmp(Data.VarDimName{ivardim},DimCell{3}) 157 VarType.nbsites_tps=[VarType.nbsites_tps ivardim]; 158 select(ifield)=select(ifield)+1; 159 elseif strcmp(Data.VarDimName{ivardim}{1},DimCell{2}) && strcmp(Data.VarDimName{ivardim}{3},DimCell{3}) 160 VarType.subrange_tps=[VarType.subrange_tps ivardim]; 161 select(ifield)=select(ifield)+1; 108 %% find scattered (unstructured) coordinates 109 ivar_coord_x=find(strcmp('coord_x',Role)); 110 % VarDimCell=cell(numel(ivar_coord_x)); 111 check_select=zeros(1,nbvar); 112 CellInfo=cell(1,numel(ivar_coord_x)); 113 NbDim=zeros(1,numel(ivar_coord_x)); 114 for icell=1:numel(ivar_coord_x) 115 DimCell=Data.VarDimName{ivar_coord_x(icell)}; 116 if ischar(DimCell),DimCell={DimCell};end 117 check_cell=zeros(numel(DimCell),nbvar); 118 for idim=1:numel(DimCell) 119 for ivar=1:nbvar 120 check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar})); 121 end 122 end 123 check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell 124 VarIndex=find(check_cell); 125 if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later) 126 if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate 127 CellInfo{icell}.CoordIndex=ivar_coord_x(icell); 128 % size of coordinate var 129 if check_dim 130 for idim=1:numel(DimCell) 131 check_index= strcmp(DimCell{idim},Data.ListDimName); 132 CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index); 133 end 134 CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize); 135 else 136 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)})); 137 end 138 ind_y=find(strcmp('coord_y',Role(VarIndex))); 139 if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y 140 NbDim(icell)=1; 141 else 142 CellInfo{icell}.CoordType='scattered'; 143 ind_z=find(strcmp('coord_z',Role(VarIndex))); 144 if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y) 145 CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex]; 146 NbDim(icell)=2; 147 else 148 CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex]; 149 NbDim(icell)=3; 162 150 end 163 151 end 164 152 end 165 end 166 VarType.coord_tps=VarType.coord_tps(select==2); 167 VarType.subrange_tps=VarType.subrange_tps(select==2); 168 VarType.nbsites_tps=VarType.nbsites_tps(select==2); 169 end 170 171 index_remove=[]; 172 for icell=1:length(CellVarIndex) 173 if checksinglecell(icell) 174 continue 175 end 176 VarIndex=CellVarIndex{icell};%set of variable indices with the same dim 177 check_remove=0; 178 for ifield=1:numel(VarType.coord_tps) 179 if isequal(VarIndex,VarType.coord_tps(ifield))||isequal(VarIndex,VarType.subrange_tps(ifield))||isequal(VarIndex,VarType.nbsites_tps(ifield)) 180 index_remove=[index_remove icell];% removes Coord_tps as field cell 181 check_remove=1; 182 end 183 end 184 185 if ~check_remove 186 for ilist=1:numel(ListRole) 187 CellVarType{icell}.(ListRole{ilist})=VarIndex(find(strcmp(ListRole{ilist},Role(VarIndex)))); 188 end 189 DimCell=Data.VarDimName{VarIndex(1)};% list of dimensions for each variable in the cell #icell 190 if numel(CellVarType{icell}.coord_x)>1 || numel(CellVarType{icell}.coord_y)>1 || numel(CellVarType{icell}.coord_z)>1 191 errormsg='multiply defined coordinates in the same cell'; 192 return 193 end 194 % case of x cordinate marked as a dimension variable (var name=dimension name) 195 if isempty(CellVarType{icell}.coord_x) 196 var_dim_index=find(strcmp(DimCell{1},Data.ListVarName(VarIndex))); 197 if ~isempty(var_dim_index) 198 CellVarType{icell}.coord_x=VarIndex(var_dim_index); 153 CellInfo{icell}.VarIndex=VarIndex; 154 check_select=check_select|check_cell; 155 end 156 end 157 158 %% look for tps coordinates 159 ivar_remain=find(~check_select); 160 check_coord_tps= strcmp('coord_tps',Role(~check_select)); 161 ivar_tps=ivar_remain(check_coord_tps); 162 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); 166 CellInfo{icell}.VarIndex_subrange_tps=[]; 167 CellInfo{icell}.VarIndex_nbsites_tps=[]; 168 if numel(DimCell)==3 169 VarDimName=Data.VarDimName(~check_select); 170 for ivardim=1:numel(VarDimName) 171 if strcmp(VarDimName{ivardim},DimCell{3}) 172 CellInfo{icell}.NbSite_tps= ivar_remain(ivardim); 173 check_cell(ivar_remain(ivardim))=1;% nbre of sites for each tps subdomain 174 elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && strcmp(VarDimName{ivardim}{3},DimCell{3}) 175 CellInfo{icell}.SubRange_tps=ivar_remain(ivardim); 176 check_cell(ivar_remain(ivardim))=1;% subrange definiton for tps 177 elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3}) 178 check_cell(ivar_remain(ivardim))=1;% variable 199 179 end 200 end 201 if numel(CellVarType{icell}.errorflag)>1 202 errormsg='multiply defined error flag in the same cell'; 203 return 204 end 205 if numel(CellVarType{icell}.warnflag)>1 206 errormsg='multiply defined warning flag in the same cell'; 207 return 208 end 209 test_coord=0; 210 % look for unstructured coordinates 211 if numel(VarIndex)>1 212 if ~isempty(CellVarType{icell}.coord_z) 213 NbDim(icell)=3; 214 test_coord=1; 215 elseif ~isempty(CellVarType{icell}.coord_y) 216 NbDim(icell)=2; 217 test_coord=1; 218 elseif ~isempty(CellVarType{icell}.coord_x) 219 NbDim(icell)=1; 220 test_coord=1; 221 elseif numel(DimCell)==1 222 NbDim(icell)=0;% set of data without coordinates 223 end 224 end 225 % look for coordinates variables 226 coord=zeros(1,numel(DimCell));%default 227 if ~test_coord && ~isempty(VarDimName) 228 for idim=1:numel(DimCell) %loop on the dimensions of the variables in cell #icell 229 ind_coord=find(strcmp(DimCell{idim},VarDimName)); 230 if ~isempty(ind_coord) 231 coord(idim)=VarDimIndex(ind_coord); 232 end 233 end 234 NbDim(icell)=numel(find(coord)); 235 end 236 CellVarType{icell}.coord=coord; 237 %look for tps data 238 if ~isempty(VarType.coord_tps) 239 for ilist=1:numel(VarType.coord_tps) 240 tps_dimnames=Data.VarDimName{VarType.coord_tps(ilist)}; 241 if length(tps_dimnames)==3 && strcmp(tps_dimnames{1},DimCell{1}) && strcmp(tps_dimnames{3},DimCell{2}) 242 CellVarIndex{icell}=[CellVarIndex{icell} VarType.coord_tps(ilist) VarType.nbsites_tps(ilist) VarType.subrange_tps(ilist)]; 243 CellVarType{icell}.coord_tps=VarType.coord_tps(ilist); 244 CellVarType{icell}.nbsites_tps=VarType.nbsites_tps(ilist); 245 CellVarType{icell}.subrange_tps=VarType.subrange_tps(ilist); 246 if isfield(Data,'ListDimName') 247 dim_index=find(strcmp(tps_dimnames{2},Data.ListDimName)); 248 NbDim(icell)=Data.DimValue(dim_index); 249 else 250 NbDim(icell)=size(Data.(Data.ListVarName{VarType.coord_tps(ilist)}),2); 251 end 252 end 253 end 254 end 255 end 256 end 257 if ~isempty(index_remove) 258 CellVarIndex(index_remove)=[]; 259 CellVarType(index_remove)=[]; 260 NbDim(index_remove)=[]; 261 end 180 end 181 end 182 CellInfo{icell}.CoordType='tps'; 183 CellInfo{icell}.VarIndex=find(check_cell); 184 if check_dim 185 check_index_1= strcmp(DimCell{1},Data.ListDimName); 186 check_index_2= strcmp(DimCell{2},Data.ListDimName); 187 check_index_3= strcmp(DimCell{3},Data.ListDimName); 188 NbDim(icell)=Data.DimValue(check_index_2); 189 CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); 190 else 191 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 end 194 check_select=check_select|check_cell; 195 end 196 197 %% look for dimension variables and corresponding gridded data 198 ivar_remain=find(~check_select); 199 VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables 200 check_coord= cellfun(@numel,VarDimName)==1|cellfun(@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 205 check_keep=logical(ones(size(ListDimName))); 206 for idim=1:numel(ListDimName) 207 prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim-1)); 208 if ~isempty(prev_ind) 209 if strcmp(ListCoordName{idim},ListDimName{idim}) %coordinate variable 210 check_keep(prev_ind)=0; 211 else 212 check_keep(idim)=0; 213 end 214 end 215 end 216 ListCoordIndex=ListCoordIndex(check_keep); 217 ListCoordName=ListCoordName(check_keep); 218 ListDimName=ListDimName(check_keep); 219 220 CoordSize=[]; 221 for ilist=1:numel(ListCoordIndex) 222 if iscell(ListDimName{ilist}) 223 ListDimName(ilist)=ListDimName{ilist};%transform cell to string 224 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); 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 243 NewCellInfo={}; 244 NewCellDimIndex={}; 245 NewNbDim=[]; 246 for ivardim=1:numel(VarDimName) % loop on the list of remaining variables 247 DimCell=VarDimName{ivardim};% dimension names of the current variable 248 if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed 249 DimIndices=[]; 250 for idim=1:numel(DimCell) 251 ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coord dimensions 252 if ~isempty(ind_dim) 253 DimIndices=[DimIndices ind_dim]; %update the list of coord dimensions included in DimCell 254 end 255 end 256 check_previous=0; 257 for iprev=1:numel(NewCellInfo) 258 if isequal(DimIndices,NewCellDimIndex{iprev}) 259 check_previous=1; 260 NewCellInfo{iprev}.VarIndex=[NewCellInfo{iprev}.VarIndex ivar_remain(ivardim)];%append the current variable index to the found field cell 261 break 262 end 263 end 264 if ~check_previous 265 nbcell=numel(NewCellInfo)+1; 266 NewCellDimIndex{nbcell}=DimIndices; 267 NewCellInfo{nbcell}.VarIndex=ivar_remain(ivardim);% create a new field cell with the current variable index 268 NewNbDim(nbcell)=numel(DimIndices); 269 NewCellInfo{nbcell}.CoordType='grid'; 270 NewCellInfo{nbcell}.CoordSize=CoordSize; 271 NewCellInfo{nbcell}.CoordIndex=ListCoordIndex(DimIndices); 272 end 273 end 274 NbDim=[NbDim NewNbDim]; 275 CellInfo=[CellInfo NewCellInfo]; 276 277 %% suppress empty cells 278 check_empty=cellfun(@isempty,CellInfo); 279 %check_empty=cellfun(@isempty,CellVarIndex); 280 CellInfo(check_empty)=[]; 281 282 % CellVarIndex(check_empty)=[]; 283 NbDim(check_empty)=[]; 284 % CoordType(check_empty)=[]; 285 % VarRole(check_empty)=[]; 286 287 %% document roles of non-coordinate variables 288 % ListRole={'vector_x','vector_y','vector_z','vector_x_tps','vector_y_tps','warnflag','errorflag',... 289 % 'ancillary','image','color','discrete','scalar'};% except coord,coord_x,_y,_z,Coord_tps already taken, into account 290 for icell=1:numel(CellInfo) 291 VarIndex=CellInfo{icell}.VarIndex; 292 for ivar=VarIndex 293 if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) 294 CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; 295 else 296 CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; 297 end 298 if ~isempty(FieldRequest{ivar}) 299 CellInfo{icell}.FieldRequest=FieldRequest{ivar}; 300 end 301 if ~isempty(Operation{ivar}) 302 CellInfo{icell}.Operation=Operation{ivar}; 303 end 304 if CheckSub(ivar)==1 305 CellInfo{icell}.CheckSub=1; 306 end 307 end 308 end -
trunk/src/get_field.m
r528 r530 218 218 219 219 set(handles.scalar,'String', Txt ) 220 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); 220 [CellInfo,NbDim,errormsg]=find_field_cells(Field); 221 % [CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Field); 221 222 if ~isempty(errormsg) 222 msgbox_uvmat('ERROR',[' error in get_field/Field_input/find_field_cells: ' errormsg])223 msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg]) 223 224 return 224 225 end 225 for icell=1:numel(Cell VarIndex)226 NbDim(icell)=max(NbDim(icell),numel(Cell VarIndex{icell}));226 for icell=1:numel(CellInfo) 227 NbDim(icell)=max(NbDim(icell),numel(CellInfo{icell}.VarIndex)); 227 228 end 228 229 [maxdim,imax]=max(NbDim); … … 242 243 if maxdim>=2 243 244 set(handles.CheckPlot1D,'Value',0) 244 if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y)245 if isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') 245 246 set(handles.CheckVector,'Value',1) 246 247 set(handles.CheckScalar,'Value',0) 247 set(handles.vector_x,'Value',VarType{imax}.vector_x(1)) 248 set(handles.vector_y,'Value',VarType{imax}.vector_y(1)) 249 if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) 250 set(handles.coord_x_vectors,'Value',VarType{imax}.coord_x+1) 251 set(handles.coord_y_vectors,'Value',VarType{imax}.coord_y+1) 252 end 253 if ~isempty(VarType{imax}.coord) 254 set(handles.coord_y_vectors,'Value',VarType{imax}.coord(1)+1) 255 if numel(VarType{imax}.coord)>=2 256 set(handles.coord_x_vectors,'Value',VarType{imax}.coord(2)+1) 257 end 248 set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1)) 249 set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1)) 250 if strcmp(CellInfo{imax}.CoordType,'scattered') 251 set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end)) 252 set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1)) 253 elseif strcmp(CellInfo{imax}.CoordType,'grid') 254 set(handles.coord_x_vectors,'Value',CellInfo{imax}.CoordIndex(end)+1) 255 set(handles.coord_y_vectors,'Value',CellInfo{imax}.CoordIndex(end-1)+1) 258 256 end 259 257 else 260 258 set(handles.CheckScalar,'Value',1) 261 259 set(handles.CheckVector,'Value',0) 262 if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1 263 set(handles.scalar,'Value',VarType{imax}.scalar(1)) 264 if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) 265 set(handles.coord_x_scalar,'Value',VarType{imax}.coord_x+1) 266 set(handles.coord_y_scalar,'Value',VarType{imax}.coord_y+1) 267 end 268 if ~isempty(VarType{imax}.coord_z) 269 set(handles.coord_z_scalar,'Value',VarType{imax}.coord_z+1) 270 end 271 if ~isempty(VarType{imax}.coord) 272 if numel(VarType{imax}.coord)>=maxdim-2 && maxdim>=3 273 set(handles.coord_z_scalar,'Value',VarType{imax}.coord(maxdim-2)+1) 274 end 275 if numel(VarType{imax}.coord)>=maxdim-1 276 set(handles.coord_y_scalar,'Value',VarType{imax}.coord(maxdim-1)+1) 277 end 278 if numel(VarType{imax}.coord)>=maxdim 279 set(handles.coord_x_scalar,'Value',VarType{imax}.coord(maxdim)+1) 280 end 260 if isfield(CellInfo{imax},'VarIndex_scalar') 261 set(handles.scalar,'Value',CellInfo{imax}.VarIndex_scalar(1)) 262 set(handles.coord_x_scalar,'Value',CellInfo{imax}.CoordIndex(end)+1) 263 set(handles.coord_y_scalar,'Value',CellInfo{imax}.CoordIndex(end-1)+1) 264 if numel(CellInfo{imax}.CoordIndex)==3 265 set(handles.coord_z_scalar,'Value',CellInfo{imax}.CoordIndex(1)+1) 281 266 end 282 267 end … … 286 271 CheckVector_Callback(handles.CheckVector, [], handles) 287 272 end 288 %scalar_Callback(handles.get_field, eventdata, handles)289 %vector_x_Callback(handles.get_field, eventdata, handles)290 273 291 274 %------------------------------------------------------------------------ … … 301 284 variables_Callback(hObject, eventdata, handles) 302 285 end 303 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); 304 for icell=1:numel(CellVarIndex) 305 VarIndex=CellVarIndex{icell}; 306 if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex)) 307 cell_select=icell; 308 break 309 end 310 end 311 312 val=get(handles.abscissa,'Value'); 313 set(handles.abscissa,'Value',min(val,2)); 314 coord_x_index=VarType{cell_select}.coord; 315 coord_x_index=coord_x_index(coord_x_index~=0); 316 set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))']) 286 [CellInfo,NbDim,errormsg]=find_field_cells(Field); 287 %[CellVarIndex,NbDim,VarRole,errormsg]=find_field_cells(Field); 288 % for icell=1:numel(CellInfo) TODO: adapt to new convention 289 % VarIndex=CellInfo{icell}.VarIndex; 290 % if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarRole{icell}.coord_x)||~isequal(VarRole{icell}.coord_x,VarIndex)) 291 % cell_select=icell; 292 % break 293 % end 294 % end 295 % 296 % val=get(handles.abscissa,'Value'); 297 % set(handles.abscissa,'Value',min(val,2)); 298 % coord_x_index=VarRole{cell_select}.coord; 299 % coord_x_index=coord_x_index(coord_x_index~=0); 300 % set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))']) 317 301 318 302 %------------------------------------------------------------------------ -
trunk/src/mouse_motion.m
r512 r530 99 99 Field=FigData.(tagaxes); 100 100 if isfield(Field,'ListVarName') 101 [Cell VarIndex,NbDim,VarType]=find_field_cells(Field);%analyse the physical fields contained in Field101 [CellInfo,NbDimArray]=find_field_cells(Field);%analyse the physical fields contained in Field 102 102 text_displ_1=''; 103 103 text_displ_2=''; … … 107 107 xName=''; 108 108 z=[]; 109 for icell=1:numel(Cell VarIndex)%look for all physical fields110 if NbDim (icell)>=2 % select 2D field111 if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data112 eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';'])113 eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';'])109 for icell=1:numel(CellInfo)%look for all physical fields 110 if NbDimArray(icell)>=2 % select 2D field 111 if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured data 112 X=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end)}); 113 Y=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 114 114 flag_vec=(X<(xy(1,1)+Field.Mesh/3) & X>(xy(1,1)-Field.Mesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse 115 115 (Y<(xy(1,2)+Field.Mesh/3) & Y>(xy(1,2)-Field.Mesh/3));%f … … 132 132 end 133 133 %display the field values 134 for ivar=1:numel(Cell VarIndex{icell})135 VarName=Field.ListVarName{Cell VarIndex{icell}(ivar)};136 eval(['VarVal=Field.' VarName '(ivec);'])134 for ivar=1:numel(CellInfo{icell}.VarIndex) 135 VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; 136 VarVal=Field.(VarName)(ivec); 137 137 var_text=[VarName '=' num2str(VarVal,3) ',']; 138 if isequal(ivar, VarType{icell}.coord_x)||isequal(ivar,VarType{icell}.coord_y)||isequal(ivar,VarType{icell}.coord_z)138 if isequal(ivar,CellInfo{icell}.CoordIndex(end))||isequal(ivar,CellInfo{icell}.CoordIndex(end-1))||isequal(ivar,CellInfo{icell}.CoordIndex(1)) 139 139 text_displ_1=[text_displ_1 var_text]; 140 elseif isequal(ivar,VarType{icell}.vector_x)||isequal(ivar,VarType{icell}.vector_y)||isequal(ivar,VarType{icell}.vector_z) 140 elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||... 141 (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z)) 141 142 text_displ_3=[text_displ_3 var_text]; 142 143 else … … 149 150 end 150 151 end 151 elseif numel(VarType{icell}.coord) >=2 & VarType{icell}.coord > 0%structured coordinates152 yName=Field.ListVarName{ VarType{icell}.coord(1)};153 xName=Field.ListVarName{ VarType{icell}.coord(2)};154 eval(['y=Field.' yName ';'])155 eval(['x=Field.' xName ';'])156 VarName=Field.ListVarName{Cell VarIndex{icell}(1)};157 eval(['nxy=size(Field.' VarName ');']);152 elseif strcmp(CellInfo{icell}.CoordType,'grid') %structured coordinates 153 yName=Field.ListVarName{CellInfo{icell}.CoordIndex(1)}; 154 xName=Field.ListVarName{CellInfo{icell}.CoordIndex(2)}; 155 y=Field.(yName); 156 x=Field.(xName); 157 VarName=Field.ListVarName{CellInfo{icell}.VarIndex(1)}; 158 nxy=size(Field.(VarName)); 158 159 MaxAY=max(y(1),y(end)); %#ok<COLND> 159 160 MinAY=min(y(1),y(end)); %#ok<COLND> … … 163 164 if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) 164 165 text_displ_2=['i=' num2str(indx0) ',j=' num2str(indy0) ',']; 165 for ivar=1:numel(Cell VarIndex{icell})166 VarName=Field.ListVarName{Cell VarIndex{icell}(ivar)};167 eval(['VarVal=Field.' VarName '(indy0,indx0,:);'])166 for ivar=1:numel(CellInfo{icell}.VarIndex) 167 VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)}; 168 VarVal=Field.(VarName)(indy0,indx0,:); 168 169 var_text=[VarName '=' num2str(VarVal) ',']; 169 170 text_displ_2=[text_displ_2 var_text]; -
trunk/src/plot_field.m
r525 r530 110 110 index_1D=[]; 111 111 index_0D=[]; 112 errormsg=check_field_structure(Data);113 if ~isempty(errormsg)114 msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])115 display(['input of plot_field/check_field_structure: ' errormsg])116 return117 end112 % errormsg=check_field_structure(Data); 113 % if ~isempty(errormsg) 114 % msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg]) 115 % display(['input of plot_field/check_field_structure: ' errormsg]) 116 % return 117 % end 118 118 % check the cells of fields : 119 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Data); 119 [CellInfo,NbDimArray,errormsg]=find_field_cells(Data); 120 %[CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Data); 120 121 if ~isempty(errormsg) 121 122 msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]); 122 123 return 123 124 end 124 index_2D=find(NbDim==2);%find 2D fields 125 index_3D=find(NbDim >2,1);125 126 index_3D=find(NbDimArray>2,1); 126 127 if ~isempty(index_3D) 127 if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)128 index_2D=[index_2D index_3D];129 else128 % if isfield(Data,'NbDimArray')&& isequal(Data.NbDimArray,2) 129 % index_2D=[index_2D index_3D]; 130 % else 130 131 msgbox_uvmat('ERROR','volume plot not implemented yet'); 131 132 return 132 end 133 end 134 index_1D=find(NbDim==1&~cellfun(@isempty,VarType)); 135 index_0D=find(NbDim==0); 133 % end 134 end 135 index_2D=find(NbDimArray==2);%find 2D fields 136 index_1D=find(NbDimArray==1); 137 index_0D=find(NbDimArray==0); 136 138 %remove coordinates variables from 1D plot 137 139 % if ~isempty(index_2D) 138 140 % for ivar=1:length(index_1D) 139 % if isequal(CellVarIndex{index_1D(ivar)},Var Type{index_1D(ivar)}.coord)141 % if isequal(CellVarIndex{index_1D(ivar)},VarRole{index_1D(ivar)}.coord) 140 142 % index_1D(ivar)=0; 141 143 % end … … 192 194 %% 2D plots 193 195 if isempty(index_2D) 194 plot_plane([],[], [],haxes);%removes images or vector plots in the absence of 2D field plot196 plot_plane([],[],haxes);%removes images or vector plots in the absence of 2D field plot 195 197 else %plot 2D field 196 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,Cell VarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);198 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo(index_2D),haxes,PlotParam,PosColorbar); 197 199 AxeData.NbDim=2; 198 200 if testzoomaxes && isempty(errormsg) 199 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,Cell VarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);201 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellInfo(index_2D),zoomaxes,PlotParam,PosColorbar); 200 202 AxeData.ZoomAxes=zoomaxes; 201 203 end … … 205 207 if isempty(index_1D) 206 208 if ~isempty(haxes) 207 plot_profile([],[], [],haxes);%removes usual praphs y vs x in the absence of 1D field plot209 plot_profile([],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot 208 210 end 209 211 else %plot 1D field (usual graph y vs x) 210 Coordinates=plot_profile(Data,Cell VarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);%212 Coordinates=plot_profile(Data,CellInfo(index_1D),haxes,PlotParam.Coordinates);% 211 213 if testzoomaxes 212 [zoomaxes,Coordinates]=plot_profile(Data,Cell VarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);214 [zoomaxes,Coordinates]=plot_profile(Data,CellInfo(index_1D),zoomaxes,PlotParam.Coordinates); 213 215 AxeData.ZoomAxes=zoomaxes; 214 216 end … … 233 235 end 234 236 else 235 [errormsg]=plot_text(Data,Cell VarIndex(index_0D),VarType(index_0D),htext);237 [errormsg]=plot_text(Data,CellInfo(index_0D),htext); 236 238 end 237 239 end … … 262 264 263 265 %------------------------------------------------------------------- 264 function errormsg=plot_text(FieldData,Cell VarIndex,VarTypeCell,htext)266 function errormsg=plot_text(FieldData,CellInfo,htext) 265 267 %------------------------------------------------------------------- 266 268 errormsg=[]; 267 269 txt_cell={}; 268 270 Data={}; 269 for icell=1:length(Cell VarIndex)270 VarIndex=Cell VarIndex{icell};% indices of the selected variables in the list data.ListVarName271 for icell=1:length(CellInfo) 272 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 271 273 for ivar=1:length(VarIndex) 272 274 checkancillary=0; … … 303 305 304 306 %------------------------------------------------------------------- 305 function CoordinatesOut=plot_profile(data,Cell VarIndex,VarType,haxes,Coordinates)307 function CoordinatesOut=plot_profile(data,CellInfo,haxes,Coordinates) 306 308 %------------------------------------------------------------------- 307 309 … … 341 343 342 344 %loop on input fields 343 for icell=1:length(CellVarIndex) 344 if isempty(VarType{icell})% coordiante variable 345 continue 346 end 347 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName 348 if ~isempty(VarType{icell}.coord_x) 349 coord_x_index=VarType{icell}.coord_x; 350 else 351 coord_x_index_cell=VarType{icell}.coord(1); 352 if isequal(coord_x_index_cell,0) 353 continue % the cell has no abscissa, skip it 354 end 355 coord_x_index=coord_x_index_cell; 356 end 345 for icell=1:numel(CellInfo) 346 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list data.ListVarName 347 coord_x_index=CellInfo{icell}.CoordIndex; 357 348 testplot=ones(size(data.ListVarName));%default test for plotted variables 358 349 coord_x_name{icell}=data.ListVarName{coord_x_index}; … … 369 360 XMax(icell)=max(coord_x{icell}); 370 361 testplot(coord_x_index)=0; 371 if ~isempty(VarType{icell}.ancillary')372 testplot( VarType{icell}.ancillary)=0;373 end 374 if ~isempty(VarType{icell}.warnflag')375 testplot( VarType{icell}.warnflag)=0;362 if isfield(CellInfo{icell},'VarIndex_ancillary') 363 testplot(CellInfo{icell}.VarIndex_ancillary)=0; 364 end 365 if isfield(CellInfo{icell},'VarIndex_warnflag') 366 testplot(CellInfo{icell}.VarIndex_warnflag)=0; 376 367 end 377 368 if isfield(data,'VarAttribute') … … 385 376 end 386 377 end 387 if ~isempty(VarType{icell}.discrete')378 if isfield(CellInfo{icell},'VarIndex_discrete') 388 379 charplot_0='''+'''; 389 380 else … … 507 498 508 499 %------------------------------------------------------------------- 509 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,Cell VarIndex,VarTypeCell,haxes,PlotParam,PosColorbar)500 function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellInfo,haxes,PlotParam,PosColorbar) 510 501 %------------------------------------------------------------------- 511 502 … … 538 529 YName=''; 539 530 y_units=''; 540 for icell=1: length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)541 VarType=VarTypeCell{icell};542 if ~isempty(VarType.coord_tps) %do not plot directly tps data (used for projection only)531 for icell=1:numel(CellInfo) % length(CellVarIndex) =1 or 2 (from the calling function) 532 % VarRole=CellInfo{icell}; 533 if strcmp(CellInfo{icell}.CoordType,'tps') %do not plot directly tps data (used for projection only) 543 534 continue 544 535 end 545 ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[]) 546 ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[]) 547 ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[]) 548 ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[]) 549 ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields 536 ivar_X=CellInfo{icell}.CoordIndex(end); % defines (unique) index for the variable representing unstructured x coordinate (default =[]) 537 ivar_Y=CellInfo{icell}.CoordIndex(end-1); % defines (unique)index for the variable representing unstructured y coordinate (default =[]) 538 ivar_C=[]; 539 if isfield(CellInfo{icell},'VarIndex_scalar') 540 ivar_C=[ivar_C CellInfo{icell}.VarIndex_scalar]; 541 end 542 if isfield(CellInfo{icell},'VarIndex_image') 543 ivar_C=[ivar_C CellInfo{icell}.VarIndex_image]; 544 end 545 if isfield(CellInfo{icell},'VarIndex_color') 546 ivar_C=[ivar_C CellInfo{icell}.VarIndex_color]; 547 end 548 if isfield(CellInfo{icell},'VarIndex_ancillary') 549 ivar_C=[ivar_C CellInfo{icell}.VarIndex_ancillary]; 550 end 550 551 if numel(ivar_C)>1 551 552 errormsg= 'error in plot_field: too many scalar inputs'; 552 553 return 553 554 end 554 ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable 555 ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable 556 ind_coord=find(VarType.coord); 557 if numel(ind_coord)==2 558 VarType.coord=VarType.coord(ind_coord); 559 end 560 if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected 555 ivar_F=[]; 556 if isfield(CellInfo{icell},'VarIndex_warnflag') 557 ivar_F=CellInfo{icell}.VarIndex_warnflag; %defines index (unique) for warning flag variable 558 end 559 ivar_FF=[]; 560 if isfield(CellInfo{icell},'VarIndex_errorflag') 561 ivar_FF=CellInfo{icell}.VarIndex_errorflag; %defines index (unique) for error flag variable 562 end 563 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') % vector components detected 561 564 if test_vec 562 565 errormsg='error in plot_field: attempt to plot two vector fields: to get the difference project on a plane with mode interp'; … … 564 567 else 565 568 test_vec=1; 566 vec_U=Data.(Data.ListVarName{ ivar_U});567 vec_V=Data.(Data.ListVarName{ ivar_V});568 if ~isempty(ivar_X) && ~isempty(ivar_Y)%2D field with unstructured coordinates569 XName=Data.ListVarName{ ivar_X};570 YName=Data.ListVarName{ ivar_Y};569 vec_U=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 570 vec_V=Data.(Data.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 571 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 572 XName=Data.ListVarName{CellInfo{icell}.CoordIndex(end)}; 573 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 571 574 vec_X=reshape(Data.(XName),[],1); %transform vectors in column matlab vectors 572 575 vec_Y=reshape(Data.(YName),[],1); 573 elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables574 y=Data.(Data.ListVarName{ VarType.coord(1)});575 x=Data.(Data.ListVarName{ VarType.coord(2)});576 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 577 y=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}); 578 x=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); 576 579 if numel(y)==2 % y defined by first and last values on aregular mesh 577 580 y=linspace(y(1),y(2),size(vec_U,1)); … … 581 584 end 582 585 [vec_X,vec_Y]=meshgrid(x,y); 583 else584 errormsg='error in plot_field: invalid coordinate definition for vector field';585 return586 586 end 587 587 if isfield(PlotParam.Vectors,'ColorScalar') && ~isempty(PlotParam.Vectors.ColorScalar) 588 588 [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([],Data,PlotParam.Vectors.ColorScalar); 589 % if ~isempty(ivar_C) 590 %vec_C=Data.(Data.ListVarName{ivar_C}); 591 if ~isempty(VarVal) 592 vec_C=reshape(VarVal{1},1,numel(VarVal{1})); 593 test_C=1; 594 end 589 if ~isempty(VarVal) 590 vec_C=reshape(VarVal{1},1,numel(VarVal{1})); 591 test_C=1; 592 end 595 593 end 596 594 if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1)) … … 613 611 return 614 612 end 615 eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']);% scalar represented as color image613 A=squeeze(Data.(Data.ListVarName{ivar_C}));% scalar represented as color image 616 614 test_ima=1; 617 if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates (then ivar_X and ivar_Y not empty)615 if strcmp(CellInfo{icell}.CoordType,'scattered')%2D field with unstructured coordinates 618 616 A=reshape(A,1,[]); 619 617 XName=Data.ListVarName{ivar_X}; … … 630 628 end 631 629 end 632 elseif numel(VarType.coord)==2 %structured coordinates 633 XName=Data.ListVarName{VarType.coord(2)}; 634 YName=Data.ListVarName{VarType.coord(1)}; 635 eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';']) 636 eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';']) 630 elseif strcmp(CellInfo{icell}.CoordType,'grid')%2D field with structured coordinates 631 YName=Data.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 632 AY=Data.(YName); 633 AX=Data.(Data.ListVarName{CellInfo{icell}.CoordIndex(end)}); 637 634 test_interp_X=0; %default, regularly meshed X coordinate 638 635 test_interp_Y=0; %default, regularly meshed Y coordinate 639 636 if isfield(Data,'VarAttribute') 640 if numel(Data.VarAttribute)>= VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')641 x_units=Data.VarAttribute{ VarType.coord(2)}.units;642 end 643 if numel(Data.VarAttribute)>= VarType.coord(1) && isfield(Data.VarAttribute{VarType.coord(1)},'units')644 y_units=Data.VarAttribute{ VarType.coord(1)}.units;637 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end)},'units') 638 x_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end)}.units; 639 end 640 if numel(Data.VarAttribute)>=CellInfo{icell}.CoordIndex(end-1) && isfield(Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)},'units') 641 y_units=Data.VarAttribute{CellInfo{icell}.CoordIndex(end-1)}.units; 645 642 end 646 643 end … … 650 647 DAY_max=max(DAY); 651 648 if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise 652 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{Var Type.coord(1)} ];649 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(1)} ]; 653 650 return 654 651 end … … 660 657 DAX_max=max(DAX); 661 658 if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise 662 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{Var Type.coord(2)} ];659 errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarRole.coord(2)} ]; 663 660 return 664 661 end … … 687 684 AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation 688 685 AY=[AY(1) AY(end)]; 689 else690 errormsg='error in plot_field: invalid coordinate definition ';691 return686 % else 687 % errormsg='error in plot_field: invalid coordinate definition '; 688 % return 692 689 end 693 690 end -
trunk/src/proj_field.m
r521 r530 148 148 [ProjData,errormsg]=proj_heading(FieldData,ObjectData); 149 149 ProjData.NbDim=0; 150 [CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData); 150 [CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData); 151 %[CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData); 151 152 if ~isempty(errormsg) 152 153 errormsg=['error in proj_field/proj_points:' errormsg]; … … 154 155 end 155 156 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 156 for icell=1:length(CellVarIndex) 157 if NbDimCell(icell)==1 158 continue 159 end 160 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 161 VarType=VarTypeCell{icell};% structure defining the types of variables in the cell 162 ivar_X=VarType.coord_x; 163 ivar_Y=VarType.coord_y; 164 ivar_Z=VarType.coord_z; 165 ivar_Anc=VarType.ancillary; 166 test_anc(ivar_Anc)=ones(size(ivar_Anc)); 167 ivar_F=VarType.warnflag; 168 ivar_FF=VarType.errorflag; 169 VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list 170 if isempty(ivar_X) 171 test_grid=1;%test for input data on regular grid (e.g. image)coordinates 172 else 173 if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1 174 errormsg='multiple coordinate input in proj_field.m'; 175 return 176 end 177 if length(ivar_Y)~=1 178 errormsg='y coordinate not defined in proj_field.m'; 179 return 180 end 181 test_grid=0; 182 end 157 for icell=1:length(CellInfo) 158 if NbDimArray(icell)<=1 159 continue %projection only for multidimensional fields 160 end 161 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 162 % VarType=CellInfo{icell}.VarType;% structure defining the types of variables in the cell 163 ivar_X=CellInfo{icell}.CoordIndex(end); 164 ivar_Y=CellInfo{icell}.CoordIndex(end-1); 165 ivar_Z=[]; 166 if NbDimArray(icell)==3 167 ivar_Z=CellInfo{icell}.CoordIndex(1); 168 end 169 % ivar_rem=[]; 170 % if isfield(CellInfo{icell},'VarIndex_ancillary') 171 % ivar_rem=CellInfo{icell}.VarIndex_ancillary; 172 % end 173 % if isfield(CellInfo{icell},'VarIndex_warnflag') 174 % ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag]; 175 % end 176 ivar_FF=[]; 177 if isfield(CellInfo{icell},'VarIndex_errorflag') 178 ivar_FF=CellInfo{icell}.VarIndex_errorflag; 179 if numel(ivar_FF)>1 180 errormsg='multiple error flag input'; 181 return 182 end 183 end 184 % 185 % select types of variables to be projected 186 ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 187 check_project=false(size(VarIndex)); 188 for ilist=1:numel(ListProject) 189 if isfield(CellInfo{icell},ListProject{ilist}) 190 check_project(CellInfo{icell}.(ListProject{ilist}))=1; 191 end 192 end 193 VarIndex=VarIndex(check_project); 194 195 % if isempty(ivar_X) 196 % test_grid=1;%test for input data on regular grid (e.g. image)coordinates 197 % else 198 % if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1 199 % errormsg='multiple coordinate input in proj_field.m'; 200 % return 201 % end 202 % if length(ivar_Y)~=1 203 % errormsg='y coordinate not defined in proj_field.m'; 204 % return 205 % end 206 % test_grid=0; 207 % end 183 208 ProjData.ListVarName={'Y','X','NbVal'}; 184 209 ProjData.VarDimName={'nb_points','nb_points','nb_points'}; … … 190 215 ProjData.ListVarName=[ProjData.ListVarName {VarName}];% add the current variable to the list of projected variables 191 216 ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}]; % projected VarName has a single dimension called 'nb_points' (set of projection points) 192 end 193 if ~test_grid 194 eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';']) 195 eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';']) 217 218 end 219 if strcmp( CellInfo{icell}.CoordType,'scattered') 220 coord_x=FieldData.(FieldData.ListVarName{ivar_X}); 221 coord_y=FieldData.(FieldData.ListVarName{ivar_Y}); 196 222 test3D=0;% TEST 3D CASE : NOT COMPLETED , 3D CASE : NOT COMPLETED 197 223 if length(ivar_Z)==1 198 eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])224 coord_z=FieldData.(FieldData.ListVarName{ivar_Z}); 199 225 test3D=1; 200 226 end 201 if length(ivar_F)>1 || length(ivar_FF)>1 202 msgbox_uvmat('ERROR','multiple flag input in proj_field.m') 203 return 204 end 227 205 228 for ipoint=1:siz(1) 206 229 Xpoint=ObjectData.Coord(ipoint,:); … … 231 254 end 232 255 else %case of structured coordinates 233 if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;234 AYName=FieldData.ListVarName{ VarType.coord(1)};235 AXName=FieldData.ListVarName{ VarType.coord(2)};256 if strcmp( CellInfo{icell}.CoordType,'grid') 257 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 258 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 236 259 eval(['AX=FieldData.' AXName ';']);% set of x positions 237 260 eval(['AY=FieldData.' AYName ';']);% set of y positions 238 261 AName=FieldData.ListVarName{VarIndex(1)};% a single variable assumed in the current cell 239 262 eval(['A=FieldData.' AName ';']);% scalar 240 npxy=size(A); 241 NbDim=numel(VarType.coord(VarType.coord>0));%number of space dimensions 263 npxy=size(A); 242 264 %update VarDimName in case of components (non coordinate dimensions e;g. color components) 243 if numel(npxy)>NbDim 265 if numel(npxy)>NbDimArray(icell) 244 266 ProjData.VarDimName{end}={'nb_points','component'}; 245 267 end 246 for idim=1:NbDim %loop on space dimensions268 for idim=1:NbDimArray(icell) %loop on space dimensions 247 269 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 248 270 test_coord(idim)=0;%test for defined coordinates, =0 by default 249 ivar= VarType.coord(idim);271 ivar=CellInfo{icell}.CoordIndex(idim); 250 272 Coord{idim}=FieldData.(FieldData.ListVarName{ivar}); % position for the first index 251 273 if numel(Coord{idim})==2 … … 342 364 % DimVarIndex=0;%initilise list of indices for dimension variables 343 365 idimvar=0; 344 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 366 [CellInfo,NbDim,errormsg]=find_field_cells(FieldData); 367 %[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 345 368 if ~isempty(errormsg) 346 369 errormsg=['error in proj_field/proj_patch:' errormsg]; … … 350 373 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 351 374 dimcounter=0; 352 for icell=1:length(Cell VarIndex)375 for icell=1:length(CellInfo) 353 376 testX=0; 354 377 testY=0; 355 378 test_Amat=0; 356 379 testfalse=0; 357 VarIndex=Cell VarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName358 VarType=VarTypeCell{icell};380 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 381 % VarType=VarTypeCell{icell}; 359 382 % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell) 360 383 if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2 361 384 continue 362 385 end 363 testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);364 testfalse= ~isempty(VarType.errorflag);386 %testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y); 387 testfalse=isfield(CellInfo{icell},'VarIndex_errorflag'); 365 388 testproj(VarIndex)=zeros(size(VarIndex));%default 366 testproj(VarType.scalar)=1; 367 testproj(VarType.vector_x)=1; 368 testproj(VarType.vector_y)=1; 369 testproj(VarType.vector_z)=1; 370 testproj(VarType.image)=1; 371 testproj(VarType.color)=1; 372 VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables 373 if check_unstructured%case of unstructured coordinates 389 ivar_X=CellInfo{icell}.CoordIndex(end); 390 ivar_Y=CellInfo{icell}.CoordIndex(end-1); 391 ivar_Z=[]; 392 if NbDimArray(icell)==3 393 ivar_Z=CellInfo{icell}.CoordIndex(1); 394 end 395 ivar_rem=[]; 396 if isfield(CellInfo{icell},'VarIndex_ancillary') 397 ivar_rem=CellInfo{icell}.VarIndex_ancillary; 398 end 399 if isfield(CellInfo{icell},'VarIndex_warnflag') 400 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag]; 401 end 402 if isfield(CellInfo{icell},'VarIndex_errorflag') 403 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_errorflag]; 404 ivar_FF=CellInfo{icell}.VarIndex_errorflag; 405 end 406 VarIndex([ivar_X ivar_Y ivar_Z ivar_rem])=[];% not projected variables removed frlom list 407 408 if strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured coordinates 374 409 eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');']) 375 410 for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag] … … 377 412 eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);']) 378 413 end 379 XName=FieldData.ListVarName{ VarType.coord_x};380 YName=FieldData.ListVarName{ VarType.coord_y};414 XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 415 YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 381 416 eval(['coord_x=FieldData.' XName ';']) 382 417 eval(['coord_y=FieldData.' YName ';']) … … 387 422 end 388 423 % image or 2D matrix 389 if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;424 if strcmp(CellInfo{icell}.CoordType,'grid')%case of structured coordinates 390 425 test_Amat=1;% test for image or 2D matrix 391 AYName=FieldData.ListVarName{ VarType.coord(1)};392 AXName=FieldData.ListVarName{ VarType.coord(2)};426 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 427 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 393 428 eval(['AX=FieldData.' AXName ';'])% x coordinate 394 429 eval(['AY=FieldData.' AYName ';'])% y coordinate … … 562 597 563 598 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions 564 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 599 %[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 600 [CellInfo,NbDim,errormsg]=find_field_cells(FieldData); 565 601 if ~isempty(errormsg) 566 602 errormsg=['error in proj_field/proj_line:' errormsg]; … … 571 607 ProjData.ListVarName={}; 572 608 ProjData.VarDimName={}; 573 testproj=zeros(size(FieldData.ListVarName)); 574 for icell=1:length(CellVarIndex) 575 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 576 VarType=VarTypeCell{icell}; %types of variables 609 for icell=1:length(CellInfo) 610 %VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 611 % VarType=VarTypeCell{icell}; %types of variables 577 612 if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case 578 613 continue 579 614 end 580 check_unstructured=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates 581 test_tps=~isempty(VarType.coord_tps); 582 testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors 583 testfalse=~isempty(VarType.errorflag);% test for error flag 584 testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0 585 %=0 for vector components, treated separately 586 testproj([VarType.scalar VarType.image VarType.color VarType.vector_x VarType.vector_y])=1; 587 VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables 615 616 % select types of variables to be projected 617 ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 618 check_project=false(size(FieldData.ListVarName)); 619 for ilist=1:numel(ListProject) 620 if isfield(CellInfo{icell},ListProject{ilist}) 621 check_project(CellInfo{icell}.(ListProject{ilist}))=1; 622 end 623 end 624 VarIndex=find(check_project); 588 625 589 626 %identify vector components 627 testU=isfield(CellInfo{icell},'VarIndex_vector_x') &&isfield(CellInfo{icell},'VarIndex_vector_y') ;% test for vectors 590 628 if testU 591 UName=FieldData.ListVarName{ VarType.vector_x};592 VName=FieldData.ListVarName{ VarType.vector_y};629 UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}; 630 VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}; 593 631 vector_x=FieldData.(UName); 594 632 vector_y=FieldData.(VName); 595 633 end 596 634 %identify error flag 635 testfalse=isfield(CellInfo{icell},'VarIndex_errorflag');% test for error flag 597 636 if testfalse 598 FFName=FieldData.ListVarName{ VarType.errorflag};637 FFName=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag}; 599 638 errorflag=FieldData.(FFName); 600 639 end 601 640 % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y 602 if check_unstructured641 if strcmp(CellInfo{icell}.CoordType,'scattered') 603 642 if ~isequal(ProjMode,'interp') 604 643 if width==0 … … 617 656 end 618 657 end 619 XName= FieldData.ListVarName{ VarType.coord_x};620 YName= FieldData.ListVarName{ VarType.coord_y};658 XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 659 YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 621 660 coord_x=FieldData.(XName); 622 661 coord_y=FieldData.(YName); … … 633 672 %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%% 634 673 %case of unstructured coordinates 635 if check_unstructured674 if strcmp(CellInfo{icell}.CoordType,'scattered') 636 675 for ip=1:siz_line(1)-1 %Loop on the segments of the polyline 637 676 linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip)); … … 725 764 726 765 %case of structured coordinates 727 elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;766 elseif strcmp(CellInfo{icell}.CoordType,'grid') 728 767 if ~isequal(ObjectData.Type,'line')% exclude polyline 729 768 errormsg=['no projection available on ' ObjectData.Type 'for structured coordinates']; % … … 732 771 test_interp2=0;%default 733 772 % if ~isempty(VarType.coord_y) 734 AYName=FieldData.ListVarName{ VarType.coord(1)};735 AXName=FieldData.ListVarName{ VarType.coord(2)};773 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 774 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 736 775 eval(['AX=FieldData.' AXName ';']);% set of x positions 737 776 eval(['AY=FieldData.' AYName ';']);% set of y positions … … 832 871 end 833 872 if testU 834 vector_x =ProjData.(FieldData.ListVarName{ VarType.vector_x});835 vector_y =ProjData.(FieldData.ListVarName{ VarType.vector_y});836 ProjData.(FieldData.ListVarName{ VarType.vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y;837 ProjData.(FieldData.ListVarName{ VarType.vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y;873 vector_x =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 874 vector_y =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 875 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y; 876 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y; 838 877 end 839 878 ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line'; … … 842 881 end 843 882 end 844 elseif test_tps883 elseif strcmp(CellInfo{icell}.CoordType,'tps') 845 884 if isfield(ObjectData,'DX')&~isempty(ObjectData.DX) 846 885 DX=abs(ObjectData.DX);%mesh of interpolation points along the line … … 972 1011 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions 973 1012 % CellVarIndex=cells of variable index arrays 974 [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1013 %[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1014 [CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData); 975 1015 if ~isempty(errormsg) 976 1016 errormsg=['error in proj_field/proj_plane:' errormsg]; … … 980 1020 %% projection modes 981 1021 check_grid=0; 982 ProjMode=cell(size( VarTypeCell));983 for icell=1:numel( VarTypeCell)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates1022 ProjMode=cell(size(CellInfo)); 1023 for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates 984 1024 ProjMode{icell}=ObjectData.ProjMode; 985 if isfield( VarTypeCell{icell},'FieldRequest')986 switch VarTypeCell{icell}.FieldRequest1025 if isfield(CellInfo{icell},'FieldRequest') 1026 switch CellInfo{icell}.FieldRequest 987 1027 case 'interp_lin' 988 1028 ProjMode{icell}='interp'; … … 1014 1054 vector_x_proj=[]; 1015 1055 vector_y_proj=[]; 1016 for icell=1:length(Cell VarIndex)1017 NbDim=NbDim Vec(icell);1056 for icell=1:length(CellInfo) 1057 NbDim=NbDimArray(icell); 1018 1058 if NbDim<2 1019 1059 continue % only cells represnting 2D or 3D fields are involved 1020 1060 end 1021 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 1022 VarType=VarTypeCell{icell}; 1023 ivar_U=VarType.vector_x; 1024 ivar_V=VarType.vector_y; 1025 if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps) 1026 ivar_U=VarType.vector_x_tps; 1027 ivar_V=VarType.vector_y_tps; 1028 end 1029 ivar_W=VarType.vector_z; 1030 1031 %type of coordinates 1032 if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y) 1033 CoordType='unstructured'; 1034 elseif ~isempty(VarType.coord_tps) 1035 CoordType='tps'; 1036 else 1037 CoordType='structured'; 1038 end 1039 1061 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 1062 ivar_U=[];ivar_V=[];ivar_W=[]; 1063 if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps') 1064 ivar_U=CellInfo{icell}.VarIndex_vector_x_tps; 1065 ivar_V=CellInfo{icell}.VarIndex_vector_y_tps; 1066 elseif isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') 1067 ivar_U=CellInfo{icell}.VarIndex_vector_x; 1068 ivar_V=CellInfo{icell}.VarIndex_vector_y; 1069 end 1070 % if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps) 1071 % ivar_U=VarType.vector_x_tps; 1072 % ivar_V=VarType.vector_y_tps; 1073 % end 1074 if isfield(CellInfo{icell},'VarIndex_vector_z') 1075 ivar_W=CellInfo{icell}.VarIndex_vector_z; 1076 end 1077 % %type of coordinates 1078 % if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y) 1079 % CoordType='unstructured'; 1080 % elseif ~isempty(VarType.coord_tps) 1081 % CoordType='tps'; 1082 % else 1083 % CoordType='structured'; 1084 % end 1085 % 1040 1086 %dimensions 1041 1087 DimCell=FieldData.VarDimName{VarIndex(1)}; … … 1046 1092 1047 1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1048 switch C oordType1094 switch CellInfo{icell}.CoordType 1049 1095 1050 1096 %% case of input fields with unstructured coordinates 1051 case ' unstructured'1097 case 'scattered' 1052 1098 if strcmp(ProjMode{icell},'filter') 1053 1099 continue %skip for filter (needs tps field cell) 1054 1100 end 1055 coord_x=FieldData.(FieldData.ListVarName{VarType.coord_x});% initial x coordinates 1056 coord_y=FieldData.(FieldData.ListVarName{VarType.coord_y});% initial y coordinates 1057 if ~isempty(VarType.coord_z) 1058 coord_z=FieldData.(FieldData.ListVarName{VarType.coord_z});% initial z coordinates 1101 coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates 1102 coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates 1103 check3D=(numel(CellInfo{icell}.CoordIndex)==3); 1104 if check3D 1105 coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)}); 1059 1106 end 1060 1107 … … 1062 1109 coord_x=coord_x-ObjectData.Coord(1,1); 1063 1110 coord_y=coord_y-ObjectData.Coord(1,2); 1064 if ~isempty(VarType.coord_z)1111 if check3D 1065 1112 coord_z=coord_z-ObjectData.Coord(1,3); 1066 1113 end 1067 1114 1068 1115 % selection of the vectors in the projection range (3D case) 1069 if ~isempty(VarType.coord_z)&& width > 01116 if check3D&& width > 0 1070 1117 %components of the unitiy vector normal to the projection plane 1071 1118 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane … … 1127 1174 coord_X=coord_X(indcut); 1128 1175 coord_Y=coord_Y(indcut); 1129 if ~isempty(VarType.coord_z)1176 if check3D 1130 1177 coord_Z=coord_Z(indcut); 1131 1178 end … … 1138 1185 for ivar=VarIndex %transfer variables to the projection plane 1139 1186 VarName=FieldData.ListVarName{ivar}; 1140 if ivar== VarType.coord_x %x coordinate1187 if ivar==CellInfo{icell}.CoordIndex(end) 1141 1188 ProjData.(VarName)=coord_X; 1142 elseif ivar== VarType.coord_y% y coordinate1189 elseif ivar==CellInfo{icell}.CoordIndex(end-1) % y coordinate 1143 1190 ProjData.(VarName)=coord_Y; 1144 elseif isempty(VarType.coord_z) || ivar~=VarType.coord_z% other variables (except Z coordinate wyhich is not reproduced)1191 elseif ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) % other variables (except Z coordinate wyhich is not reproduced) 1145 1192 ProjData.(VarName)=FieldData.(VarName); 1146 1193 end 1147 if isempty(VarType.coord_z) || ivar~=VarType.coord_z1194 if ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) 1148 1195 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1149 1196 ProjData.VarDimName=[ProjData.VarDimName DimCell]; … … 1158 1205 coord_y_proj=YMin:DY:YMax; 1159 1206 [XI,YI]=meshgrid(coord_x_proj,coord_y_proj); 1160 if ~isempty(VarType.errorflag)1161 VarName_FF=FieldData.ListVarName{ VarType.errorflag};1207 if isfield(CellInfo{icell},'VarIndex_errorflag') 1208 VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag}; 1162 1209 indsel=find(FieldData.(VarName_FF)==0); 1163 1210 coord_X=coord_X(indsel); … … 1166 1213 % testFF=0; 1167 1214 % nbvar=numel(ProjData.ListVarName); 1168 if isfield( VarType,'vector_x')&&isfield(VarType,'vector_y')&&~isempty(VarType.vector_x)1169 VarName_x=FieldData.ListVarName{ VarType.vector_x};1170 VarName_y=FieldData.ListVarName{ VarType.vector_y};1171 if ~isempty(VarType.errorflag)1215 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') 1216 VarName_x=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}; 1217 VarName_y=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}; 1218 if isfield(CellInfo{icell},'VarIndex_errorflag') 1172 1219 FieldData.(VarName_x)=FieldData.(VarName_x)(indsel); 1173 1220 FieldData.(VarName_y)=FieldData.(VarName_y)(indsel); 1174 1221 end 1175 1222 %FieldVar=cat(2,FieldData.(VarName_x),FieldData.(VarName_y)); 1176 if ~isfield( VarType,'CheckSub') || ~VarType.CheckSub1223 if ~isfield(CellInfo{icell},'CheckSub') || ~CellInfo{icell}.CheckSub 1177 1224 vector_x_proj=numel(ProjData.ListVarName)+1; 1178 1225 vector_y_proj=numel(ProjData.ListVarName)+2; 1179 1226 end 1180 1227 end 1181 if ~isempty(VarType.scalar)1182 VarName_scalar=FieldData.ListVarName{ VarType.scalar};1228 if isfield(CellInfo{icell},'VarIndex_scalar') 1229 VarName_scalar=FieldData.ListVarName{CellInfo{icell}.VarIndex_scalar}; 1183 1230 if ~isempty(VarType.errorflag) 1184 1231 FieldData.(VarName_scalar)=FieldData.(VarName_scalar)(indsel); 1185 1232 end 1186 % FieldVar=FieldData.(VarName_scalar); 1187 end 1188 if ~isempty(VarType.ancillary)% do not project ancillary data with interp 1189 FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.ancillary}); 1190 end 1191 if ~isempty(VarType.warnflag)% do not project ancillary data with interp 1192 FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.warnflag}); 1193 end 1194 [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,VarType.Operation,XI,YI); 1195 if isfield(VarType,'CheckSub') && VarType.CheckSub && ~isempty(vector_x_proj) 1233 end 1234 if isfield(CellInfo{icell},'VarIndex_ancillary')% do not project ancillary data with interp 1235 FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_ancillary}); 1236 end 1237 if isfield(CellInfo{icell},'VarIndex_warnflag')% do not project ancillary data with interp 1238 FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_warnflag}); 1239 end 1240 [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,CellInfo{icell}.Operation,XI,YI); 1241 if isfield(CellInfo{icell},'CheckSub') && CellInfo{icell}.CheckSub && ~isempty(vector_x_proj) 1196 1242 ProjData.(ProjData.ListVarName{vector_x_proj})=ProjData.(ProjData.ListVarName{vector_x_proj})-VarVal{1}; 1197 1243 ProjData.(ProjData.ListVarName{vector_y_proj})=ProjData.(ProjData.ListVarName{vector_y_proj})-VarVal{2}; … … 1242 1288 1243 1289 %% case of input fields defined on a structured grid 1244 case ' structured'1290 case 'grid' 1245 1291 1246 1292 VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions … … 1261 1307 end 1262 1308 end 1263 AYName=FieldData.ListVarName{ VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)1264 AXName=FieldData.ListVarName{ VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)1309 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim-1)};%name of input x coordinate (name preserved on projection) 1310 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim)};%name of input y coordinate (name preserved on projection) 1265 1311 if testangle% TODO modify name also in case of origin shift in x or y 1266 1312 AYProjName='Y'; … … 1287 1333 for idim=1:NbDim %loop on space dimensions 1288 1334 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 1289 ivar= VarType.coord(idim);% index of the variable corresponding to the current dimension1335 ivar=CellInfo{icell}.CoordIndex(idim);% index of the variable corresponding to the current dimension 1290 1336 if ~isequal(ivar,0)% a variable corresponds to the dimension #idim 1291 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']);% coord values for the input field1337 Coord{idim}=FieldData.(FieldData.ListVarName{ivar});% coord values for the input field 1292 1338 if numel(Coord{idim})==2 %input array defined on a regular grid 1293 1339 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim); … … 1296 1342 DCoord_min(idim)=min(DCoord); 1297 1343 DCoord_max=max(DCoord); 1298 % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise1299 1344 if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000) 1300 1345 msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m']) … … 1383 1428 ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName(VarIndex)]; 1384 1429 ProjData.VarDimName=[ProjData.VarDimName FieldData.VarDimName(VarIndex)]; 1430 if isfield(FieldData,'VarAttribute') 1385 1431 ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute(VarIndex)]; 1432 end 1386 1433 ProjData.(AYProjName)=FieldData.(AYName); 1387 1434 ProjData.(AXProjName)=FieldData.(AXName); … … 1680 1727 %----------------------------------------------------------------- 1681 1728 idimvar=0; 1682 [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);1683 if ~isempty(errormsg)1684 errormsg=['error in proj_field/proj_plane:' errormsg];1685 return1686 end1729 % [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1730 % if ~isempty(errormsg) 1731 % errormsg=['error in proj_field/proj_plane:' errormsg]; 1732 % return 1733 % end 1687 1734 1688 1735 % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS -
trunk/src/read_civxdata.m
r527 r530 85 85 end 86 86 var_ind=find(vardetect); 87 % for ilist=1:length(FieldNames) 88 % testinterp=~isempty(regexp(FieldNames{ilist},'(^curl|^div|strain|norm)', 'once'));%test need for gridded data 89 % if testinterp, break;end 90 % end 87 91 for ivar=1:length(var_ind) 88 92 Field.VarAttribute{ivar}.Role=role{var_ind(ivar)}; 89 93 Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel 94 if strcmp(role{var_ind(ivar)},'vector_x') 95 Field.VarAttribute{ivar}.Operation=FieldNames; 96 end 90 97 end 91 98 VelTypeOut=VelType; -
trunk/src/struct2nc.m
r526 r530 137 137 138 138 139 %'check_field_structure': check the validity of the field struture representation consistant with the netcdf format 140 %------------------------------------------------------------------------ 141 % function [DataOut,errormsg]=check_field_structure(Data) 142 % 143 % OUTPUT: 144 % DataOut: structure reproducing the input structure Data (TODO: suppress this output) 145 % errormsg: error message which is not empty when the input structure does not have the right form 146 % 147 % INPUT: 148 % Data: structure containing 149 % (optional) .ListGlobalAttribute: cell listing the names of the global attributes 150 % .Att_1,Att_2... : values of the global attributes 151 % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} ) 152 % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells) 153 % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName 154 155 156 function [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data) 157 errormsg=''; 158 ListDimName={}; 159 DimValue=[]; %default 160 VarDimIndex={}; 161 if ~isstruct(Data) 162 errormsg='input field is not a structure'; 163 return 164 end 165 if isfield(Data,'ListVarName') && iscell(Data.ListVarName) 166 nbfield=numel(Data.ListVarName); 167 else 168 errormsg='input field does not contain the cell array of variable names .ListVarName'; 169 return 170 end 171 %check dimension names 172 if (isfield(Data,'VarDimName') && iscell(Data.VarDimName)) 173 if numel(Data.VarDimName)~=nbfield 174 errormsg=' .ListVarName and .VarDimName have different lengths'; 175 return 176 end 177 else 178 errormsg='input field does not contain the cell array of dimension names .VarDimName'; 179 return 180 end 181 % if isfield(Data,'DimValue') 182 % Data=rmfield(Data,'DimValue'); 183 % end 184 nbdim=0; 185 ListDimName={}; 186 187 %% main loop on the list of variables 188 for ivar=1:nbfield 189 VarName=Data.ListVarName{ivar}; 190 if ~isfield(Data,VarName) 191 errormsg=['the listed variable ' VarName ' is not found']; 192 return 193 end 194 sizvar=size(Data.(VarName));% sizvar = dimension of variable 195 DimCell=Data.VarDimName{ivar}; 196 if ischar(DimCell) 197 DimCell={DimCell};%case of a single dimension name, defined by a string 198 elseif ~iscell(DimCell) 199 errormsg=['wrong format for .VarDimName{' num2str(ivar) ' (must be the cell of dimension names of the variable ' VarName]; 200 return 201 202 end 203 nbcoord=numel(sizvar);%nbre of coordinates for variable named VarName 204 testrange=0; 205 if numel(DimCell)==0 206 errormsg=['empty declared dimension .VarDimName{' num2str(ivar) '} for ' VarName]; 207 return 208 elseif numel(DimCell)==1% one dimension declared 209 if nbcoord==2 210 if sizvar(1)==1 211 nbcoord=1; 212 sizvar(1)=sizvar(2); 213 elseif sizvar(2)==1 214 nbcoord=1; 215 else 216 errormsg=['1 dimension declared in .VarDimName{' num2str(ivar) '} inconsistent with the nbre of dimensions =2 of the variable ' VarName]; 217 return 218 end 219 if sizvar(1)==2 && isequal(VarName,DimCell{1}) 220 testrange=1;% test for a dimension variable representing a range 221 end 222 else 223 errormsg=['1 dimension declared in .VarDimName{' num2str(ivar) '} inconsistent with the nbre of dimensions =' num2str(nbcoord) ' of the variable ' VarName]; 224 return 225 end 226 else 227 if numel(DimCell)>nbcoord 228 sizvar(nbcoord+1:numel(DimCell))=1;% case of singleton dimensions (not seen by the function size) 229 % DimCell=DimCell(end-nbcoord+1:end)%first singleton diemensions omitted, 230 elseif nbcoord > numel(DimCell) 231 errormsg=['nbre of declared dimensions in .VarDimName{' num2str(ivar) '} smaller than the nbre of dimensions =' num2str(nbcoord) ' of the variable ' VarName]; 232 return 233 end 234 end 235 DimIndex=[]; 236 %for idim=1:nbcoord 237 for idim=1:numel(DimCell) %loop on the coordinates of variable #ivar 238 DimName=DimCell{idim}; 239 iprev=find(strcmp(DimName,ListDimName),1);%look for dimension name DimName in the current list 240 if isempty(iprev)% append the dimension name to the current list 241 nbdim=nbdim+1; 242 RangeTest(nbdim)=0; %default 243 if sizvar(idim)==2 && strcmp(DimName,VarName)%case of a coordinate defined by the two end values (regular spacing) 244 RangeTest(nbdim)=1; %to be updated for a later variable 245 end 246 DimValue(nbdim)=sizvar(idim); 247 ListDimName{nbdim}=DimName; 248 DimIndex=[DimIndex nbdim]; 249 else % DimName is detected in the current list of dimension names 250 if ~isequal(DimValue(iprev),sizvar(idim)) 251 if isequal(DimValue(iprev),2)&& RangeTest(iprev) % the dimension has been already detected as a range [min max] 252 DimValue(iprev)=sizvar(idim); %update with actual value 253 elseif ~testrange 254 errormsg=['dimension declaration inconsistent with the size =[' num2str(sizvar) '] for ' VarName]; 255 return 256 end 257 end 258 DimIndex=[DimIndex iprev]; 259 end 260 end 261 VarDimIndex{ivar}=DimIndex; 262 end 263 DataOut=Data; -
trunk/src/uvmat.m
r528 r530 347 347 end 348 348 [FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',oldfile); 349 if ~ischar(FileName),return,end %abandon if the browser is cancelled 349 350 fileinput=[PathName FileName];%complete file name 350 if ~exist(fileinput,'file')351 return %abandon if the browser is cancelled352 end353 351 354 352 %% display the selected field and related information … … 397 395 RootPath=get(handles.RootPath,'String'); 398 396 [FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',RootPath); 397 if ~ischar(FileName),return,end %abandon if the browser is cancelled 399 398 fileinput_1=[PathName FileName];%complete file name 400 if ~exist(fileinput_1,'file')401 return %abandon of the browser is cancelled402 end403 399 404 400 % refresh the current displayed field … … 1286 1282 '*.*', 'All Files (*.*)'}, ... 1287 1283 'Pick a mask file *.png',FileBase); 1284 if ~ischar(FileName),return,end %abandon if the browser is cancelled 1288 1285 maskname=fullfile(PathName,FileName); 1289 if ~exist(maskname,'file')1290 errormsg='no file browsed';1291 end1292 1286 [RootDir,SubDir,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname); 1293 1287 Mask.Base=fullfile(RootDir,SubDir,RootFile); … … 2388 2382 2389 2383 %% analyse input field 2390 test_x=0;2391 test_z=0;% test for unstructured z coordinate2392 [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure2393 if ~isempty(errormsg)2394 errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error2395 return2396 end2397 [Cell VarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse the input field structure2384 %test_x=0; 2385 %test_z=0;% test for unstructured z coordinate 2386 %[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure 2387 % if ~isempty(errormsg) 2388 % errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error 2389 % return 2390 % end 2391 [CellInfo,NbDimArray,errormsg]=find_field_cells(UvData.Field);% analyse the input field structure 2398 2392 if ~isempty(errormsg) 2399 2393 errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error 2400 2394 return 2401 2395 end 2402 [NbDim,imax]=max(NbDim);% spatial dimension of the input field 2396 2397 NbDim=max(NbDimArray);% spatial dimension of the input field 2398 imax=find(NbDimArray==NbDim);% indices of field cells to consider 2403 2399 if isfield(UvData.Field,'NbDim') 2404 NbDim=UvData.Field.NbDim;% deal with plane fields containing z coordinates 2405 end 2400 NbDim=double(UvData.Field.NbDim);% deal with plane fields containing z coordinates 2401 end 2402 2406 2403 2407 2404 %% get bounds and mesh (needed to propose default options for projection objects) 2408 2405 if NbDim>1 2409 XName=''; %default 2410 YName=''; 2411 %unstructured coordinates 2412 if ~isempty(VarType{imax}.coord_x)&&~isempty(VarType{imax}.coord_y) 2413 XName=UvData.Field.ListVarName{VarType{imax}.coord_x}; 2414 YName=UvData.Field.ListVarName{VarType{imax}.coord_y}; 2415 test_x=1;%test for unstructured coordinates 2416 if ~isempty(VarType{imax}.coord_z) 2417 ZName=UvData.Field.ListVarName{VarType{imax}.coord_z}; 2418 else 2419 NbDim=2; 2420 end 2421 %structured coordinate 2422 elseif numel(VarType)>=imax && numel(VarType{imax}.coord)>=NbDim && VarType{imax}.coord(NbDim)>0 2423 XName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim)}; 2424 if NbDim> 1 && VarType{imax}.coord(NbDim-1)>0 2425 YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates 2426 end 2427 DimIndex=VarDimIndex{CellVarIndex{imax}(1)}; %list of dim indices for the variable 2428 nbpoints_x=DimValue(DimIndex(NbDim)); 2429 XMax=nbpoints_x;%default 2430 XMin=1;%default 2431 end 2432 2406 CoordMax=zeros(1,numel(imax)); 2407 CoordMin=zeros(1,numel(imax)); 2408 for ind=1:numel(imax) 2409 XName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)}; 2410 YName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)}; 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))); 2415 % test_x=1;%test for unstructured coordinates 2416 if NbDim==3 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))); 2420 end 2421 2422 switch CellInfo{imax(ind)}.CoordType 2423 2424 case 'scattered' %unstructured coordinates 2425 NbPoints(ind)=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 case 'grid'%structured coordinate 2428 NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points 2429 Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./NbPoints); 2430 2431 end 2432 end 2433 UvData.Field.Mesh=min(Mesh); 2434 UvData.Field.XMax=max(CoordMax(ind,1)); 2435 UvData.Field.XMin=min(CoordMin(ind,1)); 2436 UvData.Field.YMax=max(CoordMax(ind,2)); 2437 UvData.Field.YMin=max(CoordMin(ind,2)); 2433 2438 if NbDim==3 2434 if ~test_x 2435 ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D 2436 end 2437 ZMax=max(UvData.Field.(ZName)); 2438 ZMin=min(UvData.Field.(ZName)); 2439 UvData.Field.ZMax=ZMax; 2440 UvData.Field.ZMin=ZMin; 2441 test_z=1; 2442 if isequal(ZMin,ZMax)%no z dependency 2443 NbDim=2; 2444 test_z=0; 2445 end 2446 end 2447 if ~isempty (XName) 2448 XMax=max(max(UvData.Field.(XName))); 2449 XMin=min(min(UvData.Field.(XName))); 2450 UvData.Field.NbDim=NbDim; 2451 UvData.Field.XMax=XMax; 2452 UvData.Field.XMin=XMin; 2453 if NbDim >1&& ~isempty(YName) 2454 YMax=max(max(UvData.Field.(YName))); 2455 YMin=min(min(UvData.Field.(YName))); 2456 UvData.Field.YMax=YMax; 2457 UvData.Field.YMin=YMin; 2458 end 2459 nbvec=length(UvData.Field.(XName)); 2460 if test_x %unstructured coordinates 2461 if test_z 2462 UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector 2463 UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3); 2464 else 2465 UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D 2466 end 2467 end 2468 end 2469 % case of structured coordinates 2470 if ~test_x 2471 DX=(XMax-XMin)/(nbpoints_x-1); 2472 if NbDim >1 2473 nbpoints_y=DimValue(DimIndex(NbDim-1)); 2474 if isempty(YName)% if the y coordinate is not expressed, it is taken as the matrix index 2475 DY=1; 2476 UvData.Field.YMax=nbpoints_y; 2477 UvData.Field.YMin=1; 2478 else 2479 DY=(YMax-YMin)/(nbpoints_y-1); 2480 end 2481 end 2482 if NbDim==3 2483 nbpoints_z=DimValue(DimIndex(1)); 2484 DZ=(ZMax-ZMin)/(nbpoints_z-1); 2485 UvData.Field.Mesh=(DX*DY*DZ)^(1/3); 2486 UvData.Field.ZMax=ZMax; 2487 UvData.Field.ZMin=ZMin; 2488 else 2489 UvData.Field.Mesh=DX;%sqrt(DX*DY); 2490 end 2439 UvData.Field.ZMax=max(CoordMax(ind,3)); 2440 UvData.Field.ZMin=max(CoordMin(ind,3)); 2491 2441 end 2492 2442 % adjust the mesh to a value 1, 2 , 5 *10^n … … 2664 2614 ObjectData.A=flag_mask.*double(ObjectData.A); 2665 2615 ObjectData.A=feval(AClass,ObjectData.A); 2666 ind_off=[]; 2667 if isfield(ObjectData,'ListVarName') 2668 for ilist=1:length(ObjectData.ListVarName) 2669 if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY') 2670 ind_off=[ind_off ilist]; 2671 end 2672 end 2673 ObjectData.ListVarName(ind_off)=[]; 2674 VarDimIndex(ind_off)=[]; 2675 ind_off=[]; 2676 for ilist=1:length(ListDimName) 2677 if isequal(ListDimName{ilist},'MaskX') || isequal(ListDimName{ilist},'MaskY') 2678 ind_off=[ind_off ilist]; 2679 end 2680 end 2681 ListDimName(ind_off)=[]; 2682 DimValue(ind_off)=[]; 2683 end 2616 % ind_off=[]; 2617 % if isfield(ObjectData,'ListVarName') 2618 % for ilist=1:length(ObjectData.ListVarName) 2619 % if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY') 2620 % ind_off=[ind_off ilist]; 2621 % end 2622 % end 2623 % ObjectData.ListVarName(ind_off)=[]; 2624 % VarDimIndex(ind_off)=[]; 2625 % ind_off=[]; 2626 % 2627 % end 2684 2628 end 2685 2629 if ~isempty(ObjectData) … … 2752 2696 function histo1_menu_Callback(hObject, eventdata, handles) 2753 2697 %-------------------------------------------- 2754 %plot first histo2755 %huvmat=get(handles.histo1_menu,'parent');2756 2698 histo_menu=get(handles.histo1_menu,'String'); 2757 2699 histo_value=get(handles.histo1_menu,'Value'); 2758 2700 FieldName=histo_menu{histo_value}; 2759 % update_histo(handles.HistoAxes,handles.uvmat,FieldName) 2760 % 2761 % %------------------------------------------------------------------------ 2762 % function histo2_menu_Callback(hObject, eventdata, handles) 2763 % %------------------------------------------------------------------------ 2764 % %plot second histo 2765 % %huvmat=get(handles.histo2_menu,'parent'); 2766 % histo_menu=get(handles.histo2_menu,'String'); 2767 % histo_value=get(handles.histo2_menu,'Value'); 2768 % FieldName=histo_menu{histo_value}; 2769 % update_histo(handles.histo_v,handles.uvmat,FieldName) 2770 % 2771 % %------------------------------------------------------------------------ 2772 % %read the field .Fieldname stored in UvData and plot its histogram 2773 % function update_histo(haxes,huvmat,FieldName) 2774 %------------------------------------------------------------------------ 2701 2775 2702 UvData=get(handles.uvmat,'UserData'); 2776 2703 Field=UvData.Field; … … 2845 2772 set(hlegend,'String',{FieldName;FieldName_2}) 2846 2773 end 2847 % hh=get(handles.HistoAxes,'children');2848 % get(hh(1))2849 % get(hh(2))2850 2774 end 2851 2775 end … … 3097 3021 '*.vol','.volume images (png)'; ... 3098 3022 '*.*', 'All Files (*.*)'}, ... 3099 'Pick an image',imagename); 3023 'Pick an image',imagename); 3024 if ~ischar(FileName),return,end %abandon if the browser is cancelled 3100 3025 imagename=[PathName FileName]; 3101 3026 end … … 3111 3036 '*.*', 'All Files (*.*)'}, ... 3112 3037 'Pick a netcdf file',FileBase); 3038 if ~ischar(FileName),return,end %abandon if the browser is cancelled 3113 3039 FullFileName=[PathName FileName]; 3114 3040 % display the selected field and related information … … 3209 3135 '*.*', 'All Files (*.*)'}, ... 3210 3136 'Pick an image',imagename); 3137 if ~ischar(FileName),return,end %abandon if the browser is cancelled 3211 3138 imagename=[PathName FileName]; 3212 3139 end … … 3545 3472 '*.*', 'All Files (*.*)'}, ... 3546 3473 'Pick the transform function', prev_path); 3474 if ~ischar(FileName),return,end %abandon if the browser is cancelled 3547 3475 path_transform_fct =fullfile(PathName,FileName); 3548 if ~exist(path_transform_fct,'file')% cancel has been activated3549 return3550 end3551 3476 if isempty(regexp(FileName,'.m$'))% detect file extension .m 3552 3477 msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
Note: See TracChangeset
for help on using the changeset viewer.