source: trunk/src/get_field.m @ 140

Last change on this file since 140 was 128, checked in by sommeria, 13 years ago

series: give writting access to the group for all subdirectories produced
uvmat.fig: change of vect and scalar frames (to be consistent with view_field)
uvmat: various cleaning
plot_field: various cleaning to improve axes definition and avoid blinking
geometry_calib: improved dispay of point coordiantes, improved link with dataview for REPLICATE.
struct2nc: repair bug , file was not closed.
cell2tab: cleaning
dataview: improve the browser
civ: solve pb of image naming

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