Changeset 648 for trunk/src/get_field.m


Ignore:
Timestamp:
Jun 9, 2013, 10:31:58 PM (11 years ago)
Author:
sommeria
Message:

get_field updated, several bugs corrected,open_uvmat suppressd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/get_field.m

    r646 r648  
    2222function varargout = get_field(varargin)
    2323
    24 % Last Modified by GUIDE v2.5 02-Jun-2013 14:00:39
     24% Last Modified by GUIDE v2.5 09-Jun-2013 11:15:54
    2525
    2626% Begin initialization code - DO NOT EDIT
     
    4545%------------------------------------------------------------------------
    4646% --- Executes just before get_field is made visible.
     47%------------------------------------------------------------------------
    4748function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
    48 %------------------------------------------------------------------------
    49 global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
    50 
    51 %% Choose default command line output for get_field
     49
     50%% GUI settings
    5251handles.output = 'Cancel';
    53 
    54 %% Update handles structure
    5552guidata(hObject, handles);
    5653set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
    5754
    58 %% settings for 'slave' mode, called by uvmat, or 'master' mode
    59 if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
    60     set(handles.inputfile,'String',filename)% prefill the input file name
    61     Field=nc2struct(filename,[]);% reads the  field structure, without the variables
    62     if isfield(Field,'Txt')
    63         msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])
    64     else
    65         if ~exist('ParamIn','var')
    66             ParamIn=[];
    67         end
    68         Field_input(handles,Field,ParamIn);
    69     end
    70 else  %master mode
    71     set(handles.inputfile,'String','')
    72 end
    73 
    74 %% put the GUI on the lower right of the sceen
    75 set(hObject,'Unit','pixel')
    76 pos_view_field=get(hObject,'Position');
    77 set(0,'Unit','pixels')
    78 ScreenSize=get(0,'ScreenSize');
    79 pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
    80 pos_view_field(2)=ScreenSize(2);
    81 set(hObject,'Position',pos_view_field)
    82 set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
    83 drawnow
    84 uiwait(handles.get_field);
    85 
    86 %------------------------------------------------------------------------
    87 % --- update the display when a new field is introduced.
    88 function Field_input(handles,Field,ParamIn)
    89 %------------------------------------------------------------------------
    90 
    91 %% fill the list and values of dimensions
    92 if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
    93     Tabcell(:,1)=Field.ListDimName;
    94     for iline=1:length(Field.ListDimName)
    95         Tabcell{iline,2}=num2str(Field.DimValue(iline));
    96     end
    97     Tabchar=cell2tab(Tabcell,' = ');
    98     set(handles.dimensions,'String',Tabchar)
     55%% enter input data
     56set(handles.inputfile,'String',filename)% fill the input file name
     57Field=nc2struct(filename,[]);% reads the  field structure, without the variables
     58if isfield(Field,'Txt')
     59    msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])% display error message for input fiel reading
     60    return
    9961end
    10062if ~isfield(Field,'ListVarName')
    10163    return
    10264end
    103 
    104 %% fill the list of variables
    105 Txt=Field.ListVarName;
    106 set(handles.variables,'Value',1)
    107 set(handles.variables,'String',[{'*'} Txt])
    108 variables_Callback(handles.variables,[], handles)
    109 set(handles.ordinate,'String',Txt)
    110 set(handles.vector_x,'String',Txt)
    111 set(handles.vector_y,'String',Txt )
    112 set(handles.vector_z,'String',[{''} Txt ])
    113 set(handles.vec_color,'String',[{''} Txt ])
    114 set(handles.XVarName,'String',Txt )
    115 set(handles.YVarName,'String',Txt )
    116 set(handles.ZVarName,'String',Txt )
    117 set(handles.scalar,'Value',1)
    118 set(handles.scalar,'String', Txt )
     65if ~exist('ParamIn','var')
     66    ParamIn=[];
     67end
     68
     69%% look at singletons and variables with a single dimension
     70Field.Display=Field;
     71Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value
     72NbVar=numel(Field.VarDimName);
     73for ilist=1:NbVar
     74    if ischar(Field.VarDimName{ilist})
     75        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
     76    end
     77    NbDim=numel(Field.VarDimName{ilist});
     78    check_singleton=false(1,NbDim);
     79    for idim=1:NbDim
     80        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions
     81        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton
     82    end
     83    Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)));% =1 if the variable reduces to a single value
     84    if ~Field.Check0D(ilist)
     85    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
     86    end
     87    %Field.NbDim(ilist)=numel(Field.VarDimNameNonSingleton{ilist});%nbre of array dimensions after elimination of singletons
     88end
     89if numel(Field.VarAttribute)<NbVar% complement VarAttribute by blanjs if neded
     90    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
     91end
     92Field.Display.ListVarName=Field.ListVarName(~Field.Check0D);
     93Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
     94Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D);
     95Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);
     96Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);
    11997
    12098%% analyse the input field cells
    121 [CellInfo,NbDim,errormsg]=find_field_cells(Field);
    122 if ~isempty(errormsg) 
     99[CellInfo,NbDim,errormsg]=find_field_cells(Field.Display);
     100if ~isempty(errormsg)
    123101    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
    124102    return
    125 end 
     103end
    126104[Field.MaxDim,imax]=max(NbDim);
    127 % look at variables with a single dimension
    128 for ilist=1:numel(Field.VarDimName)
    129     if ischar(Field.VarDimName{ilist})
    130         Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
    131     end
    132     NbDim=numel(Field.VarDimName{ilist});% TODO eliminate singleton dimensions
    133     check_singleton=false(1,NbDim);
    134     for idim=1:NbDim
    135         dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);
    136         check_singleton(idim)=isequal(Field.DimValue(dim_index),1);
    137     end
    138     Field.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);
    139     Field.NbDim(ilist)=numel(Field.VarDimName{ilist});
    140     if Field.NbDim(ilist)==1
    141         Field.VarDimName{ilist}=cell2mat(Field.VarDimName{ilist});
    142     end
    143 end
    144 SingleVarName=Field.ListVarName(Field.NbDim==1);%list of variables with a single dim
    145 MultiVarName=Field.ListVarName(Field.NbDim>1);
    146 check_dim=zeros(size(Field.VarDimName));
    147 for ilist=1:numel(Field.VarDimName);
    148     if iscell(Field.VarDimName{ilist})% exclude single dim
    149         for idim=1:numel(Field.VarDimName{ilist})
    150             check_dim=check_dim|strcmp(Field.VarDimName{ilist}{idim},Field.VarDimName);
    151         end
    152     end
    153 end
    154 Field.SingleVarName=Field.ListVarName(find(check_dim));%list of variables with a single dim
    155 Field.SingleDimName=Field.VarDimName(find(check_dim));% corresponding list of dimensions for variables with a single dim
    156 Field.MaxDim=max(Field.NbDim);
    157105
    158106%% set time mode
     
    166114    check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
    167115end
    168 Field.ListNumAttributes=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
    169 if ~isempty(Field.ListNumAttributes)
     116Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
     117if ~isempty(Field.Display.ListGlobalAttribute)
    170118    ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute
    171119end
     
    174122    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];% the time can be chosen as a dim index
    175123end
    176 if Field.MaxDim>=4% for dim >=4, one dim is proposed as time
    177     option=nboption+1;
    178 elseif ~isempty(find(check_time, 1))
    179     option=2;
     124if ~isempty(find(check_time, 1))
     125    set(handles.SwitchVarIndexTime,'Value',2);
    180126else
    181     option=1;
     127    set(handles.SwitchVarIndexTime,'Value',1);
    182128end
    183129set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
    184 set(handles.SwitchVarIndexTime,'Value',option)
    185130set(handles.get_field,'UserData',Field);% record the finput field structure
    186 SwitchVarIndexTime_Callback([],[], handles)
    187 
    188 %% set z coordinate menu if relevant
    189 if Field.MaxDim>=3
    190     set(handles.vector_z,'Visible','on')
    191     set(handles.vector_z,'String',[{''} Txt ])
    192         set(handles.ZVarName,'Visible','on')
    193     set(handles.SwitchVarIndexZ,'Visible','on')
    194     set(handles.Z_title,'Visible','on')
    195 else
    196     set(handles.vector_z,'Visible','off')
    197     set(handles.ZVarName,'Visible','off')
    198 %    set(handles.SwitchVarIndexZ,'Visible','off')
    199     set(handles.Z_title,'Visible','off')
    200 end
     131SwitchVarIndexTime_Callback([], [], handles)
    201132
    202133%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
     134set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
     135set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
     136set(handles.vector_z,'String',[{''} Field.ListVarName])% fill the menu of y vector components
     137set(handles.vec_color,'String',[{''} Field.ListVarName])% fill the menu of y vector components
     138set(handles.scalar,'Value',1)% fill the menu of y vector components
     139set(handles.scalar,'String',Field.ListVarName)% fill the menu of y vector components
     140set(handles.ordinate,'Value',1)% fill the menu of y vector components
     141set(handles.ordinate,'String',Field.ListVarName)% fill the menu of y vector components
    203142if Field.MaxDim>=2 % case of 2D (or 3D) fields
    204     if isfield(CellInfo{imax},'VarIndex_coord_x')&&  isfield(CellInfo{imax},'VarIndex_coord_y')
    205         set(handles.XVarName,'Value',CellInfo{imax}.VarIndex_coord_x(1))
    206         set(handles.YVarName,'Value',CellInfo{imax}.VarIndex_coord_y(1))
    207     end
    208     if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
     143    if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
    209144        set(handles.FieldOption,'Value',3)% set vector selection option
    210145        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
     
    218153end
    219154
     155%% fill the general list of dimensions, variables, attributes
     156if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
     157    Tabcell(:,1)=Field.ListDimName;
     158    for iline=1:length(Field.ListDimName)
     159        Tabcell{iline,2}=num2str(Field.DimValue(iline));
     160    end
     161    Tabchar=cell2tab(Tabcell,' = ');
     162    set(handles.dimensions,'String',Tabchar)
     163end
     164set(handles.variables,'Value',1)
     165set(handles.variables,'String',[{'*'} Field.ListVarName])
     166variables_Callback(handles.variables,[], handles)% list the global attributes
     167
     168%% fill menus for coordinates and time
     169FieldOption_Callback(handles.variables,[], handles)% list the global attributes
     170%     if isfield(CellInfo{imax},'VarIndex_coord_x')&&  isfield(CellInfo{imax},'VarIndex_coord_y')
     171%         set(handles.Coord_x,'Value',CellInfo{imax}.VarIndex_coord_x(1))
     172%         set(handles.Coord_y,'Value',CellInfo{imax}.VarIndex_coord_y(1))
     173%     end
    220174
    221175%% Make choices in menus from input
    222 if exist('ParamIn','var')&&~isempty(ParamIn)
    223     fill_GUI(ParamIn,handles.get_field);
    224 end
    225 FieldOption_Callback([],[],handles)
     176% if exist('ParamIn','var')&&~isempty(ParamIn)
     177%     fill_GUI(ParamIn,handles.get_field);
     178% end
     179%FieldOption_Callback([],[],handles)
     180
     181
     182%% put the GUI on the lower right of the sceen
     183set(hObject,'Unit','pixel')
     184pos_view_field=get(hObject,'Position');
     185set(0,'Unit','pixels')
     186ScreenSize=get(0,'ScreenSize');
     187pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
     188pos_view_field(2)=ScreenSize(2);
     189set(hObject,'Position',pos_view_field)
     190set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
     191drawnow
     192uiwait(handles.get_field);
     193
     194return
     195
     196SwitchVarIndexTime_Callback([],[], handles)
     197
     198%% set z coordinate menu if relevant
     199if Field.MaxDim>=3
     200    set(handles.vector_z,'Visible','on')
     201    set(handles.vector_z,'String',Field.ListVarName(~Field.Check0D))
     202    set(handles.Coord_z,'Visible','on')
     203    set(handles.SwitchVarIndexZ,'Visible','on')
     204    set(handles.Z_title,'Visible','on')
     205else
     206    set(handles.vector_z,'Visible','off')
     207    set(handles.Coord_z,'Visible','off')
     208    set(handles.Z_title,'Visible','off')
     209end
     210
     211
     212
     213%------------------------------------------------------------------------
    226214
    227215%------------------------------------------------------------------------
     
    232220delete(handles.get_field)
    233221
     222%------------------------------------------------------------------------
     223% --- Executes when user attempts to close get_field.
     224%------------------------------------------------------------------------
     225function get_field_CloseRequestFcn(hObject, eventdata, handles)
     226
     227if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
     228    % The GUI is still in UIWAIT, us UIRESUME
     229    uiresume(handles.get_field);
     230else
     231    % The GUI is no longer waiting, just close it
     232    delete(handles.get_field);
     233end
     234
     235%---------------------------------------------------------
     236% --- Executes on button press in OK.
     237%------------------------------------------------------------------------
     238function OK_Callback(hObject, eventdata, handles)
     239
     240handles.output=read_GUI(handles.get_field);
     241guidata(hObject, handles);% Update handles structure
     242uiresume(handles.get_field);
     243drawnow
    234244
    235245% -----------------------------------------------------------------------
     
    250260            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
    251261            if isfield(Field, Field.ListGlobalAttribute{iline})
    252                 eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
     262                val=Field.(Field.ListGlobalAttribute{iline});
    253263                if ischar(val);% attribute value is char string
    254264                    Tabcell{iline,2}=val;
     
    285295if ~isempty(Tabcell)
    286296    Tabchar=cell2tab(Tabcell,'=');
    287     Tabchar=[{''};Tabchar];
     297%     Tabchar=[{''};Tabchar];
    288298end
    289299set(handles.attributes,'Value',1);% select the first item
     
    319329end 
    320330
    321 
    322 
    323 %------------------------------------------------------------------------
    324 % --- Executes on button press in CheckPlot1D.
    325 function CheckPlot1D_Callback(hObject, eventdata, handles)
    326 %------------------------------------------------------------------------
    327 val=get(handles.CheckPlot1D,'Value');
    328 if isequal(val,0)
    329     set(handles.Panel1Dplot,'Visible','off')
     331%------------------------------------------------------------------------
     332% --- Executes on selection change in FieldOption.
     333%------------------------------------------------------------------------
     334function FieldOption_Callback(hObject, eventdata, handles)
     335
     336FieldList=get(handles.FieldOption,'String');
     337FieldOption=FieldList{get(handles.FieldOption,'Value')};
     338switch FieldOption
     339    case '1D plot'
     340        set(handles.PanelOrdinate,'Visible','on')
     341        pos=get(handles.PanelOrdinate,'Position');
     342        pos(1)=2;
     343        pos_coord=get(handles.Coordinates,'Position');
     344        pos(2)=pos_coord(2)-pos(4)-2;
     345        set(handles.PanelOrdinate,'Position',pos)
     346        set(handles.PanelScalar,'Visible','off')
     347        set(handles.PanelVectors,'Visible','off')
     348        set(handles.Coord_y,'Visible','off')
     349        set(handles.Y_title,'Visible','off')
     350        set(handles.Coord_z,'Visible','off')
     351        set(handles.Z_title,'Visible','off')
     352        ordinate_Callback(hObject, eventdata, handles)
     353    case 'scalar'
     354        set(handles.PanelOrdinate,'Visible','off')
     355        set(handles.PanelScalar,'Visible','on')
     356        set(handles.PanelVectors,'Visible','off')
     357        pos=get(handles.PanelScalar,'Position');
     358        pos(1)=2;
     359        pos_coord=get(handles.Coordinates,'Position');
     360        pos(2)=pos_coord(2)-pos(4)-2;
     361        set(handles.PanelScalar,'Position',pos)
     362        set(handles.Coord_y,'Visible','on')
     363        set(handles.Y_title,'Visible','on')
     364        scalar_Callback(hObject, eventdata, handles)
     365    case 'vectors'
     366        set(handles.PanelOrdinate,'Visible','off')
     367        set(handles.PanelScalar,'Visible','off')
     368        set(handles.PanelVectors,'Visible','on')
     369        pos=get(handles.PanelVectors,'Position');
     370        pos(1)=2;
     371        pos_coord=get(handles.Coordinates,'Position');
     372        pos(2)=pos_coord(2)-pos(4)-2;
     373        set(handles.PanelVectors,'Position',pos)
     374        set(handles.Coord_y,'Visible','on')
     375        set(handles.Y_title,'Visible','on')     
     376        vector_Callback(handles)
     377end
     378
     379%------------------------------------------------------------------------
     380function ordinate_Callback(hObject, eventdata, handles)
     381%------------------------------------------------------------------------
     382Field=get(handles.get_field,'UserData');
     383y_index=get(handles.ordinate,'Value');
     384y_menu=get(handles.ordinate,'String');
     385YName=y_menu{y_index};
     386
     387%% set list of possible coordinates
     388test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
     389test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
     390ListCoord={''};
     391dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable
     392
     393for ilist=1:numel(Field.Display.VarDimName)
     394    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     395    if isequal(dimnames,dim_var)
     396        test_component(ilist)=1;
     397    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
     398        test_coord(ilist)=1;
     399    end
     400end
     401var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
     402var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
     403ListCoord=Field.Display.ListVarName([var_component var_coord]);
     404
     405%% set default coord selection
     406if numel(find(test_coord))>3
     407    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
     408end
     409if numel(var_component)<2
     410    if numel(test_coord)<2
     411        ListCoord={''};
     412    else
     413        set(handles.Coord_x,'Value',2)
     414        set(handles.Coord_y,'Value',1)
     415    end
    330416else
    331    
    332 end
    333 
    334 %------------------------------------------------------------------------
    335 function ordinate_Callback(hObject, eventdata, handles)
    336 %------------------------------------------------------------------------
     417    coord_val=1;
     418    for ilist=1:numel(var_component)
     419        ivar=var_component(ilist);
     420        if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
     421            Role=Field.Display.VarAttribute{ivar}.Role;
     422            if strcmp(Role,'coord_x')
     423                coord_val=ilist;
     424            end
     425        end
     426    end
     427    set(handles.Coord_x,'Value',coord_val)
     428end
     429set(handles.Coord_x,'String',ListCoord)
     430
     431
     432%% set list of time coordinates
     433menu=get(handles.SwitchVarIndexTime,'String');
     434TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
     435switch TimeOption
     436    case 'variable'
     437        if numel(find(test_coord))<3
     438            ListTime={''};
     439        else
     440            ListTime=Field.Display.ListVarName(find(test_coord,end));
     441        end
     442        set(handles.TimeName,'Value',1)
     443        set(handles.TimeName,'String',ListTime)
     444    case 'dim index'
     445        if numel(find(test_coord))<3
     446            ListTime={''};
     447        else
     448            ListTime=Field.Display.VarDimName{find(test_coord,end)};
     449        end
     450        set(handles.TimeName,'Value',1)
     451        set(handles.TimeName,'String',ListTime)
     452end 
     453update_field(handles,YName)
     454
     455%------------------------------------------------------------------------
     456% --- Executes on selection change in scalar menu.
     457%------------------------------------------------------------------------
     458function scalar_Callback(hObject, eventdata, handles)
     459
    337460Field=get(handles.get_field,'UserData');
    338 list=get(handles.ordinate,'String');
    339 yindex=get(handles.ordinate,'Value');
    340 yindex=name2index(list{yindex(1)},Field.ListVarName);
    341 if ~isempty(yindex)
    342     set(handles.variables,'Value',yindex+1)
    343     variables_Callback(hObject, eventdata, handles)
    344 end
    345 [CellInfo,NbDim,errormsg]=find_field_cells(Field);
    346 %[CellVarIndex,NbDim,VarRole,errormsg]=find_field_cells(Field);
    347 for icell=1:numel(CellInfo)
    348     VarIndex=CellInfo{icell}.VarIndex;
    349     if ~isempty(find(VarIndex==yindex,1)) && (isempty(CellInfo{icell}.VarIndex_coord_x)||~isequal(CellInfo{icell}.VarIndex_coord_x,VarIndex))
    350         cell_select=icell;
    351         break
    352     end
    353 end
    354 %val=get(handles.abscissa,'Value');
    355 %set(handles.abscissa,'Value',min(val,2));
    356 coord_x_index=CellInfo{cell_select}.VarIndex_coord_x;
    357 coord_x_index=coord_x_index(coord_x_index~=0);
    358 %set(handles.XVarName,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
    359 set(handles.XVarName,'String',[(Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
    360 
    361 %------------------------------------------------------------------------
    362 % --- Executes on button press in CheckScalar.
    363 function CheckScalar_Callback(hObject, eventdata, handles)
    364 %------------------------------------------------------------------------
    365 val=get(handles.CheckScalar,'Value');
    366 if isequal(val,0)
    367     set(handles.PanelScalar,'Visible','off')
     461scalar_index=get(handles.scalar,'Value');
     462scalar_menu=get(handles.scalar,'String');
     463ScalarName=scalar_menu{scalar_index};
     464
     465%% set list of possible coordinates
     466test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
     467test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
     468ListCoord={''};
     469dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
     470
     471for ilist=1:numel(Field.Display.VarDimName)
     472    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     473    if isequal(dimnames,dim_var)
     474        test_component(ilist)=1;
     475    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
     476        test_coord(ilist)=1;
     477    end
     478end
     479var_component=find(test_component);% list of variable indices elligible as unstructured coordiantes
     480var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
     481ListCoord=Field.Display.ListVarName([var_component var_coord]);
     482
     483%% set default coord selection
     484if numel(find(test_coord))>3
     485    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
     486end
     487if numel(var_component)<2
     488    if numel(test_coord)<2
     489        ListCoord={''};
     490    else
     491        set(handles.Coord_x,'Value',2)
     492        set(handles.Coord_y,'Value',1)
     493    end
    368494else
    369    
    370 end
    371 
    372 %------------------------------------------------------------------------
    373 % --- Executes on button press in CheckVector.
    374 function CheckVector_Callback(hObject, eventdata, handles)
    375 %------------------------------------------------------------------------
    376 val=get(handles.CheckVector,'Value');
    377 if isequal(val,0)
    378     set(handles.PanelVectors,'Visible','off')
    379 else
    380    
    381 end
    382 
    383 
    384 %------------------------------------------------------------------------
    385 % --- Executes on selection change in scalar menu.
    386 function scalar_Callback(hObject, eventdata, handles)
    387 %------------------------------------------------------------------------
    388 Field=get(handles.get_field,'UserData');
    389 index=get(handles.scalar,'Value');
    390 string=get(handles.scalar,'String');
    391 VarName=string{index};
    392 update_field(hObject, eventdata, handles,VarName)
    393 
    394 %eliminate time
    395 TimeDimName='';%default
    396 
    397 % SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
    398 % TimeVarOption=SwitchVarIndexTime{get(handles.SwitchVarIndexTime,'Value')};
    399 List=get(handles.TimeVarName,'String');
    400 if get(handles.CheckDimensionTime)
    401          TimeDimName=List{get(handles.TimeVarName,'Value')};
    402 elseif ~get(handles.CheckAttributeTime)
    403     TimeVarName=List{get(handles.TimeVarName,'Value')};
    404 end
    405 % A completer
    406 % if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on')
    407 %     TimeDimList=get(handles.TimeDimensionMenu,'String');
    408 %     TimeDimIndex=get(handles.TimeDimensionMenu,'Value');
    409 %     TimeDimName=TimeDimList{TimeDimIndex};
    410 % end
    411 
    412 %check possible coordinates
    413 Field=get(handles.get_field,'UserData');
    414 dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar
    415 test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
    416 for ilist=1:numel(Field.VarDimName)
    417     dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
    418     if isequal(dimnames,TimeDimName)
    419         test_coord(ilist)=0;%mark time variables fo elimination
    420     end
    421     if ischar(dimnames)
    422         dimnames={dimnames};
    423     end
    424     for idim=1:numel(dimnames)
    425         if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable
    426             test_coord(ilist)=0;
    427             break
    428         end
    429     end
    430 end
    431 test_coord(index)=0;%the coordinate variable must be different from the scalar
    432 
    433 string_coord=[{''};string(test_coord==1)];
    434 val=get(handles.XVarName,'Value');
    435 if val>numel(string_coord)
    436     set(handles.XVarName,'Value',1)
    437 end
    438 set(handles.XVarName,'String',string_coord);
    439 val=get(handles.ZVarName,'Value');
    440 if val>numel(string_coord)
    441     set(handles.ZVarName,'Value',1)
    442 end
    443 set(handles.ZVarName,'String',string_coord);
    444 val=get(handles.ZVarName,'Value');
    445 if val>numel(string_coord)
    446     set(handles.ZVarName,'Value',1)
    447 end
    448 set(handles.YVarName,'String',string_coord);
    449 
    450 
    451 %------------------------------------------------------------------------
    452 % --- Executes on selection change in abscissa.
    453 function abscissa_Callback(hObject, eventdata, handles)
    454 %------------------------------------------------------------------------
    455  hselect_field=get(handles.inputfile,'parent');
    456  Field=get(hselect_field,'UserData');%current input field
    457  xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
    458 % test_2D=get(handles.CheckVector,'Value');% =1 for vector fields
    459 % test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields
    460 %if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa
    461 %     Txt=Field.ListVarName;
    462 %     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
    463 %     xindex=[];
    464 % else
    465      xlist=get(handles.abscissa,'String');%list of abscissa
    466      VarName=xlist{xdispindex}; %selected variable name
    467      update_field(hObject, eventdata, handles,VarName)
    468 %      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
    469 %      if ~isempty(xindex)
    470 %         set(handles.variables,'Value',xindex+1)
    471 %         variables_Callback(hObject, eventdata, handles)
    472 %      end
    473 %     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
    474 %     variables_Callback(hObject, eventdata, handles)  %display properties of the TimeVariable (dim, attributes)
    475 %     if  ~test_2D &  ~test_scalar% look for possible varaibles to OK in ordinate   
    476 %         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
    477 %         VarIndex=[];
    478 %         for ilist=1:length(Field.VarDimIndex)%detect
    479 %             index_i=Field.VarDimIndex{ilist};
    480 %             if ~isempty(index_i)
    481 %                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, OK is possible
    482 %                     VarIndex=[VarIndex ilist];
    483 %                 end
    484 %             end
    485 %         end
    486 % %         set(handles.ordinate,'Value',1)
    487 %         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
    488 %     end
    489 % end
    490 %
    491 % update_UserData(handles)
    492 
    493 
    494 
    495 %------------------------------------------------------------------------
    496 % --- Executes on selection change in XVarName.
    497 function XVarName_Callback(hObject, eventdata, handles)
    498 %------------------------------------------------------------------------
    499 index=get(handles.XVarName,'Value');
    500 string=get(handles.XVarName,'String');
    501 VarName=string{index};
    502 update_field(hObject, eventdata, handles,VarName)
    503 
    504 %------------------------------------------------------------------------
    505 % --- Executes on selection change in ZVarName.
    506 function ZVarName_Callback(hObject, eventdata, handles)
    507 %------------------------------------------------------------------------
    508 index=get(handles.ZVarName,'Value');
    509 string=get(handles.ZVarName,'String');
    510 VarName=string{index};
    511 update_field(hObject, eventdata, handles,VarName)
    512 
    513 %------------------------------------------------------------------------
    514 % --- Executes on selection change in YVarName.
    515 function YVarName_Callback(hObject, eventdata, handles)
    516 %------------------------------------------------------------------------
    517 index=get(handles.YVarName,'Value');
    518 string=get(handles.YVarName,'String');
    519 VarName=string{index};
    520 update_field(hObject, eventdata, handles,VarName)
     495    coord_val=[1 2];
     496    for ilist=1:numel(var_component)
     497        ivar=var_component(ilist);
     498        if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
     499            Role=Field.Display.VarAttribute{ivar}.Role;
     500            if strcmp(Role,'coord_x')
     501                coord_val(1)=ilist;
     502            elseif strcmp(Role,'coord_y')
     503                coord_val(2)=ilist;
     504            end
     505        end
     506    end
     507    set(handles.Coord_x,'Value',coord_val(1))
     508    set(handles.Coord_y,'Value',coord_val(2))
     509end
     510
     511set(handles.Coord_y,'String',ListCoord)
     512set(handles.Coord_x,'String',ListCoord)
     513
     514
     515%% set list of time coordinates
     516menu=get(handles.SwitchVarIndexTime,'String');
     517TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
     518switch TimeOption
     519    case 'variable'
     520        if numel(find(test_coord))<3
     521            ListTime={''};
     522        else
     523            ListTime=Field.Display.ListVarName(find(test_coord,end));
     524        end
     525        set(handles.TimeName,'Value',1)
     526        set(handles.TimeName,'String',ListTime)
     527    case 'dim index'
     528        if numel(find(test_coord))<3
     529            ListTime={''};
     530        else
     531            ListTime=Field.Display.VarDimName{find(test_coord,end)};
     532        end
     533        set(handles.TimeName,'Value',1)
     534        set(handles.TimeName,'String',ListTime)
     535end 
     536update_field(handles,ScalarName)
     537
     538% --- Executes on button press in check_rgb.
     539function check_rgb_Callback(hObject, eventdata, handles)
     540
    521541
    522542%------------------------------------------------------------------------
     
    524544function vector_x_Callback(hObject, eventdata, handles)
    525545%------------------------------------------------------------------------
    526 index=get(handles.vector_x,'Value');
    527 string=get(handles.vector_x,'String');
    528 VarName=string{index};
    529 
    530 %check possible coordinates
    531 Field=get(handles.get_field,'UserData');
    532 dim_var=Field.VarDimName{index};%list of dimensions of the selected variable
    533 test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
    534 test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component
    535 for ilist=1:numel(Field.VarDimName)
    536     dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
    537     if ~isequal(dimnames,dim_var)
    538         test_component(ilist)=0;
    539     end
    540     for idim=1:numel(dimnames)
    541         if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable
    542             test_coord(ilist)=0;
    543             break
    544         end
    545     end
    546 end
    547 %eliminate time
    548 if get(handles.TimeVariable,'Value')
    549     TimeName=get(handles.TimeName,'String');
    550     index_time=find(strcmp( TimeName,Field.ListVarName));
    551     test_coord(index_time)=0;
    552 end
    553 vlength=numel(string(test_component==1));
    554 val=get(handles.vector_y,'Value');
    555 if val>vlength
    556     set(handles.vector_y,'Value',1)
    557 end
    558 set(handles.vector_y,'String',[string(test_component==1)])
    559 val=get(handles.vector_z,'Value');
    560 if val>vlength+1
    561     set(handles.vector_z,'Value',1)
    562 end
    563 set(handles.vector_z,'String',[{''};string(test_component==1)])
    564 val=get(handles.vec_color,'Value');
    565 if val>vlength+1
    566     set(handles.vec_color,'Value',1)
    567 end
    568 set(handles.vec_color,'String',[{''};string(test_component==1)])
    569 string_coord=[{''};string(test_coord==1)];
    570 val=get(handles.XVarName,'Value');
    571 if val>numel(string_coord)
    572     set(handles.XVarName,'Value',1)
    573 end
    574 set(handles.XVarName,'Visible','on');
    575 set(handles.XVarName,'String',string_coord);
    576 val=get(handles.YVarName,'Value');
    577 if val>numel(string_coord)
    578     set(handles.YVarName,'Value',1)
    579 end
    580 set(handles.YVarName,'Visible','on');
    581 set(handles.YVarName,'String',string_coord);
    582 val=get(handles.TimeVarName,'Value');
    583 if val>numel(string_coord)
    584     set(handles.TimeVarName,'Value',1)
    585 end
    586 set(handles.TimeVarName,'String',string_coord);
    587 
    588 update_field(hObject, eventdata, handles,VarName)
    589 
    590 %------------------------------------------------------------------------
    591 % --- Executes on selection change in vector_y.
     546vector_x_menu=get(handles.vector_x,'String');
     547vector_x_index=get(handles.vector_x,'Value');
     548vector_x=vector_x_menu{vector_x_index};
     549vector_Callback(handles)
     550update_field(handles,vector_x)
     551
     552%------------------------------------------------------------------------
     553% --- Executes on selection change in vector_x.
    592554function vector_y_Callback(hObject, eventdata, handles)
    593555%------------------------------------------------------------------------
    594 index=get(handles.vector_y,'Value');
    595 string=get(handles.vector_y,'String');
    596 VarName=string{index};
    597 update_field(hObject, eventdata, handles,VarName)
     556vector_y_menu=get(handles.vector_x,'String');
     557vector_y_index=get(handles.vector_x,'Value');
     558vector_y=vector_y_menu{vector_y_index};
     559vector_Callback(handles)
     560update_field(handles,vector_y)
    598561
    599562%------------------------------------------------------------------------
     
    601564function vector_z_Callback(hObject, eventdata, handles)
    602565%------------------------------------------------------------------------
    603 index=get(handles.vector_z,'Value');
    604 string=get(handles.vector_z,'String');
    605 VarName=Astring{index};
    606 update_field(hObject, eventdata, handles,VarName)
    607 
    608 %------------------------------------------------------------------------
    609 % --- Executes on selection change in coord_x_vectors.
    610 function coord_x_vectors_Callback(hObject, eventdata, handles)
    611 %------------------------------------------------------------------------
    612 index=get(handles.coord_x_vectors,'Value');
    613 string=get(handles.coord_x_vectors,'String');
    614 VarName=string{index};
    615 update_field(hObject, eventdata, handles,VarName)
    616 
    617 %------------------------------------------------------------------------
    618 % --- Executes on selection change in coord_y_vectors.
    619 function coord_y_vectors_Callback(hObject, eventdata, handles)
    620 %------------------------------------------------------------------------
    621 index=get(handles.coord_y_vectors,'Value');
    622 string=get(handles.coord_y_vectors,'String');
    623 VarName=string{index};
    624 update_field(hObject, eventdata, handles,VarName)
    625 
    626 %------------------------------------------------------------------------
    627 % --- Executes on selection change in YVarName.
    628 function TimeVarName_Callback(hObject, eventdata, handles)
    629 %------------------------------------------------------------------------
    630 index=get(handles.TimeVarName,'Value');
    631 string=get(handles.TimeVarName,'String');
    632 VarName=string{index};
    633 update_field(hObject, eventdata, handles,VarName)
     566vector_z_menu=get(handles.vector_z,'String');
     567vector_z_index=get(handles.vector_z,'Value');
     568vector_z=vector_z_menu{vector_z_index};
     569vector_Callback(handles)
     570update_field(handles,vector_z)
    634571
    635572%------------------------------------------------------------------------
     
    640577string=get(handles.vec_color,'String');
    641578VarName=string{index};
    642 update_field(hObject, eventdata, handles,VarName)
     579vector_Callback(handles)
     580update_field(handles,VarName)
     581
     582%------------------------------------------------------------------------
     583% --- Executes on selection change in vector_x or vector_y
     584function vector_Callback( handles)
     585%------------------------------------------------------------------------
     586Field=get(handles.get_field,'UserData');
     587vector_x_index=get(handles.vector_x,'Value');
     588vector_y_index=get(handles.vector_y,'Value');
     589vec_color_index=get(handles.vec_color,'Value');
     590
     591%% set list of possible coordinates
     592test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
     593test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
     594check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn
     595ListCoord={''};
     596dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable
     597if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index})
     598    check_consistent=0;
     599elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index})
     600    check_consistent=0;
     601end
     602if check_consistent
     603    for ilist=1:numel(Field.Display.VarDimName)
     604        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     605        if isequal(dimnames,dim_var)
     606            test_component(ilist)=1;
     607        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
     608            test_coord(ilist)=1;
     609        end
     610    end
     611    var_component=find(test_component);% list of variable indices elligible as unstructured coordiantes
     612    var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
     613    ListCoord=Field.Display.ListVarName([var_component var_coord]);
     614   
     615    %% set default coord selection
     616    if numel(find(test_coord))>3
     617        set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
     618    end
     619    if numel(var_component)<2
     620        if numel(test_coord)<2
     621            ListCoord={''};
     622        else
     623            set(handles.Coord_x,'Value',2)
     624            set(handles.Coord_y,'Value',1)
     625        end
     626    else
     627        coord_val=[1 2];
     628        for ilist=1:numel(var_component)
     629            ivar=var_component(ilist);
     630            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
     631                Role=Field.Display.VarAttribute{ivar}.Role;
     632                if strcmp(Role,'coord_x')
     633                    coord_val(1)=ilist;
     634                elseif strcmp(Role,'coord_y')
     635                    coord_val(2)=ilist;
     636                end
     637            end
     638        end
     639        set(handles.Coord_x,'Value',coord_val(1))
     640        set(handles.Coord_y,'Value',coord_val(2))
     641    end
     642end
     643set(handles.Coord_y,'String',ListCoord)
     644set(handles.Coord_x,'String',ListCoord)
     645
     646
     647%% set list of time coordinates
     648menu=get(handles.SwitchVarIndexTime,'String');
     649TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
     650switch TimeOption
     651    case 'variable'
     652        if numel(find(test_coord))<3
     653            ListTime={''};
     654        else
     655            ListTime=Field.Display.ListVarName(find(test_coord,end));
     656        end
     657        set(handles.TimeName,'Value',1)
     658        set(handles.TimeName,'String',ListTime)
     659    case 'dim index'
     660        if numel(find(test_coord))<3
     661            ListTime={''};
     662        else
     663            ListTime=Field.Display.VarDimName{find(test_coord,end)};
     664        end
     665        set(handles.TimeName,'Value',1)
     666        set(handles.TimeName,'String',ListTime)
     667end 
     668
     669%------------------------------------------------------------------------
     670% --- Executes on selection change in SwitchVarIndexX.
     671%------------------------------------------------------------------------
     672function SwitchVarIndexX_Callback(hObject, eventdata, handles)
     673
     674%------------------------------------------------------------------------
     675% --- Executes on selection change in Coord_x.
     676function Coord_x_Callback(hObject, eventdata, handles)
     677%------------------------------------------------------------------------
     678index=get(handles.Coord_x,'Value');
     679string=get(handles.Coord_x,'String');
     680VarName=string{index};
     681update_field(handles,VarName)
     682
     683%------------------------------------------------------------------------
     684% --- Executes on selection change in Coord_y.
     685function Coord_y_Callback(hObject, eventdata, handles)
     686%------------------------------------------------------------------------
     687index=get(handles.Coord_y,'Value');
     688string=get(handles.Coord_y,'String');
     689VarName=string{index};
     690update_field(handles,VarName)
     691
     692%------------------------------------------------------------------------
     693% --- Executes on selection change in Coord_z.
     694function Coord_z_Callback(hObject, eventdata, handles)
     695%------------------------------------------------------------------------
     696index=get(handles.Coord_z,'Value');
     697string=get(handles.Coord_z,'String');
     698VarName=string{index};
     699update_field(handles,VarName)
     700
     701%------------------------------------------------------------------------
     702% --- Executes on selection change in SwitchVarIndexTime.
     703%------------------------------------------------------------------------
     704function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
     705Field=get(handles.get_field,'UserData');
     706menu=get(handles.SwitchVarIndexTime,'String');
     707option=menu{get(handles.SwitchVarIndexTime,'Value')};
     708
     709switch option
     710    case 'file index'
     711        set(handles.TimeName, 'Visible','off')% the time is taken as the file index
     712    case 'attribute'
     713        set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes
     714        time_index=[];
     715        PreviousList=get(handles.TimeName, 'String');
     716        index=[];
     717        if ~isempty(PreviousList)
     718            PreviousAttr=PreviousList{get(handles.TimeName, 'Value')};
     719            index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes));
     720        end
     721        if isempty(index)
     722            time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')));% index of the attributes containing the string 'Time'
     723        end
     724        if ~isempty(time_index)
     725            set(handles.TimeName,'Value',time_index(1))
     726        else
     727            set(handles.TimeName,'Value',1)
     728        end
     729        set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute)
     730    case 'variable'% TimeName menu represents the available variables
     731        set(handles.TimeName, 'Visible','on')
     732        TimeVarName=Field.Display.SingleVarName;% slist of variables with a single dimension (candidate for time)
     733        List=get(handles.TimeName,'String');
     734        option=List{get(handles.TimeName,'Value')};
     735        ind=find(strcmp(option,TimeVarName));
     736        if isempty(ind)
     737            set(handles.TimeName, 'Value',1);
     738        else
     739            set(handles.TimeName, 'Value',ind);
     740        end
     741        set(handles.TimeName, 'String',TimeVarName)
     742    case 'dim index'% TimeName menu represents the available dimensions
     743        set(handles.TimeName, 'Visible','on')
     744        TimeVarName=Field.Display.SingleDimName;
     745        List=get(handles.TimeName,'String');
     746        option=List{get(handles.TimeName,'Value')};
     747        ind=find(strcmp(option,TimeVarName));
     748        if isempty(ind)
     749            set(handles.TimeName, 'Value',1);
     750        else
     751            set(handles.TimeName, 'Value',ind);
     752        end
     753        set(handles.TimeName, 'String',TimeVarName)
     754end
    643755
    644756%-----------------------------------------------------------------------
    645 function update_field(hObject, eventdata, handles,VarName)
     757function update_field(handles,VarName)
    646758%-----------------------------------------------------------------------
    647759Field=get(handles.get_field,'UserData');
     
    649761if ~isempty(index)
    650762    set(handles.variables,'Value',index+1)
    651     variables_Callback(hObject, eventdata, handles)
    652 end
    653 
    654 %------------------------------------------------------------------------
    655 % update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
    656 function update_UserData(handles)
    657 %------------------------------------------------------------------------
    658 return
    659 % global SubField
    660 hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
    661 Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
    662 if isfield(Field,'VarAttribute')
    663     VarAttribute=Field.VarAttribute;
    664 else
    665     VarAttribute={};
    666 end
    667 
    668 
    669 % select the indices of field variables for 2D plots
    670 test_CheckPlot1D=get(handles.CheckPlot1D,'Value');
    671 test_scalar=get(handles.CheckScalar,'Value');
    672 test_vector=get(handles.CheckVector,'Value');
    673 
    674 %transform if needed (calibration)
    675 list=get(handles.menu_coord,'String');
    676 index=get(handles.menu_coord,'Value');
    677 transform=list{index};
    678 if ~isequal(transform,'')
    679     Field=feval(transform,Field);
    680 end
    681 VarIndex.u=[];
    682 VarIndex.v=[];
    683 VarIndex.w=[];
    684 VarIndex.A=[];
    685 VarIndex_tot=[];
    686 iuA=[];
    687 if test_scalar
    688     Astring=get(handles.scalar,'String');
    689     Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
    690     list_var=Astring(Aindex);
    691     VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
    692     VarIndex_tot= [VarIndex_tot VarIndex.A];
    693     DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
    694     DimValue=Field.DimValue(DimIndex);
    695     ind=find(DimValue==1);
    696     DimIndex(ind)=[];%Mremove singleton
    697 end
    698 if test_vector
    699     Ustring=get(handles.vector_x,'String');
    700     Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
    701     list_var=Ustring{Uindex};%name of the selected scalar
    702     VarIndex.u=name2index(list_var,Field.ListVarName);
    703     Vstring=get(handles.vector_y,'String');
    704     Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
    705     list_var=Ustring{Vindex};%name of the selected scalar
    706     VarIndex.v=name2index(list_var,Field.ListVarName);
    707     if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
    708         iuA=VarIndex.A; %same variable used for vector and scalar
    709         VarIndex_tot(iuA)=[];
    710     end
    711     VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
    712     %dimensions
    713     DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
    714     DimValue=Field.DimValue(DimIndex_u);
    715     ind=find(DimValue==1);
    716     DimIndex_u(ind)=[];%Mremove singleton
    717     DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
    718     DimValue=Field.DimValue(DimIndex_v);
    719     ind=find(DimValue==1);
    720     DimIndex_v(ind)=[];%Mremove singleton
    721     if ~isequal(DimIndex_u,DimIndex_v)
    722         msgbox_uvmat('ERROR','inconsistent dimensions for u and v')
    723         set(handles.vector_y,'Value',1);
    724         return
    725     elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
    726          msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color')
    727          set(handles.scalar,'Value',1);
    728          return
    729     end
    730     DimIndex=DimIndex_u;
    731     %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components
    732 end
    733 
    734 
    735 % select the TimeVariable  index (or indices) for z coordinates
    736 test_grid=0;
    737 if test_scalar | test_vector
    738     nbdim=length(DimIndex);
    739     if nbdim > 3
    740         msgbox_uvmat('ERROR','array with more than three dimensions, not supported')
    741         return
    742     else
    743         perm_ind=1:nbdim;
    744     end
    745     if nbdim==3
    746         zstring=get(handles.coord_z_vectors_scalar,'String');
    747         zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
    748         list_var=zstring(zindex);
    749         VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
    750         if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
    751             if zindex ~= 1
    752                 set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
    753                 return
    754             end
    755         else
    756             VarIndex_tot=[VarIndex_tot VarIndex_z];
    757             DimIndex_z=Field.VarDimIndex{VarIndex_z};
    758             DimValue=Field.DimValue(DimIndex_z);
    759             ind=find(DimValue==1);         
    760             DimIndex_z(ind)=[];%Mremove singleton
    761             if isequal(DimIndex_z,DimIndex)
    762                 VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
    763             elseif length(DimIndex_z)==1
    764                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
    765                 ind_z=find(DimIndex==DimIndex_z(1));
    766                 perm_ind(ind_z)=1;
    767                 test_grid=1;
    768             else
    769                 msgbox_uvmat('ERROR','multiple dimensions for the z coordinate')
    770                 return
    771             end
    772         end
    773 %         if ~isempty(VarIndex_z)
    774 %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable   
    775 %             if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable
    776 %                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
    777 %                 ind_z=find(DimIndex==DimIndex_z(1));
    778 %                 perm_ind(ind_z)=1;
    779 %                 test_grid=1;
    780 %             end
    781 %         end
    782     end
    783 end
    784 
    785 % select the TimeVariable  index (or indices) for ordinate
    786 ystring=get(handles.ordinate,'String');
    787 yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
    788 list_var=ystring(yindex);
    789 VarIndex.y=name2index(list_var,Field.ListVarName);
    790 if isequal(VarIndex.A,VarIndex.y)
    791     set(handles.ZVarName,'Value',1)
    792 elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
    793    set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
    794 else
    795     for ivar=1:length(VarIndex.y)
    796         VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
    797     end
    798     VarIndex_tot=[VarIndex_tot VarIndex.y];
    799 end
    800 if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
    801     DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
    802     if length(DimIndex_y)==1
    803         ind_y=find(DimIndex==DimIndex_y(1));
    804         test_grid=1;
    805         if nbdim==3
    806             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    807             perm_ind(ind_y)=2;
    808         elseif nbdim==2
    809             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    810              perm_ind(ind_y)=1;
    811         end
    812     elseif test_grid
    813         msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1')   
    814     end
    815 end
    816 
    817 %select the TimeVariable index for the abscissa
    818 xstring=get(handles.abscissa,'String');
    819 xindex=get(handles.abscissa,'Value');
    820 list_var=xstring(xindex);
    821 VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
    822 if length(VarIndex.x)==1   
    823     DimIndex_x=Field.VarDimIndex{VarIndex.x};
    824     DimValue=Field.DimValue(DimIndex_x);
    825     ind=find(DimValue==1);         
    826     DimIndex_x(ind)=[];%Mremove singleton                     
    827     VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
    828 %     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
    829     index_detect=find(VarIndex_tot==VarIndex.x);
    830 else
    831     index_detect=[];%coord x variable not already used
    832 end
    833 if isempty(index_detect)
    834     VarIndex_tot=[VarIndex_tot VarIndex.x];
    835 elseif ~test_CheckPlot1D
    836     VarIndex.x=[];
    837     set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
    838 end
    839 
    840 if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
    841     DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
    842     if length(DimIndex_x)==1
    843         ind_x=find(DimIndex==DimIndex_x(1));
    844         if nbdim==3
    845             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    846             perm_ind(ind_x)=3;
    847         elseif nbdim==2
    848             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    849              perm_ind(ind_x)=2;
    850         end
    851         if isequal(perm_ind,1:nbdim)
    852             test_grid=0;
    853         end
    854         DimIndex=DimIndex(perm_ind);
    855     elseif test_grid
    856         msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1')   
    857     end
    858     if isequal(DimIndex_x,DimIndex)
    859                 VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
    860     end
    861 end
    862 
    863 %defined the selected sub-field SubField
    864 SubField.ListGlobalAttribute{1}='InputFile';
    865 SubField.InputFile=get(handles.inputfile,'String');
    866 SubField.ListDimName=Field.ListDimName;
    867 SubField.DimValue=Field.DimValue;
    868 SubField.ListVarName=Field.ListVarName(VarIndex_tot);
    869 SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
    870 
    871 testperm=0;
    872 testattr=0;
    873 for ivar=VarIndex.u
    874     VarAttribute{ivar}.Role='vector_x';
    875     testattr=1;
    876     if test_grid
    877         VarDimIndex{ivar}=DimIndex; %permute dimensions
    878         testperm=1;
    879     end
    880 end
    881 for ivar=VarIndex.v
    882     VarAttribute{ivar}.Role='vector_y';
    883     testattr=1;
    884      if test_grid
    885         VarDimIndex{ivar}=DimIndex;%permute dimensions
    886         testperm=1;
    887     end
    888 end
    889 for ivar=VarIndex.A
    890     if test_grid
    891         VarDimIndex{ivar}=DimIndex;%permute dimensions
    892         testperm=1;
    893     end
    894     if isempty(iuA)
    895         VarAttribute{ivar}.Role='scalar';%Role =scalar
    896         testattr=1;
    897     else
    898        VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
    899        nbattr=length(VarAttribute);
    900        VarAttribute{nbattr}.Role='scalar';
    901        testattr=1;
    902     end
    903 end
    904 if testperm
    905     SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
    906 end
    907 if testattr
    908     SubField.VarAttribute=VarAttribute(VarIndex_tot);
    909 end
    910 set(hselect_field,'UserData',Field)
    911 
    912 %---------------------------------------------------------
    913 % --- Executes on button press in OK.
    914 
    915 function OK_Callback(hObject, eventdata, handles)
    916 %---------------------------------------------------------
    917 
    918 handles.output=read_GUI(handles.get_field);
    919 guidata(hObject, handles);% Update handles structure
    920 uiresume(handles.get_field);
    921 drawnow
    922 return
    923 
    924 %%%% SKIPPED %%%%
    925 hfield=[];
    926 huvmat=findobj(allchild(0),'tag','uvmat');
    927 hseries=findobj(allchild(0),'tag','series');
    928 check_series=0;
    929 % look for the status of the GUI uvmat
    930 if ~isempty(huvmat)
    931     hh=guidata(huvmat);
    932     FieldMenu=get(hh.FieldName,'String');
    933     FieldName=FieldMenu{get(hh.FieldName,'Value')};
    934     if strcmp(FieldName,'get_field...')
    935         hfield=hh.FieldName; %FieldName on uvmat
    936     elseif strcmp(get(hh.FieldName_1,'Visible'),'on')
    937         FieldMenu=get(hh.FieldName_1,'String');
    938         if ~isempty(FieldMenu)
    939             FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
    940             if strcmp(FieldName,'get_field...')
    941                 hfield=hh.FieldName_1; %FieldName_1 on uvmat
    942             end
    943         end
    944     end
    945 end
    946 % if no filed data is concerned on uvmat, look at the GUI series
    947 if isempty(hfield) && ~isempty(hseries)
    948     check_series=1;
    949     hh=guidata(hseries);
    950     FieldMenu=get(hh.FieldName,'String');
    951     FieldName=FieldMenu{get(hh.FieldName,'Value')};
    952     if strcmp(FieldName,'get_field...')
    953         hfield=hh.FieldName; %FieldName on series
    954     else
    955        FieldMenu=get(hh.FieldName_1,'String');
    956        FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
    957        if strcmp(FieldName,'get_field...')
    958             hfield=hh.FieldName_1; %FieldName_1 on series
    959        end
    960     end
    961 end
    962 if ~isempty(hfield)
    963     get_field_GUI=read_GUI(handles.get_field);
    964     if isfield(get_field_GUI,'PanelVectors')
    965         set(hh.Coord_x,'value',1)
    966         set(hh.Coord_y,'value',1)
    967         set(hh.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors})
    968         set(hh.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors})
    969         UName=get_field_GUI.PanelVectors.vector_x;
    970         VName=get_field_GUI.PanelVectors.vector_y;
    971         menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}];
    972         menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}];
    973         set(hfield,'Value',1)
    974         set(hfield,'String',menu_str)
    975         if ~check_series
    976             ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color));
    977             if ~isempty(ind_menu)
    978                 set(hh.ColorScalar,'Value',ind_menu)
    979             else
    980                 set(hh.ColorScalar,'Value',1)
    981             end
    982             set(hh.ColorScalar,'String',menu_color)
    983         end
    984     elseif isfield(get_field_GUI,'PanelScalar')
    985         set(hh.Coord_x,'value',1)
    986         set(hh.Coord_y,'value',1)
    987         set(hh.Coord_x,'String',{get_field_GUI.PanelScalar.coord_x_scalar})
    988         set(hh.Coord_y,'String',{get_field_GUI.PanelScalar.coord_y_scalar})
    989         AName=get_field_GUI.PanelScalar.scalar;
    990         menu=get(hfield,'String');
    991         ind_select=find(strcmp(AName,menu));
    992         if isempty(ind_select)
    993             menu=[menu(1:end-1);{AName};{'get_field...'}];
    994             ind_select=numel(menu)-1;
    995         end
    996         set(hfield,'Value',ind_select);
    997         set(hfield,'String',menu);
    998     elseif isfield(get_field_GUI,'Panel1Dplot')
    999         set(hh.Coord_x,'Value',1)
    1000         set(hh.Coord_x,'String',{get_field_GUI.Panel1Dplot.abscissa})
    1001         set(hh.Coord_y,'String',get_field_GUI.Panel1Dplot.ordinate)
    1002         set(hh.Coord_y,'Max', numel(get_field_GUI.Panel1Dplot.ordinate))
    1003         set(hh.Coord_y,'Value',1:numel(get_field_GUI.Panel1Dplot.ordinate))
    1004         set(hfield,'Value',1)
    1005         set(hfield,'String',[{''};{'get_field...'}])
    1006     end
    1007     if  ~check_series && strcmp(get(gcbf,'tag'),'get_field')%get_field is not called by another GUI (uvmat)
    1008         uvmat('run0_Callback',hObject,eventdata,hh); %refresh uvmat
    1009     end
    1010 end
    1011 delete(handles.get_field)
    1012 
    1013 
     763    variables_Callback(handles.variables, [], handles)
     764end
    1014765
    1015766%-------------------------------------------------
     
    1036787    end
    1037788end
    1038 
    1039 
    1040 % -----------------------------------------------------------------------
    1041 function TimeName_Callback(hObject, eventdata, handles)
    1042 
    1043 scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
    1044 vector_x_Callback(hObject, eventdata, handles)
    1045 
    1046 %------------------------------------------------------------------------
    1047 % --- Executes on button press in TimeAttribute.
    1048 function TimeAttribute_Callback(hObject, eventdata, handles)
    1049 %------------------------------------------------------------------------
    1050 val=get(handles.TimeAttribute,'Value');
    1051 if val
    1052     set(handles.TimeAttributeMenu,'Visible','on')
    1053     Field=get(handles.get_field,'UserData');
    1054     time_value=zeros(size(Field.ListGlobalAttribute));
    1055     test_time=zeros(size(Field.ListGlobalAttribute));
    1056     for ilist=1:numel(Field.ListGlobalAttribute)
    1057         if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
    1058             eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
    1059             if ~isempty(time_val)
    1060                 time_value(ilist)=time_val;
    1061                 test_time(ilist)=1;
    1062             end
    1063         end
    1064     end
    1065     ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
    1066     attr_index=get(handles.TimeAttributeMenu,'Value');
    1067     if attr_index>numel(ListTimeAttribute)
    1068         attr_index=1;
    1069         set(handles.TimeAttributeMenu,'Value',1);
    1070     end
    1071     if isempty(ListTimeAttribute)
    1072         set(handles.TimeAttributeMenu,'String',{''})
    1073         set(handles.TimeValue,'Visible','off')
    1074     else
    1075         set(handles.TimeValue,'Visible','on')
    1076         set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
    1077         set(handles.TimeValue,'String',num2str(time_value(attr_index)))
    1078     end
    1079     set(handles.TimeDimension,'Value',0)
    1080     TimeDimension_Callback(hObject, eventdata, handles)
    1081     set(handles.TimeVariable,'Value',0)
    1082     TimeVariable_Callback(hObject, eventdata, handles)
    1083 else
    1084     set(handles.TimeAttributeMenu,'Visible','off')
    1085     set(handles.TimeValue,'Visible','off')
    1086 end
    1087 
    1088 %------------------------------------------------------------------------
    1089 % --- Executes on selection change in TimeAttributeMenu.
    1090 function TimeAttributeMenu_Callback(hObject, eventdata, handles)
    1091  ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
    1092  index=get(handles.TimeAttributeMenu,'Value');
    1093  AttrName=ListTimeAttribute{index};
    1094  Field=get(handles.get_field,'UserData');
    1095  eval(['time_val=Field.' AttrName ';'])
    1096  set(handles.TimeValue,'String',num2str(time_val))
    1097 %------------------------------------------------------------------------
    1098 
    1099 %------------------------------------------------------------------------
    1100 % --- Executes on button press in TimeVariable.
    1101 function TimeDimension_Callback(hObject, eventdata, handles)
    1102 %------------------------------------------------------------------------
    1103 val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
    1104 if val  %if check box TimeDimension is selected
    1105     Field=get(handles.get_field,'UserData');% structure describing the currently opened field
    1106     previous_menu=get(handles.TimeDimensionMenu,'String');
    1107     if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
    1108         ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
    1109         if isempty(ind_select)
    1110             ind_select=1;% select the first item in the list if 'time' is not found
    1111         end
    1112         set(handles.TimeDimensionMenu,'Value',ind_select);
    1113         set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
    1114     end   
    1115     set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
    1116     set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
    1117     TimeDimensionMenu_Callback(hObject, eventdata, handles) 
    1118     set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
    1119     set(handles.TimeVariable,'Value',0)
    1120     TimeAttribute_Callback(hObject, eventdata, handles)
    1121 else
    1122     set(handles.TimeDimensionMenu,'Visible','off')
    1123     set(handles.TimeIndexValue,'Visible','off')
    1124 end
    1125 %
    1126 % %------------------------------------------------------------------------
    1127 % % --- Executes on selection change in TimeDimensionMenu.
    1128 % function TimeDimensionMenu_Callback(hObject, eventdata, handles)
    1129 % %------------------------------------------------------------------------
    1130 % index=get(handles.TimeDimensionMenu,'Value');
    1131 % DimList=get(handles.TimeDimensionMenu,'String');
    1132 % DimName=DimList{index};
    1133 % Field=get(handles.get_field,'UserData');
    1134 % DimIndex=find(strcmp(DimName,Field.ListDimName),1);
    1135 % ref_index=round(Field.DimValue(DimIndex)/2);   
    1136 % set(handles.TimeIndexValue,'String',num2str(ref_index))
    1137 % scalar_Callback(hObject, eventdata, handles)
    1138 % vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
    1139 %  % look for a corresponding time variable and value
    1140 %  time_test=zeros(size(Field.VarDimName));
    1141 %  for ilist=1:numel(Field.VarDimName)
    1142 %      if isequal(Field.VarDimName{ilist},{DimName})
    1143 %          time_test(ilist)=1;
    1144 %      end
    1145 %  end
    1146 %  ListVariable=Field.ListVarName(time_test==1);
    1147 %  set(handles.TimeVariableMenu,'Value',1)
    1148 %  if isempty(ListVariable)     
    1149 %      set(handles.TimeVariableMenu,'String',{''})
    1150 %      set(handles.TimeVarValue,'String','')
    1151 %  else
    1152 %     set(handles.TimeVariableMenu,'String',ListVariable)
    1153 %     TimeVarName=ListVariable{1};
    1154 %     VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
    1155 %     inputfile=get(handles.inputfile,'String');% read the input file
    1156 %     SubField=nc2struct(inputfile,{TimeVarName});
    1157 %     eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
    1158 %     set(handles.TimeVarValue,'Visible','on')
    1159 %     set(handles.TimeVariableMenu,'Visible','on')
    1160 %     set(handles.TimeVarValue,'String',num2str(TimeValue))
    1161 %  end
    1162 %
    1163 %
    1164 % % % -----------------------------------------------------------------------
    1165 % % % --- Executes on button press in TimeVariable.
    1166 % % function TimeVariable_Callback(hObject, eventdata, handles)
    1167 % % % -----------------------------------------------------------------------
    1168 % % val=get(handles.TimeVariable,'Value');
    1169 % % if val
    1170 % %     Field=get(handles.get_field,'UserData');
    1171 % %     time_test=zeros(size(Field.VarDimName));
    1172 % %     for ilist=1:numel(Field.VarDimName)
    1173 % %         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
    1174 % %             time_test(ilist)=1;
    1175 % %         end
    1176 % %     end
    1177 % %     ind_test=find(time_test);
    1178 % %     if isempty(time_test)
    1179 % %         set(handles.TimeVariable,'Value',0)
    1180 % %         set(handles.TimeVariableMenu,'Visible','off')
    1181 % %         set(handles.TimeVarValue,'Visible','off')
    1182 % %     else
    1183 % %         set(handles.TimeVariableMenu,'Visible','on')
    1184 % %         set(handles.TimeVarValue,'Visible','on')
    1185 % %         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
    1186 % %             set(handles.TimeVariableMenu,'Value',1)
    1187 % %         end
    1188 % %         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
    1189 % %         TimeVariableMenu_Callback(hObject, eventdata, handles)
    1190 % %         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
    1191 % %         set(handles.TimeAttribute,'Value',0)
    1192 % %         TimeAttribute_Callback(hObject, eventdata, handles)
    1193 % %     end
    1194 % % else
    1195 % %     set(handles.TimeVariableMenu,'Visible','off')
    1196 % %     set(handles.TimeVarValue,'Visible','off')
    1197 % % end
    1198 %
    1199 % % -----------------------------------------------------------------------
    1200 % % --- Executes on selection change in TimeVariableMenu.
    1201 % function TimeVariableMenu_Callback(hObject, eventdata, handles)
    1202 % % -----------------------------------------------------------------------
    1203 % ListVar=get(handles.TimeVariableMenu,'String');
    1204 % index=get(handles.TimeVariableMenu,'Value');
    1205 % TimeVariable=ListVar{index};% name of the selected variable
    1206 % if isempty(TimeVariable)% case of blank selection
    1207 %     return
    1208 % end
    1209 % Field=get(handles.get_field,'UserData'); %index of
    1210 % VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
    1211 % DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
    1212 % set(handles.TimeDimensionMenu,'Value',1)
    1213 % set(handles.TimeDimensionMenu,'String',DimName)
    1214 % inputfile=get(handles.inputfile,'String');% read the input file
    1215 % SubField=nc2struct(inputfile,{TimeVariable});
    1216 % eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
    1217 % ref_index=round(TimeDimension/2);
    1218 % eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
    1219 % set(handles.TimeIndexValue,'String',num2str(ref_index))
    1220 % set(handles.TimeVarValue,'String',num2str(TimeValue))
    1221 
    1222 
    1223 % --- Executes on button press in check_rgb.
    1224 function check_rgb_Callback(hObject, eventdata, handles)
    1225 
    1226 
    1227 % --- Executes when user attempts to close get_field.
    1228 function get_field_CloseRequestFcn(hObject, eventdata, handles)
    1229 if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
    1230     % The GUI is still in UIWAIT, us UIRESUME
    1231     uiresume(handles.get_field);
    1232 else
    1233     % The GUI is no longer waiting, just close it
    1234     delete(handles.get_field);
    1235 end
    1236 
    1237 
    1238 
    1239 %------------------------------------------------------------------------
    1240 % --- Executes on selection change in SwitchVarIndexX.
    1241 %------------------------------------------------------------------------
    1242 function SwitchVarIndexX_Callback(hObject, eventdata, handles)
    1243 
    1244 %------------------------------------------------------------------------
    1245 % --- Executes on selection change in SwitchVarIndexTime.
    1246 %------------------------------------------------------------------------
    1247 function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
    1248 
    1249 menu=get(handles.SwitchVarIndexTime,'String');
    1250 option=menu{get(handles.SwitchVarIndexTime,'Value')};
    1251 Field=get(handles.get_field,'UserData');
    1252 switch option
    1253     case 'file index'
    1254         set(handles.TimeVarName, 'Visible','off')
    1255     case 'attribute'
    1256         set(handles.TimeVarName, 'Visible','on')
    1257         time_index=[];
    1258         PreviousList=get(handles.TimeVarName, 'String');
    1259          index=[];
    1260         if ~isempty(PreviousList)
    1261         PreviousAttr=PreviousList{get(handles.TimeVarName, 'Value')};
    1262         index=find(strcmp(PreviousAttr,Field.ListNumAttributes));
    1263         end
    1264         if isempty(index)
    1265             time_index=find(~cellfun('isempty',regexp(Field.ListNumAttributes,'Time')));% index of the attributes containing the string 'Time'
    1266         end
    1267         if ~isempty(time_index)
    1268             set(handles.TimeVarName,'Value',time_index(1))
    1269         else
    1270             set(handles.TimeVarName,'Value',1)
    1271         end
    1272         set(handles.TimeVarName, 'String',Field.ListNumAttributes)
    1273     case 'variable'
    1274         set(handles.TimeVarName, 'Visible','on')
    1275         TimeVarName=Field.SingleVarName;
    1276         List=get(handles.TimeVarName,'String');
    1277         option=List{get(handles.TimeVarName,'Value')};
    1278         ind=find(strcmp(option,TimeVarName));
    1279         if isempty(ind)
    1280             set(handles.TimeVarName, 'Value',1);
    1281         else
    1282             set(handles.TimeVarName, 'Value',ind);
    1283         end
    1284         set(handles.TimeVarName, 'String',TimeVarName)
    1285     case 'dim index'
    1286         set(handles.TimeVarName, 'Visible','on')
    1287         TimeVarName=Field.SingleDimName;
    1288         List=get(handles.TimeVarName,'String');
    1289         option=List{get(handles.TimeVarName,'Value')};
    1290         ind=find(strcmp(option,TimeVarName));
    1291         if isempty(ind)
    1292             set(handles.TimeVarName, 'Value',1);
    1293         else
    1294             set(handles.TimeVarName, 'Value',ind);
    1295         end
    1296         set(handles.TimeVarName, 'String',TimeVarName)
    1297 end
    1298 
    1299 % --- Executes on selection change in FieldOption.
    1300 function FieldOption_Callback(hObject, eventdata, handles)
    1301 FieldList=get(handles.FieldOption,'String');
    1302 FieldOption=FieldList{get(handles.FieldOption,'Value')};
    1303 switch FieldOption
    1304     case '1D plot'
    1305         set(handles.Panel1Dplot,'Visible','on')
    1306         pos=get(handles.Panel1Dplot,'Position');
    1307         pos(1)=2;
    1308         pos_coord=get(handles.Coordinates,'Position');
    1309         pos(2)=pos_coord(2)-pos(4)-2;
    1310         set(handles.Panel1Dplot,'Position',pos)
    1311         set(handles.PanelScalar,'Visible','off')
    1312         set(handles.PanelVectors,'Visible','off')
    1313         set(handles.YVarName,'Visible','off')
    1314         %    set(handles.SwitchVarIndexY,'Visible','off')
    1315         set(handles.Y_title,'Visible','off')
    1316         set(handles.ZVarName,'Visible','off')
    1317         %   set(handles.SwitchVarIndexZ,'Visible','off')
    1318         set(handles.Z_title,'Visible','off')
    1319     case 'scalar'
    1320         set(handles.Panel1Dplot,'Visible','off')
    1321         set(handles.PanelScalar,'Visible','on')
    1322         set(handles.PanelVectors,'Visible','off')
    1323         pos=get(handles.PanelScalar,'Position');
    1324         pos(1)=2;
    1325         pos_coord=get(handles.Coordinates,'Position');
    1326         pos(2)=pos_coord(2)-pos(4)-2;
    1327         set(handles.PanelScalar,'Position',pos)
    1328         set(handles.YVarName,'Visible','on')
    1329         set(handles.Y_title,'Visible','on')
    1330     case 'vectors'
    1331         set(handles.Panel1Dplot,'Visible','off')
    1332         set(handles.PanelScalar,'Visible','off')
    1333         set(handles.PanelVectors,'Visible','on')
    1334         pos=get(handles.PanelVectors,'Position');
    1335         pos(1)=2;
    1336         pos_coord=get(handles.Coordinates,'Position');
    1337         pos(2)=pos_coord(2)-pos(4)-2;
    1338         set(handles.PanelVectors,'Position',pos)
    1339         set(handles.YVarName,'Visible','on')
    1340         set(handles.Y_title,'Visible','on')
    1341 end
Note: See TracChangeset for help on using the changeset viewer.