source: trunk/src/get_field.m @ 517

Last change on this file since 517 was 517, checked in by sommeria, 9 years ago

various bugs corrected. get_field now used in a passive way from uvmat: variable names are transferred from get_field to uvmat.

File size: 69.4 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%---------------------------------------------------------
833% set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action
834% test_fig=get(handles.SelectFigure,'Value');
835%
836% % plot requested in uvmat
837% if ~test_fig
838%     inputfile=get(handles.inputfile,'String');
839%     huvmat=findobj(allchild(0),'tag','uvmat');
840%     if isempty(huvmat)
841%         input.InputFile=inputfile;
842%         input.FieldsString={'get_field...'};
843%         uvmat(input)
844%     else
845%         set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases)
846%         hhuvmat=guidata(huvmat);
847%         set(hhuvmat.Fields,'Value',1)
848%         set(hhuvmat.Fields,'String',{'get_field...'})
849%         uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
850%     end
851%   
852% % other kind of plot
853% else  %TODO: check and update: add plot on an existing axes
854%     figcell=get(handles.list_fig,'String');
855%     index=get(handles.list_fig,'value');
856%     figstring=figcell{index};
857%     index=get(handles.ACTION,'Value');
858%     list_func=get(handles.ACTION,'UserData');
859%     h_fun=list_func{index};
860%     set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
861%     drawnow
862%     SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field
863%     if ~isempty(SubField)
864%         plot_get_field(SubField,handles)
865%     end
866%     browse_fig(handles.list_fig); %update the list of new existing figures
867% end
868% set(handles.RUN,'BackgroundColor',[1 0 0])
869huvmat=findobj(allchild(0),'tag','uvmat');
870if ~isempty(huvmat)
871         set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases)
872         hhuvmat=guidata(huvmat);
873         get_field_GUI=read_GUI(handles.get_field);
874         if isfield(get_field_GUI,'PanelVectors')
875             set(hhuvmat.Coord_x,'value',1)
876             set(hhuvmat.Coord_y,'value',1)
877             set(hhuvmat.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors})
878             set(hhuvmat.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors})
879             UName=get_field_GUI.PanelVectors.vector_x;
880             VName=get_field_GUI.PanelVectors.vector_y;
881             menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}];
882             menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}];
883             FieldsMenu=get(hhuvmat.Fields,'String');
884             Fields=FieldsMenu{get(hhuvmat.Fields,'Value')};
885             if strcmp(Fields,'get_field...')
886                  set(hhuvmat.Fields,'Value',1)
887                 set(hhuvmat.Fields,'String',menu_str)
888             else %get_field has been called by Fields_1
889                  set(hhuvmat.Fields_1,'Value',1)
890                 set(hhuvmat.Fields_1,'String',menu_str)
891             end
892             ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color));
893             if ~isempty(ind_menu)
894             set(hhuvmat.ColorScalar,'Value',ind_menu)
895             else
896                 set(hhuvmat.ColorScalar,'Value',1)
897             end
898               set(hhuvmat.ColorScalar,'String',menu_color)
899         end
900end
901delete(handles.get_field)
902%         set(hhuvmat.Fields,'String',{'get_field...'})
903%         uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
904%     end
905
906%------------------------------------------------------------------------
907% --- Function for plotting the current subfield
908function plot_get_field(SubField,handles)
909%------------------------------------------------------------------------
910list_fig=get(handles.list_fig,'String');
911val=get(handles.list_fig,'Value');
912if strcmp(list_fig{val},'uvmat')
913    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
914    set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
915    set(handles.MenuOpen,'Visible','off')
916    set(handles.MenuExport,'Visible','off')
917    uvmat(get(handles.inputfile,'String'))
918elseif strcmp(list_fig{val},'view_field')
919    view_field(SubField)
920else
921    hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI
922    if isnan(hfig)
923        hfig=figure;
924        list_fig=[list_fig;num2str(hfig)];
925        set(handles.list_fig,'String',list_fig);
926        haxes=axes;
927    else
928        figure(hfig);
929    end
930    haxes=findobj(hfig,'Type','axes');
931    plot_field(SubField,haxes)
932end
933
934% %------------------------------------------------
935% % --- Executes on button press in Plot_histo.
936% %RUN global histograms
937% %-------------------------------------------------
938% function RUN_histo_Callback(hObject, eventdata, handles)
939% % hObject    handle to RUN (see GCBO)
940% % eventdata  reserved - to be defined in a future version of MATLAB
941% % handles    structure with handles and user data (see GUIDATA)
942%
943% %timename plots
944% leg={};
945% n=0;
946% if (get(handles.cm_switch,'Value')==1)
947%     Uval_p=Uval_cm;
948%     Vval_p=Vval_cm;
949%     Uhist_p=Uhist_cm;
950%     Vhist_p=Vhist_cm;
951%     xlab='velocity (cm/s)';
952% else
953%     Uval_p=Uval;
954%     Vval_p=Vval;
955%     Uhist_p=Uhist;
956%     Vhist_p=Vhist;
957%     xlab='velocity (pixels)';
958% end
959% if (get(handles.vector_y,'Value') == 1)
960%    hhh=figure(2);
961%    hold on
962%    title([filebase ', ' strindex ', ' fieldtitle])
963%    plot(Uval_p,Uhist_p,'b-')
964%    n=n+1;
965%    leg{n}='Uhist';
966%    xlabel(xlab)
967% end
968% if (get(handles.Vhist_input,'Value') == 1)
969%    hhh=figure(2);
970%    hold on
971%    title([filebase ', ' strindex ', ' fieldtitle])
972%    plot(Vval_p,Vhist_p,'r-')
973%    n=n+1;
974%    leg{n}='Vhist';
975%    xlabel(xlab);
976% end
977% if (get(handles.Chist_input,'Value') == 1)
978%    hhhh=figure(3);
979%    hold on
980%    title([filebase ', ' strindex ', ' fieldtitle])
981%    plot(Cval,Chist,'k-')
982%    leg{1}='Chist';
983% end
984% % hold off
985% grid on
986% legend(leg);
987
988% %-------------------------------------------------------------
989% % --- Executes on button press in Save_input.
990% function Save_input_Callback(hObject, eventdata, handles)
991% list_str=get(handles.abscissa,'String');
992% val=get(handles.abscissa,'Value');
993% var=list_str{val};
994% hselect_field=get(handles.Save_input,'parent')
995% set(hselect_field,'UserData',var);
996% set(hselect_field,'Tag','idle')
997
998%     
999% %-------------------------------------------------------------
1000% % --- Executes on button press in save_histo.
1001% function save_histo_Callback(hObject, eventdata, handles)
1002% global filebase
1003%
1004% pathstr = fileparts(filebase)
1005% if (get(handles.Chist_input,'Value') == 1)
1006%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
1007%     else
1008
1009%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
1010% end
1011% prompt={'save figure(2) as'}
1012% dlg_title = 'save figure';
1013% num_lines= 1;
1014% answer = inputdlg(prompt,dlg_title,num_lines,def)
1015% saveas(2,answer{1})
1016 
1017
1018%%-------------------------------------------------------
1019% --- Executes on button press in peaklocking.
1020%-------------------------------------------------
1021function peaklocking(handles)
1022%evaluation of peacklocking errors
1023%use splinhist: give spline coeff cc for a smooth histo (call spline4)
1024%use histsmooth(x,cc): calculate the smooth histo for any value x
1025%use histder(x,cc): calculate the derivative of the smooth histo
1026global hfig1 hfig2 hfig3
1027global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
1028global xval xerror yval yerror
1029
1030set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
1031set(handles.Vhist_input,'Value',1)
1032set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
1033
1034%adjust the extremal values of the histogram in U with respect to integer
1035%values
1036minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
1037maximU=round(max(Uval)-0.5)+0.5;
1038minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
1039maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
1040nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
1041nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
1042Uval=[minim_fin:(1/nbb):maxim_fin];
1043histu_min=zeros(nb_bin_min,1);
1044histu_max=zeros(nb_bin_max,1);
1045Uhist=[histu_min; Uhist ;histu_max]; % column vector
1046
1047%adjust the extremal values of the histogram in V
1048minimV=round(min(Vval-0.5)+0.5);
1049maximV=round(max(Vval-0.5)+0.5);
1050minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
1051maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
1052nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
1053nb_bin_max=round((maxim_fin -max(Vval))*nbb);
1054Vval=[minim_fin:(1/nbb):maxim_fin];
1055histu_min=zeros(nb_bin_min,1);
1056histu_max=zeros(nb_bin_max,1);
1057Vhist=[histu_min; Vhist ;histu_max]; % column vector
1058
1059% RUN_histo_Callback(hObject, eventdata, handles)
1060% %adjust the histogram to integer values:
1061
1062%histoU and V
1063[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
1064[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
1065
1066% selection of value ranges such that histo>=10 (enough statistics)
1067Uval_ind=find(Uhist>=10);
1068ind_min=min(Uval_ind);
1069ind_max=max(Uval_ind);
1070U_min=Uval(ind_min);% minimum allowed value
1071U_max=Uval(ind_max);%maximum allowed value
1072
1073% selection of value ranges such that histo>=10 (enough statistics)
1074Vval_ind=find(Vhist>=10);
1075ind_min=min(Vval_ind);
1076ind_max=max(Vval_ind);
1077V_min=Vval(ind_min);% minimum allowed value
1078V_max=Vval(ind_max);%maximum allowed value
1079
1080figure(4)% plot U histogram with smoothed one
1081plot(Uval,Uhist,'b')
1082grid on
1083hold on
1084plot(Uval,Uhistinter,'r');
1085hold off
1086
1087figure(5)% plot V histogram with smoothed one
1088plot(Vval,Vhist,'b')
1089grid on
1090hold on
1091plot(Vval,Vhistinter,'r');
1092hold off
1093
1094figure(6)% plot pixel error in two subplots
1095hfig4=subplot(2,1,1);
1096hfig5=subplot(2,1,2);
1097axes(hfig4)
1098plot(xval,xerror)
1099axis([U_min U_max -0.4 0.4])
1100xlabel('velocity u (pix)')
1101ylabel('peaklocking error (pix)')
1102grid on
1103axes(hfig5)
1104plot(yval,yerror)
1105axis([V_min V_max -0.4 0.4]);
1106xlabel('velocity v (pix)')
1107ylabel('peaklocking error (pix)')
1108grid on
1109
1110
1111% ------------------------------------------------------------------
1112function variables_Callback(hObject, eventdata, handles)
1113Tabchar={''};%default
1114Tabcell=[];
1115hselect_field=get(handles.variables,'parent');
1116Field=get(handles.get_field,'UserData');
1117index=get(handles.variables,'Value');%index in the list 'variables'
1118
1119%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
1120if isequal(index,1)
1121    set(handles.attributes_txt,'String','global attributes')
1122    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
1123        for iline=1:length(Field.ListGlobalAttribute)
1124            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
1125            if isfield(Field, Field.ListGlobalAttribute{iline})
1126                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
1127                if ischar(val);% attribute value is char string
1128                    Tabcell{iline,2}=val;
1129                elseif size(val,1)==1 %attribute value is a number or matlab vector
1130                    Tabcell{iline,2}=num2str(val);
1131                end
1132            end
1133        end
1134        Tabchar=cell2tab(Tabcell,'=');
1135    end
1136%% list Attribute names and values associated to the Variable # index-1   
1137else
1138    list_var=get(handles.variables,'String');
1139    var_select=list_var{index};
1140    set(handles.attributes_txt,'String', ['attributes of ' var_select])
1141    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
1142%         nbline=0;
1143        VarAttr=Field.VarAttribute{index-1};
1144        if isstruct(VarAttr)
1145            attr_list=fieldnames(VarAttr);
1146            for iline=1:length(attr_list)
1147                Tabcell{iline,1}=attr_list{iline};
1148                eval(['val=VarAttr.' attr_list{iline} ';'])
1149                if ischar(val);
1150                    Tabcell{iline,2}=val;
1151                else
1152                     Tabcell{iline,2}=num2str(val);
1153                end
1154            end
1155        end
1156    end
1157
1158end
1159if ~isempty(Tabcell)
1160    Tabchar=cell2tab(Tabcell,'=');
1161    Tabchar=[{''};Tabchar];
1162end
1163set(handles.attributes,'Value',1);% select the first item
1164set(handles.attributes,'String',Tabchar);
1165
1166%% update dimensions;
1167if isfield(Field,'ListDimName')
1168    Tabdim={};%default
1169    if isequal(index,1)%list all dimensions
1170        dim_indices=1:length(Field.ListDimName);
1171        set(handles.dimensions_txt,'String', 'dimensions')
1172    else
1173        DimCell=Field.VarDimName{index-1};
1174        if ischar(DimCell)
1175            DimCell={DimCell};
1176        end   
1177        dim_indices=[];
1178        for idim=1:length(DimCell)
1179            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
1180            dim_index=find(dim_index,1);
1181            dim_indices=[dim_indices dim_index];
1182        end
1183        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1184    end
1185    for iline=1:length(dim_indices)
1186        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1187        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1188    end
1189    Tabchar=cell2tab(Tabdim,' = ');
1190    Tabchar=[{''} ;Tabchar];
1191    set(handles.dimensions,'Value',1)
1192    set(handles.dimensions,'String',Tabchar) 
1193end 
1194
1195%------------------------------------------------------------------------
1196% --- Executes on button press in CheckPlot1D.
1197function CheckPlot1D_Callback(hObject, eventdata, handles)
1198%------------------------------------------------------------------------
1199val=get(handles.CheckPlot1D,'Value');
1200if isequal(val,0)
1201    set(handles.Panel1Dplot,'Visible','off')
1202else
1203    set(handles.Panel1Dplot,'Visible','on')
1204end
1205
1206%------------------------------------------------------------------------
1207% --- Executes on button press in CheckScalar.
1208function CheckScalar_Callback(hObject, eventdata, handles)
1209%------------------------------------------------------------------------
1210val=get(handles.CheckScalar,'Value');
1211if isequal(val,0)
1212    set(handles.PanelScalar,'Visible','off')
1213else
1214    set(handles.PanelScalar,'Visible','on')
1215end
1216
1217%------------------------------------------------------------------------
1218% --- Executes on button press in CheckVector.
1219function CheckVector_Callback(hObject, eventdata, handles)
1220%------------------------------------------------------------------------
1221val=get(handles.CheckVector,'Value');
1222if isequal(val,0)
1223    set(handles.PanelVectors,'Visible','off')
1224else
1225    set(handles.PanelVectors,'Visible','on')
1226end
1227
1228% %------------------------------------------------------------------------
1229% function mouse_up_gui(ggg,eventdata,handles)
1230% %------------------------------------------------------------------------
1231% if isequal(get(ggg,'SelectionType'),'alt')
1232%     message=''; 
1233%     global CurData
1234%     inputfield=get(handles.inputfile,'String');
1235%     if exist(inputfield,'file')
1236%         CurData=nc2struct(inputfield);
1237%     else
1238%         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1239%     end
1240%   %%%% TODO: put the matalb command window in front
1241%     evalin('base','global CurData')%make CurData global in the workspace
1242%     evalin('base','CurData') %display CurData in the workspace
1243% end
1244
1245%------------------------------------------------------------------------
1246% --- Executes on selection change in ACTION.
1247%------------------------------------------------------------------------
1248function ACTION_Callback(hObject, eventdata, handles)
1249global nb_builtin
1250list_ACTION=get(handles.ACTION,'String');% list menu fields
1251index_ACTION=get(handles.ACTION,'Value');% selected string index
1252ACTION= list_ACTION{index_ACTION}; % selected string
1253list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
1254ff=functions(list_func_handles{end});
1255% add a new function to the menu
1256if isequal(ACTION,'more...')
1257    [FileName, PathName] = uigetfile( ...
1258       {'*.m', ' (*.m)';
1259        '*.m',  '.m files '; ...
1260        '*.*', 'All Files (*.*)'}, ...
1261        'Pick a file',ff.file);
1262    if length(FileName)<2
1263        return
1264    end
1265    [pp,ACTION,ext_fct]=fileparts(FileName);
1266    if ~isequal(ext_fct,'.m')
1267        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1268        return
1269    end
1270
1271    % insert the choice in the action menu
1272   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1273   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1274   addpath(PathName)
1275   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
1276   set(handles.ACTION,'UserData',list_func_handles)
1277   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1278   %list_path{index_ACTION}=PathName;
1279   if length(menu_str)>nb_builtin+5;
1280       nbremove=length(menu_str)-nb_builtin-5;
1281       menu_str(nb_builtin+1:end-5)=[];
1282       list_func_handles(nb_builtin+1:end-4)=[];
1283       index_ACTION=index_ACTION-nbremove;
1284       set(handles.ACTION,'Value',index_ACTION)
1285       set(handles.ACTION,'String',menu_str)
1286   end   
1287   %record the current menu in personal file profil_perso
1288   dir_perso=prefdir;
1289   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1290   get_field_fct={};
1291   for ilist=nb_builtin+1:length(menu_str)-1
1292       ff=functions(list_func_handles{ilist});
1293       get_field_fct{ilist-nb_builtin}=ff.file;
1294   end
1295   if exist(profil_perso,'file')
1296        save(profil_perso,'get_field_fct','-append')
1297   else
1298     txt=ver('MATLAB');
1299    Release=txt.Release;
1300       relnumb=str2num(Release(3:4));
1301        if relnumb >= 14
1302            save(profil_perso,'get_field_fct','-V6')
1303        else
1304            save(profil_perso, 'get_field_fct')
1305        end
1306   end
1307end
1308
1309%check the current path to the selected function
1310h_fun=list_func_handles{index_ACTION};
1311if isa(h_fun,'function_handle')
1312    func=functions(h_fun);
1313    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
1314    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
1315else
1316    set(handles.path_action,'String','')
1317    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
1318    return
1319end
1320
1321%prepare the GUI options for the selected ACTION
1322test_1Dplot=0;
1323test_scalar=0;
1324test_vector=0;
1325if iscell(GUI_input)
1326    for ilist=1:size(GUI_input,1)
1327        switch GUI_input{ilist,1}
1328                           %RootFile always visible
1329            case 'CheckPlot1D'   
1330                 test_1Dplot=isequal(GUI_input{ilist,2},'on');
1331            case 'CheckScalar'
1332                 test_scalar=isequal(GUI_input{ilist,2},'on');   
1333            case 'CheckVector'   
1334                 test_vector=isequal(GUI_input{ilist,2},'on');
1335        end
1336    end
1337end
1338set(handles.CheckPlot1D,'Value',test_1Dplot);
1339set(handles.CheckScalar,'Value',test_scalar);
1340set(handles.CheckVector,'Value',test_vector);
1341CheckPlot1D_Callback(hObject, eventdata, handles)
1342CheckScalar_Callback(hObject, eventdata, handles)
1343CheckVector_Callback(hObject, eventdata, handles)
1344
1345
1346%-----------------------------------------------------
1347% --- browse existing figures
1348%-----------------------------------------------------
1349function browse_fig(menu_handle)
1350hh=findobj(allchild(0),'Type','figure');
1351ilist=0;
1352list={};
1353for ifig=1:length(hh)  %look for all existing figures
1354    name=get(hh(ifig),'Name');
1355     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
1356        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1357        nbaxe=0;
1358        for ichild=1:length(hchild)           
1359            Type=get(hchild(ichild),'Type');
1360            Tag=get(hchild(ichild),'Tag');
1361            if isequal(Type,'axes')
1362                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1363                     nbaxe=nbaxe+1;%count the existing axis
1364                end
1365            end
1366        end   
1367        if nbaxe==1
1368             ilist=ilist+1;%add a line in the list of axis
1369            list{ilist,1}=num2str(hh(ifig));
1370        elseif nbaxe>1
1371            for iaxe=1:nbaxe
1372               ilist=ilist+1;%add a line in the list of axis
1373               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1374            end
1375        end
1376     end
1377end
1378list=['uvmat';list];
1379set(menu_handle,'Value',1)
1380set(menu_handle,'String',list)
1381
1382
1383%-----------------------------------------------------
1384function list_fig_Callback(hObject, eventdata, handles)
1385%-----------------------------------------------------
1386list_fig=get(handles.list_fig,'String');
1387fig_val=get(handles.list_fig,'Value');
1388plot_fig=list_fig{fig_val};
1389if strcmp(plot_fig,'view_field')
1390%     huvmat=findobj(allchild(0),'name','uvmat');
1391%     if ~isempty(huvmat)
1392%         uistack(huvmat,'top')
1393%     end   
1394else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1395    sep=regexp(plot_fig,'_');
1396    if ~isempty(sep)
1397        plot_fig=plot_fig([1:sep-1]);
1398    end
1399    if ishandle(str2num(plot_fig))
1400        figure(str2num(plot_fig))% display existing figure
1401    else
1402        browse_fig(handles.list_fig); %reset the current list of figures
1403    end
1404end
1405
1406
1407%-------------------------------------------------
1408% give index numbers of the strings str in the list ListvarName
1409function VarIndex_y=name2index(cell_str,ListVarName)
1410VarIndex_y=[];
1411if ischar(cell_str)
1412    for ivar=1:length(ListVarName)
1413        varlist=ListVarName{ivar};
1414        if isequal(varlist,cell_str)
1415            VarIndex_y= ivar;
1416            break
1417        end
1418    end
1419elseif iscell(cell_str)
1420    for isel=1:length(cell_str)
1421        varsel=cell_str{isel};
1422        for ivar=1:length(ListVarName)
1423            varlist=ListVarName{ivar};
1424            if isequal(varlist,varsel)
1425                VarIndex_y=[VarIndex_y ivar];
1426            end
1427        end
1428    end
1429end
1430
1431% --------------------------------------------------------------------
1432function MenuOpen_Callback(hObject, eventdata, handles)
1433% hObject    handle to MenuOpen (see GCBO)
1434% eventdata  reserved - to be defined in a future version of MATLAB
1435% handles    structure with handles and user data (see GUIDATA)
1436
1437
1438% --------------------------------------------------------------------
1439function MenuExport_Callback(hObject, eventdata, handles)
1440% hObject    handle to MenuExport (see GCBO)
1441% eventdata  reserved - to be defined in a future version of MATLAB
1442% handles    structure with handles and user data (see GUIDATA)
1443
1444
1445% --------------------------------------------------------------------
1446function MenuBrowse_Callback(hObject, eventdata, handles)
1447
1448oldfile=get(handles.inputfile,'String');
1449testrootfile=0;
1450testsubdir=0;
1451if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1452        oldfile='';
1453        dir_perso=prefdir;
1454         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1455         if exist(profil_perso,'file')
1456              h=load (profil_perso);
1457             if isfield(h,'RootPath')
1458                  RootPath=h.RootPath;
1459             end
1460             if isfield(h,'SubDir')
1461                  SubDir=h.SubDir;
1462                  if ~isempty(SubDir)
1463                    testsubdir=1;
1464                  end
1465             end
1466             if isfield(h,'RootFile')
1467                  RootFile=h.RootFile;
1468                  if ~isempty(RootFile)
1469                    testrootfile=1;
1470                  end
1471             end
1472         end
1473end
1474if testrootfile
1475    if ~testsubdir
1476        oldfile=fullfile(RootPath,RootFile);
1477    else
1478        oldfile=fullfile(RootPath,SubDir,RootFile);
1479    end
1480end
1481[FileName, PathName] = uigetfile( ...
1482       {'*.nc', ' *.nc';...
1483       '*.cdf', ' *.cdf';...
1484        '*.*',  'All Files (*.*)'}, ...
1485        'Pick a file',oldfile);
1486
1487%global inputfile
1488fileinput=[PathName FileName];%complete file name
1489sizf=size(fileinput);
1490if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1491set(handles.inputfile,'String',fileinput)
1492inputfile_Callback(hObject, eventdata, handles)
1493
1494%update list of recent files in the menubar
1495MenuFile_1=fileinput;
1496MenuFile_2=get(handles.MenuFile_1,'Label');
1497MenuFile_3=get(handles.MenuFile_2,'Label');
1498MenuFile_4=get(handles.MenuFile_3,'Label');
1499MenuFile_5=get(handles.MenuFile_4,'Label');
1500set(handles.MenuFile_1,'Label',MenuFile_1)
1501set(handles.MenuFile_2,'Label',MenuFile_2)
1502set(handles.MenuFile_3,'Label',MenuFile_3)
1503set(handles.MenuFile_4,'Label',MenuFile_4)
1504set(handles.MenuFile_5,'Label',MenuFile_5)
1505dir_perso=prefdir;
1506profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1507display(profil_perso)
1508if exist(profil_perso,'file')
1509    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1510else
1511    txt=ver('MATLAB');
1512    Release=txt.Release;
1513    relnumb=str2double(Release(3:4));
1514    if relnumb >= 14
1515        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1516    else
1517        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1518    end
1519end
1520
1521% --------------------------------------------------------------------
1522function MenuFile_1_Callback(hObject, eventdata, handles)
1523fileinput=get(handles.MenuFile_1,'Label');
1524set(handles.inputfile,'String',fileinput)
1525inputfile_Callback(hObject, eventdata, handles)
1526
1527% --------------------------------------------------------------------
1528function MenuFile_2_Callback(hObject, eventdata, handles)
1529fileinput=get(handles.MenuFile_2,'Label');
1530set(handles.inputfile,'String',fileinput)
1531inputfile_Callback(hObject, eventdata, handles)
1532
1533% -----------------------------------------------------------------------
1534function MenuFile_3_Callback(hObject, eventdata, handles)
1535% -----------------------------------------------------------------------
1536fileinput=get(handles.MenuFile_3,'Label');
1537set(handles.inputfile,'String',fileinput)
1538inputfile_Callback(hObject, eventdata, handles)
1539
1540% -----------------------------------------------------------------------
1541function MenuFile_4_Callback(hObject, eventdata, handles)
1542% -----------------------------------------------------------------------
1543fileinput=get(handles.MenuFile_4,'Label');
1544set(handles.inputfile,'String',fileinput)
1545inputfile_Callback(hObject, eventdata, handles)
1546
1547% -----------------------------------------------------------------------
1548function MenuFile_5_Callback(hObject, eventdata, handles)
1549% -----------------------------------------------------------------------
1550fileinput=get(handles.MenuFile_5,'Label');
1551set(handles.inputfile,'String',fileinput)
1552inputfile_Callback(hObject, eventdata, handles)
1553
1554%------------------------------------------------------------------------
1555function MenuExportField_Callback(hObject, eventdata, handles)
1556%------------------------------------------------------------------------
1557global Data_get_field
1558% huvmat=findobj(allchild(0),'Name','uvmat');
1559inputfile=get(handles.inputfile,'String');
1560Data_get_field=nc2struct(inputfile);
1561% Data_view_field=UvData.ProjField_2;
1562evalin('base','global Data_get_field')%make CurData global in the workspace
1563display(['content of ' inputfile ':'])
1564evalin('base','Data_get_field') %display CurData in the workspace
1565commandwindow;
1566
1567%------------------------------------------------------------------------
1568function MenuHelp_Callback(hObject, eventdata, handles)
1569%------------------------------------------------------------------------
1570path_to_uvmat=which ('uvmat');% check the path of uvmat
1571pathelp=fileparts(path_to_uvmat);
1572helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1573if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1574else
1575web([helpfile '#get_field'])   
1576end
1577
1578% -----------------------------------------------------------------------
1579function TimeName_Callback(hObject, eventdata, handles)
1580
1581scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
1582vector_x_Callback(hObject, eventdata, handles)
1583
1584%------------------------------------------------------------------------
1585% --- Executes on button press in TimeAttribute.
1586function TimeAttribute_Callback(hObject, eventdata, handles)
1587%------------------------------------------------------------------------
1588val=get(handles.TimeAttribute,'Value');
1589if val
1590    set(handles.TimeAttributeMenu,'Visible','on')
1591    Field=get(handles.get_field,'UserData');
1592    time_value=zeros(size(Field.ListGlobalAttribute));
1593    test_time=zeros(size(Field.ListGlobalAttribute));
1594    for ilist=1:numel(Field.ListGlobalAttribute)
1595        if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
1596            eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
1597            if ~isempty(time_val)
1598                time_value(ilist)=time_val;
1599                test_time(ilist)=1;
1600            end
1601        end
1602    end
1603    ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
1604    attr_index=get(handles.TimeAttributeMenu,'Value');
1605    if attr_index>numel(ListTimeAttribute)
1606        attr_index=1;
1607        set(handles.TimeAttributeMenu,'Value',1);
1608    end
1609    if isempty(ListTimeAttribute)
1610        set(handles.TimeAttributeMenu,'String',{''})
1611        set(handles.TimeValue,'Visible','off')
1612    else
1613        set(handles.TimeValue,'Visible','on')
1614        set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
1615        set(handles.TimeValue,'String',num2str(time_value(attr_index)))
1616    end
1617    set(handles.TimeDimension,'Value',0)
1618    TimeDimension_Callback(hObject, eventdata, handles)
1619    set(handles.TimeVariable,'Value',0)
1620    TimeVariable_Callback(hObject, eventdata, handles)
1621else
1622    set(handles.TimeAttributeMenu,'Visible','off')
1623    set(handles.TimeValue,'Visible','off')
1624end
1625
1626%------------------------------------------------------------------------
1627% --- Executes on selection change in TimeAttributeMenu.
1628function TimeAttributeMenu_Callback(hObject, eventdata, handles)
1629 ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
1630 index=get(handles.TimeAttributeMenu,'Value');
1631 AttrName=ListTimeAttribute{index};
1632 Field=get(handles.get_field,'UserData');
1633 eval(['time_val=Field.' AttrName ';'])
1634 set(handles.TimeValue,'String',num2str(time_val))
1635%------------------------------------------------------------------------
1636
1637%------------------------------------------------------------------------
1638% --- Executes on button press in TimeVariable.
1639function TimeDimension_Callback(hObject, eventdata, handles)
1640%------------------------------------------------------------------------
1641val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
1642if val  %if check box TimeDimension is selected
1643    Field=get(handles.get_field,'UserData');% structure describing the currently opened field
1644    previous_menu=get(handles.TimeDimensionMenu,'String');
1645    if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
1646        ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
1647        if isempty(ind_select)
1648            ind_select=1;% select the first item in the list if 'time' is not found
1649        end
1650        set(handles.TimeDimensionMenu,'Value',ind_select);
1651        set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
1652    end   
1653    set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
1654    set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
1655    TimeDimensionMenu_Callback(hObject, eventdata, handles) 
1656    set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
1657    set(handles.TimeVariable,'Value',0)
1658    TimeAttribute_Callback(hObject, eventdata, handles)
1659else
1660    set(handles.TimeDimensionMenu,'Visible','off')
1661    set(handles.TimeIndexValue,'Visible','off')
1662end
1663
1664%------------------------------------------------------------------------
1665% --- Executes on selection change in TimeDimensionMenu.
1666function TimeDimensionMenu_Callback(hObject, eventdata, handles)
1667%------------------------------------------------------------------------
1668index=get(handles.TimeDimensionMenu,'Value');
1669DimList=get(handles.TimeDimensionMenu,'String');
1670DimName=DimList{index};
1671Field=get(handles.get_field,'UserData');
1672DimIndex=find(strcmp(DimName,Field.ListDimName),1);
1673ref_index=round(Field.DimValue(DimIndex)/2);   
1674set(handles.TimeIndexValue,'String',num2str(ref_index))
1675scalar_Callback(hObject, eventdata, handles)
1676vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
1677 % look for a corresponding time variable and value
1678 time_test=zeros(size(Field.VarDimName));
1679 for ilist=1:numel(Field.VarDimName)
1680     if isequal(Field.VarDimName{ilist},{DimName})
1681         time_test(ilist)=1;
1682     end
1683 end
1684 ListVariable=Field.ListVarName(time_test==1);
1685 set(handles.TimeVariableMenu,'Value',1)
1686 if isempty(ListVariable)     
1687     set(handles.TimeVariableMenu,'String',{''})
1688     set(handles.TimeVarValue,'String','')
1689 else
1690    set(handles.TimeVariableMenu,'String',ListVariable)
1691    TimeVarName=ListVariable{1};
1692    VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
1693    inputfile=get(handles.inputfile,'String');% read the input file
1694    SubField=nc2struct(inputfile,{TimeVarName});
1695    eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
1696    set(handles.TimeVarValue,'Visible','on')
1697    set(handles.TimeVariableMenu,'Visible','on')
1698    set(handles.TimeVarValue,'String',num2str(TimeValue))
1699 end
1700
1701
1702% % -----------------------------------------------------------------------
1703% % --- Executes on button press in TimeVariable.
1704% function TimeVariable_Callback(hObject, eventdata, handles)
1705% % -----------------------------------------------------------------------
1706% val=get(handles.TimeVariable,'Value');
1707% if val
1708%     Field=get(handles.get_field,'UserData');
1709%     time_test=zeros(size(Field.VarDimName));
1710%     for ilist=1:numel(Field.VarDimName)
1711%         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
1712%             time_test(ilist)=1;
1713%         end
1714%     end
1715%     ind_test=find(time_test);
1716%     if isempty(time_test)
1717%         set(handles.TimeVariable,'Value',0)
1718%         set(handles.TimeVariableMenu,'Visible','off')
1719%         set(handles.TimeVarValue,'Visible','off')
1720%     else
1721%         set(handles.TimeVariableMenu,'Visible','on')
1722%         set(handles.TimeVarValue,'Visible','on')
1723%         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
1724%             set(handles.TimeVariableMenu,'Value',1)
1725%         end
1726%         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
1727%         TimeVariableMenu_Callback(hObject, eventdata, handles)
1728%         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
1729%         set(handles.TimeAttribute,'Value',0)
1730%         TimeAttribute_Callback(hObject, eventdata, handles)
1731%     end
1732% else
1733%     set(handles.TimeVariableMenu,'Visible','off')
1734%     set(handles.TimeVarValue,'Visible','off')
1735% end
1736
1737% -----------------------------------------------------------------------
1738% --- Executes on selection change in TimeVariableMenu.
1739function TimeVariableMenu_Callback(hObject, eventdata, handles)
1740% -----------------------------------------------------------------------
1741ListVar=get(handles.TimeVariableMenu,'String');
1742index=get(handles.TimeVariableMenu,'Value');
1743TimeVariable=ListVar{index};% name of the selected variable
1744if isempty(TimeVariable)% case of blank selection
1745    return
1746end
1747Field=get(handles.get_field,'UserData'); %index of
1748VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
1749DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
1750set(handles.TimeDimensionMenu,'Value',1)
1751set(handles.TimeDimensionMenu,'String',DimName)
1752inputfile=get(handles.inputfile,'String');% read the input file
1753SubField=nc2struct(inputfile,{TimeVariable});
1754eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
1755ref_index=round(TimeDimension/2);
1756eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
1757set(handles.TimeIndexValue,'String',num2str(ref_index))
1758set(handles.TimeVarValue,'String',num2str(TimeValue))
1759
1760
1761function TimeValue_Callback(hObject, eventdata, handles)
1762%TO suppress
1763
1764% -----------------------------------------------------------------------
1765function TimeIndexValue_Callback(hObject, eventdata, handles)
1766% -----------------------------------------------------------------------
1767TimeIndex=str2double(get(handles.TimeIndexValue,'String'));
1768TimeVarName=Field.ListVarName{time_index};
1769set(handles.TimeVariable,'Value',1)
1770set(handles.TimeName,'String',TimeVarName)
1771fileinput=get(handles.inputfile,'String');
1772SubField=nc2struct(fileinput,{TimeVarName});
1773eval(['TimeValue=SubField.' TimeVarName '(ref_index);']);
1774set(handles.TimeValue,'Visible','on')
1775set(handles.TimeValue,'String',num2str(TimeValue))
1776
1777% -----------------------------------------------------------------------
1778function SelectFigure_Callback(hObject, eventdata, handles)
1779% -----------------------------------------------------------------------
1780val=get(handles.SelectFigure,'Value');
1781if val
1782    set(handles.list_fig,'Visible','on')
1783    %% look at the existing figures in the work space
1784    browse_fig(handles.list_fig)
1785else
1786   set(handles.list_fig,'Visible','off')
1787end
1788
1789
1790function TimeVarValue_Callback(hObject, eventdata, handles)
1791
1792
1793
1794% --- Executes on button press in check_rgb.
1795function check_rgb_Callback(hObject, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.