source: trunk/src/get_field.m @ 1049

Last change on this file since 1049 was 1045, checked in by sommeria, 7 years ago

find field cells improved

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