source: trunk/src/get_field.m @ 1040

Last change on this file since 1040 was 1040, checked in by sommeria, 3 years ago

get_field improved to select variables, uvmat rationalized with respect to input file types

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