source: trunk/src/get_field.m @ 586

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

tps_coeff_field introduced and several bugs corrected

File size: 65.3 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 10-Mar-2013 21:19:52
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.
47function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
48%------------------------------------------------------------------------
49global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
50
51%% Choose default command line output for get_field
52handles.output = 'Cancel';
53
54%% Update handles structure
55guidata(hObject, handles);
56set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
57
58%% settings for 'slave' mode, called by uvmat, or 'master' mode
59if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
60    set(handles.inputfile,'String',filename)% prefill the input file name
61    Field=nc2struct(filename,[]);% reads the  field structure, without the variables
62    if isfield(Field,'Txt')
63        msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])
64    else
65        if ~exist('ParamIn','var')
66            ParamIn=[];
67        end
68        Field_input(handles,Field,ParamIn);
69    end
70else  %master mode
71    set(handles.inputfile,'String','')
72end
73
74%% put the GUI on the lower right of the sceen
75set(hObject,'Unit','pixel')
76pos_view_field=get(hObject,'Position');
77ScreenSize=get(0,'ScreenSize');
78pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
79pos_view_field(2)=ScreenSize(2);
80set(hObject,'Position',pos_view_field)
81set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
82drawnow
83uiwait(handles.get_field);
84
85%------------------------------------------------------------------------
86% --- update the display when a new field is introduced.
87function Field_input(handles,Field,ParamIn)
88%------------------------------------------------------------------------
89
90%% fill the list and values of dimensions
91if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
92    Tabcell(:,1)=Field.ListDimName;
93    for iline=1:length(Field.ListDimName)
94        Tabcell{iline,2}=num2str(Field.DimValue(iline));
95    end
96    Tabchar=cell2tab(Tabcell,' = ');
97    set(handles.dimensions,'String',Tabchar)
98end
99if ~isfield(Field,'ListVarName')
100    return
101end
102
103%% fill the list of variables
104Txt=Field.ListVarName;
105set(handles.variables,'Value',1)
106set(handles.variables,'String',[{'*'} Txt])
107variables_Callback(handles.variables,[], handles)
108
109% set(handles.abscissa,'String',[{''} Txt ])
110set(handles.ordinate,'String',Txt)
111set(handles.vector_x,'String',[Txt ])
112set(handles.vector_y,'String',[Txt ])
113set(handles.vector_z,'String',[{''} Txt ])
114set(handles.vec_color,'String',[{''} Txt ])
115set(handles.XVarName,'String',[{''} Txt ])
116set(handles.YVarName,'String',[{''} Txt ])
117set(handles.ZVarName,'String',[{''} Txt ])
118% set(handles.coord_x_vectors,'String',[{''} Txt ])
119% set(handles.coord_y_vectors,'String',[{''} Txt ])
120% set(handles.YVarName,'String',[{''} Txt ])
121% set(handles.TimeVarName,'String',[{''} Txt ])
122set(handles.scalar,'Value',1)
123set(handles.scalar,'String', Txt )
124
125%% ananlyse the input field cells
126[CellInfo,NbDim,errormsg]=find_field_cells(Field);
127if ~isempty(errormsg) 
128    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
129    return
130end 
131[Field.MaxDim,imax]=max(NbDim);
132% look at variables with a single dimension
133for ilist=1:numel(Field.VarDimName)
134    if ischar(Field.VarDimName{ilist})
135        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
136    end
137    NbDim=numel(Field.VarDimName{ilist});% TODO eliminate singleton dimensions
138    check_singleton=false(1,NbDim);
139    for idim=1:NbDim
140        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);
141        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);
142    end
143    Field.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);
144    Field.NbDim(ilist)=numel(Field.VarDimName{ilist});
145    if Field.NbDim(ilist)==1
146        Field.VarDimName{ilist}=cell2mat(Field.VarDimName{ilist});
147    end
148end
149SingleVarName=Field.ListVarName(Field.NbDim==1);%list of variables with a single dim
150MultiVarName=Field.ListVarName(Field.NbDim>1);
151check_dim=zeros(size(Field.VarDimName));
152for ilist=1:numel(Field.VarDimName);
153    if iscell(Field.VarDimName{ilist})% exclude single dim
154        for idim=1:numel(Field.VarDimName{ilist})
155            check_dim=check_dim|strcmp(Field.VarDimName{ilist}{idim},Field.VarDimName);
156        end
157    end
158end
159Field.SingleVarName=Field.ListVarName(find(check_dim));%list of variables with a single dim
160Field.SingleDimName=Field.VarDimName(find(check_dim));% corresponding list of dimensions for variables with a single dim
161Field.MaxDim=max(Field.NbDim);
162
163%% set time mode
164ListSwitchVarIndexTime={'file index'};
165% look at global attributes with numerical values
166check_numvalue=false;
167check_time=false;
168    for ilist=1:numel(Field.ListGlobalAttribute)
169        Value=Field.(Field.ListGlobalAttribute{ilist});
170        check_numvalue(ilist)=isnumeric(Value);
171        check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
172    end 
173Field.ListNumAttributes=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
174if ~isempty(Field.ListNumAttributes)
175ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];
176end
177nboption=numel(ListSwitchVarIndexTime);
178if Field.MaxDim>=2
179    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];
180end
181if Field.MaxDim>=4
182        option=nboption+1;
183elseif ~isempty(find(check_time, 1))
184    option=2;
185else
186    option=1;
187end
188set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
189set(handles.SwitchVarIndexTime,'Value',option)
190set(handles.get_field,'UserData',Field);% record the finput field structure
191SwitchVarIndexTime_Callback([],[], handles)
192
193%% set z coordinate menu if relevant
194if Field.MaxDim>=3
195    set(handles.vector_z,'Visible','on')
196    set(handles.vector_z,'String',[{''} Txt ])
197        set(handles.ZVarName,'Visible','on')
198    set(handles.SwitchVarIndexZ,'Visible','on')
199    set(handles.Z_title,'Visible','on')
200else
201    set(handles.vector_z,'Visible','off')
202    set(handles.ZVarName,'Visible','off')
203    set(handles.SwitchVarIndexZ,'Visible','off')
204    set(handles.Z_title,'Visible','off')
205end
206
207%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
208if Field.MaxDim>=2 % case of 2D (or 3D) fields
209    set(handles.CheckPlot1D,'Value',0)
210    if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
211        set(handles.CheckVector,'Value',1)
212        set(handles.CheckScalar,'Value',0)
213        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
214        set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))
215    else
216        set(handles.CheckScalar,'Value',1)
217        set(handles.CheckVector,'Value',0)
218    end
219else % case of 1D fields
220    set(handles.CheckPlot1D,'Value',1)
221    set(handles.CheckScalar,'Value',0)
222    set(handles.CheckVector,'Value',0)
223end
224
225%% Make choices in menus from input
226if exist('ParamIn','var')&&~isempty(ParamIn)
227    fill_GUI(ParamIn,handles);
228end
229CheckPlot1D_Callback(handles.CheckPlot1D, [], handles)
230CheckScalar_Callback(handles.CheckScalar, [], handles)
231CheckVector_Callback(handles.CheckVector, [], handles)
232
233%------------------------------------------------------------------------
234% --- Outputs from this function are returned to the command line.
235function varargout = get_field_OutputFcn(hObject, eventdata, handles)
236%------------------------------------------------------------------------
237varargout{1} = handles.output;
238delete(handles.get_field)
239
240
241% -----------------------------------------------------------------------
242% --- Activated by selection in the list of variables
243function variables_Callback(hObject, eventdata, handles)
244% -----------------------------------------------------------------------
245Tabchar={''};%default
246Tabcell=[];
247hselect_field=get(handles.variables,'parent');
248Field=get(handles.get_field,'UserData');
249index=get(handles.variables,'Value');%index in the list 'variables'
250
251%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
252if isequal(index,1)
253    set(handles.attributes_txt,'String','global attributes')
254    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
255        for iline=1:length(Field.ListGlobalAttribute)
256            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
257            if isfield(Field, Field.ListGlobalAttribute{iline})
258                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
259                if ischar(val);% attribute value is char string
260                    Tabcell{iline,2}=val;
261                elseif size(val,1)==1 %attribute value is a number or matlab vector
262                    Tabcell{iline,2}=num2str(val);
263                end
264            end
265        end
266        Tabchar=cell2tab(Tabcell,'=');
267    end
268%% list Attribute names and values associated to the Variable # index-1   
269else
270    list_var=get(handles.variables,'String');
271    var_select=list_var{index};
272    set(handles.attributes_txt,'String', ['attributes of ' var_select])
273    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
274%         nbline=0;
275        VarAttr=Field.VarAttribute{index-1};
276        if isstruct(VarAttr)
277            attr_list=fieldnames(VarAttr);
278            for iline=1:length(attr_list)
279                Tabcell{iline,1}=attr_list{iline};
280                eval(['val=VarAttr.' attr_list{iline} ';'])
281                if ischar(val);
282                    Tabcell{iline,2}=val;
283                else
284                     Tabcell{iline,2}=num2str(val);
285                end
286            end
287        end
288    end
289
290end
291if ~isempty(Tabcell)
292    Tabchar=cell2tab(Tabcell,'=');
293    Tabchar=[{''};Tabchar];
294end
295set(handles.attributes,'Value',1);% select the first item
296set(handles.attributes,'String',Tabchar);
297
298%% update dimensions;
299if isfield(Field,'ListDimName')
300    Tabdim={};%default
301    if isequal(index,1)%list all dimensions
302        dim_indices=1:length(Field.ListDimName);
303        set(handles.dimensions_txt,'String', 'dimensions')
304    else
305        DimCell=Field.VarDimName{index-1};
306        if ischar(DimCell)
307            DimCell={DimCell};
308        end   
309        dim_indices=[];
310        for idim=1:length(DimCell)
311            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
312            dim_index=find(dim_index,1);
313            dim_indices=[dim_indices dim_index];
314        end
315        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
316    end
317    for iline=1:length(dim_indices)
318        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
319        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
320    end
321    Tabchar=cell2tab(Tabdim,' = ');
322    Tabchar=[{''} ;Tabchar];
323    set(handles.dimensions,'Value',1)
324    set(handles.dimensions,'String',Tabchar) 
325end 
326
327
328
329%------------------------------------------------------------------------
330% --- Executes on button press in CheckPlot1D.
331function CheckPlot1D_Callback(hObject, eventdata, handles)
332%------------------------------------------------------------------------
333val=get(handles.CheckPlot1D,'Value');
334if isequal(val,0)
335    set(handles.Panel1Dplot,'Visible','off')
336else
337    set(handles.Panel1Dplot,'Visible','on')
338    set(handles.PanelScalar,'Visible','off')
339    set(handles.CheckScalar,'Value',0)
340    set(handles.PanelVectors,'Visible','off')
341    set(handles.CheckVector,'Value',0)
342    set(handles.XVarName,'Visible','on')
343    set(handles.SwitchVarIndexX,'Visible','on')
344    set(handles.X_title,'Visible','on')
345    set(handles.YVarName,'Visible','off')
346    set(handles.SwitchVarIndexY,'Visible','off')
347    set(handles.Y_title,'Visible','off')
348    set(handles.ZVarName,'Visible','off')
349    set(handles.SwitchVarIndexZ,'Visible','off')
350    set(handles.Z_title,'Visible','off')
351    ordinate_Callback(hObject, eventdata, handles)
352end
353
354%------------------------------------------------------------------------
355function ordinate_Callback(hObject, eventdata, handles)
356%------------------------------------------------------------------------
357Field=get(handles.get_field,'UserData');
358list=get(handles.ordinate,'String');
359yindex=get(handles.ordinate,'Value');
360yindex=name2index(list{yindex(1)},Field.ListVarName);
361if ~isempty(yindex)
362    set(handles.variables,'Value',yindex+1)
363    variables_Callback(hObject, eventdata, handles)
364end
365[CellInfo,NbDim,errormsg]=find_field_cells(Field);
366%[CellVarIndex,NbDim,VarRole,errormsg]=find_field_cells(Field);
367for icell=1:numel(CellInfo)
368    VarIndex=CellInfo{icell}.VarIndex;
369    if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarRole{icell}.coord_x)||~isequal(VarRole{icell}.coord_x,VarIndex))
370        cell_select=icell;
371        break
372    end
373end
374val=get(handles.abscissa,'Value');
375set(handles.abscissa,'Value',min(val,2));
376coord_x_index=VarRole{cell_select}.coord;
377coord_x_index=coord_x_index(coord_x_index~=0);
378set(handles.XVarname,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
379
380%------------------------------------------------------------------------
381% --- Executes on button press in CheckScalar.
382function CheckScalar_Callback(hObject, eventdata, handles)
383%------------------------------------------------------------------------
384val=get(handles.CheckScalar,'Value');
385if isequal(val,0)
386    set(handles.PanelScalar,'Visible','off')
387else
388    set(handles.Panel1Dplot,'Visible','off')
389    set(handles.CheckPlot1D,'Value',0)
390    set(handles.PanelScalar,'Visible','on')
391    set(handles.PanelVectors,'Visible','off')
392    set(handles.CheckVector,'Value',0)
393end
394
395%------------------------------------------------------------------------
396% --- Executes on button press in CheckVector.
397function CheckVector_Callback(hObject, eventdata, handles)
398%------------------------------------------------------------------------
399val=get(handles.CheckVector,'Value');
400if isequal(val,0)
401    set(handles.PanelVectors,'Visible','off')
402else
403    set(handles.Panel1Dplot,'Visible','off')
404    set(handles.CheckPlot1D,'Value',0)
405    set(handles.PanelScalar,'Visible','off')
406    set(handles.CheckScalar,'Value',0)
407    set(handles.PanelVectors,'Visible','on')
408    set(handles.XVarName,'Visible','on')
409    set(handles.YVarName,'Visible','on')
410    set(handles.X_title,'Visible','on')
411    set(handles.Y_title,'Visible','on')
412end
413
414
415%------------------------------------------------------------------------
416% --- Executes on selection change in scalar menu.
417function scalar_Callback(hObject, eventdata, handles)
418%------------------------------------------------------------------------
419Field=get(handles.get_field,'UserData');
420index=get(handles.scalar,'Value');
421string=get(handles.scalar,'String');
422VarName=string{index};
423update_field(hObject, eventdata, handles,VarName)
424
425%eliminate time
426TimeDimName='';%default
427SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
428TimeVarOption=SwitchVarIndexTime{get(handles.SwitchVarIndexTime,'Value')};
429if strcmp(TimeVarOption,'variable')
430    List=get(handles.TimeVarName,'String');
431    TimeVarName=List{get(handles.TimeVarName,'Value')};
432elseif  strcmp(TimeVarOption,'dim index')
433    List=get(handles.TimeVarName,'String');
434    TimeDimName=List{get(handles.TimeVarName,'Value')};
435end
436% A completer
437% if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on')
438%     TimeDimList=get(handles.TimeDimensionMenu,'String');
439%     TimeDimIndex=get(handles.TimeDimensionMenu,'Value');
440%     TimeDimName=TimeDimList{TimeDimIndex};
441% end
442
443%check possible coordinates
444Field=get(handles.get_field,'UserData');
445dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar
446test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
447for ilist=1:numel(Field.VarDimName)
448    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
449    if isequal(dimnames,TimeDimName)
450        test_coord(ilist)=0;%mark time variables fo elimination
451    end
452    if ischar(dimnames)
453        dimnames={dimnames};
454    end
455    for idim=1:numel(dimnames)
456        if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable
457            test_coord(ilist)=0;
458            break
459        end
460    end
461end
462test_coord(index)=0;%the coordinate variable must be different from the scalar
463
464string_coord=[{''};string(test_coord==1)];
465val=get(handles.XVarName,'Value');
466if val>numel(string_coord)
467    set(handles.XVarName,'Value',1)
468end
469set(handles.XVarName,'String',string_coord);
470val=get(handles.ZVarName,'Value');
471if val>numel(string_coord)
472    set(handles.ZVarName,'Value',1)
473end
474set(handles.ZVarName,'String',string_coord);
475val=get(handles.ZVarName,'Value');
476if val>numel(string_coord)
477    set(handles.ZVarName,'Value',1)
478end
479set(handles.YVarName,'String',string_coord);
480
481
482%------------------------------------------------------------------------
483% --- Executes on selection change in abscissa.
484function abscissa_Callback(hObject, eventdata, handles)
485%------------------------------------------------------------------------
486 hselect_field=get(handles.inputfile,'parent');
487 Field=get(hselect_field,'UserData');%current input field
488 xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
489% test_2D=get(handles.CheckVector,'Value');% =1 for vector fields
490% test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields
491%if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa
492%     Txt=Field.ListVarName;
493%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
494%     xindex=[];
495% else
496     xlist=get(handles.abscissa,'String');%list of abscissa
497     VarName=xlist{xdispindex}; %selected variable name
498     update_field(hObject, eventdata, handles,VarName)
499%      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
500%      if ~isempty(xindex)
501%         set(handles.variables,'Value',xindex+1)
502%         variables_Callback(hObject, eventdata, handles)
503%      end
504%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
505%     variables_Callback(hObject, eventdata, handles)  %display properties of the TimeVariable (dim, attributes)
506%     if  ~test_2D &  ~test_scalar% look for possible varaibles to OK in ordinate   
507%         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
508%         VarIndex=[];
509%         for ilist=1:length(Field.VarDimIndex)%detect
510%             index_i=Field.VarDimIndex{ilist};
511%             if ~isempty(index_i)
512%                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, OK is possible
513%                     VarIndex=[VarIndex ilist];
514%                 end
515%             end
516%         end
517% %         set(handles.ordinate,'Value',1)
518%         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
519%     end
520% end
521%
522% update_UserData(handles)
523
524
525
526%------------------------------------------------------------------------
527% --- Executes on selection change in XVarName.
528function XVarName_Callback(hObject, eventdata, handles)
529%------------------------------------------------------------------------
530index=get(handles.XVarName,'Value');
531string=get(handles.XVarName,'String');
532VarName=string{index};
533update_field(hObject, eventdata, handles,VarName)
534
535%------------------------------------------------------------------------
536% --- Executes on selection change in ZVarName.
537function ZVarName_Callback(hObject, eventdata, handles)
538%------------------------------------------------------------------------
539index=get(handles.ZVarName,'Value');
540string=get(handles.ZVarName,'String');
541VarName=string{index};
542update_field(hObject, eventdata, handles,VarName)
543
544%------------------------------------------------------------------------
545% --- Executes on selection change in YVarName.
546function YVarName_Callback(hObject, eventdata, handles)
547%------------------------------------------------------------------------
548index=get(handles.YVarName,'Value');
549string=get(handles.YVarName,'String');
550VarName=string{index};
551update_field(hObject, eventdata, handles,VarName)
552
553%------------------------------------------------------------------------
554% --- Executes on selection change in vector_x.
555function vector_x_Callback(hObject, eventdata, handles)
556%------------------------------------------------------------------------
557index=get(handles.vector_x,'Value');
558string=get(handles.vector_x,'String');
559VarName=string{index};
560
561%check possible coordinates
562Field=get(handles.get_field,'UserData');
563dim_var=Field.VarDimName{index};%list of dimensions of the selected variable
564test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
565test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component
566for ilist=1:numel(Field.VarDimName)
567    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
568    if ~isequal(dimnames,dim_var)
569        test_component(ilist)=0;
570    end
571    for idim=1:numel(dimnames)
572        if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable
573            test_coord(ilist)=0;
574            break
575        end
576    end
577end
578%eliminate time
579if get(handles.TimeVariable,'Value')
580    TimeName=get(handles.TimeName,'String');
581    index_time=find(strcmp( TimeName,Field.ListVarName));
582    test_coord(index_time)=0;
583end
584vlength=numel(string(test_component==1));
585val=get(handles.vector_y,'Value');
586if val>vlength
587    set(handles.vector_y,'Value',1)
588end
589set(handles.vector_y,'String',[string(test_component==1)])
590val=get(handles.vector_z,'Value');
591if val>vlength+1
592    set(handles.vector_z,'Value',1)
593end
594set(handles.vector_z,'String',[{''};string(test_component==1)])
595val=get(handles.vec_color,'Value');
596if val>vlength+1
597    set(handles.vec_color,'Value',1)
598end
599set(handles.vec_color,'String',[{''};string(test_component==1)])
600string_coord=[{''};string(test_coord==1)];
601val=get(handles.XVarName,'Value');
602if val>numel(string_coord)
603    set(handles.XVarName,'Value',1)
604end
605set(handles.XVarName,'Visible','on');
606set(handles.XVarName,'String',string_coord);
607val=get(handles.YVarName,'Value');
608if val>numel(string_coord)
609    set(handles.YVarName,'Value',1)
610end
611set(handles.YVarName,'Visible','on');
612set(handles.YVarName,'String',string_coord);
613val=get(handles.TimeVarName,'Value');
614if val>numel(string_coord)
615    set(handles.TimeVarName,'Value',1)
616end
617set(handles.TimeVarName,'String',string_coord);
618
619update_field(hObject, eventdata, handles,VarName)
620
621%------------------------------------------------------------------------
622% --- Executes on selection change in vector_y.
623function vector_y_Callback(hObject, eventdata, handles)
624%------------------------------------------------------------------------
625index=get(handles.vector_y,'Value');
626string=get(handles.vector_y,'String');
627VarName=string{index};
628update_field(hObject, eventdata, handles,VarName)
629
630%------------------------------------------------------------------------
631% --- Executes on selection change in vector_z.
632function vector_z_Callback(hObject, eventdata, handles)
633%------------------------------------------------------------------------
634index=get(handles.vector_z,'Value');
635string=get(handles.vector_z,'String');
636VarName=Astring{index};
637update_field(hObject, eventdata, handles,VarName)
638
639%------------------------------------------------------------------------
640% --- Executes on selection change in coord_x_vectors.
641function coord_x_vectors_Callback(hObject, eventdata, handles)
642%------------------------------------------------------------------------
643index=get(handles.coord_x_vectors,'Value');
644string=get(handles.coord_x_vectors,'String');
645VarName=string{index};
646update_field(hObject, eventdata, handles,VarName)
647
648%------------------------------------------------------------------------
649% --- Executes on selection change in coord_y_vectors.
650function coord_y_vectors_Callback(hObject, eventdata, handles)
651%------------------------------------------------------------------------
652index=get(handles.coord_y_vectors,'Value');
653string=get(handles.coord_y_vectors,'String');
654VarName=string{index};
655update_field(hObject, eventdata, handles,VarName)
656
657%------------------------------------------------------------------------
658% --- Executes on selection change in YVarName.
659function TimeVarName_Callback(hObject, eventdata, handles)
660%------------------------------------------------------------------------
661index=get(handles.TimeVarName,'Value');
662string=get(handles.TimeVarName,'String');
663VarName=string{index};
664update_field(hObject, eventdata, handles,VarName)
665
666%------------------------------------------------------------------------
667% --- Executes on selection change in vec_color.
668function vec_color_Callback(hObject, eventdata, handles)
669%------------------------------------------------------------------------
670index=get(handles.vec_color,'Value');
671string=get(handles.vec_color,'String');
672VarName=string{index};
673update_field(hObject, eventdata, handles,VarName)
674
675%-----------------------------------------------------------------------
676function update_field(hObject, eventdata, handles,VarName)
677%-----------------------------------------------------------------------
678Field=get(handles.get_field,'UserData');
679index=name2index(VarName,Field.ListVarName);
680if ~isempty(index)
681    set(handles.variables,'Value',index+1)
682    variables_Callback(hObject, eventdata, handles)
683end
684
685%------------------------------------------------------------------------
686% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
687function update_UserData(handles)
688%------------------------------------------------------------------------
689return
690% global SubField
691hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
692Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
693if isfield(Field,'VarAttribute')
694    VarAttribute=Field.VarAttribute;
695else
696    VarAttribute={};
697end
698
699
700% select the indices of field variables for 2D plots
701test_CheckPlot1D=get(handles.CheckPlot1D,'Value');
702test_scalar=get(handles.CheckScalar,'Value');
703test_vector=get(handles.CheckVector,'Value');
704
705%transform if needed (calibration)
706list=get(handles.menu_coord,'String');
707index=get(handles.menu_coord,'Value');
708transform=list{index};
709if ~isequal(transform,'')
710    Field=feval(transform,Field);
711end
712VarIndex.u=[];
713VarIndex.v=[];
714VarIndex.w=[];
715VarIndex.A=[];
716VarIndex_tot=[];
717iuA=[];
718if test_scalar
719    Astring=get(handles.scalar,'String');
720    Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
721    list_var=Astring(Aindex);
722    VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
723    VarIndex_tot= [VarIndex_tot VarIndex.A];
724    DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
725    DimValue=Field.DimValue(DimIndex);
726    ind=find(DimValue==1);
727    DimIndex(ind)=[];%Mremove singleton
728end
729if test_vector
730    Ustring=get(handles.vector_x,'String');
731    Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
732    list_var=Ustring{Uindex};%name of the selected scalar
733    VarIndex.u=name2index(list_var,Field.ListVarName);
734    Vstring=get(handles.vector_y,'String');
735    Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
736    list_var=Ustring{Vindex};%name of the selected scalar
737    VarIndex.v=name2index(list_var,Field.ListVarName);
738    if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
739        iuA=VarIndex.A; %same variable used for vector and scalar
740        VarIndex_tot(iuA)=[];
741    end
742    VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
743    %dimensions
744    DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
745    DimValue=Field.DimValue(DimIndex_u);
746    ind=find(DimValue==1);
747    DimIndex_u(ind)=[];%Mremove singleton
748    DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
749    DimValue=Field.DimValue(DimIndex_v);
750    ind=find(DimValue==1);
751    DimIndex_v(ind)=[];%Mremove singleton
752    if ~isequal(DimIndex_u,DimIndex_v)
753        msgbox_uvmat('ERROR','inconsistent dimensions for u and v')
754        set(handles.vector_y,'Value',1);
755        return
756    elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
757         msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color')
758         set(handles.scalar,'Value',1);
759         return
760    end
761    DimIndex=DimIndex_u;
762    %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components
763end
764
765
766% select the TimeVariable  index (or indices) for z coordinates
767test_grid=0;
768if test_scalar | test_vector
769    nbdim=length(DimIndex);
770    if nbdim > 3
771        msgbox_uvmat('ERROR','array with more than three dimensions, not supported')
772        return
773    else
774        perm_ind=1:nbdim;
775    end
776    if nbdim==3
777        zstring=get(handles.coord_z_vectors_scalar,'String');
778        zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
779        list_var=zstring(zindex);
780        VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
781        if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
782            if zindex ~= 1
783                set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
784                return
785            end
786        else
787            VarIndex_tot=[VarIndex_tot VarIndex_z];
788            DimIndex_z=Field.VarDimIndex{VarIndex_z};
789            DimValue=Field.DimValue(DimIndex_z);
790            ind=find(DimValue==1);         
791            DimIndex_z(ind)=[];%Mremove singleton
792            if isequal(DimIndex_z,DimIndex)
793                VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
794            elseif length(DimIndex_z)==1
795                VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
796                ind_z=find(DimIndex==DimIndex_z(1));
797                perm_ind(ind_z)=1;
798                test_grid=1;
799            else
800                msgbox_uvmat('ERROR','multiple dimensions for the z coordinate')
801                return
802            end
803        end
804%         if ~isempty(VarIndex_z)
805%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable   
806%             if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable
807%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
808%                 ind_z=find(DimIndex==DimIndex_z(1));
809%                 perm_ind(ind_z)=1;
810%                 test_grid=1;
811%             end
812%         end
813    end
814end
815
816% select the TimeVariable  index (or indices) for ordinate
817ystring=get(handles.ordinate,'String');
818yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
819list_var=ystring(yindex);
820VarIndex.y=name2index(list_var,Field.ListVarName);
821if isequal(VarIndex.A,VarIndex.y)
822    set(handles.ZVarName,'Value',1)
823elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
824   set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
825else
826    for ivar=1:length(VarIndex.y)
827        VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
828    end
829    VarIndex_tot=[VarIndex_tot VarIndex.y];
830end
831if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
832    DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
833    if length(DimIndex_y)==1
834        ind_y=find(DimIndex==DimIndex_y(1));
835        test_grid=1;
836        if nbdim==3
837            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
838            perm_ind(ind_y)=2;
839        elseif nbdim==2
840            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
841             perm_ind(ind_y)=1;
842        end
843    elseif test_grid
844        msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1')   
845    end
846end
847
848%select the TimeVariable index for the abscissa
849xstring=get(handles.abscissa,'String');
850xindex=get(handles.abscissa,'Value');
851list_var=xstring(xindex);
852VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
853if length(VarIndex.x)==1   
854    DimIndex_x=Field.VarDimIndex{VarIndex.x};
855    DimValue=Field.DimValue(DimIndex_x);
856    ind=find(DimValue==1);         
857    DimIndex_x(ind)=[];%Mremove singleton                     
858    VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
859%     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
860    index_detect=find(VarIndex_tot==VarIndex.x);
861else
862    index_detect=[];%coord x variable not already used
863end
864if isempty(index_detect)
865    VarIndex_tot=[VarIndex_tot VarIndex.x];
866elseif ~test_CheckPlot1D
867    VarIndex.x=[];
868    set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
869end
870
871if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
872    DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
873    if length(DimIndex_x)==1
874        ind_x=find(DimIndex==DimIndex_x(1));
875        if nbdim==3
876            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
877            perm_ind(ind_x)=3;
878        elseif nbdim==2
879            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
880             perm_ind(ind_x)=2;
881        end
882        if isequal(perm_ind,1:nbdim)
883            test_grid=0;
884        end
885        DimIndex=DimIndex(perm_ind);
886    elseif test_grid
887        msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1')   
888    end
889    if isequal(DimIndex_x,DimIndex)
890                VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
891    end
892end
893
894%defined the selected sub-field SubField
895SubField.ListGlobalAttribute{1}='InputFile';
896SubField.InputFile=get(handles.inputfile,'String');
897SubField.ListDimName=Field.ListDimName;
898SubField.DimValue=Field.DimValue;
899SubField.ListVarName=Field.ListVarName(VarIndex_tot);
900SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
901
902testperm=0;
903testattr=0;
904for ivar=VarIndex.u
905    VarAttribute{ivar}.Role='vector_x';
906    testattr=1;
907    if test_grid
908        VarDimIndex{ivar}=DimIndex; %permute dimensions
909        testperm=1;
910    end
911end
912for ivar=VarIndex.v
913    VarAttribute{ivar}.Role='vector_y';
914    testattr=1;
915     if test_grid
916        VarDimIndex{ivar}=DimIndex;%permute dimensions
917        testperm=1;
918    end
919end
920for ivar=VarIndex.A
921    if test_grid
922        VarDimIndex{ivar}=DimIndex;%permute dimensions
923        testperm=1;
924    end
925    if isempty(iuA)
926        VarAttribute{ivar}.Role='scalar';%Role =scalar
927        testattr=1;
928    else
929       VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
930       nbattr=length(VarAttribute);
931       VarAttribute{nbattr}.Role='scalar';
932       testattr=1;
933    end
934end
935if testperm
936    SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
937end
938if testattr
939    SubField.VarAttribute=VarAttribute(VarIndex_tot);
940end
941set(hselect_field,'UserData',Field)
942
943%---------------------------------------------------------
944% --- Executes on button press in OK.
945
946function OK_Callback(hObject, eventdata, handles)
947%---------------------------------------------------------
948
949handles.output=read_GUI(handles.get_field);
950guidata(hObject, handles);% Update handles structure
951uiresume(handles.get_field);
952drawnow
953return
954
955%%%% SKIPPED %%%%
956hfield=[];
957huvmat=findobj(allchild(0),'tag','uvmat');
958hseries=findobj(allchild(0),'tag','series');
959check_series=0;
960% look for the status of the GUI uvmat
961if ~isempty(huvmat)
962    hh=guidata(huvmat);
963    FieldMenu=get(hh.FieldName,'String');
964    FieldName=FieldMenu{get(hh.FieldName,'Value')};
965    if strcmp(FieldName,'get_field...')
966        hfield=hh.FieldName; %FieldName on uvmat
967    elseif strcmp(get(hh.FieldName_1,'Visible'),'on')
968        FieldMenu=get(hh.FieldName_1,'String');
969        if ~isempty(FieldMenu)
970            FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
971            if strcmp(FieldName,'get_field...')
972                hfield=hh.FieldName_1; %FieldName_1 on uvmat
973            end
974        end
975    end
976end
977% if no filed data is concerned on uvmat, look at the GUI series
978if isempty(hfield) && ~isempty(hseries)
979    check_series=1;
980    hh=guidata(hseries);
981    FieldMenu=get(hh.FieldName,'String');
982    FieldName=FieldMenu{get(hh.FieldName,'Value')};
983    if strcmp(FieldName,'get_field...')
984        hfield=hh.FieldName; %FieldName on series
985    else
986       FieldMenu=get(hh.FieldName_1,'String');
987       FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
988       if strcmp(FieldName,'get_field...')
989            hfield=hh.FieldName_1; %FieldName_1 on series
990       end
991    end
992end
993if ~isempty(hfield)
994    get_field_GUI=read_GUI(handles.get_field);
995    if isfield(get_field_GUI,'PanelVectors')
996        set(hh.Coord_x,'value',1)
997        set(hh.Coord_y,'value',1)
998        set(hh.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors})
999        set(hh.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors})
1000        UName=get_field_GUI.PanelVectors.vector_x;
1001        VName=get_field_GUI.PanelVectors.vector_y;
1002        menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}];
1003        menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}];
1004        set(hfield,'Value',1)
1005        set(hfield,'String',menu_str)
1006        if ~check_series
1007            ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color));
1008            if ~isempty(ind_menu)
1009                set(hh.ColorScalar,'Value',ind_menu)
1010            else
1011                set(hh.ColorScalar,'Value',1)
1012            end
1013            set(hh.ColorScalar,'String',menu_color)
1014        end
1015    elseif isfield(get_field_GUI,'PanelScalar')
1016        set(hh.Coord_x,'value',1)
1017        set(hh.Coord_y,'value',1)
1018        set(hh.Coord_x,'String',{get_field_GUI.PanelScalar.coord_x_scalar})
1019        set(hh.Coord_y,'String',{get_field_GUI.PanelScalar.coord_y_scalar})
1020        AName=get_field_GUI.PanelScalar.scalar;
1021        menu=get(hfield,'String');
1022        ind_select=find(strcmp(AName,menu));
1023        if isempty(ind_select)
1024            menu=[menu(1:end-1);{AName};{'get_field...'}];
1025            ind_select=numel(menu)-1;
1026        end
1027        set(hfield,'Value',ind_select);
1028        set(hfield,'String',menu);
1029    elseif isfield(get_field_GUI,'Panel1Dplot')
1030        set(hh.Coord_x,'Value',1)
1031        set(hh.Coord_x,'String',{get_field_GUI.Panel1Dplot.abscissa})
1032        set(hh.Coord_y,'String',get_field_GUI.Panel1Dplot.ordinate)
1033        set(hh.Coord_y,'Max', numel(get_field_GUI.Panel1Dplot.ordinate))
1034        set(hh.Coord_y,'Value',1:numel(get_field_GUI.Panel1Dplot.ordinate))
1035        set(hfield,'Value',1)
1036        set(hfield,'String',[{''};{'get_field...'}])
1037    end
1038    if  ~check_series && strcmp(get(gcbf,'tag'),'get_field')%get_field is not called by another GUI (uvmat)
1039        uvmat('run0_Callback',hObject,eventdata,hh); %refresh uvmat
1040    end
1041end
1042delete(handles.get_field)
1043
1044
1045
1046% %------------------------------------------------------------------------
1047% function mouse_up_gui(ggg,eventdata,handles)
1048% %------------------------------------------------------------------------
1049% if isequal(get(ggg,'SelectionType'),'alt')
1050%     message=''; 
1051%     global CurData
1052%     inputfield=get(handles.inputfile,'String');
1053%     if exist(inputfield,'file')
1054%         CurData=nc2struct(inputfield);
1055%     else
1056%         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1057%     end
1058%   %%%% TODO: put the matalb command window in front
1059%     evalin('base','global CurData')%make CurData global in the workspace
1060%     evalin('base','CurData') %display CurData in the workspace
1061% end
1062
1063%------------------------------------------------------------------------
1064% --- Executes on selection change in ACTION.
1065%------------------------------------------------------------------------
1066function ACTION_Callback(hObject, eventdata, handles)
1067global nb_builtin
1068list_ACTION=get(handles.ACTION,'String');% list menu fields
1069index_ACTION=get(handles.ACTION,'Value');% selected string index
1070ACTION= list_ACTION{index_ACTION}; % selected string
1071list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
1072ff=functions(list_func_handles{end});
1073% add a new function to the menu
1074if isequal(ACTION,'more...')
1075    [FileName, PathName] = uigetfile( ...
1076       {'*.m', ' (*.m)';
1077        '*.m',  '.m files '; ...
1078        '*.*', 'All Files (*.*)'}, ...
1079        'Pick a file',ff.file);
1080    if length(FileName)<2
1081        return
1082    end
1083    [pp,ACTION,ext_fct]=fileparts(FileName);
1084    if ~isequal(ext_fct,'.m')
1085        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1086        return
1087    end
1088
1089    % insert the choice in the action menu
1090   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1091   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1092   addpath(PathName)
1093   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
1094   set(handles.ACTION,'UserData',list_func_handles)
1095   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1096   %list_path{index_ACTION}=PathName;
1097   if length(menu_str)>nb_builtin+5;
1098       nbremove=length(menu_str)-nb_builtin-5;
1099       menu_str(nb_builtin+1:end-5)=[];
1100       list_func_handles(nb_builtin+1:end-4)=[];
1101       index_ACTION=index_ACTION-nbremove;
1102       set(handles.ACTION,'Value',index_ACTION)
1103       set(handles.ACTION,'String',menu_str)
1104   end   
1105   %record the current menu in personal file profil_perso
1106   dir_perso=prefdir;
1107   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1108   get_field_fct={};
1109   for ilist=nb_builtin+1:length(menu_str)-1
1110       ff=functions(list_func_handles{ilist});
1111       get_field_fct{ilist-nb_builtin}=ff.file;
1112   end
1113   if exist(profil_perso,'file')
1114        save(profil_perso,'get_field_fct','-append')
1115   else
1116     txt=ver('MATLAB');
1117    Release=txt.Release;
1118       relnumb=str2num(Release(3:4));
1119        if relnumb >= 14
1120            save(profil_perso,'get_field_fct','-V6')
1121        else
1122            save(profil_perso, 'get_field_fct')
1123        end
1124   end
1125end
1126
1127%check the current path to the selected function
1128h_fun=list_func_handles{index_ACTION};
1129if isa(h_fun,'function_handle')
1130    func=functions(h_fun);
1131    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
1132    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
1133else
1134    set(handles.path_action,'String','')
1135    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
1136    return
1137end
1138
1139%prepare the GUI options for the selected ACTION
1140test_1Dplot=0;
1141test_scalar=0;
1142test_vector=0;
1143if iscell(GUI_input)
1144    for ilist=1:size(GUI_input,1)
1145        switch GUI_input{ilist,1}
1146                           %RootFile always visible
1147            case 'CheckPlot1D'   
1148                 test_1Dplot=isequal(GUI_input{ilist,2},'on');
1149            case 'CheckScalar'
1150                 test_scalar=isequal(GUI_input{ilist,2},'on');   
1151            case 'CheckVector'   
1152                 test_vector=isequal(GUI_input{ilist,2},'on');
1153        end
1154    end
1155end
1156set(handles.CheckPlot1D,'Value',test_1Dplot);
1157set(handles.CheckScalar,'Value',test_scalar);
1158set(handles.CheckVector,'Value',test_vector);
1159CheckPlot1D_Callback(hObject, eventdata, handles)
1160CheckScalar_Callback(hObject, eventdata, handles)
1161CheckVector_Callback(hObject, eventdata, handles)
1162
1163
1164%-----------------------------------------------------
1165% --- browse existing figures
1166%-----------------------------------------------------
1167function browse_fig(menu_handle)
1168hh=findobj(allchild(0),'Type','figure');
1169ilist=0;
1170list={};
1171for ifig=1:length(hh)  %look for all existing figures
1172    name=get(hh(ifig),'Name');
1173     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
1174        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1175        nbaxe=0;
1176        for ichild=1:length(hchild)           
1177            Type=get(hchild(ichild),'Type');
1178            Tag=get(hchild(ichild),'Tag');
1179            if isequal(Type,'axes')
1180                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1181                     nbaxe=nbaxe+1;%count the existing axis
1182                end
1183            end
1184        end   
1185        if nbaxe==1
1186             ilist=ilist+1;%add a line in the list of axis
1187            list{ilist,1}=num2str(hh(ifig));
1188        elseif nbaxe>1
1189            for iaxe=1:nbaxe
1190               ilist=ilist+1;%add a line in the list of axis
1191               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1192            end
1193        end
1194     end
1195end
1196list=['uvmat';list];
1197set(menu_handle,'Value',1)
1198set(menu_handle,'String',list)
1199
1200
1201%-----------------------------------------------------
1202function list_fig_Callback(hObject, eventdata, handles)
1203%-----------------------------------------------------
1204list_fig=get(handles.list_fig,'String');
1205fig_val=get(handles.list_fig,'Value');
1206plot_fig=list_fig{fig_val};
1207if strcmp(plot_fig,'view_field')
1208%     huvmat=findobj(allchild(0),'name','uvmat');
1209%     if ~isempty(huvmat)
1210%         uistack(huvmat,'top')
1211%     end   
1212else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1213    sep=regexp(plot_fig,'_');
1214    if ~isempty(sep)
1215        plot_fig=plot_fig([1:sep-1]);
1216    end
1217    if ishandle(str2num(plot_fig))
1218        figure(str2num(plot_fig))% display existing figure
1219    else
1220        browse_fig(handles.list_fig); %reset the current list of figures
1221    end
1222end
1223
1224
1225%-------------------------------------------------
1226% give index numbers of the strings str in the list ListvarName
1227function VarIndex_y=name2index(cell_str,ListVarName)
1228VarIndex_y=[];
1229if ischar(cell_str)
1230    for ivar=1:length(ListVarName)
1231        varlist=ListVarName{ivar};
1232        if isequal(varlist,cell_str)
1233            VarIndex_y= ivar;
1234            break
1235        end
1236    end
1237elseif iscell(cell_str)
1238    for isel=1:length(cell_str)
1239        varsel=cell_str{isel};
1240        for ivar=1:length(ListVarName)
1241            varlist=ListVarName{ivar};
1242            if isequal(varlist,varsel)
1243                VarIndex_y=[VarIndex_y ivar];
1244            end
1245        end
1246    end
1247end
1248
1249% --------------------------------------------------------------------
1250function MenuOpen_Callback(hObject, eventdata, handles)
1251% hObject    handle to MenuOpen (see GCBO)
1252% eventdata  reserved - to be defined in a future version of MATLAB
1253% handles    structure with handles and user data (see GUIDATA)
1254
1255
1256% --------------------------------------------------------------------
1257function MenuExport_Callback(hObject, eventdata, handles)
1258% hObject    handle to MenuExport (see GCBO)
1259% eventdata  reserved - to be defined in a future version of MATLAB
1260% handles    structure with handles and user data (see GUIDATA)
1261
1262
1263% --------------------------------------------------------------------
1264function MenuBrowse_Callback(hObject, eventdata, handles)
1265
1266oldfile=get(handles.inputfile,'String');
1267testrootfile=0;
1268testsubdir=0;
1269if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1270        oldfile='';
1271        dir_perso=prefdir;
1272         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1273         if exist(profil_perso,'file')
1274              h=load (profil_perso);
1275             if isfield(h,'RootPath')
1276                  RootPath=h.RootPath;
1277             end
1278             if isfield(h,'SubDir')
1279                  SubDir=h.SubDir;
1280                  if ~isempty(SubDir)
1281                    testsubdir=1;
1282                  end
1283             end
1284             if isfield(h,'RootFile')
1285                  RootFile=h.RootFile;
1286                  if ~isempty(RootFile)
1287                    testrootfile=1;
1288                  end
1289             end
1290         end
1291end
1292if testrootfile
1293    if ~testsubdir
1294        oldfile=fullfile(RootPath,RootFile);
1295    else
1296        oldfile=fullfile(RootPath,SubDir,RootFile);
1297    end
1298end
1299[FileName, PathName] = uigetfile( ...
1300       {'*.nc', ' *.nc';...
1301       '*.cdf', ' *.cdf';...
1302        '*.*',  'All Files (*.*)'}, ...
1303        'Pick a file',oldfile);
1304
1305%global inputfile
1306fileinput=[PathName FileName];%complete file name
1307sizf=size(fileinput);
1308if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1309set(handles.inputfile,'String',fileinput)
1310inputfile_Callback(hObject, eventdata, handles)
1311
1312%update list of recent files in the menubar
1313MenuFile_1=fileinput;
1314MenuFile_2=get(handles.MenuFile_1,'Label');
1315MenuFile_3=get(handles.MenuFile_2,'Label');
1316MenuFile_4=get(handles.MenuFile_3,'Label');
1317MenuFile_5=get(handles.MenuFile_4,'Label');
1318set(handles.MenuFile_1,'Label',MenuFile_1)
1319set(handles.MenuFile_2,'Label',MenuFile_2)
1320set(handles.MenuFile_3,'Label',MenuFile_3)
1321set(handles.MenuFile_4,'Label',MenuFile_4)
1322set(handles.MenuFile_5,'Label',MenuFile_5)
1323dir_perso=prefdir;
1324profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1325display(profil_perso)
1326if exist(profil_perso,'file')
1327    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1328else
1329    txt=ver('MATLAB');
1330    Release=txt.Release;
1331    relnumb=str2double(Release(3:4));
1332    if relnumb >= 14
1333        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1334    else
1335        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1336    end
1337end
1338
1339% --------------------------------------------------------------------
1340function MenuFile_1_Callback(hObject, eventdata, handles)
1341fileinput=get(handles.MenuFile_1,'Label');
1342set(handles.inputfile,'String',fileinput)
1343inputfile_Callback(hObject, eventdata, handles)
1344
1345% --------------------------------------------------------------------
1346function MenuFile_2_Callback(hObject, eventdata, handles)
1347fileinput=get(handles.MenuFile_2,'Label');
1348set(handles.inputfile,'String',fileinput)
1349inputfile_Callback(hObject, eventdata, handles)
1350
1351% -----------------------------------------------------------------------
1352function MenuFile_3_Callback(hObject, eventdata, handles)
1353% -----------------------------------------------------------------------
1354fileinput=get(handles.MenuFile_3,'Label');
1355set(handles.inputfile,'String',fileinput)
1356inputfile_Callback(hObject, eventdata, handles)
1357
1358% -----------------------------------------------------------------------
1359function MenuFile_4_Callback(hObject, eventdata, handles)
1360% -----------------------------------------------------------------------
1361fileinput=get(handles.MenuFile_4,'Label');
1362set(handles.inputfile,'String',fileinput)
1363inputfile_Callback(hObject, eventdata, handles)
1364
1365% -----------------------------------------------------------------------
1366function MenuFile_5_Callback(hObject, eventdata, handles)
1367% -----------------------------------------------------------------------
1368fileinput=get(handles.MenuFile_5,'Label');
1369set(handles.inputfile,'String',fileinput)
1370inputfile_Callback(hObject, eventdata, handles)
1371
1372%------------------------------------------------------------------------
1373function MenuExportField_Callback(hObject, eventdata, handles)
1374%------------------------------------------------------------------------
1375global Data_get_field
1376% huvmat=findobj(allchild(0),'Name','uvmat');
1377inputfile=get(handles.inputfile,'String');
1378Data_get_field=nc2struct(inputfile);
1379% Data_view_field=UvData.ProjField_2;
1380evalin('base','global Data_get_field')%make CurData global in the workspace
1381display(['content of ' inputfile ':'])
1382evalin('base','Data_get_field') %display CurData in the workspace
1383commandwindow;
1384
1385%------------------------------------------------------------------------
1386function MenuHelp_Callback(hObject, eventdata, handles)
1387%------------------------------------------------------------------------
1388path_to_uvmat=which ('uvmat');% check the path of uvmat
1389pathelp=fileparts(path_to_uvmat);
1390helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1391if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1392else
1393web([helpfile '#get_field'])   
1394end
1395
1396% -----------------------------------------------------------------------
1397function TimeName_Callback(hObject, eventdata, handles)
1398
1399scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
1400vector_x_Callback(hObject, eventdata, handles)
1401
1402%------------------------------------------------------------------------
1403% --- Executes on button press in TimeAttribute.
1404function TimeAttribute_Callback(hObject, eventdata, handles)
1405%------------------------------------------------------------------------
1406val=get(handles.TimeAttribute,'Value');
1407if val
1408    set(handles.TimeAttributeMenu,'Visible','on')
1409    Field=get(handles.get_field,'UserData');
1410    time_value=zeros(size(Field.ListGlobalAttribute));
1411    test_time=zeros(size(Field.ListGlobalAttribute));
1412    for ilist=1:numel(Field.ListGlobalAttribute)
1413        if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
1414            eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
1415            if ~isempty(time_val)
1416                time_value(ilist)=time_val;
1417                test_time(ilist)=1;
1418            end
1419        end
1420    end
1421    ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
1422    attr_index=get(handles.TimeAttributeMenu,'Value');
1423    if attr_index>numel(ListTimeAttribute)
1424        attr_index=1;
1425        set(handles.TimeAttributeMenu,'Value',1);
1426    end
1427    if isempty(ListTimeAttribute)
1428        set(handles.TimeAttributeMenu,'String',{''})
1429        set(handles.TimeValue,'Visible','off')
1430    else
1431        set(handles.TimeValue,'Visible','on')
1432        set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
1433        set(handles.TimeValue,'String',num2str(time_value(attr_index)))
1434    end
1435    set(handles.TimeDimension,'Value',0)
1436    TimeDimension_Callback(hObject, eventdata, handles)
1437    set(handles.TimeVariable,'Value',0)
1438    TimeVariable_Callback(hObject, eventdata, handles)
1439else
1440    set(handles.TimeAttributeMenu,'Visible','off')
1441    set(handles.TimeValue,'Visible','off')
1442end
1443
1444%------------------------------------------------------------------------
1445% --- Executes on selection change in TimeAttributeMenu.
1446function TimeAttributeMenu_Callback(hObject, eventdata, handles)
1447 ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
1448 index=get(handles.TimeAttributeMenu,'Value');
1449 AttrName=ListTimeAttribute{index};
1450 Field=get(handles.get_field,'UserData');
1451 eval(['time_val=Field.' AttrName ';'])
1452 set(handles.TimeValue,'String',num2str(time_val))
1453%------------------------------------------------------------------------
1454
1455%------------------------------------------------------------------------
1456% --- Executes on button press in TimeVariable.
1457function TimeDimension_Callback(hObject, eventdata, handles)
1458%------------------------------------------------------------------------
1459val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
1460if val  %if check box TimeDimension is selected
1461    Field=get(handles.get_field,'UserData');% structure describing the currently opened field
1462    previous_menu=get(handles.TimeDimensionMenu,'String');
1463    if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
1464        ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
1465        if isempty(ind_select)
1466            ind_select=1;% select the first item in the list if 'time' is not found
1467        end
1468        set(handles.TimeDimensionMenu,'Value',ind_select);
1469        set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
1470    end   
1471    set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
1472    set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
1473    TimeDimensionMenu_Callback(hObject, eventdata, handles) 
1474    set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
1475    set(handles.TimeVariable,'Value',0)
1476    TimeAttribute_Callback(hObject, eventdata, handles)
1477else
1478    set(handles.TimeDimensionMenu,'Visible','off')
1479    set(handles.TimeIndexValue,'Visible','off')
1480end
1481%
1482% %------------------------------------------------------------------------
1483% % --- Executes on selection change in TimeDimensionMenu.
1484% function TimeDimensionMenu_Callback(hObject, eventdata, handles)
1485% %------------------------------------------------------------------------
1486% index=get(handles.TimeDimensionMenu,'Value');
1487% DimList=get(handles.TimeDimensionMenu,'String');
1488% DimName=DimList{index};
1489% Field=get(handles.get_field,'UserData');
1490% DimIndex=find(strcmp(DimName,Field.ListDimName),1);
1491% ref_index=round(Field.DimValue(DimIndex)/2);   
1492% set(handles.TimeIndexValue,'String',num2str(ref_index))
1493% scalar_Callback(hObject, eventdata, handles)
1494% vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
1495%  % look for a corresponding time variable and value
1496%  time_test=zeros(size(Field.VarDimName));
1497%  for ilist=1:numel(Field.VarDimName)
1498%      if isequal(Field.VarDimName{ilist},{DimName})
1499%          time_test(ilist)=1;
1500%      end
1501%  end
1502%  ListVariable=Field.ListVarName(time_test==1);
1503%  set(handles.TimeVariableMenu,'Value',1)
1504%  if isempty(ListVariable)     
1505%      set(handles.TimeVariableMenu,'String',{''})
1506%      set(handles.TimeVarValue,'String','')
1507%  else
1508%     set(handles.TimeVariableMenu,'String',ListVariable)
1509%     TimeVarName=ListVariable{1};
1510%     VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
1511%     inputfile=get(handles.inputfile,'String');% read the input file
1512%     SubField=nc2struct(inputfile,{TimeVarName});
1513%     eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
1514%     set(handles.TimeVarValue,'Visible','on')
1515%     set(handles.TimeVariableMenu,'Visible','on')
1516%     set(handles.TimeVarValue,'String',num2str(TimeValue))
1517%  end
1518%
1519%
1520% % % -----------------------------------------------------------------------
1521% % % --- Executes on button press in TimeVariable.
1522% % function TimeVariable_Callback(hObject, eventdata, handles)
1523% % % -----------------------------------------------------------------------
1524% % val=get(handles.TimeVariable,'Value');
1525% % if val
1526% %     Field=get(handles.get_field,'UserData');
1527% %     time_test=zeros(size(Field.VarDimName));
1528% %     for ilist=1:numel(Field.VarDimName)
1529% %         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
1530% %             time_test(ilist)=1;
1531% %         end
1532% %     end
1533% %     ind_test=find(time_test);
1534% %     if isempty(time_test)
1535% %         set(handles.TimeVariable,'Value',0)
1536% %         set(handles.TimeVariableMenu,'Visible','off')
1537% %         set(handles.TimeVarValue,'Visible','off')
1538% %     else
1539% %         set(handles.TimeVariableMenu,'Visible','on')
1540% %         set(handles.TimeVarValue,'Visible','on')
1541% %         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
1542% %             set(handles.TimeVariableMenu,'Value',1)
1543% %         end
1544% %         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
1545% %         TimeVariableMenu_Callback(hObject, eventdata, handles)
1546% %         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
1547% %         set(handles.TimeAttribute,'Value',0)
1548% %         TimeAttribute_Callback(hObject, eventdata, handles)
1549% %     end
1550% % else
1551% %     set(handles.TimeVariableMenu,'Visible','off')
1552% %     set(handles.TimeVarValue,'Visible','off')
1553% % end
1554%
1555% % -----------------------------------------------------------------------
1556% % --- Executes on selection change in TimeVariableMenu.
1557% function TimeVariableMenu_Callback(hObject, eventdata, handles)
1558% % -----------------------------------------------------------------------
1559% ListVar=get(handles.TimeVariableMenu,'String');
1560% index=get(handles.TimeVariableMenu,'Value');
1561% TimeVariable=ListVar{index};% name of the selected variable
1562% if isempty(TimeVariable)% case of blank selection
1563%     return
1564% end
1565% Field=get(handles.get_field,'UserData'); %index of
1566% VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
1567% DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
1568% set(handles.TimeDimensionMenu,'Value',1)
1569% set(handles.TimeDimensionMenu,'String',DimName)
1570% inputfile=get(handles.inputfile,'String');% read the input file
1571% SubField=nc2struct(inputfile,{TimeVariable});
1572% eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
1573% ref_index=round(TimeDimension/2);
1574% eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
1575% set(handles.TimeIndexValue,'String',num2str(ref_index))
1576% set(handles.TimeVarValue,'String',num2str(TimeValue))
1577
1578
1579% --- Executes on button press in check_rgb.
1580function check_rgb_Callback(hObject, eventdata, handles)
1581
1582
1583% --- Executes when user attempts to close get_field.
1584function get_field_CloseRequestFcn(hObject, eventdata, handles)
1585if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
1586    % The GUI is still in UIWAIT, us UIRESUME
1587    uiresume(handles.get_field);
1588else
1589    % The GUI is no longer waiting, just close it
1590    delete(handles.get_field);
1591end
1592
1593
1594
1595
1596
1597% --- Executes on selection change in listbox30.
1598function listbox30_Callback(hObject, eventdata, handles)
1599% hObject    handle to listbox30 (see GCBO)
1600% eventdata  reserved - to be defined in a future version of MATLAB
1601% handles    structure with handles and user data (see GUIDATA)
1602
1603% Hints: contents = cellstr(get(hObject,'String')) returns listbox30 contents as cell array
1604%        contents{get(hObject,'Value')} returns selected item from listbox30
1605
1606
1607% --- Executes on selection change in SwitchVarIndexX.
1608function SwitchVarIndexX_Callback(hObject, eventdata, handles)
1609% hObject    handle to SwitchVarIndexX (see GCBO)
1610% eventdata  reserved - to be defined in a future version of MATLAB
1611% handles    structure with handles and user data (see GUIDATA)
1612
1613% Hints: contents = cellstr(get(hObject,'String')) returns SwitchVarIndexX contents as cell array
1614%        contents{get(hObject,'Value')} returns selected item from SwitchVarIndexX
1615
1616
1617% --- Executes on selection change in SwitchVarIndexTime.
1618function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
1619menu=get(handles.SwitchVarIndexTime,'String');
1620option=menu{get(handles.SwitchVarIndexTime,'Value')};
1621Field=get(handles.get_field,'UserData');
1622switch option
1623    case 'file index'
1624        set(handles.TimeVarName, 'Visible','off')
1625    case 'attribute'
1626        set(handles.TimeVarName, 'Visible','on')
1627        time_index=[];
1628        PreviousList=get(handles.TimeVarName, 'String');
1629         index=[];
1630        if ~isempty(PreviousList)
1631        PreviousAttr=PreviousList{get(handles.TimeVarName, 'Value')};
1632        index=find(strcmp(PreviousAttr,Field.ListNumAttributes));
1633        end
1634        if isempty(index)
1635            time_index=find(~cellfun('isempty',regexp(Field.ListNumAttributes,'Time')));% index of the attributes containing the string 'Time'
1636        end
1637        if ~isempty(time_index)
1638            set(handles.TimeVarName,'Value',time_index(1))
1639        else
1640            set(handles.TimeVarName,'Value',1)
1641        end
1642        set(handles.TimeVarName, 'String',Field.ListNumAttributes)
1643    case 'variable'
1644        set(handles.TimeVarName, 'Visible','on')
1645        TimeVarName=Field.SingleVarName;
1646        List=get(handles.TimeVarName,'String');
1647        option=List{get(handles.TimeVarName,'Value')};
1648        ind=find(strcmp(option,TimeVarName));
1649        if isempty(ind)
1650            set(handles.TimeVarName, 'Value',1);
1651        else
1652            set(handles.TimeVarName, 'Value',ind);
1653        end
1654        set(handles.TimeVarName, 'String',TimeVarName)
1655    case 'dim index'
1656        set(handles.TimeVarName, 'Visible','on')
1657        TimeVarName=Field.SingleDimName;
1658        List=get(handles.TimeVarName,'String');
1659        option=List{get(handles.TimeVarName,'Value')};
1660        ind=find(strcmp(option,TimeVarName));
1661        if isempty(ind)
1662            set(handles.TimeVarName, 'Value',1);
1663        else
1664            set(handles.TimeVarName, 'Value',ind);
1665        end
1666        set(handles.TimeVarName, 'String',TimeVarName)
1667end
1668
1669
Note: See TracBrowser for help on using the repository browser.