Changeset 1045 for trunk


Ignore:
Timestamp:
May 21, 2018, 7:06:45 PM (6 years ago)
Author:
sommeria
Message:

find field cells improved

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_field_cells.m

    r1041 r1045  
    1818%              _vector_x,_y,_z: indices of variables giving the vector components x, y, z
    1919%              _warnflag: index of warnflag   
     20%       .DimIndex
    2021%      .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation  or derivatives (tps) is needed to calculate the requested field
    2122%      .FieldName = operation to be performed to finalise the field cell after projection
     
    6465
    6566function [CellInfo,NbDim,errormsg]=find_field_cells(Data)
    66 CellInfo={};
     67CellInfo={};%default output
    6768NbDim=0;
    6869errormsg='';
     
    8788FieldName=cell(size(Role)); % fieldRequest set to {} by default
    8889CheckSub=zeros(size(Role));% =1 for fields to substract
    89 Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
     90%Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
    9091if isfield(Data,'VarAttribute')
    9192    for ivar=1:numel(Data.VarAttribute)
     
    105106end
    106107
    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
     109ind_scalar=find(strcmp('scalar',Role));
     110ind_errorflag=find(strcmp('errorflag',Role));
     111ind_image=find(strcmp('image',Role));
     112ind_vector_x=[find(strcmp('vector_x',Role)) find(strcmp('vector_x_tps',Role))];
     113if ~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));
     118end
     119ind_discrete=find(strcmp('discrete',Role));
     120ind_coord_x=find(strcmp('coord_x',Role));
     121ind_coord_y=find(strcmp('coord_y',Role));
     122ind_coord_z=find(strcmp('coord_z',Role));
     123ind_coord_tps=find(strcmp('coord_tps',Role));
     124check_string=cellfun(@ischar,Data.VarDimName)==1;
     125index_string=find(check_string);
     126for ivar=index_string
     127    Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char strings into cells
     128end
     129check_coord_names= cellfun(@numel,Data.VarDimName)==1;
     130check_coord_raster=false(size(check_coord_names));% check variables describing regular mesh (raster coordinates), from two values, min and max.
     131if 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
     137else
     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
     144end
     145
     146
     147%% initate cells around each scalar field
     148index_remove=[];
     149cell_nbre=numel(ind_scalar)+numel(ind_vector_x);
     150flag_remove=false(1,cell_nbre);
     151NbDim=zeros(1,cell_nbre);
     152index_coord_x=zeros(size(ind_coord_x));
     153for 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
     167end
     168
     169%% initate cells around each vector field
     170for 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
     228end
     229
     230%% find coordinates for each cell around field variables, scalars or vectors
     231for 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;
    130373            if check_var
    131                 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
     374                NbDim(icell)=size(Data.(Data.ListVarName{ivar}),2);
    132375            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
    136384                end
    137                 CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);
    138             end
    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             else
    147                 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
     389end
     390
     391%% get number of coordinate points for each cell
     392if 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))];
    152400                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))];
    155402                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
     408else
     409    for icell=1:numel(CellInfo)
     410        CellInfo{icell}.CoordSize=size(Data.DimValue(CellInfo{icell}.DimIndex));
     411    end
     412end
     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
     455iremove=false(1,numel(ind_coord_y));
     456for 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
     463end
     464ind_coord_y(iremove)=[];
     465if ~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))];
     484end
    307485
    308486%% document roles of non-coordinate variables
    309487for 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
     507end
     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  
    135135    return
    136136end
    137 [Field.MaxDim,imax]=max(NbDim);
     137if isempty(CellInfo)
     138    Field.MaxDim=max(cellfun(@numel,Field.Display.VarDimName));
     139    check_cellinfo=false;
     140else
     141    [Field.MaxDim,imax]=max(NbDim);
     142    check_cellinfo=true;
     143end
    138144
    139145%% set time mode
     
    210216%% set default field options
    211217checknbdim=cellfun('size',Field.Display.VarDimName,2);
    212 if max(checknbdim)<=1
    213     Field.MaxDim=1;% only 1D fields, considered as a time series by default
    214 end
     218% if max(checknbdim)<=1
     219%     Field.MaxDim=1;% only 1D fields, considered as a time series by default
     220% end
    215221if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields
    216222    check_vec_input=0;
     223    % case of vector initially selected from uvmat input
    217224    if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y')
    218225        ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1);
     
    224231        end
    225232    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')
    227235        set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1))
    228236        set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1))
     
    252260
    253261%% 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
    275303
    276304%% put the GUI on the lower right of the sceen
     
    304332% --- Activated by selection in the list of variables
    305333% ----------------------------------------------------------------------
    306 function variables_Callback(hObject, eventdata, handles)
     334function variables_Callback(hObject, VarName, handles)
    307335
    308336Tabchar={''};%default
     
    388416end
    389417
    390 %% propose a plot by default if a variable has been selected
    391 if ~isequal(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)
     419if ~ischar(VarName) && ~isequal(index,1)
    392420    if numel(DimCell)==1
    393421        set(handles.FieldOption,'Value',1)%propose 1D plot
     
    412440FieldOption=FieldList{get(handles.FieldOption,'Value')};
    413441switch FieldOption
    414    
    415442    case '1D plot'
    416443        set(handles.Coordinates,'Visible','on')
     
    423450        set(handles.PanelScalar,'Visible','off')
    424451        set(handles.PanelVectors,'Visible','off')
    425         set(handles.Coord_y,'Visible','off')
    426         set(handles.Y_title,'Visible','off')
     452        set(handles.Coord_y,'Visible','on')
     453        set(handles.Y_title,'Visible','on')
    427454        set(handles.Coord_z,'Visible','off')
    428455        set(handles.Z_title,'Visible','off')
    429         ordinate_Callback(hObject, VarName, handles)
    430        
     456        %ordinate_Callback(hObject, VarName, handles)       
    431457    case {'scalar'}
    432458        set(handles.Coordinates,'Visible','on')
     
    440466        set(handles.PanelScalar,'Position',pos)
    441467        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
    452481                    test_coord(ilist)=1;
    453482                end
    454483            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)       
    470492    case 'vectors'
    471493        set(handles.PanelVectors,'Visible','on')
     
    509531            end
    510532        end
    511         vector_Callback(handles)
    512        
     533        vector_Callback(handles)     
    513534    case 'civdata...'
    514535        set(handles.PanelOrdinate,'Visible','off')
     
    576597        end
    577598    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)
     600end
     601set(handles.Coord_x,'String',[{''}; ListCoord])
    581602
    582603
     
    611632function scalar_Callback(hObject, VarName, handles)
    612633
    613 Field=get(handles.get_field,'UserData');
    614 scalar_menu=get(handles.scalar,'String');
    615 if ischar(VarName)
     634Field=get(handles.get_field,'UserData');% get the input field info stored in UserData of the GUI
     635scalar_menu=get(handles.scalar,'String');% read the menu for scalar selection
     636if ischar(VarName)% case of a call with input variable
    616637    ScalarName=VarName;
    617638    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
     640else % no input variable, the variable ScalarName is selected from the menu
    620641    scalar_index=get(handles.scalar,'Value');
    621642        ScalarName=scalar_menu{scalar_index};
     
    626647test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
    627648dim_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') 
    629650    %look for coordinate variables among the other variables
    630651    for ilist=1:numel(Field.Display.VarDimName)
     
    636657        end
    637658    end
    638 end
     659%end
    639660var_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 coordinates
     661var_coord=find(test_coord);% % list of variable indices elligible as gridded coordinates
    641662var_coord(var_coord==scalar_index)=[];
    642663var_component(var_component==scalar_index)=[];
     
    664685        elseif strcmp(Role,'coord_y')
    665686            coord_val(2)=ilist;
    666             elseif strcmp(Role,'coord_z')
     687        elseif strcmp(Role,'coord_z')
    667688            coord_val(3)=ilist;
     689            Check3D=1;
    668690        end
    669691    end
     
    679701    end
    680702end
    681 if  get(handles.CheckDimensionX,'Value')
    682     set(handles.Coord_x,'Value',2)
    683     set(handles.Coord_x,'String',dim_var')
    684 else
     703% if  get(handles.CheckDimensionX,'Value')
     704%     set(handles.Coord_x,'Value',2)
     705%     set(handles.Coord_x,'String',dim_var')
     706% else
    685707    set(handles.Coord_x,'Value',coord_val(1))
    686708    set(handles.Coord_x,'String',ListCoord)
    687 end
    688 if  get(handles.CheckDimensionX,'Value')
    689     set(handles.Coord_y,'Value',1)
    690     set(handles.Coord_y,'String',dim_var')
    691 else
     709% end
     710% if  get(handles.CheckDimensionX,'Value')
     711%     set(handles.Coord_y,'Value',1)
     712%     set(handles.Coord_y,'String',dim_var')
     713% else
    692714    set(handles.Coord_y,'Value',coord_val(2))
    693715    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
     721if numel(test_coord)>=3
    699722    set(handles.Coord_z,'Value',coord_val(2))
    700723    set(handles.Coord_z,'String',ListCoord)
     724    set(handles.Coord_z,'Visible','on')
     725    set(handles.Check3D,'Value', 1)
    701726end
    702727
     
    911936string=get(handles.Coord_y,'String');
    912937VarName=string{index};
     938
    913939if ~ischar(DimCell)
    914940update_field(handles,VarName)
     
    9921018if ~isempty(index)
    9931019    set(handles.variables,'Value',index+1)
    994     variables_Callback(handles.variables, [], handles)
     1020    variables_Callback(handles.variables, VarName, handles)
    9951021end
    9961022
     
    10221048
    10231049% --- Executes on button press in CheckDimensionY.
    1024 function CheckDimensionX_Callback(hObject, eventdata, handles)
    1025 CheckDimensionX=get(handles.CheckDimensionX,'value')
    1026 if CheckDimensionX
    1027     set(handles.Coordinates,'visible','off')
    1028 else
    1029     set(handles.Coordinates,'visible','on')
    1030 end
     1050% 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
    10311057% FieldList=get(handles.FieldOption,'String');
    10321058% FieldOption=FieldList{get(handles.FieldOption,'Value')};
  • trunk/src/plot_field.m

    r1031 r1045  
    115115%% check input structure
    116116% 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
    131138
    132139%% test axes and figure
     
    228235    if ~isempty(htext)%&&~isempty(hchecktable)
    229236        if isempty(index_0D)
    230             %         set(htext,'Data',{})
    231             %         set(htext,'visible','off')
    232             %         set(hchecktable,'visible','off')
    233             %         set(hchecktable,'Value',0)
    234237        else
    235238            errormsg=plot_text(Data,CellInfo(index_0D),htext);
    236239            set(htext,'visible','on')
    237 %             set(hchecktable,'visible','on')
    238 %             set(hchecktable,'Value',1)
    239240        end
    240241        set(hfig,'Unit','pixels');
     
    409410%loop on input  fields
    410411for icell=1:numel(CellInfo)
    411     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
    412     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;
    413414    coord_x_name{icell}=data.ListVarName{coord_x_index};
    414415    coord_x{icell}=data.(data.ListVarName{coord_x_index});%coordinate variable set as coord_x
  • trunk/src/proj_field.m

    r1027 r1045  
    554554    return
    555555end
    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
     556CellInfo=CellInfo(NbDim>=2); %keep only the 2D or 3D cells
    558557cell_select=true(size(CellInfo));
    559558
    560559for icell=1:length(CellInfo)
    561560    if isfield(CellInfo{icell},'ProjModeRequest')
    562         if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode)
    563             cell_select(icell)=0;
    564         end
     561%         if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode)
     562%             cell_select(icell)=0;
     563%         end
    565564        if strcmp(ProjMode,'interp_tps')&& ~strcmp(CellInfo{icell}.CoordType,'tps')
    566565            cell_select(icell)=0;
     
    851850                end
    852851               
    853                
    854                
    855                
    856                
    857852            else
    858853                AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
     
    929924                ProjData.ListVarName=[ProjData.ListVarName {AXName}];
    930925                ProjData.VarDimName=[ProjData.VarDimName {AXName}];
     926                nbvar=numel(ProjData.VarDimName);
     927                ProjData.VarAttribute{nbvar}.Role='coord_x';
    931928                for ivar=VarIndex
    932929                    %VarName{ivar}=FieldData.ListVarName{ivar};
     
    950947                    ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName{ivar}];
    951948                    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
    953951                end
    954952                if nbcolor==3
     
    11221120
    11231121check_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
     1122ProjMode=num2cell(blanks(numel(CellInfo)));
     1123ProjMode=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
    11281128icell_grid=[];% field cell index which defines the grid
    11291129if ~strcmp(ObjectData.ProjMode,'projection')&& ~strcmp(ObjectData.Type,'plane_z')% TODO:rationalize
     
    12021202    ProjData.ListVarName={AYName,AXName};
    12031203   
    1204     ProjData.VarAttribute={[],[]};
     1204    ProjData.VarAttribute{1}.Role='coord_y';
     1205    ProjData.VarAttribute{2}.Role='coord_x';
    12051206end
    12061207   
     
    12191220        continue % only cells represnting 2D or 3D fields are involved
    12201221    end
    1221     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
     1222    VarIndex= CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
    12221223    %dimensions
    12231224    DimCell=FieldData.VarDimName{VarIndex(1)};
     
    12371238                continue %skip for next cell (needs tps field cell)
    12381239            end
    1239             coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates
    1240             coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates
     1240            coord_x=FieldData.(CellInfo{icell}.XName);% initial x coordinates
     1241            coord_y=FieldData.(CellInfo{icell}.YName);% initial y coordinates
    12411242            check3D=(numel(CellInfo{icell}.CoordIndex)==3);
    12421243            if check3D
    1243                 coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
     1244                coord_z=FieldData.(CellInfo{icell}.ZName);
    12441245            end
    12451246           
     
    12561257                fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane
    12571258                indcut=find(abs(fieldZ) <= width);
    1258                 for ivar=VarIndex
     1259                for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex]
    12591260                    VarName=FieldData.ListVarName{ivar};
    12601261                    FieldData.(VarName)=FieldData.(VarName)(indcut);
     
    13051306                    return
    13061307                end
    1307                 for ivar=VarIndex
     1308                for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex]
    13081309                    VarName=FieldData.ListVarName{ivar};
    13091310                    FieldData.(VarName)=FieldData.(VarName)(indcut);
     
    13211322                    nbvar=0;
    13221323                    %nbvar=numel(ProjData.ListVarName);
    1323                     for ivar=VarIndex %transfer variables to the projection plane
     1324                    for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex] %transfer variables to the projection plane
    13241325                        VarName=FieldData.ListVarName{ivar};
    13251326                        if ivar==CellInfo{icell}.CoordIndex(end)
     
    14011402                SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps});
    14021403                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}));
    14051406                    checkUV=1;
    14061407                end
  • trunk/src/read_field.m

    r1041 r1045  
    88%        .FieldName; field name
    99%        .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)....
    1111%        .Npx,.Npy: for images, nbre of pixels in x and y
    1212% errormsg: error message, ='' by default
     
    2020%     .ColorVar: variable used for vector color
    2121%     .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'
    2323% num: frame number for movies
    2424%
     
    9494        ParamOut.CivStage=Field.CivStage;
    9595    case 'netcdf'% general netcdf file (not recognized as civ)
    96         ListVar={};
     96        ListVarName={};
    9797        Role={};
    9898        ProjModeRequest={};
    99         ListInputField={};
    100         ListOperator={};
    101         checkU=0;
    102         checkV=0;
     99        %ListInputField={};
     100        %checkU=0;
     101        %checkV=0;
    103102        % scan the list InputField
     103        Operator=cell(1,numel(InputField));
     104        InputVar=cell(1,numel(InputField));
    104105        for ilist=1:numel(InputField)
    105106            % look for input variables to read
    106107            r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
    107108            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'}];
    117127                    end
    118128                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)}='';           
    128137                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)
    130140                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}='';
    150143                end
    151144            end
     
    156149        NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z);
    157150        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]);
    159152        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]);
    161154            if numel(num)~=1
    162155                NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected
    163156            end
    164157        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]);
    166159        end
    167160        if ~isempty(errormsg)
     
    169162        end
    170163        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;
    197192        end
    198193        NormName='';
    199194        UName='';
    200195        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};
    205221                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       
    254242    case 'video'
    255243        if strcmp(class(ParamIn),'VideoReader')
     
    286274        for ilist=1:numel(Input.Frames{1}.Attributes)
    287275            if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries')
    288         timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000;
    289         break
     276                timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000;
     277                break
    290278            end
    291279        end
     
    294282    otherwise
    295283        errormsg=[ FileType ': invalid input file type for uvmat'];
     284       
    296285end
    297286
     
    311300    Field.VarAttribute{1}.Unit='pixel';
    312301    Field.VarAttribute{2}.Unit='pixel';
     302    Field.VarAttribute{1}.Role='coord_y';
     303    Field.VarAttribute{2}.Role='coord_x';
    313304    Field.VarAttribute{3}.Role='scalar';
    314305    if ndims(A)==3
  • trunk/src/uvmat.m

    r1041 r1045  
    17481748set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
    17491749drawnow
    1750 % read the current input file name:
     1750% get the current input file name:
    17511751[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    17521752% detect the file type, get the movie object if relevant, and look for the corresponding file series:
     
    20022002UvData.NewSeries=1; %flag for REFRESH: begin a new series
    20032003UvData.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;
    20052005UvData.FileInfo{index}=FileInfo;
    20062006UvData.MovieObject{index}=VideoObject;
     
    21962196UvData.XmlData{index}=XmlData;
    21972197UvData.NewSeries=1;
     2198set(handles.uvmat,'UserData',UvData)
    21982199
    21992200%display warning message
     
    22332234    set(handles.Coord_y,'String','Coord_y');
    22342235end
    2235 set(handles.uvmat,'UserData',UvData)
     2236
    22362237
    22372238%% set index navigation options
     
    31573158if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
    31583159if 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 % else
    31633160if 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)
    31653162else
    31663163    filename=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];%
     
    32503247    for iobj=1:numel(UvData.ProjObject)
    32513248        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
    32533250            break
    32543251        end
     
    32853282    end
    32863283end
    3287 switch UvData.FileInfo{1}.FileType
    3288     case {'civx','civdata','netcdf','pivdata_fluidimage'};
     3284switch UvData.FileInfo{1}.FieldType
     3285    case {'civdata','netcdf'};
    32893286        list_fields=get(handles.FieldName,'String');% list menu fields
    32903287        FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
     
    37753772        set(handles.ListObject_1,'String',{'plane'})
    37763773        if UvData.Field.NbDim==3 %3D case
    3777 %             ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    3778 %             ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    37793774            UvData.ProjObject{1}.NbDim=3;%test for 3D objects
    37803775            UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
    37813776            UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
    37823777            UvData.ProjObject{1}.Angle=[0 0];
     3778            if isfield(UvData.Field,'CoordUnit')
     3779                UvData.ProjObject{1}.CoordUnit=CoordUnit;
     3780            end
    37833781        elseif isfield(UvData,'Z')
    37843782            %multilevel case (single menuplane in a 3D space)
     
    38463844            UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
    38473845            if ~isfield(UvData.ProjObject{iobj},'RangeZ')
    3848             UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
     3846                UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
    38493847            end
    38503848            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                  UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
     3849                UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
    38523850            end
    38533851        end
     
    39793977    % display menus and plot histograms
    39803978    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
     3988end
     3989% open the set_object for interactive plane projection in 3D case
    39913990if UvData.Field.NbDim==3
    39923991    set(handles.CheckEditObject,'Value',1)
    39933992    CheckEditObject_Callback(handles.uvmat, [], handles)
    39943993end
    3995 %ResizeFcn(handles.uvmat,[],handles)
     3994
    39963995set(handles.uvmat,'Pointer',pointer)
    39973996
     
    43594358[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    43604359if isempty(regexp(RootPath,'^http://'))
    4361 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4360    FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
    43624361else
    43634362    FileName=[RootPath '/' SubDir '/' RootFile FileIndices FileExt];
     
    44524451                set(handles.Coord_y,'Max',2)
    44534452                %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
    44554454                display_file_name(handles,FileName,1)
    44564455        end
     
    44594458            if isfield(GetFieldData,'Coordinates')
    44604459                XName=GetFieldData.Coordinates.Coord_x;
    4461 %                set(handles.SwitchCoordIndex,'String','var'); % variable used as coordinate
    4462 %             else
    4463 %                 set(handles.SwitchCoordIndex,'String','dim'); % matrix index used a coordinate
    44644460            end
    44654461            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
     
    44774473                    MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
    44784474                    set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
    4479                     UvData=get(handles.uvmat,'UserData');
    44804475                    UvData.TimeUnit=GetFieldData.Time.TimeUnit;
    44814476                    set(handles.uvmat,'UserData',UvData);
     
    44904485                    MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
    44914486                    set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
    4492                     UvData=get(handles.uvmat,'UserData');
    44934487                    UvData.TimeUnit=GetFieldData.Time.TimeUnit;
    44944488                    set(handles.uvmat,'UserData',UvData);
     
    44974491            end
    44984492            set(handles.Coord_x,'String',XName)
    4499 %             if ischar(YName)
    4500 %                 YName={YName};
    4501 %             end
    45024493            set(handles.Coord_y,'String',YName)
    45034494            set(handles.Coord_z,'String',ZName)
     
    45064497            set(handles.ColorScalar,'Value',1)
    45074498            set(handles.ColorScalar,'String',VecColorList);
    4508             UvData.FileInfo{1}.FileType='netcdf';
     4499           % UvData.FileInfo{1}.FileType='netcdf';
    45094500            set(handles.uvmat,'UserData',UvData)
    45104501            REFRESH_Callback(hObject, eventdata, handles)
     
    46724663            set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
    46734664           
    4674             UvData.FileType{2}='netcdf';
     4665            UvData.FileInfo{2}.FileType='netcdf';
    46754666            set(handles.uvmat,'UserData',UvData)
    46764667            REFRESH_Callback(hObject, eventdata, handles)
     
    48044795else% we introduce the same file (with a different field) for the second series
    48054796     FileName_1=FileName;% we compare two fields in the same file
    4806      UvData.FileType{2}=UvData.FileInfo{1}.FileType;
     4797     UvData.FileInfo{2}.FileType=UvData.FileInfo{1}.FileType;
    48074798     UvData.XmlData{2}= UvData.XmlData{1};
    48084799     set(handles.SubField,'Value',1)
     
    57215712%------------------------------------------------------------------------
    57225713check_view=get(handles.CheckViewObject,'Value');
    5723     hset_object=findobj(allchild(0),'tag','set_object');
    5724     if ~isempty(hset_object)
    5725         delete(hset_object)% delete existing version of set_object
    5726     end
     5714hset_object=findobj(allchild(0),'tag','set_object');
     5715if ~isempty(hset_object)
     5716    delete(hset_object)% delete existing version of set_object
     5717end
    57275718if check_view %activate set_object
    57285719    IndexObj=get(handles.ListObject,'Value');
     
    57475738        data.Type='plane';
    57485739    end
    5749 
     5740   
    57505741    %% initiate the new projection object
    57515742    hset_object=set_object(data,[],ZBounds);
     
    57585749        set(hhset_object.SAVE,'Enable','on')
    57595750    end
    5760 else
    5761 %     hset_object=findobj(allchild(0),'tag','set_object');
    5762 %     if ~isempty(hset_object)
    5763 %         delete(hset_object)% delete existing version of set_object
    5764 %     end
    57655751end
    57665752
Note: See TracChangeset for help on using the changeset viewer.