source: trunk/src/get_field.m @ 173

Last change on this file since 173 was 150, checked in by sommeria, 13 years ago

various corrections for plotting and using view_field and get_field. The current field of uvmat or view_field is now stored in the structure userdata.axes3. Introduction of live correlation to test PIV (civ1)

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