source: trunk/src/get_field.m @ 323

Last change on this file since 323 was 236, checked in by sommeria, 14 years ago

correct Matlab PIV, remove call to image tool box. Improve menu of uvmat VelType? (replacement of buttons)

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