Changeset 672 for trunk/src/get_field.m


Ignore:
Timestamp:
Aug 6, 2013, 3:47:07 PM (11 years ago)
Author:
sommeria
Message:

various bugs corrected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r669 r672  
    9393    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
    9494end
     95% Field.Display = list of variables and corresponding properties obtained after removal of singletons
    9596Field.Display.ListVarName=Field.ListVarName(~Field.Check0D);
    9697Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
     
    137138set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
    138139set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
    139 set(handles.vector_z,'String',[{''} Field.ListVarName])% fill the menu of y vector components
    140 set(handles.vec_color,'String',[{''} Field.ListVarName])% fill the menu of y vector components
     140set(handles.vector_z,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
     141set(handles.vec_color,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
    141142set(handles.scalar,'Value',1)% fill the menu of y vector components
    142 set(handles.scalar,'String',Field.ListVarName)% fill the menu of y vector components
     143set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu of y vector components
    143144set(handles.ordinate,'Value',1)% fill the menu of y vector components
    144 set(handles.ordinate,'String',Field.ListVarName)% fill the menu of y vector components
     145set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y vector components
    145146if isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
    146         set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})
     147    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})
    147148else
    148      set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'})
     149    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'})
    149150end
    150151if Field.MaxDim>=2 % case of 2D (or 3D) fields
     
    157158        set(handles.FieldOption,'Value',2)
    158159    end
    159 
    160160else % case of 1D fields
    161161    set(handles.FieldOption,'Value',1)
     
    182182%     end
    183183
    184 %% Make choices in menus from input
    185 % if exist('ParamIn','var')&&~isempty(ParamIn)
    186 %     fill_GUI(ParamIn,handles.get_field);
    187 % end
    188 %FieldOption_Callback([],[],handles)
    189 
     184%% Make choices of coordinates from input
     185if isfield(CellInfo{imax},'CoordIndex')
     186    CoordIndex=CellInfo{imax}.CoordIndex;
     187    if numel(CoordIndex)==2
     188        YName=Field.ListVarName{CoordIndex(1)};
     189        XName=Field.ListVarName{CoordIndex(2)};
     190        ListCoord=get(handles.Coord_x,'String');
     191        XIndex=find(strcmp(XName,ListCoord));
     192        if ~isempty(XIndex)
     193            set(handles.Coord_x,'Value',XIndex)
     194        end
     195        YIndex=find(strcmp(YName,ListCoord));
     196        if ~isempty(YIndex)
     197            set(handles.Coord_y,'Value',YIndex)
     198        end
     199    end
     200end
    190201
    191202%% put the GUI on the lower right of the sceen
     
    218229end
    219230
    220 
    221 
    222 %------------------------------------------------------------------------
    223 
    224231%------------------------------------------------------------------------
    225232% --- Outputs from this function are returned to the command line.
     233%------------------------------------------------------------------------
    226234function varargout = get_field_OutputFcn(hObject, eventdata, handles)
    227 %------------------------------------------------------------------------
     235
    228236varargout{1} = handles.output;
    229237delete(handles.get_field)
     
    242250end
    243251
    244 %---------------------------------------------------------
     252%------------------------------------------------------------------------
    245253% --- Executes on button press in OK.
    246254%------------------------------------------------------------------------
     
    254262% -----------------------------------------------------------------------
    255263% --- Activated by selection in the list of variables
     264% ----------------------------------------------------------------------
    256265function variables_Callback(hObject, eventdata, handles)
    257 % -----------------------------------------------------------------------
     266
    258267Tabchar={''};%default
    259268Tabcell=[];
     
    263272
    264273%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
    265 if isequal(index,1) 
     274if isequal(index,1)
    266275    set(handles.attributes_txt,'String','global attributes')
    267276    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
    268277        for iline=1:length(Field.ListGlobalAttribute)
    269             Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
     278            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
    270279            if isfield(Field, Field.ListGlobalAttribute{iline})
    271280                val=Field.(Field.ListGlobalAttribute{iline});
     
    279288        Tabchar=cell2tab(Tabcell,'=');
    280289    end
    281 %% list Attribute names and values associated to the Variable # index-1   
     290    %% list Attribute names and values associated to the Variable # index-1
    282291else
    283292    list_var=get(handles.variables,'String');
     
    285294    set(handles.attributes_txt,'String', ['attributes of ' var_select])
    286295    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
    287 %         nbline=0;
     296        %         nbline=0;
    288297        VarAttr=Field.VarAttribute{index-1};
    289298        if isstruct(VarAttr)
     
    291300            for iline=1:length(attr_list)
    292301                Tabcell{iline,1}=attr_list{iline};
    293                 eval(['val=VarAttr.' attr_list{iline} ';']) 
     302                eval(['val=VarAttr.' attr_list{iline} ';'])
    294303                if ischar(val);
    295304                    Tabcell{iline,2}=val;
    296305                else
    297                      Tabcell{iline,2}=num2str(val);
     306                    Tabcell{iline,2}=num2str(val);
    298307                end
    299308            end
    300309        end
    301310    end
    302 
     311   
    303312end
    304313if ~isempty(Tabcell)
    305314    Tabchar=cell2tab(Tabcell,'=');
    306 %     Tabchar=[{''};Tabchar];
     315    %     Tabchar=[{''};Tabchar];
    307316end
    308317set(handles.attributes,'Value',1);% select the first item
     
    319328        if ischar(DimCell)
    320329            DimCell={DimCell};
    321         end   
     330        end
    322331        dim_indices=[];
    323332        for idim=1:length(DimCell)
    324             dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 
     333            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
    325334            dim_index=find(dim_index,1);
    326335            dim_indices=[dim_indices dim_index];
     
    335344    Tabchar=[{''} ;Tabchar];
    336345    set(handles.dimensions,'Value',1)
    337     set(handles.dimensions,'String',Tabchar) 
    338 end 
     346    set(handles.dimensions,'String',Tabchar)
     347end
    339348
    340349%------------------------------------------------------------------------
     
    343352function FieldOption_Callback(hObject, eventdata, handles)
    344353
     354Field=get(handles.get_field,'UserData');
    345355FieldList=get(handles.FieldOption,'String');
    346356FieldOption=FieldList{get(handles.FieldOption,'Value')};
    347357switch FieldOption
     358   
    348359    case '1D plot'
    349360        set(handles.Coordinates,'Visible','on')
     
    361372        set(handles.Z_title,'Visible','off')
    362373        ordinate_Callback(hObject, eventdata, handles)
     374       
    363375    case 'scalar'
    364376        set(handles.Coordinates,'Visible','on')
     
    373385        set(handles.Coord_y,'Visible','on')
    374386        set(handles.Y_title,'Visible','on')
     387        %default scalar selection
     388        test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
     389        for ilist=1:numel(Field.Display.VarDimName)
     390            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
     391                Role=Field.Display.VarAttribute{ilist}.Role;
     392                if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
     393                    test_coord(ilist)=1;
     394                end
     395            end
     396            dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     397            if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
     398                test_coord(ilist)=1;
     399            end
     400        end
     401        scalar_index=find(~test_coord,1);%get the first variable not a coordiante
     402        if isempty(scalar_index)
     403            set(handles.scalar,'Value',1)
     404        else
     405            set(handles.scalar,'Value',scalar_index)
     406        end       
    375407        scalar_Callback(hObject, eventdata, handles)
     408       
    376409    case 'vectors'
    377410        set(handles.Coordinates,'Visible','on')
     
    385418        set(handles.PanelVectors,'Position',pos)
    386419        set(handles.Coord_y,'Visible','on')
    387         set(handles.Y_title,'Visible','on')     
     420        set(handles.Y_title,'Visible','on')
     421        %default vector selection
     422        test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
     423        for ilist=1:numel(Field.Display.VarDimName)
     424            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
     425                Role=Field.Display.VarAttribute{ilist}.Role;
     426                if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
     427                    test_coord(ilist)=1;
     428                end
     429            end
     430            dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     431            if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
     432                test_coord(ilist)=1;
     433            end
     434        end
     435        vector_index=find(~test_coord,2);%get the first variable not a coordiante
     436        if isempty(vector_index)
     437            set(handles.vector_x,'Value',1)
     438            set(handles.vector_y,'Value',2)
     439        else
     440            set(handles.vector_x,'Value',vector_index(1))
     441            set(handles.vector_y,'Value',vector_index(2))
     442        end       
    388443        vector_Callback(handles)
     444       
    389445    case 'civdata...'
    390446        set(handles.PanelOrdinate,'Visible','off')
     
    483539test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
    484540test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
    485 ListCoord={''};
    486541dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
    487 
    488542for ilist=1:numel(Field.Display.VarDimName)
    489543    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     
    494548    end
    495549end
    496 var_component=find(test_component);% list of variable indices elligible as unstructured coordiantes
     550var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
    497551var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
    498552ListCoord=Field.Display.ListVarName([var_component var_coord]);
     
    502556    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
    503557end
    504 if numel(var_component)<2
    505     if numel(test_coord)<2
    506         ListCoord={''};
     558% if numel(var_component)<2
     559%     if numel(test_coord)<2
     560%         ListCoord={''};
     561%     else
     562%         set(handles.Coord_x,'Value',2)
     563%         set(handles.Coord_y,'Value',1)
     564%     end
     565% else
     566coord_val=[0 0];
     567% look for labelled unstructured coordinates
     568for ilist=1:numel(var_component)
     569    ivar=var_component(ilist);
     570    if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
     571        Role=Field.Display.VarAttribute{ivar}.Role;
     572        if strcmp(Role,'coord_x')
     573            coord_val(1)=ilist;
     574        elseif strcmp(Role,'coord_y')
     575            coord_val(2)=ilist;
     576        end
     577    end
     578end
     579if numel(find(coord_val))<2
     580    if numel(var_coord)>=2
     581        coord_val=[numel(var_component)+2 numel(var_component)+1];
    507582    else
    508         set(handles.Coord_x,'Value',2)
    509         set(handles.Coord_y,'Value',1)
    510     end
    511 else
    512     coord_val=[1 2];
    513     for ilist=1:numel(var_component)
    514         ivar=var_component(ilist);
    515         if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
    516             Role=Field.Display.VarAttribute{ivar}.Role;
    517             if strcmp(Role,'coord_x')
    518                 coord_val(1)=ilist;
    519             elseif strcmp(Role,'coord_y')
    520                 coord_val(2)=ilist;
    521             end
    522         end
    523     end
    524     set(handles.Coord_x,'Value',coord_val(1))
    525     set(handles.Coord_y,'Value',coord_val(2))
    526 end
    527 
     583        coord_val=[1 2];
     584    end
     585end
     586set(handles.Coord_x,'Value',coord_val(1))
     587set(handles.Coord_y,'Value',coord_val(2))
    528588set(handles.Coord_y,'String',ListCoord)
    529589set(handles.Coord_x,'String',ListCoord)
     
    559619%------------------------------------------------------------------------
    560620% --- Executes on selection change in vector_x.
     621%------------------------------------------------------------------------
    561622function vector_x_Callback(hObject, eventdata, handles)
    562 %------------------------------------------------------------------------
     623
    563624vector_x_menu=get(handles.vector_x,'String');
    564625vector_x_index=get(handles.vector_x,'Value');
     
    617678    check_consistent=0;
    618679end
     680% the two vector components have consistent dimensions
    619681if check_consistent
    620682    for ilist=1:numel(Field.Display.VarDimName)
     
    642704        end
    643705    else
    644         coord_val=[1 2];
     706        coord_val=[0 0];
    645707        for ilist=1:numel(var_component)
    646708            ivar=var_component(ilist);
     
    654716            end
    655717        end
     718        if isempty(coord_val)
     719            coord_val=var_coord;% case of dimension coordinates
     720        end
     721        if numel(find(coord_val))<2
     722            coord_val=[numel(var_component)+2 numel(var_component)+1];
     723        end
    656724        set(handles.Coord_x,'Value',coord_val(1))
    657725        set(handles.Coord_y,'Value',coord_val(2))
     
    691759%------------------------------------------------------------------------
    692760% --- Executes on selection change in Coord_x.
     761%------------------------------------------------------------------------
    693762function Coord_x_Callback(hObject, eventdata, handles)
    694 %------------------------------------------------------------------------
     763
    695764index=get(handles.Coord_x,'Value');
    696765string=get(handles.Coord_x,'String');
     
    700769%------------------------------------------------------------------------
    701770% --- Executes on selection change in Coord_y.
     771%------------------------------------------------------------------------
    702772function Coord_y_Callback(hObject, eventdata, handles)
    703 %------------------------------------------------------------------------
     773
    704774index=get(handles.Coord_y,'Value');
    705775string=get(handles.Coord_y,'String');
     
    709779%------------------------------------------------------------------------
    710780% --- Executes on selection change in Coord_z.
     781%------------------------------------------------------------------------
    711782function Coord_z_Callback(hObject, eventdata, handles)
    712 %------------------------------------------------------------------------
     783
    713784index=get(handles.Coord_z,'Value');
    714785string=get(handles.Coord_z,'String');
     
    720791%------------------------------------------------------------------------
    721792function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
     793
    722794Field=get(handles.get_field,'UserData');
    723795menu=get(handles.SwitchVarIndexTime,'String');
     
    781853end
    782854
    783 %-------------------------------------------------
    784 % give index numbers of the strings str in the list ListvarName
     855%------------------------------------------------------------------------
     856% --- give index numbers of the strings str in the list ListvarName
     857% -----------------------------------------------------------------------
    785858function VarIndex_y=name2index(cell_str,ListVarName)
     859
    786860VarIndex_y=[];
    787861if ischar(cell_str)
Note: See TracChangeset for help on using the changeset viewer.