source: trunk/src/get_field.m @ 747

Last change on this file since 747 was 747, checked in by sommeria, 10 years ago

adpatations to 3D fields

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