source: trunk/src/get_field.m @ 1080

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

ima2temperature.m added and various bug repairs

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