source: trunk/src/get_field.m @ 1098

Last change on this file since 1098 was 1098, checked in by sommeria, 4 years ago

various bugs repaired

File size: 47.1 KB
Line 
1%'get_field': display variables and attributes from a Netcdf file, and OK selected fields
2%------------------------------------------------------------------------
3% GetFieldData=get_field(FileName,ParamIn)
4% associated with the GUI get_field.fig
5%
6% OUTPUT:
7% GetFieldData: structure containing the information on the selected
8%      fields, obtained by applying the fct red_GUI to the GUI get_field
9%   .FieldOption='vectors': variables are used for vector plot
10%                  'scalar': variables are used for scalar plot,
11%                  '1Dplot': variables are used for usual x-y plot,
12%                  'civdata...': go back to automatic reading of civ data
13%   .PanelVectors: sub-structure variables used as vector components
14%   .PanelScalar:
15% INPUT:
16% FileName: name (including path) of the netcdf file to open
17% ParmIn: structure containing parameters for preselecting menus:
18%   .Title: set the title of the GUI get_field
19%   .SwitchVarIndexTime='file index','variable' or 'matrix index': select the default option for 'time'
20%   .TimeAttrName: preselect the name of a global attribute for time
21%   .SeriesInput=1 if get_field is called by the GUI series,=0 otherwise (plot options provided in the latter case)
22%   .Coord_x,.Coord_y,.Coord_z, names of the variables used as the three coordinates
23%   .scalar : set the default choise of the scale variable
24%   .vector_x, .vector_y : set the default choise for the variables used for the x and y vector components
25
26%=======================================================================
27% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
28%   http://www.legi.grenoble-inp.fr
29%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
30%
31%     This file is part of the toolbox UVMAT.
32%
33%     UVMAT is free software; you can redistribute it and/or modify
34%     it under the terms of the GNU General Public License as published
35%     by the Free Software Foundation; either version 2 of the license,
36%     or (at your option) any later version.
37%
38%     UVMAT is distributed in the hope that it will be useful,
39%     but WITHOUT ANY WARRANTY; without even the implied warranty of
40%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41%     GNU General Public License (see LICENSE.txt) for more details.
42%=======================================================================
43
44function varargout = get_field(varargin)
45
46% Last Modified by GUIDE v2.5 18-Feb-2015 23:42:12
47
48% Begin initialization code - DO NOT EDIT
49gui_Singleton = 1;
50gui_State = struct('gui_Name',       mfilename, ...
51                   'gui_Singleton',  gui_Singleton, ...
52                   'gui_OpeningFcn', @get_field_OpeningFcn, ...
53                   'gui_OutputFcn',  @get_field_OutputFcn, ...
54                   'gui_LayoutFcn',  [] , ...
55                   'gui_Callback',   []);
56if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
57    gui_State.gui_Callback = str2func(varargin{1});
58end
59
60if nargout
61    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
62else
63    gui_mainfcn(gui_State, varargin{:});
64end
65% End initialization code - DO NOT EDIT
66     
67%------------------------------------------------------------------------
68% --- Executes just before get_field is made visible.
69%------------------------------------------------------------------------
70function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
71
72%% GUI settings
73handles.output = 'Cancel';
74guidata(hObject, handles);
75set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
76set(hObject,'CloseRequestFcn',{@closefcn,handles})
77
78%% enter input data
79if ischar(filename) % input file name
80    set(handles.inputfile,'String',filename)% fill the input file name
81    if ~isempty(regexp(filename,'.mat$'))%case of .mat file
82        Field=mat2struct(filename);
83        errormsg='';
84    else
85    [Field,tild,tild,errormsg]=nc2struct(filename,[]);% reads the  field structure, without the variables
86    end
87else
88    msgbox_uvmat('ERROR','get_field requires a file name as input')% display error message for input file reading
89    return
90end
91if ~isempty(errormsg)
92    msgbox_uvmat('ERROR',['get_field/nc2struct/' errormsg])% display error message for input file reading
93    return
94end
95if ~isfield(Field,'ListVarName')
96    msgbox_uvmat('ERROR',['no variable found in ' filename])% display error message for input file reading
97    return
98end
99if ~exist('ParamIn','var')
100    ParamIn.Coord_z='';
101end
102
103%% look at singletons and variables with a single dimension
104Field.Display=Field;
105Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value
106NbVar=numel(Field.VarDimName);%nbre of variables in the input data
107for ilist=1:NbVar
108    if ischar(Field.VarDimName{ilist})
109        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
110    end
111    NbDim=numel(Field.VarDimName{ilist});
112    check_singleton=false(1,NbDim);%  check singleton, false by default
113    for idim=1:NbDim
114        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions
115        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton
116    end
117    Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)))||(~isequal(Field.VarType(ilist),4)&&~isequal(Field.VarType(ilist),5)&&~isequal(Field.VarType(ilist),6));% =1 if the variable reduces to a single value
118    if ~Field.Check0D(ilist)
119    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
120    end
121end
122if ~isfield(Field,'VarAttribute')
123    Field.VarAttribute={};
124end
125if numel(Field.VarAttribute)<NbVar% complement VarAttribute by blanjs if neded
126    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
127end
128% Field.Display = list of variables and corresponding properties obtained after removal of variables with a single value and singleton dimensions
129Field.Display.ListVarName=Field.ListVarName(~Field.Check0D); %list of variables available for plots, after eliminating variables with a single value
130Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
131Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D);
132Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);% list of non singleton dimension names
133Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);% corresponding list of non singleton dimension values
134
135
136%% analyse the input field cells
137[CellInfo,NbDim,errormsg]=find_field_cells(Field.Display);
138if ~isempty(errormsg)
139    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
140    return
141end
142if isempty(CellInfo)
143    [Field.MaxDim,imax]=max(cellfun(@numel,Field.Display.VarDimName));% maximum number of dimensions for the input fields
144    ListDim=Field.Display.VarDimName{imax};
145    check_cellinfo=false;
146else
147    [Field.MaxDim,imax]=max(NbDim);% maximum number of dimensions for the input fields identified by attributes
148    check_cellinfo=true;
149end
150
151%% set time mode
152ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index
153% look at global attributes with numerical values
154check_numvalue=false(1,numel(Field.ListGlobalAttribute));
155for ilist=1:numel(Field.ListGlobalAttribute)
156    Value=Field.(Field.ListGlobalAttribute{ilist});
157    check_numvalue(ilist)=isnumeric(Value);
158end
159Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
160if ~isempty(Field.Display.ListGlobalAttribute)
161    ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute
162end
163
164Check_index=0;
165if Field.MaxDim>=2
166    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'matrix index'}];% the time can be chosen as a dim index
167else
168    for ilist=1:numel(Field.Display.VarDimName)
169        NbComponent=numel(Field.Display.VarDimName{ilist});
170        if NbComponent>=2% multicomponent matrices without coordinate variables (thus not considered in the fct find_field_cell)
171            ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'matrix index'}];% the time can be chosen as a dim index
172            Check_index=1;
173            break
174        end
175    end
176end
177
178%% select the Time attribute from input
179if Field.MaxDim >2
180    variable_index=find(strcmp('variable',ListSwitchVarIndexTime),1);
181    set(handles.SwitchVarIndexTime,'Value',variable_index);
182else
183    if isfield(ParamIn,'TimeAttrName')&& ~isempty(ParamIn.TimeAttrName)
184        time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1);
185    else
186        time_index=find(strcmp('Time',Field.Display.ListGlobalAttribute));% look for global attribute containing name 'Time'
187    end
188    if isempty(time_index)
189        set(handles.SwitchVarIndexTime,'Value',1);
190    else
191        set(handles.SwitchVarIndexTime,'Value',2);
192        set(handles.TimeName,'UserData',time_index)
193    end
194end
195set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
196set(handles.SwitchVarIndexTime,'UserData',ListSwitchVarIndexTime); % keep string in memory for check3D
197set(handles.get_field,'UserData',Field);% record the finput field structure
198SwitchVarIndexTime_Callback([], [], handles)
199
200%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
201set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
202set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
203set(handles.vector_z,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
204set(handles.vec_color,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
205set(handles.scalar,'Value',1)% fill the menu of y vector components
206set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu for scalar
207%set(handles.ordinate,'Value',1)% fill the menu of y vector components
208%set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y coordinate for 1D plots
209checkseries=0;
210if isfield(ParamIn,'SeriesInput') && ParamIn.SeriesInput% case of call by series
211    set(handles.FieldOption,'value',1)
212    if isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
213    set(handles.FieldOption,'String',{'scalar';'vectors';'civdata...'})
214    else
215       set(handles.FieldOption,'String',{'scalar';'vectors'})
216    end
217    checkseries=1;
218    set(handles.scalar,'Max',2)
219elseif isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
220    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})% provides the possibility to come back to civdata
221    set(handles.scalar,'Max',1)
222else
223    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'})
224    set(handles.scalar,'Max',1)
225end
226
227%% set default field options
228checknbdim=cellfun('size',Field.Display.VarDimName,2);
229% if max(checknbdim)<=1
230%     Field.MaxDim=1;% only 1D fields, considered as a time series by default
231% end
232if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields
233    check_vec_input=0;
234    % case of vector initially selected from uvmat input
235    if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y')
236        ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1);
237        ichoice_y=find(strcmp(ParamIn.vector_y,Field.Display.ListVarName),1);
238        if ~isempty(ichoice_x)&&~isempty(ichoice_y)
239            set(handles.vector_x,'UserData',ichoice_x)
240            set(handles.vector_y,'UserData',ichoice_y)
241            check_vec_input=1;
242        end
243    end
244    % otherwise select vectors marked as attributes in the input field
245    if check_cellinfo && ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
246        set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1))
247        set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1))
248        check_vec_input=1;
249    end
250    if check_vec_input
251        set(handles.FieldOption,'Value',3)% set vector selection option
252    else     
253        set(handles.FieldOption,'Value',2)% set scalar selection option
254    end
255else % case of 1D fields
256    set(handles.FieldOption,'Value',1)
257end
258
259%% fill the general list of dimensions, variables, attributes
260if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
261    Tabcell(:,1)=Field.ListDimName;
262    for iline=1:length(Field.ListDimName)
263        Tabcell{iline,2}=num2str(Field.DimValue(iline));
264    end
265    Tabchar=cell2tab(Tabcell,' = ');
266    set(handles.dimensions,'String',Tabchar)
267end
268
269%% fill menus for coordinates and time
270FieldOption_Callback(handles.variables,[], handles)% list the global attributes
271
272%% put the GUI on the lower right of the sceen
273set(hObject,'Unit','pixels')
274%pos_view_field=get(hObject,'Position');
275set(0,'Unit','pixels')
276ScreenSize=get(0,'ScreenSize');
277pos_view_field(3:4)=[955 648];
278pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
279pos_view_field(2)=ScreenSize(2);
280set(hObject,'Position',pos_view_field)
281set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
282if isfield(ParamIn,'Title')
283    set(hObject,'Name',ParamIn.Title)
284end
285
286%% set z coordinate menu if relevant
287if Field.MaxDim>=3 && prod(Field.DimValue)<10^8 && ~(isfield(ParamIn,'Coord_z') && isempty(ParamIn.Coord_z)) % 3D field (with memory content smaller than 400 Mo)
288    set(handles.Check3D,'Value',1)
289else
290    set(handles.Check3D,'Value',0)
291end
292Check3D_Callback(hObject, eventdata, handles)
293set(handles.variables,'Value',1)
294set(handles.variables,'String',[{'*'} Field.ListVarName])
295variables_Callback(handles.variables,[], handles)% list the global attributes
296drawnow
297uiwait(handles.get_field);
298
299% -----------------------------------------------------------------------
300% --- Activated by selection in the list of variables
301% ----------------------------------------------------------------------
302function variables_Callback(hObject, VarName, handles)
303
304Tabchar={''};%default
305Tabcell=[];
306hselect_field=get(handles.variables,'parent');
307Field=get(handles.get_field,'UserData');
308index=get(handles.variables,'Value');%index in the list 'variables'
309
310%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
311if isequal(index,1)
312    set(handles.attributes_txt,'String','global attributes')
313    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
314        for iline=1:length(Field.ListGlobalAttribute)
315            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
316            if isfield(Field, Field.ListGlobalAttribute{iline})
317                val=Field.(Field.ListGlobalAttribute{iline});
318                if ischar(val);% attribute value is char string
319                    Tabcell{iline,2}=val;
320                elseif size(val,1)==1 %attribute value is a number or matlab vector
321                    Tabcell{iline,2}=num2str(val);
322                end
323            end
324        end
325        Tabchar=cell2tab(Tabcell,'=');
326    end
327    %% list Attribute names and values associated to the Variable # index-1
328else
329    list_var=get(handles.variables,'String');
330    if index>numel(list_var)
331        return
332    end
333    VarName=list_var{index};
334    set(handles.attributes_txt,'String', ['attributes of ' VarName])
335    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
336        VarAttr=Field.VarAttribute{index-1};
337        if isstruct(VarAttr)
338            attr_list=fieldnames(VarAttr);
339            for iline=1:length(attr_list)
340                Tabcell{iline,1}=attr_list{iline};
341                val=VarAttr.(attr_list{iline}) ;
342                if ischar(val);
343                    Tabcell{iline,2}=val;
344                else
345                    Tabcell{iline,2}=num2str(val);
346                end
347            end
348        end
349    end
350end
351if ~isempty(Tabcell)
352    Tabchar=cell2tab(Tabcell,'=');
353end
354set(handles.attributes,'Value',1);% select the first item
355set(handles.attributes,'String',Tabchar);
356
357%% update dimensions;
358if isfield(Field,'ListDimName')
359    Tabdim={};%default
360    if isequal(index,1)%list all dimensions if '*' is selected as the variable
361        dim_indices=1:length(Field.ListDimName);
362        set(handles.dimensions_txt,'String', 'dimensions')
363    else   % a specific variable has been selected
364        DimCell=Field.VarDimName{index-1};
365        if ischar(DimCell)
366            DimCell={DimCell};% transform into a cell for a single dimension defined by a char string
367        end
368        dim_indices=[];
369        for idim=1:length(DimCell)
370            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
371            dim_index=find(dim_index,1);
372            dim_indices=[dim_indices dim_index];
373        end
374        set(handles.dimensions_txt,'String', ['dimensions of ' VarName])
375    end
376    for iline=1:length(dim_indices)
377        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
378        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
379    end
380    Tabchar=cell2tab(Tabdim,' = ');
381    Tabchar=[{''} ;Tabchar];
382    set(handles.dimensions,'Value',1)
383    set(handles.dimensions,'String',Tabchar)
384end
385
386%% propose a plot by default if variables_Callback has not been already called by FieldOption_Callback (VarName is not a char string)
387if ~ischar(VarName) && ~isequal(index,1)
388    if numel(DimCell)==1
389        set(handles.FieldOption,'Value',1)%propose 1D plot
390    else
391        set(handles.FieldOption,'Value',2)%propose scalar plot
392    end
393    if numel(DimCell)<=2
394        set(handles.Check3D,'Value',0)
395    else
396        set(handles.Check3D,'Value',1)
397    end
398    FieldOption_Callback(hObject, VarName, handles)
399end
400
401%------------------------------------------------------------------------
402% --- Executes on selection change in FieldOption.
403%------------------------------------------------------------------------
404function FieldOption_Callback(hObject, VarName, handles)
405
406Field=get(handles.get_field,'UserData');
407FieldList=get(handles.FieldOption,'String');
408FieldOption=FieldList{get(handles.FieldOption,'Value')};
409switch FieldOption
410    case '1D plot'
411        set(handles.Coordinates,'Visible','on')
412        set(handles.PanelScalar,'Visible','off')
413        set(handles.PanelVectors,'Visible','off')
414        set(handles.Coord_y,'Visible','on')
415        set(handles.Coord_y,'Max',2)%allow multiple selection
416        set(handles.Y_title,'Visible','on')
417        set(handles.Coord_z,'Visible','off')
418        set(handles.Z_title,'Visible','off')
419        set(handles.Coord_x,'String',Field.Display.ListVarName')
420        Coord_x_Callback(hObject, VarName, handles)     
421    case {'scalar'}
422        set(handles.Coordinates,'Visible','on')
423        set(handles.PanelScalar,'Visible','on')
424        set(handles.PanelVectors,'Visible','off')
425        pos=get(handles.PanelScalar,'Position');
426        pos(1)=2;
427        pos_coord=get(handles.Coordinates,'Position');
428        pos(2)=pos_coord(2)-pos(4)-2;
429        set(handles.PanelScalar,'Position',pos)
430        set(handles.Coord_y,'Visible','on')
431        set(handles.Y_title,'Visible','on')     
432        if ~ischar(VarName)     
433            %default scalar selection
434            test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
435            for ilist=1:numel(Field.Display.VarDimName)
436                if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
437                    Role=Field.Display.VarAttribute{ilist}.Role;
438                    if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
439                        test_coord(ilist)=1;
440                    end
441                end
442                dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
443                if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
444                    test_coord(ilist)=1;
445                end
446            end
447            scalar_index=find(~test_coord,1);%get the first variable not a coordinate
448            if isempty(scalar_index)
449                set(handles.scalar,'Value',1)
450            else
451                set(handles.scalar,'Value',scalar_index)
452            end
453        end
454        scalar_Callback(hObject,VarName, handles)       
455    case 'vectors'
456        set(handles.PanelVectors,'Visible','on')
457        set(handles.Coordinates,'Visible','on')
458        %set(handles.PanelOrdinate,'Visible','off')
459        set(handles.PanelScalar,'Visible','off')
460        pos=get(handles.PanelVectors,'Position');
461        pos(1)=2;
462        pos_coord=get(handles.Coordinates,'Position');
463        pos(2)=pos_coord(2)-pos(4)-2;
464        set(handles.PanelVectors,'Position',pos)
465        set(handles.Coord_y,'Visible','on')
466        set(handles.Y_title,'Visible','on')
467        set(handles.Coord_x,'Visible','on')
468        %default vector selection
469        vector_x_value=get(handles.vector_x,'UserData');
470        vector_y_value=get(handles.vector_y,'UserData');
471        if ~isempty(vector_x_value)&&~isempty(vector_y_value)
472            set(handles.vector_x,'Value',vector_x_value)
473            set(handles.vector_y,'Value',vector_y_value)
474        else
475            test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate
476            for ilist=1:numel(Field.Display.VarDimName)
477                if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
478                    Role=Field.Display.VarAttribute{ilist}.Role;
479                    if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
480                        test_coord(ilist)=1;
481                    end
482                end
483                dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
484                if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
485                    test_coord(ilist)=1;
486                end
487            end
488            vector_index=find(~test_coord,2);%get the two first variables not a coordinate
489            if isempty(vector_index)
490                set(handles.vector_x,'Value',1)
491                set(handles.vector_y,'Value',2)
492            else
493                set(handles.vector_x,'Value',vector_index(1))
494                set(handles.vector_y,'Value',vector_index(2))
495            end
496        end
497        vector_Callback(handles)     
498    case 'civdata...'
499        %set(handles.PanelOrdinate,'Visible','off')
500        set(handles.PanelScalar,'Visible','off')
501        set(handles.PanelVectors,'Visible','off')
502        set(handles.Coordinates,'Visible','off')
503end
504
505
506function set_coord_y_options(handles,VarName)
507%------------------------------------------------------------------------
508Field=get(handles.get_field,'UserData');
509VarIndex=find(strcmp(VarName,Field.Display.ListVarName),1);
510DimCell=Field.Display.VarDimName{VarIndex};
511% y_index=get(handles.Coord_y,'Value');
512% y_menu=get(handles.Coord_y,'String');
513% if isempty(y_menu)
514%     return
515% else
516% YName=y_menu{y_index};
517% end
518
519%% set list of possible coordinates
520% test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
521test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
522% ListCoord={''};
523% dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable
524
525for ilist=1:numel(Field.Display.VarDimName)
526    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
527    if isequal(dimnames,DimCell)||isequal(dimnames(1:end-1),DimCell)||isequal(dimnames(2:end),DimCell)
528        test_coord(ilist)=1;
529    end
530end
531ListCoord=Field.Display.ListVarName(find(test_coord));
532set(handles.Coord_y,'String',ListCoord)
533val_y=1;
534if strcmp(VarName,ListCoord{1})&& numel(ListCoord)>=2
535    val_y=2;
536end
537set(handles.Coord_y,'Value',val_y)
538
539%% set default coord selection
540% if numel(find(test_coord))>3
541%      SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
542%     if numel(SwitchVarIndexTime)<3
543%         SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
544%         set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
545%     end
546%     set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
547%     SwitchVarIndexTime_Callback([], [], handles)
548% end
549% if numel(var_component)<2
550%     if numel(test_coord)<2
551%         ListCoord={''};
552%     else
553%         set(handles.Coord_x,'Value',2)
554%         set(handles.Coord_y,'Value',1)
555%     end
556% else
557%     coord_val=1;
558%     for ilist=1:numel(var_component)
559%         ivar=var_component(ilist);
560%         if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
561%             Role=Field.Display.VarAttribute{ivar}.Role;
562%             if strcmp(Role,'coord_x')
563%                 coord_val=ilist;
564%             end
565%         end
566%     end
567%     set(handles.Coord_x,'Value',coord_val+1)
568% end
569% set(handles.Coord_x,'String',[{''}; ListCoord])
570
571
572% %% set list of time coordinates
573% menu=get(handles.SwitchVarIndexTime,'String');
574% TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
575% switch TimeOption
576%     case 'variable'
577%         if numel(find(test_coord))<3
578%             ListTime={''};
579%         else
580%             ListTime=Field.Display.ListVarName(find(test_coord,end));
581%         end
582%         set(handles.TimeName,'Value',1)
583%         set(handles.TimeName,'String',ListTime)
584%     case 'matrix index'
585%         if numel(find(test_coord))<3
586%             ListTime={''};
587%         else
588%             ListTime=Field.Display.VarDimName{find(test_coord,end)};
589%         end
590%         set(handles.TimeName,'Value',1)
591%         set(handles.TimeName,'String',ListTime)
592% end 
593% if ~ischar(DimCell)
594% update_field(handles,YName)
595% end
596         
597%------------------------------------------------------------------------
598% --- Executes on selection change in scalar menu.
599%------------------------------------------------------------------------
600function scalar_Callback(hObject, VarName, handles)
601
602Field=get(handles.get_field,'UserData');% get the input field info stored in UserData of the GUI
603scalar_menu=get(handles.scalar,'String');% read the menu for scalar selection
604if ischar(VarName)% case of a call with input variable
605    ScalarName=VarName;
606    scalar_index=find(strcmp(VarName,scalar_menu));
607    set(handles.scalar,'Value',scalar_index)% select the input variable field in the menu
608else % no input variable, the variable ScalarName is selected from the menu
609    scalar_index=get(handles.scalar,'Value');
610    ScalarName=scalar_menu{scalar_index};
611end
612
613%% set list of possible coordinates
614test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
615test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
616dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
617%if ~get(handles.CheckDimensionX,'Value')
618%look for coordinate variables among the other variables
619for ilist=1:numel(Field.Display.VarDimName)
620    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
621    if isequal(dimnames,dim_var)
622        test_component(ilist)=1;% the listed variable has the same dimension as the selected scalar-> possibly chosen as unstructured coordinate
623    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var), 1))%variable ilist is a 1D array which can be coordinate variable
624        test_coord(ilist)=1;
625    end
626end
627%end
628var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
629var_coord=find(test_coord);% % list of variable indices elligible as gridded coordinates
630index_coord=[];
631index_component=[];
632for iscalar=1:numel(scalar_index)
633    index_component=[index_component find(var_component==scalar_index(iscalar),1)];
634    index_coord=[index_coord find(var_coord==scalar_index(iscalar),1)];
635end
636var_component(index_component)=[];
637var_coord(index_coord)=[];
638ListCoord=Field.Display.ListVarName([var_coord var_component]);
639coord_val=zeros(size(ListCoord));
640
641%% set default selection for grid coordinates
642if numel(var_coord)>=2
643    coord_val(1)=var_coord(end);
644    coord_val(2)=var_coord(end-1);
645    if numel(var_coord)>=3
646        coord_val(3)=var_coord(end-2);
647    end
648end
649% if numel(find(test_coord))>3
650%     SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
651%     if numel(SwitchVarIndexTime)<3
652%         SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
653%         set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
654%     end
655%     set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
656%     SwitchVarIndexTime_Callback([], [], handles)
657% end
658
659%% default selection for labelled unstructured coordinates
660for ilist=1:numel(var_component)
661    ivar=var_component(ilist);
662    if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
663        Role=Field.Display.VarAttribute{ivar}.Role;
664        if strcmp(Role,'coord_x')
665            coord_val(1)=ilist;
666        elseif strcmp(Role,'coord_y')
667            coord_val(2)=ilist;
668        elseif strcmp(Role,'coord_z')
669            coord_val(3)=ilist;
670        end
671    end
672end
673if numel(find(coord_val))<2 % no predefiend components
674    if numel(var_coord)>=3
675        coord_val(3)=3;
676    end
677    coord_val([1 2])=[1 2];
678end
679
680%% set menu and default selection for coordinates
681set(handles.Coord_x,'Value',coord_val(1))
682set(handles.Coord_x,'String',ListCoord)
683set(handles.Coord_y,'Value',coord_val(2))
684set(handles.Coord_y,'String',ListCoord)
685if numel(find(coord_val))>=3
686    set(handles.Coord_z,'Value',coord_val(3))
687    set(handles.Coord_z,'String',ListCoord)
688    set(handles.Coord_z,'Visible','on')
689    set(handles.Check3D,'Value', 1)
690end
691
692%% set list of time coordinates
693menu=get(handles.SwitchVarIndexTime,'String');
694TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
695switch TimeOption
696    case 'variable'
697        if numel(find(test_coord))<3
698            ListTime={''};
699        else
700            ListTime=Field.Display.ListVarName(find(test_coord,end));
701        end
702        set(handles.TimeName,'Value',1)
703        set(handles.TimeName,'String',ListTime)
704    case 'dim index'
705        if numel(find(test_coord))<3
706            ListTime={''};
707        else
708            ListTime=Field.Display.VarDimName{find(test_coord,end)};
709        end
710        set(handles.TimeName,'Value',1)
711        set(handles.TimeName,'String',ListTime)
712end
713if ~ischar(VarName)
714    update_field(handles,ScalarName)
715end
716
717% --- Executes on button press in check_rgb.
718function check_rgb_Callback(hObject, eventdata, handles)
719
720
721%------------------------------------------------------------------------
722% --- Executes on selection change in vector_x.
723%------------------------------------------------------------------------
724function vector_x_Callback(hObject, DimCell, handles)
725
726vector_x_menu=get(handles.vector_x,'String');
727vector_x_index=get(handles.vector_x,'Value');
728vector_x=vector_x_menu{vector_x_index};
729vector_Callback(handles)
730if ~ischar(DimCell)
731update_field(handles,vector_x)
732end
733
734%------------------------------------------------------------------------
735% --- Executes on selection change in vector_x.
736%------------------------------------------------------------------------
737function vector_y_Callback(hObject, DimCell, handles)
738
739vector_y_menu=get(handles.vector_x,'String');
740vector_y_index=get(handles.vector_x,'Value');
741vector_y=vector_y_menu{vector_y_index};
742vector_Callback(handles)
743if ~ischar(DimCell)
744update_field(handles,vector_y)
745end
746
747%------------------------------------------------------------------------
748% --- Executes on selection change in vector_z.
749function vector_z_Callback(hObject, DimCell, handles)
750%------------------------------------------------------------------------
751vector_z_menu=get(handles.vector_z,'String');
752vector_z_index=get(handles.vector_z,'Value');
753vector_z=vector_z_menu{vector_z_index};
754vector_Callback(handles)
755if ~ischar(DimCell)
756update_field(handles,vector_z)
757end
758%------------------------------------------------------------------------
759% --- Executes on selection change in vec_color.
760function vec_color_Callback(hObject, DimCell, handles)
761%------------------------------------------------------------------------
762index=get(handles.vec_color,'Value');
763string=get(handles.vec_color,'String');
764VarName=string{index};
765vector_Callback(handles)
766if ~ischar(DimCell)
767update_field(handles,VarName)
768end
769
770%------------------------------------------------------------------------
771% --- Executes on selection change in vector_x or vector_y
772function vector_Callback( handles)
773%------------------------------------------------------------------------
774Field=get(handles.get_field,'UserData');
775vector_x_index=get(handles.vector_x,'Value');
776vector_y_index=get(handles.vector_y,'Value');
777vec_color_index=get(handles.vec_color,'Value');
778
779%% set list of possible coordinates
780test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
781test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate
782check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn
783ListCoord={''};
784dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable
785if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index})
786    check_consistent=0;
787elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index})
788    check_consistent=0;
789end
790% the two vector components have consistent dimensions
791if check_consistent
792    for ilist=1:numel(Field.Display.VarDimName)
793        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
794        if isequal(dimnames,dim_var)
795            test_component(ilist)=1;
796        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
797            test_coord(ilist)=1;
798        end
799    end
800    var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
801    var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
802    var_component(var_component==vector_x_index|var_component==vector_y_index)=[];
803    var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components from the possible list of coordinates
804    ListCoord=Field.Display.ListVarName([var_coord var_component]);
805   
806    %% set default coord selection
807    if numel(find(test_coord))>3
808        set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
809    end
810    if numel(var_component)<2 %unstructured coordinates excluded
811        if numel(find(test_coord))<2
812            ListCoord={''};
813        else
814            if numel(find(test_coord))>=3
815                set(handles.Coord_x,'Value',3)
816                set(handles.Coord_y,'Value',2)
817                set(handles.Coord_z,'Value',1)
818            else
819                set(handles.Coord_x,'Value',2)
820                set(handles.Coord_y,'Value',1)
821            end
822        end
823    else
824        coord_val=[0 0];
825        for ilist=1:numel(var_component)
826            ivar=var_component(ilist);
827            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
828                Role=Field.Display.VarAttribute{ivar}.Role;
829                if strcmp(Role,'coord_x')
830                    coord_val(1)=ilist;
831                elseif strcmp(Role,'coord_y')
832                    coord_val(2)=ilist;
833                elseif strcmp(Role,'coord_z')
834                    coord_val(3)=ilist;
835                end
836            end
837        end
838        if isempty(find(coord_val))
839            coord_val=var_coord;% case of dimension coordinates
840        end
841        if numel(find(coord_val))<2
842            coord_val=[1 2 3];
843        end
844        set(handles.Coord_x,'Value',min(coord_val(end),numel(ListCoord)))
845        set(handles.Coord_y,'Value',min(coord_val(end-1),numel(ListCoord)))
846        if numel(coord_val)>=3
847            set(handles.Coord_z,'Value',coord_val(end-2))
848        end
849    end
850end
851set(handles.Coord_z,'String',ListCoord)
852set(handles.Coord_y,'String',ListCoord)
853set(handles.Coord_x,'String',ListCoord)
854
855
856%% set list of time coordinates
857menu=get(handles.SwitchVarIndexTime,'String');
858TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
859switch TimeOption
860    case 'variable'
861        if numel(find(test_coord))<3
862            ListTime={''};
863        else
864            ListTime=Field.Display.ListVarName(find(test_coord,end));
865        end
866        set(handles.TimeName,'Value',1)
867        set(handles.TimeName,'String',ListTime)
868    case 'dim index'
869        if numel(find(test_coord))<3
870            ListTime={''};
871        else
872            ListTime=Field.Display.VarDimName{find(test_coord,end)};
873        end
874        set(handles.TimeName,'Value',1)
875        set(handles.TimeName,'String',ListTime)
876end 
877
878%------------------------------------------------------------------------
879% --- Executes on selection change in SwitchVarIndexX.
880%------------------------------------------------------------------------
881function SwitchVarIndexX_Callback(hObject, eventdata, handles)
882
883%------------------------------------------------------------------------
884% --- Executes on selection change in Coord_x.
885%------------------------------------------------------------------------
886function Coord_x_Callback(hObject, DimCell, handles)
887
888index=get(handles.Coord_x,'Value');
889string=get(handles.Coord_x,'String');
890VarName=string{index};
891if ~ischar(DimCell)
892    update_field(handles,VarName)
893end
894if isequal(get(handles.FieldOption,'Value'),1)
895set_coord_y_options(handles,VarName)
896end
897
898%------------------------------------------------------------------------
899% --- Executes on selection change in Coord_y.
900%------------------------------------------------------------------------
901function Coord_y_Callback(hObject, DimCell, handles)
902
903index=get(handles.Coord_y,'Value');
904string=get(handles.Coord_y,'String');
905VarName=string{index};
906
907if ~ischar(DimCell)
908update_field(handles,VarName)
909end
910
911%------------------------------------------------------------------------
912% --- Executes on selection change in Coord_z.
913%------------------------------------------------------------------------
914function Coord_z_Callback(hObject, DimCell, handles)
915
916index=get(handles.Coord_z,'Value');
917string=get(handles.Coord_z,'String');
918VarName=string{index};
919if ~ischar(DimCell)
920update_field(handles,VarName)
921end
922
923%------------------------------------------------------------------------
924% --- Executes on selection change in SwitchVarIndexTime.
925%------------------------------------------------------------------------
926
927function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
928
929Field=get(handles.get_field,'UserData');
930menu=get(handles.SwitchVarIndexTime,'String');
931option=menu{get(handles.SwitchVarIndexTime,'Value')};
932
933switch option
934    case 'file index'
935        set(handles.TimeName, 'Visible','off')% the time is taken as the file index
936    case 'attribute'
937        set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes
938        time_index=get(handles.TimeName,'UserData');    %select the input data
939        if isempty(time_index)
940            PreviousList=get(handles.TimeName, 'String');
941            if ~isempty(PreviousList)
942                PreviousAttr=PreviousList{get(handles.TimeName, 'Value')};
943                index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttribute),1);
944            end
945        end
946        if isempty(time_index)
947            time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% index of the attributes containing the string 'Time'
948        end     
949        if ~isempty(time_index)
950            set(handles.TimeName,'Value',time_index)
951        else
952            set(handles.TimeName,'Value',1)
953        end
954        set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute)
955
956    case 'variable'% TimeName menu represents the available variables
957        set(handles.TimeName, 'Visible','on')
958        VarNbDim=cellfun('length',Field.Display.VarDimName); % check the nbre of dimensions of each input variable
959        TimeVarName=Field.Display.ListVarName(VarNbDim==1);% list of variables with a single dimension (candidate for time)
960        List=get(handles.TimeName,'String');% list of names on the menu for time
961        if isempty(List)
962            ind=1;
963        else
964            option=List{get(handles.TimeName,'Value')};% previous selected option
965            ind=find(strcmp(option,TimeVarName)); %check whether the previous selection is available in the newlist
966            if isempty(ind)
967                ind=1;
968            end
969        end
970        if ~isempty(TimeVarName)
971            set(handles.TimeName, 'Value',ind);% select first value in the menu if the option is not found
972            set(handles.TimeName, 'String',TimeVarName)% update the menu for time name
973        end
974    case 'matrix index'% TimeName menu represents the available dimensions
975        set(handles.TimeName, 'Visible','on')     
976        set(handles.TimeName, 'Value',1);
977        set(handles.TimeName, 'String',Field.Display.ListDimName)
978end
979TimeName_Callback(hObject, [], handles)
980
981%-----------------------------------------------------------------------
982% update the display of the variable 'VarName' and its dimensions in the list of variables
983function update_field(handles,VarName)
984%-----------------------------------------------------------------------
985Field=get(handles.get_field,'UserData');
986index=name2index(VarName,Field.ListVarName);
987if ~isempty(index)
988    set(handles.variables,'Value',index+1)
989    variables_Callback(handles.variables, VarName, handles)
990end
991
992%------------------------------------------------------------------------
993% --- give index numbers of the strings str in the list ListvarName
994% -----------------------------------------------------------------------
995function VarIndex_y=name2index(cell_str,ListVarName)
996
997VarIndex_y=[];
998if ischar(cell_str)
999    VarIndex_y=find(strcmp(cell_str,ListVarName),1);
1000elseif iscell(cell_str)
1001    for isel=1:length(cell_str)
1002        varsel=cell_str{isel};
1003        for ivar=1:length(ListVarName)
1004            varlist=ListVarName{ivar};
1005            if isequal(varlist,varsel)
1006                VarIndex_y=[VarIndex_y ivar];
1007            end
1008        end
1009    end
1010end
1011
1012
1013
1014% % --- Executes on button press in CheckDimensionY.
1015% function CheckDimensionY_Callback(hObject, eventdata, handles)
1016% FieldList=get(handles.FieldOption,'String');
1017% FieldOption=FieldList{get(handles.FieldOption,'Value')};
1018% switch FieldOption
1019%     case '1D plot'
1020%         
1021%     case {'scalar','pick variables'}
1022%        scalar_Callback(hObject, eventdata, handles)
1023%     case 'vectors'
1024% end
1025%
1026%
1027% % --- Executes on button press in CheckDimensionZ.
1028% function CheckDimensionZ_Callback(hObject, eventdata, handles)
1029% FieldList=get(handles.FieldOption,'String');
1030% FieldOption=FieldList{get(handles.FieldOption,'Value')};
1031% switch FieldOption
1032%     case '1D plot'
1033%         
1034%     case 'scalar'
1035%        scalar_Callback(hObject, eventdata, handles)
1036%     case 'vectors'
1037% end
1038
1039% --- Executes on selection change in TimeName.
1040function TimeName_Callback(hObject, eventdata, handles)
1041Field=get(handles.get_field,'UserData');
1042index=get(handles.SwitchVarIndexTime,'Value');
1043MenuIndex=get(handles.TimeName,'Value');
1044string=get(handles.TimeName,'String');
1045TimeName='';%default
1046if ~isempty(string)&&iscell(string)
1047TimeName=string{MenuIndex};
1048end
1049switch index
1050    case 1
1051        set(handles.num_TimeDimension,'String','')
1052        set(handles.TimeUnit,'String','index')
1053    case 2
1054        set(handles.num_TimeDimension,'String','')
1055        attr_index=find(strcmpi([TimeName 'Unit'],Field.ListGlobalAttribute));% look for time unit
1056        if ~isempty(attr_index)
1057            AttrName=Field.ListGlobalAttribute{attr_index};
1058            set(handles.TimeUnit,'String',Field.(AttrName))
1059        else
1060            set(handles.TimeUnit,'String','')
1061        end
1062    case {3 ,4}
1063        if index==3  % TimeName is used to chose a variable
1064            VarIndex=name2index(TimeName,Field.ListVarName);
1065            DimName=Field.VarDimName{VarIndex};
1066            DimIndex=name2index(DimName,Field.ListDimName);
1067            DimValue=Field.DimValue(DimIndex);
1068            set(handles.num_TimeDimension,'String',num2str(DimValue))
1069            unit='';
1070            if isfield(Field,'VarAttribute')&& isfield(Field.VarAttribute{VarIndex},'Unit')
1071                unit=Field.VarAttribute{VarIndex}.Unit;
1072            end
1073            set(handles.TimeUnit,'String',unit)
1074            update_field(handles,TimeName)
1075        elseif index==4% TimeName is used to chose a dimension
1076            DimName=string{MenuIndex};
1077            DimIndex=name2index(DimName,Field.ListDimName);
1078            DimValue=Field.DimValue(DimIndex);
1079            set(handles.num_TimeDimension,'String',num2str(DimValue))
1080            set(handles.TimeUnit,'String','index')
1081        end
1082end
1083
1084%-----------------------------------------------------------------------
1085% --- Executes on button press in Check3D.
1086%-----------------------------------------------------------------------
1087function Check3D_Callback(hObject, eventdata, handles)
1088if get(handles.Check3D,'Value')% 3D fields
1089    status='on';
1090else% fields studied as 2D
1091    status='off';
1092end
1093
1094set(handles.Coord_z,'Visible',status)
1095% set(handles.CheckDimensionZ,'Visible',status)
1096set(handles.Z_title,'Visible',status)
1097set(handles.vector_z,'Visible',status)
1098set(handles.W_title,'Visible',status)
1099Field=get(handles.get_field,'UserData');
1100if strcmp(status,'on')% ask for 3D input       
1101    if Field.MaxDim>3% for 4D fields, propose to use the fourth variable as time
1102        %set(handles.Time,'Visible','on')
1103        menu=get(handles.SwitchVarIndexTime,'String');
1104        val=find(strcmp('variable',menu));
1105        if ~isempty(val)
1106            set(handles.SwitchVarIndexTime,'Value',val)
1107        end
1108    else
1109        set(handles.SwitchVarIndexTime,'Value',1)
1110        set(handles.SwitchVarIndexTime,'String',{'file index';'attribute'})
1111    end
1112else
1113   set(handles.SwitchVarIndexTime,'String',get(handles.SwitchVarIndexTime,'UserData'))
1114   if Field.MaxDim >=3
1115       var_index=find(strcmp('variable',get(handles.SwitchVarIndexTime,'UserData')));
1116       set(handles.SwitchVarIndexTime,'Value',var_index)
1117   end
1118end
1119SwitchVarIndexTime_Callback(handles.SwitchVarIndexTime,[], handles)
1120
1121%------------------------------------------------------------------------
1122% --- Executes on button press in OK.
1123%------------------------------------------------------------------------
1124function OK_Callback(hObject, eventdata, handles)
1125handles.output=read_GUI(handles.get_field);
1126guidata(hObject, handles);% Update handles structure
1127uiresume(handles.get_field);
1128drawnow
1129% this function then activate get_field_OutputFcn
1130
1131%------------------------------------------------------------------------
1132% --- Executes when the GUI is closed by the mouse on upper right corner.
1133%------------------------------------------------------------------------
1134function closefcn(hObject, eventdata, handles)
1135handles.output=[];
1136guidata(hObject, handles);% Update handles structure
1137uiresume(handles.get_field);
1138drawnow
1139
1140%------------------------------------------------------------------------
1141% --- Outputs from this function are returned to the command line.
1142%------------------------------------------------------------------------
1143function varargout = get_field_OutputFcn(hObject, eventdata, handles)
1144
1145varargout{1} =handles.output;
1146delete(handles.get_field)
Note: See TracBrowser for help on using the repository browser.