source: trunk/src/get_field.m @ 527

Last change on this file since 527 was 526, checked in by sommeria, 12 years ago

bugs corrected; Posiibility of usual 1D plots introduced with the new way of using get_field. time_series and aver_stat updated

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