source: trunk/src/get_field.m @ 653

Last change on this file since 653 was 648, checked in by sommeria, 11 years ago

get_field updated, several bugs corrected,open_uvmat suppressd

File size: 31.4 KB
Line 
1%'get_field': display variables and attributes from a Netcdf file, and OK selected fields
2%------------------------------------------------------------------------
3%function varargout = get_field(varargin)
4% associated with the GUI get_field.fig
5%
6%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%     This file is part of the toolbox UVMAT.
10%
11%     UVMAT is free software; you can redistribute it and/or modify
12%     it under the terms of the GNU General Public License as published by
13%     the Free Software Foundation; either version 2 of the License, or
14%     (at your option) any later version.
15%
16%     UVMAT is distributed in the hope that it will be useful,
17%     but WITHOUT ANY WARRANTY; without even the implied warranty of
18%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21
22function varargout = get_field(varargin)
23
24% Last Modified by GUIDE v2.5 09-Jun-2013 11:15:54
25
26% Begin initialization code - DO NOT EDIT
27gui_Singleton = 1;
28gui_State = struct('gui_Name',       mfilename, ...
29                   'gui_Singleton',  gui_Singleton, ...
30                   'gui_OpeningFcn', @get_field_OpeningFcn, ...
31                   'gui_OutputFcn',  @get_field_OutputFcn, ...
32                   'gui_LayoutFcn',  [] , ...
33                   'gui_Callback',   []);
34if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
35    gui_State.gui_Callback = str2func(varargin{1});
36end
37
38if nargout
39    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
40else
41    gui_mainfcn(gui_State, varargin{:});
42end
43% End initialization code - DO NOT EDIT
44
45%------------------------------------------------------------------------
46% --- Executes just before get_field is made visible.
47%------------------------------------------------------------------------
48function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
49
50%% GUI settings
51handles.output = 'Cancel';
52guidata(hObject, handles);
53set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
54
55%% enter input data
56set(handles.inputfile,'String',filename)% fill the input file name
57Field=nc2struct(filename,[]);% reads the  field structure, without the variables
58if isfield(Field,'Txt')
59    msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])% display error message for input fiel reading
60    return
61end
62if ~isfield(Field,'ListVarName')
63    return
64end
65if ~exist('ParamIn','var')
66    ParamIn=[];
67end
68
69%% look at singletons and variables with a single dimension
70Field.Display=Field;
71Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value
72NbVar=numel(Field.VarDimName);
73for ilist=1:NbVar
74    if ischar(Field.VarDimName{ilist})
75        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
76    end
77    NbDim=numel(Field.VarDimName{ilist});
78    check_singleton=false(1,NbDim);
79    for idim=1:NbDim
80        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions
81        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton
82    end
83    Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)));% =1 if the variable reduces to a single value
84    if ~Field.Check0D(ilist)
85    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
86    end
87    %Field.NbDim(ilist)=numel(Field.VarDimNameNonSingleton{ilist});%nbre of array dimensions after elimination of singletons
88end
89if numel(Field.VarAttribute)<NbVar% complement VarAttribute by blanjs if neded
90    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
91end
92Field.Display.ListVarName=Field.ListVarName(~Field.Check0D);
93Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
94Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D);
95Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);
96Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);
97
98%% analyse the input field cells
99[CellInfo,NbDim,errormsg]=find_field_cells(Field.Display);
100if ~isempty(errormsg)
101    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
102    return
103end
104[Field.MaxDim,imax]=max(NbDim);
105
106%% set time mode
107ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index
108% look at global attributes with numerical values
109check_numvalue=false;
110check_time=false;
111for ilist=1:numel(Field.ListGlobalAttribute)
112    Value=Field.(Field.ListGlobalAttribute{ilist});
113    check_numvalue(ilist)=isnumeric(Value);
114    check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
115end
116Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
117if ~isempty(Field.Display.ListGlobalAttribute)
118    ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute
119end
120nboption=numel(ListSwitchVarIndexTime);
121if Field.MaxDim>=2
122    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];% the time can be chosen as a dim index
123end
124if ~isempty(find(check_time, 1))
125    set(handles.SwitchVarIndexTime,'Value',2);
126else
127    set(handles.SwitchVarIndexTime,'Value',1);
128end
129set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
130set(handles.get_field,'UserData',Field);% record the finput field structure
131SwitchVarIndexTime_Callback([], [], handles)
132
133%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
134set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
135set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
136set(handles.vector_z,'String',[{''} Field.ListVarName])% fill the menu of y vector components
137set(handles.vec_color,'String',[{''} Field.ListVarName])% fill the menu of y vector components
138set(handles.scalar,'Value',1)% fill the menu of y vector components
139set(handles.scalar,'String',Field.ListVarName)% fill the menu of y vector components
140set(handles.ordinate,'Value',1)% fill the menu of y vector components
141set(handles.ordinate,'String',Field.ListVarName)% fill the menu of y vector components
142if Field.MaxDim>=2 % case of 2D (or 3D) fields
143    if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
144        set(handles.FieldOption,'Value',3)% set vector selection option
145        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
146        set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))
147        set(handles.FieldOption,'Value',3)
148    else
149        set(handles.FieldOption,'Value',2)
150    end
151else % case of 1D fields
152    set(handles.FieldOption,'Value',1)
153end
154
155%% fill the general list of dimensions, variables, attributes
156if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
157    Tabcell(:,1)=Field.ListDimName;
158    for iline=1:length(Field.ListDimName)
159        Tabcell{iline,2}=num2str(Field.DimValue(iline));
160    end
161    Tabchar=cell2tab(Tabcell,' = ');
162    set(handles.dimensions,'String',Tabchar)
163end
164set(handles.variables,'Value',1)
165set(handles.variables,'String',[{'*'} Field.ListVarName])
166variables_Callback(handles.variables,[], handles)% list the global attributes
167
168%% fill menus for coordinates and time
169FieldOption_Callback(handles.variables,[], handles)% list the global attributes
170%     if isfield(CellInfo{imax},'VarIndex_coord_x')&&  isfield(CellInfo{imax},'VarIndex_coord_y')
171%         set(handles.Coord_x,'Value',CellInfo{imax}.VarIndex_coord_x(1))
172%         set(handles.Coord_y,'Value',CellInfo{imax}.VarIndex_coord_y(1))
173%     end
174
175%% Make choices in menus from input
176% if exist('ParamIn','var')&&~isempty(ParamIn)
177%     fill_GUI(ParamIn,handles.get_field);
178% end
179%FieldOption_Callback([],[],handles)
180
181
182%% put the GUI on the lower right of the sceen
183set(hObject,'Unit','pixel')
184pos_view_field=get(hObject,'Position');
185set(0,'Unit','pixels')
186ScreenSize=get(0,'ScreenSize');
187pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
188pos_view_field(2)=ScreenSize(2);
189set(hObject,'Position',pos_view_field)
190set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
191drawnow
192uiwait(handles.get_field);
193
194return
195
196SwitchVarIndexTime_Callback([],[], handles)
197
198%% set z coordinate menu if relevant
199if Field.MaxDim>=3
200    set(handles.vector_z,'Visible','on')
201    set(handles.vector_z,'String',Field.ListVarName(~Field.Check0D))
202    set(handles.Coord_z,'Visible','on')
203    set(handles.SwitchVarIndexZ,'Visible','on')
204    set(handles.Z_title,'Visible','on')
205else
206    set(handles.vector_z,'Visible','off')
207    set(handles.Coord_z,'Visible','off')
208    set(handles.Z_title,'Visible','off')
209end
210
211
212
213%------------------------------------------------------------------------
214
215%------------------------------------------------------------------------
216% --- Outputs from this function are returned to the command line.
217function varargout = get_field_OutputFcn(hObject, eventdata, handles)
218%------------------------------------------------------------------------
219varargout{1} = handles.output;
220delete(handles.get_field)
221
222%------------------------------------------------------------------------
223% --- Executes when user attempts to close get_field.
224%------------------------------------------------------------------------
225function get_field_CloseRequestFcn(hObject, eventdata, handles)
226
227if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
228    % The GUI is still in UIWAIT, us UIRESUME
229    uiresume(handles.get_field);
230else
231    % The GUI is no longer waiting, just close it
232    delete(handles.get_field);
233end
234
235%---------------------------------------------------------
236% --- Executes on button press in OK.
237%------------------------------------------------------------------------
238function OK_Callback(hObject, eventdata, handles)
239
240handles.output=read_GUI(handles.get_field);
241guidata(hObject, handles);% Update handles structure
242uiresume(handles.get_field);
243drawnow
244
245% -----------------------------------------------------------------------
246% --- Activated by selection in the list of variables
247function variables_Callback(hObject, eventdata, handles)
248% -----------------------------------------------------------------------
249Tabchar={''};%default
250Tabcell=[];
251hselect_field=get(handles.variables,'parent');
252Field=get(handles.get_field,'UserData');
253index=get(handles.variables,'Value');%index in the list 'variables'
254
255%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
256if isequal(index,1)
257    set(handles.attributes_txt,'String','global attributes')
258    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
259        for iline=1:length(Field.ListGlobalAttribute)
260            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
261            if isfield(Field, Field.ListGlobalAttribute{iline})
262                val=Field.(Field.ListGlobalAttribute{iline});
263                if ischar(val);% attribute value is char string
264                    Tabcell{iline,2}=val;
265                elseif size(val,1)==1 %attribute value is a number or matlab vector
266                    Tabcell{iline,2}=num2str(val);
267                end
268            end
269        end
270        Tabchar=cell2tab(Tabcell,'=');
271    end
272%% list Attribute names and values associated to the Variable # index-1   
273else
274    list_var=get(handles.variables,'String');
275    var_select=list_var{index};
276    set(handles.attributes_txt,'String', ['attributes of ' var_select])
277    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
278%         nbline=0;
279        VarAttr=Field.VarAttribute{index-1};
280        if isstruct(VarAttr)
281            attr_list=fieldnames(VarAttr);
282            for iline=1:length(attr_list)
283                Tabcell{iline,1}=attr_list{iline};
284                eval(['val=VarAttr.' attr_list{iline} ';'])
285                if ischar(val);
286                    Tabcell{iline,2}=val;
287                else
288                     Tabcell{iline,2}=num2str(val);
289                end
290            end
291        end
292    end
293
294end
295if ~isempty(Tabcell)
296    Tabchar=cell2tab(Tabcell,'=');
297%     Tabchar=[{''};Tabchar];
298end
299set(handles.attributes,'Value',1);% select the first item
300set(handles.attributes,'String',Tabchar);
301
302%% update dimensions;
303if isfield(Field,'ListDimName')
304    Tabdim={};%default
305    if isequal(index,1)%list all dimensions
306        dim_indices=1:length(Field.ListDimName);
307        set(handles.dimensions_txt,'String', 'dimensions')
308    else
309        DimCell=Field.VarDimName{index-1};
310        if ischar(DimCell)
311            DimCell={DimCell};
312        end   
313        dim_indices=[];
314        for idim=1:length(DimCell)
315            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
316            dim_index=find(dim_index,1);
317            dim_indices=[dim_indices dim_index];
318        end
319        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
320    end
321    for iline=1:length(dim_indices)
322        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
323        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
324    end
325    Tabchar=cell2tab(Tabdim,' = ');
326    Tabchar=[{''} ;Tabchar];
327    set(handles.dimensions,'Value',1)
328    set(handles.dimensions,'String',Tabchar) 
329end 
330
331%------------------------------------------------------------------------
332% --- Executes on selection change in FieldOption.
333%------------------------------------------------------------------------
334function FieldOption_Callback(hObject, eventdata, handles)
335
336FieldList=get(handles.FieldOption,'String');
337FieldOption=FieldList{get(handles.FieldOption,'Value')};
338switch FieldOption
339    case '1D plot'
340        set(handles.PanelOrdinate,'Visible','on')
341        pos=get(handles.PanelOrdinate,'Position');
342        pos(1)=2;
343        pos_coord=get(handles.Coordinates,'Position');
344        pos(2)=pos_coord(2)-pos(4)-2;
345        set(handles.PanelOrdinate,'Position',pos)
346        set(handles.PanelScalar,'Visible','off')
347        set(handles.PanelVectors,'Visible','off')
348        set(handles.Coord_y,'Visible','off')
349        set(handles.Y_title,'Visible','off')
350        set(handles.Coord_z,'Visible','off')
351        set(handles.Z_title,'Visible','off')
352        ordinate_Callback(hObject, eventdata, handles)
353    case 'scalar'
354        set(handles.PanelOrdinate,'Visible','off')
355        set(handles.PanelScalar,'Visible','on')
356        set(handles.PanelVectors,'Visible','off')
357        pos=get(handles.PanelScalar,'Position');
358        pos(1)=2;
359        pos_coord=get(handles.Coordinates,'Position');
360        pos(2)=pos_coord(2)-pos(4)-2;
361        set(handles.PanelScalar,'Position',pos)
362        set(handles.Coord_y,'Visible','on')
363        set(handles.Y_title,'Visible','on')
364        scalar_Callback(hObject, eventdata, handles)
365    case 'vectors'
366        set(handles.PanelOrdinate,'Visible','off')
367        set(handles.PanelScalar,'Visible','off')
368        set(handles.PanelVectors,'Visible','on')
369        pos=get(handles.PanelVectors,'Position');
370        pos(1)=2;
371        pos_coord=get(handles.Coordinates,'Position');
372        pos(2)=pos_coord(2)-pos(4)-2;
373        set(handles.PanelVectors,'Position',pos)
374        set(handles.Coord_y,'Visible','on')
375        set(handles.Y_title,'Visible','on')     
376        vector_Callback(handles)
377end
378
379%------------------------------------------------------------------------
380function ordinate_Callback(hObject, eventdata, handles)
381%------------------------------------------------------------------------
382Field=get(handles.get_field,'UserData');
383y_index=get(handles.ordinate,'Value');
384y_menu=get(handles.ordinate,'String');
385YName=y_menu{y_index};
386
387%% set list of possible coordinates
388test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
389test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
390ListCoord={''};
391dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable
392
393for ilist=1:numel(Field.Display.VarDimName)
394    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
395    if isequal(dimnames,dim_var)
396        test_component(ilist)=1;
397    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
398        test_coord(ilist)=1;
399    end
400end
401var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
402var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
403ListCoord=Field.Display.ListVarName([var_component var_coord]);
404
405%% set default coord selection
406if numel(find(test_coord))>3
407    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
408end
409if numel(var_component)<2
410    if numel(test_coord)<2
411        ListCoord={''};
412    else
413        set(handles.Coord_x,'Value',2)
414        set(handles.Coord_y,'Value',1)
415    end
416else
417    coord_val=1;
418    for ilist=1:numel(var_component)
419        ivar=var_component(ilist);
420        if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
421            Role=Field.Display.VarAttribute{ivar}.Role;
422            if strcmp(Role,'coord_x')
423                coord_val=ilist;
424            end
425        end
426    end
427    set(handles.Coord_x,'Value',coord_val)
428end
429set(handles.Coord_x,'String',ListCoord)
430
431
432%% set list of time coordinates
433menu=get(handles.SwitchVarIndexTime,'String');
434TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
435switch TimeOption
436    case 'variable'
437        if numel(find(test_coord))<3
438            ListTime={''};
439        else
440            ListTime=Field.Display.ListVarName(find(test_coord,end));
441        end
442        set(handles.TimeName,'Value',1)
443        set(handles.TimeName,'String',ListTime)
444    case 'dim index'
445        if numel(find(test_coord))<3
446            ListTime={''};
447        else
448            ListTime=Field.Display.VarDimName{find(test_coord,end)};
449        end
450        set(handles.TimeName,'Value',1)
451        set(handles.TimeName,'String',ListTime)
452end 
453update_field(handles,YName)
454
455%------------------------------------------------------------------------
456% --- Executes on selection change in scalar menu.
457%------------------------------------------------------------------------
458function scalar_Callback(hObject, eventdata, handles)
459
460Field=get(handles.get_field,'UserData');
461scalar_index=get(handles.scalar,'Value');
462scalar_menu=get(handles.scalar,'String');
463ScalarName=scalar_menu{scalar_index};
464
465%% set list of possible coordinates
466test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
467test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
468ListCoord={''};
469dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
470
471for ilist=1:numel(Field.Display.VarDimName)
472    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
473    if isequal(dimnames,dim_var)
474        test_component(ilist)=1;
475    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
476        test_coord(ilist)=1;
477    end
478end
479var_component=find(test_component);% list of variable indices elligible as unstructured coordiantes
480var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
481ListCoord=Field.Display.ListVarName([var_component var_coord]);
482
483%% set default coord selection
484if numel(find(test_coord))>3
485    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
486end
487if numel(var_component)<2
488    if numel(test_coord)<2
489        ListCoord={''};
490    else
491        set(handles.Coord_x,'Value',2)
492        set(handles.Coord_y,'Value',1)
493    end
494else
495    coord_val=[1 2];
496    for ilist=1:numel(var_component)
497        ivar=var_component(ilist);
498        if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
499            Role=Field.Display.VarAttribute{ivar}.Role;
500            if strcmp(Role,'coord_x')
501                coord_val(1)=ilist;
502            elseif strcmp(Role,'coord_y')
503                coord_val(2)=ilist;
504            end
505        end
506    end
507    set(handles.Coord_x,'Value',coord_val(1))
508    set(handles.Coord_y,'Value',coord_val(2))
509end
510
511set(handles.Coord_y,'String',ListCoord)
512set(handles.Coord_x,'String',ListCoord)
513
514
515%% set list of time coordinates
516menu=get(handles.SwitchVarIndexTime,'String');
517TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
518switch TimeOption
519    case 'variable'
520        if numel(find(test_coord))<3
521            ListTime={''};
522        else
523            ListTime=Field.Display.ListVarName(find(test_coord,end));
524        end
525        set(handles.TimeName,'Value',1)
526        set(handles.TimeName,'String',ListTime)
527    case 'dim index'
528        if numel(find(test_coord))<3
529            ListTime={''};
530        else
531            ListTime=Field.Display.VarDimName{find(test_coord,end)};
532        end
533        set(handles.TimeName,'Value',1)
534        set(handles.TimeName,'String',ListTime)
535end 
536update_field(handles,ScalarName)
537
538% --- Executes on button press in check_rgb.
539function check_rgb_Callback(hObject, eventdata, handles)
540
541
542%------------------------------------------------------------------------
543% --- Executes on selection change in vector_x.
544function vector_x_Callback(hObject, eventdata, handles)
545%------------------------------------------------------------------------
546vector_x_menu=get(handles.vector_x,'String');
547vector_x_index=get(handles.vector_x,'Value');
548vector_x=vector_x_menu{vector_x_index};
549vector_Callback(handles)
550update_field(handles,vector_x)
551
552%------------------------------------------------------------------------
553% --- Executes on selection change in vector_x.
554function vector_y_Callback(hObject, eventdata, handles)
555%------------------------------------------------------------------------
556vector_y_menu=get(handles.vector_x,'String');
557vector_y_index=get(handles.vector_x,'Value');
558vector_y=vector_y_menu{vector_y_index};
559vector_Callback(handles)
560update_field(handles,vector_y)
561
562%------------------------------------------------------------------------
563% --- Executes on selection change in vector_z.
564function vector_z_Callback(hObject, eventdata, handles)
565%------------------------------------------------------------------------
566vector_z_menu=get(handles.vector_z,'String');
567vector_z_index=get(handles.vector_z,'Value');
568vector_z=vector_z_menu{vector_z_index};
569vector_Callback(handles)
570update_field(handles,vector_z)
571
572%------------------------------------------------------------------------
573% --- Executes on selection change in vec_color.
574function vec_color_Callback(hObject, eventdata, handles)
575%------------------------------------------------------------------------
576index=get(handles.vec_color,'Value');
577string=get(handles.vec_color,'String');
578VarName=string{index};
579vector_Callback(handles)
580update_field(handles,VarName)
581
582%------------------------------------------------------------------------
583% --- Executes on selection change in vector_x or vector_y
584function vector_Callback( handles)
585%------------------------------------------------------------------------
586Field=get(handles.get_field,'UserData');
587vector_x_index=get(handles.vector_x,'Value');
588vector_y_index=get(handles.vector_y,'Value');
589vec_color_index=get(handles.vec_color,'Value');
590
591%% set list of possible coordinates
592test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
593test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
594check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn
595ListCoord={''};
596dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable
597if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index})
598    check_consistent=0;
599elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index})
600    check_consistent=0;
601end
602if check_consistent
603    for ilist=1:numel(Field.Display.VarDimName)
604        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
605        if isequal(dimnames,dim_var)
606            test_component(ilist)=1;
607        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
608            test_coord(ilist)=1;
609        end
610    end
611    var_component=find(test_component);% list of variable indices elligible as unstructured coordiantes
612    var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
613    ListCoord=Field.Display.ListVarName([var_component var_coord]);
614   
615    %% set default coord selection
616    if numel(find(test_coord))>3
617        set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
618    end
619    if numel(var_component)<2
620        if numel(test_coord)<2
621            ListCoord={''};
622        else
623            set(handles.Coord_x,'Value',2)
624            set(handles.Coord_y,'Value',1)
625        end
626    else
627        coord_val=[1 2];
628        for ilist=1:numel(var_component)
629            ivar=var_component(ilist);
630            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
631                Role=Field.Display.VarAttribute{ivar}.Role;
632                if strcmp(Role,'coord_x')
633                    coord_val(1)=ilist;
634                elseif strcmp(Role,'coord_y')
635                    coord_val(2)=ilist;
636                end
637            end
638        end
639        set(handles.Coord_x,'Value',coord_val(1))
640        set(handles.Coord_y,'Value',coord_val(2))
641    end
642end
643set(handles.Coord_y,'String',ListCoord)
644set(handles.Coord_x,'String',ListCoord)
645
646
647%% set list of time coordinates
648menu=get(handles.SwitchVarIndexTime,'String');
649TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
650switch TimeOption
651    case 'variable'
652        if numel(find(test_coord))<3
653            ListTime={''};
654        else
655            ListTime=Field.Display.ListVarName(find(test_coord,end));
656        end
657        set(handles.TimeName,'Value',1)
658        set(handles.TimeName,'String',ListTime)
659    case 'dim index'
660        if numel(find(test_coord))<3
661            ListTime={''};
662        else
663            ListTime=Field.Display.VarDimName{find(test_coord,end)};
664        end
665        set(handles.TimeName,'Value',1)
666        set(handles.TimeName,'String',ListTime)
667end 
668
669%------------------------------------------------------------------------
670% --- Executes on selection change in SwitchVarIndexX.
671%------------------------------------------------------------------------
672function SwitchVarIndexX_Callback(hObject, eventdata, handles)
673
674%------------------------------------------------------------------------
675% --- Executes on selection change in Coord_x.
676function Coord_x_Callback(hObject, eventdata, handles)
677%------------------------------------------------------------------------
678index=get(handles.Coord_x,'Value');
679string=get(handles.Coord_x,'String');
680VarName=string{index};
681update_field(handles,VarName)
682
683%------------------------------------------------------------------------
684% --- Executes on selection change in Coord_y.
685function Coord_y_Callback(hObject, eventdata, handles)
686%------------------------------------------------------------------------
687index=get(handles.Coord_y,'Value');
688string=get(handles.Coord_y,'String');
689VarName=string{index};
690update_field(handles,VarName)
691
692%------------------------------------------------------------------------
693% --- Executes on selection change in Coord_z.
694function Coord_z_Callback(hObject, eventdata, handles)
695%------------------------------------------------------------------------
696index=get(handles.Coord_z,'Value');
697string=get(handles.Coord_z,'String');
698VarName=string{index};
699update_field(handles,VarName)
700
701%------------------------------------------------------------------------
702% --- Executes on selection change in SwitchVarIndexTime.
703%------------------------------------------------------------------------
704function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
705Field=get(handles.get_field,'UserData');
706menu=get(handles.SwitchVarIndexTime,'String');
707option=menu{get(handles.SwitchVarIndexTime,'Value')};
708
709switch option
710    case 'file index'
711        set(handles.TimeName, 'Visible','off')% the time is taken as the file index
712    case 'attribute'
713        set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes
714        time_index=[];
715        PreviousList=get(handles.TimeName, 'String');
716        index=[];
717        if ~isempty(PreviousList)
718            PreviousAttr=PreviousList{get(handles.TimeName, 'Value')};
719            index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes));
720        end
721        if isempty(index)
722            time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')));% index of the attributes containing the string 'Time'
723        end
724        if ~isempty(time_index)
725            set(handles.TimeName,'Value',time_index(1))
726        else
727            set(handles.TimeName,'Value',1)
728        end
729        set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute)
730    case 'variable'% TimeName menu represents the available variables
731        set(handles.TimeName, 'Visible','on')
732        TimeVarName=Field.Display.SingleVarName;% slist of variables with a single dimension (candidate for time)
733        List=get(handles.TimeName,'String');
734        option=List{get(handles.TimeName,'Value')};
735        ind=find(strcmp(option,TimeVarName));
736        if isempty(ind)
737            set(handles.TimeName, 'Value',1);
738        else
739            set(handles.TimeName, 'Value',ind);
740        end
741        set(handles.TimeName, 'String',TimeVarName)
742    case 'dim index'% TimeName menu represents the available dimensions
743        set(handles.TimeName, 'Visible','on')
744        TimeVarName=Field.Display.SingleDimName;
745        List=get(handles.TimeName,'String');
746        option=List{get(handles.TimeName,'Value')};
747        ind=find(strcmp(option,TimeVarName));
748        if isempty(ind)
749            set(handles.TimeName, 'Value',1);
750        else
751            set(handles.TimeName, 'Value',ind);
752        end
753        set(handles.TimeName, 'String',TimeVarName)
754end
755
756%-----------------------------------------------------------------------
757function update_field(handles,VarName)
758%-----------------------------------------------------------------------
759Field=get(handles.get_field,'UserData');
760index=name2index(VarName,Field.ListVarName);
761if ~isempty(index)
762    set(handles.variables,'Value',index+1)
763    variables_Callback(handles.variables, [], handles)
764end
765
766%-------------------------------------------------
767% give index numbers of the strings str in the list ListvarName
768function VarIndex_y=name2index(cell_str,ListVarName)
769VarIndex_y=[];
770if ischar(cell_str)
771    for ivar=1:length(ListVarName)
772        varlist=ListVarName{ivar};
773        if isequal(varlist,cell_str)
774            VarIndex_y= ivar;
775            break
776        end
777    end
778elseif iscell(cell_str)
779    for isel=1:length(cell_str)
780        varsel=cell_str{isel};
781        for ivar=1:length(ListVarName)
782            varlist=ListVarName{ivar};
783            if isequal(varlist,varsel)
784                VarIndex_y=[VarIndex_y ivar];
785            end
786        end
787    end
788end
Note: See TracBrowser for help on using the repository browser.