source: trunk/src/get_field.m @ 179

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

various bug repairs, in particular for 3D fields

File size: 56.7 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%---------------------------------------------------------
798figcell=get(handles.list_fig,'String');
799index=get(handles.list_fig,'value');
800figstring=figcell{index};
801if isequal(figstring,'uvmat')
802    huvmat=findobj(allchild(0),'tag','uvmat');
803    hhuvmat=guidata(huvmat);
804    uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
805else
806    huvmat=findobj(allchild(0),'tag','uvmat');
807    delete(huvmat)%
808    index=get(handles.ACTION,'Value');
809    list_func=get(handles.ACTION,'UserData');
810    h_fun=list_func{index};
811    set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
812    drawnow
813    SubField=h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
814    if ~isempty(SubField)
815        plot_get_field(SubField,handles)
816    end
817    browse_fig(handles.list_fig); %update the list of new existing figures
818end
819
820%------------------------------------------------------------------------
821% --- Function for plotting the current subfield
822function plot_get_field(SubField,handles)
823%------------------------------------------------------------------------
824list_fig=get(handles.list_fig,'String');
825val=get(handles.list_fig,'Value');
826if strcmp(list_fig{val},'uvmat')
827    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
828    set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
829    set(handles.MenuOpen,'Visible','off')
830    set(handles.MenuExport,'Visible','off')
831    uvmat(get(handles.inputfile,'String'))
832elseif strcmp(list_fig{val},'view_field')
833    view_field(SubField)
834else
835    hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI
836    if isnan(hfig)
837        hfig=figure;
838        list_fig=[list_fig;num2str(hfig)];
839        set(handles.list_fig,'String',list_fig);
840        haxes=axes;
841    else
842        figure(hfig);
843    end
844    haxes=findobj(hfig,'Type','axes');
845    plot_field(SubField,haxes)
846end
847
848% %------------------------------------------------
849% % --- Executes on button press in Plot_histo.
850% %RUN global histograms
851% %-------------------------------------------------
852% function RUN_histo_Callback(hObject, eventdata, handles)
853% % hObject    handle to RUN (see GCBO)
854% % eventdata  reserved - to be defined in a future version of MATLAB
855% % handles    structure with handles and user data (see GUIDATA)
856%
857% %time plots
858% leg={};
859% n=0;
860% if (get(handles.cm_switch,'Value')==1)
861%     Uval_p=Uval_cm;
862%     Vval_p=Vval_cm;
863%     Uhist_p=Uhist_cm;
864%     Vhist_p=Vhist_cm;
865%     xlab='velocity (cm/s)';
866% else
867%     Uval_p=Uval;
868%     Vval_p=Vval;
869%     Uhist_p=Uhist;
870%     Vhist_p=Vhist;
871%     xlab='velocity (pixels)';
872% end
873% if (get(handles.vector_y,'Value') == 1)
874%    hhh=figure(2);
875%    hold on
876%    title([filebase ', ' strindex ', ' fieldtitle])
877%    plot(Uval_p,Uhist_p,'b-')
878%    n=n+1;
879%    leg{n}='Uhist';
880%    xlabel(xlab)
881% end
882% if (get(handles.Vhist_input,'Value') == 1)
883%    hhh=figure(2);
884%    hold on
885%    title([filebase ', ' strindex ', ' fieldtitle])
886%    plot(Vval_p,Vhist_p,'r-')
887%    n=n+1;
888%    leg{n}='Vhist';
889%    xlabel(xlab);
890% end
891% if (get(handles.Chist_input,'Value') == 1)
892%    hhhh=figure(3);
893%    hold on
894%    title([filebase ', ' strindex ', ' fieldtitle])
895%    plot(Cval,Chist,'k-')
896%    leg{1}='Chist';
897% end
898% % hold off
899% grid on
900% legend(leg);
901
902% %-------------------------------------------------------------
903% % --- Executes on button press in Save_input.
904% function Save_input_Callback(hObject, eventdata, handles)
905% list_str=get(handles.abscissa,'String');
906% val=get(handles.abscissa,'Value');
907% var=list_str{val};
908% hselect_field=get(handles.Save_input,'parent')
909% set(hselect_field,'UserData',var);
910% set(hselect_field,'Tag','idle')
911
912%     
913% %-------------------------------------------------------------
914% % --- Executes on button press in save_histo.
915% function save_histo_Callback(hObject, eventdata, handles)
916% global filebase
917%
918% pathstr = fileparts(filebase)
919% if (get(handles.Chist_input,'Value') == 1)
920%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
921%     else
922
923%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
924% end
925% prompt={'save figure(2) as'}
926% dlg_title = 'save figure';
927% num_lines= 1;
928% answer = inputdlg(prompt,dlg_title,num_lines,def)
929% saveas(2,answer{1})
930 
931
932%%-------------------------------------------------------
933% --- Executes on button press in peaklocking.
934%-------------------------------------------------
935function peaklocking(handles)
936%evaluation of peacklocking errors
937%use splinhist: give spline coeff cc for a smooth histo (call spline4)
938%use histsmooth(x,cc): calculate the smooth histo for any value x
939%use histder(x,cc): calculate the derivative of the smooth histo
940global hfig1 hfig2 hfig3
941global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
942global xval xerror yval yerror
943
944set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
945set(handles.Vhist_input,'Value',1)
946set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
947
948%adjust the extremal values of the histogram in U with respect to integer
949%values
950minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
951maximU=round(max(Uval)-0.5)+0.5;
952minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
953maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
954nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
955nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
956Uval=[minim_fin:(1/nbb):maxim_fin];
957histu_min=zeros(nb_bin_min,1);
958histu_max=zeros(nb_bin_max,1);
959Uhist=[histu_min; Uhist ;histu_max]; % column vector
960
961%adjust the extremal values of the histogram in V
962minimV=round(min(Vval-0.5)+0.5);
963maximV=round(max(Vval-0.5)+0.5);
964minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
965maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
966nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
967nb_bin_max=round((maxim_fin -max(Vval))*nbb);
968Vval=[minim_fin:(1/nbb):maxim_fin];
969histu_min=zeros(nb_bin_min,1);
970histu_max=zeros(nb_bin_max,1);
971Vhist=[histu_min; Vhist ;histu_max]; % column vector
972
973% RUN_histo_Callback(hObject, eventdata, handles)
974% %adjust the histogram to integer values:
975
976%histoU and V
977[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
978[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
979
980% selection of value ranges such that histo>=10 (enough statistics)
981Uval_ind=find(Uhist>=10);
982ind_min=min(Uval_ind);
983ind_max=max(Uval_ind);
984U_min=Uval(ind_min);% minimum allowed value
985U_max=Uval(ind_max);%maximum allowed value
986
987% selection of value ranges such that histo>=10 (enough statistics)
988Vval_ind=find(Vhist>=10);
989ind_min=min(Vval_ind);
990ind_max=max(Vval_ind);
991V_min=Vval(ind_min);% minimum allowed value
992V_max=Vval(ind_max);%maximum allowed value
993
994figure(4)% plot U histogram with smoothed one
995plot(Uval,Uhist,'b')
996grid on
997hold on
998plot(Uval,Uhistinter,'r');
999hold off
1000
1001figure(5)% plot V histogram with smoothed one
1002plot(Vval,Vhist,'b')
1003grid on
1004hold on
1005plot(Vval,Vhistinter,'r');
1006hold off
1007
1008figure(6)% plot pixel error in two subplots
1009hfig4=subplot(2,1,1);
1010hfig5=subplot(2,1,2);
1011axes(hfig4)
1012plot(xval,xerror)
1013axis([U_min U_max -0.4 0.4])
1014xlabel('velocity u (pix)')
1015ylabel('peaklocking error (pix)')
1016grid on
1017axes(hfig5)
1018plot(yval,yerror)
1019axis([V_min V_max -0.4 0.4]);
1020xlabel('velocity v (pix)')
1021ylabel('peaklocking error (pix)')
1022grid on
1023
1024
1025% ------------------------------------------------------------------
1026function variables_Callback(hObject, eventdata, handles)
1027Tabchar={''};%default
1028Tabcell=[];
1029hselect_field=get(handles.variables,'parent');
1030Field=get(hselect_field,'UserData');
1031index=get(handles.variables,'Value');%index in the list 'variables'
1032if isequal(index,1)
1033    set(handles.attributes_txt,'String','global attributes')
1034% list global attribute names and values if index=1 (blank variable display) is selected
1035    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
1036        for iline=1:length(Field.ListGlobalAttribute)
1037            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
1038            if isfield(Field, Field.ListGlobalAttribute{iline})
1039                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
1040                if ischar(val);% attribute value is char string
1041                    Tabcell{iline,2}=val;
1042                elseif size(val,1)==1 %attribute value is a number or matlab vector
1043                    Tabcell{iline,2}=num2str(val);
1044                end
1045            end
1046        end
1047        Tabchar=cell2tab(Tabcell,'=');
1048    end
1049else
1050%list attribute names and values associated to the variable # injdex-1   
1051    list_var=get(handles.variables,'String');
1052    var_select=list_var{index};
1053    set(handles.attributes_txt,'String', ['attributes of ' var_select])
1054    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
1055%         nbline=0;
1056        VarAttr=Field.VarAttribute{index-1};
1057        if isstruct(VarAttr)
1058            attr_list=fieldnames(VarAttr);
1059            for iline=1:length(attr_list)
1060                Tabcell{iline,1}=attr_list{iline};
1061                eval(['val=VarAttr.' attr_list{iline} ';'])
1062                if ischar(val);
1063                    Tabcell{iline,2}=val;
1064                else
1065                     Tabcell{iline,2}=num2str(val);
1066                end
1067            end
1068        end
1069    end
1070
1071end
1072if ~isempty(Tabcell)
1073    Tabchar=cell2tab(Tabcell,'=');
1074    Tabchar=[{''};Tabchar];
1075end
1076set(handles.attributes,'Value',1);% select the first item
1077set(handles.attributes,'String',Tabchar);
1078
1079% list_var=get(handles.dimensions,'String');
1080% val=get(handles.dimensions,'Value');
1081
1082% update dimensions;
1083if isfield(Field,'ListDimName')
1084    Tabdim={};%default
1085    if isequal(index,1)%list all dimensions
1086        dim_indices=1:length(Field.ListDimName);
1087        set(handles.dimensions_txt,'String', 'dimensions')
1088    else
1089        DimCell=Field.VarDimName{index-1};
1090        if ischar(DimCell)
1091            DimCell={DimCell};
1092        end   
1093        dim_indices=[];
1094        for idim=1:length(DimCell)
1095            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
1096            dim_index=find(dim_index,1);
1097            dim_indices=[dim_indices dim_index];
1098        end
1099        %dim_indices=find(dim_list) %removes 0 values
1100        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1101    end
1102    for iline=1:length(dim_indices)
1103        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1104        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1105    end
1106    Tabchar=cell2tab(Tabdim,'=');
1107    Tabchar=[{''} ;Tabchar];
1108    set(handles.dimensions,'String',Tabchar) 
1109end 
1110
1111% --- Executes on button press in check_1Dplot.
1112function check_1Dplot_Callback(hObject, eventdata, handles)
1113val=get(handles.check_1Dplot,'Value');
1114if isequal(val,0)
1115    set(handles.Panel1Dplot,'Visible','off')
1116%      set(handles.scalar,'Visible','off')
1117%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1118%     if isequal(get(handles.check_vector,'Value'),0);
1119%         set(handles.coord_z_vectors_scalar,'Visible','off')
1120%     end
1121else
1122    set(handles.Panel1Dplot,'Visible','on')
1123%     set(handles.scalar,'Visible','on')
1124%     val=get(handles.ordinate,'Value');
1125%     val=val(1);
1126%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1127%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1128%       set(handles.coord_z_vectors_scalar,'Visible','on')
1129end
1130
1131% --- Executes on button press in check_scalar.
1132function check_scalar_Callback(hObject, eventdata, handles)
1133val=get(handles.check_scalar,'Value');
1134if isequal(val,0)
1135    set(handles.PanelScalar,'Visible','off')
1136else
1137    set(handles.PanelScalar,'Visible','on')
1138end
1139
1140%---------------------------
1141% --- Executes on button press in check_vector.
1142function check_vector_Callback(hObject, eventdata, handles)
1143val=get(handles.check_vector,'Value');
1144if isequal(val,0)
1145    set(handles.PanelVectors,'Visible','off')
1146else
1147    set(handles.PanelVectors,'Visible','on')
1148end
1149
1150%-----------------------------
1151function mouse_up_gui(ggg,eventdata,handles)
1152if isequal(get(ggg,'SelectionType'),'alt')
1153    message=''; 
1154    global CurData
1155    inputfield=get(handles.inputfile,'String');
1156    if exist(inputfield,'file')
1157        CurData=nc2struct(inputfield);
1158    else
1159        CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1160    end
1161  %%%% TODO: put the matalb command window in front
1162    evalin('base','global CurData')%make CurData global in the workspace
1163    evalin('base','CurData') %display CurData in the workspace
1164end
1165
1166%---------------------------------------------
1167% --- Executes on selection change in ACTION.
1168function ACTION_Callback(hObject, eventdata, handles)
1169global nb_builtin
1170list_ACTION=get(handles.ACTION,'String');% list menu fields
1171index_ACTION=get(handles.ACTION,'Value');% selected string index
1172ACTION= list_ACTION{index_ACTION}; % selected string
1173list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
1174ff=functions(list_func_handles{end});
1175% add a new function to the menu
1176if isequal(ACTION,'more...')
1177%     pathfct=fileparts(path_get_field);
1178%     browse_name=fullfile(path_get_field,'FIELD_FCT');
1179%     if length(list_path)>nb_builtin
1180%         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
1181%     end
1182    [FileName, PathName] = uigetfile( ...
1183       {'*.m', ' (*.m)';
1184        '*.m',  '.m files '; ...
1185        '*.*', 'All Files (*.*)'}, ...
1186        'Pick a file',ff.file);
1187    if length(FileName)<2
1188        return
1189    end
1190    [pp,ACTION,ext_fct]=fileparts(FileName);
1191    if ~isequal(ext_fct,'.m')
1192        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1193        return
1194    end
1195
1196    % insert the choice in the action menu
1197   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1198   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1199   addpath(PathName)
1200   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
1201   set(handles.ACTION,'UserData',list_func_handles)
1202   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1203   %list_path{index_ACTION}=PathName;
1204   if length(menu_str)>nb_builtin+5;
1205       nbremove=length(menu_str)-nb_builtin-5;
1206       menu_str(nb_builtin+1:end-5)=[];
1207       list_func_handles(nb_builtin+1:end-4)=[];
1208       index_ACTION=index_ACTION-nbremove;
1209       set(handles.ACTION,'Value',index_ACTION)
1210       set(handles.ACTION,'String',menu_str)
1211   end   
1212   %record the current menu in personal file profil_perso
1213   dir_perso=prefdir;
1214   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1215   for ilist=nb_builtin+1:length(menu_str)-1
1216       ff=functions(list_func_handles{ilist});
1217       get_field_fct{ilist-nb_builtin}=ff.file;
1218   end
1219   if exist(profil_perso,'file')
1220        save(profil_perso,'get_field_fct','-append')
1221   else
1222     txt=ver('MATLAB');
1223    Release=txt.Release;
1224       relnumb=str2num(Release(3:4));
1225        if relnumb >= 14
1226            save(profil_perso,'get_field_fct','-V6')
1227        else
1228            save(profil_perso, 'get_field_fct')
1229        end
1230   end
1231end
1232
1233%check the current path to the selected function
1234h_fun=list_func_handles{index_ACTION};
1235if isa(h_fun,'function_handle')
1236    func=functions(h_fun);
1237    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
1238    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
1239else
1240    set(handles.path_action,'String','')
1241    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
1242    return
1243end
1244
1245%prepare the GUI options for the selected ACTION
1246test_1Dplot=0;
1247test_scalar=0;
1248test_vector=0;
1249if iscell(GUI_input)
1250    for ilist=1:length(GUI_input)
1251        switch GUI_input{ilist}
1252                           %RootFile always visible
1253            case 'check_1Dplot'   
1254                 test_1Dplot=1;
1255            case 'check_scalar'
1256                 test_scalar=1;   
1257            case 'check_vector'   
1258                 test_vector=1;
1259        end
1260    end
1261end
1262set(handles.check_1Dplot,'Value',test_1Dplot);
1263set(handles.check_scalar,'Value',test_scalar);
1264set(handles.check_vector,'Value',test_vector);
1265check_1Dplot_Callback(hObject, eventdata, handles)
1266check_scalar_Callback(hObject, eventdata, handles)
1267check_vector_Callback(hObject, eventdata, handles)
1268
1269
1270%-----------------------------------------------------
1271% --- browse existing figures
1272%-----------------------------------------------------
1273function browse_fig(menu_handle)
1274hh=findobj(allchild(0),'Type','figure');
1275ilist=0;
1276list={};
1277for ifig=1:length(hh)  %look for all existing figures
1278    name=get(hh(ifig),'Name');
1279     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
1280        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1281        nbaxe=0;
1282        for ichild=1:length(hchild)           
1283            Type=get(hchild(ichild),'Type');
1284            Tag=get(hchild(ichild),'Tag');
1285            if isequal(Type,'axes')
1286                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1287                     nbaxe=nbaxe+1;%count the existing axis
1288                end
1289            end
1290        end   
1291        if nbaxe==1
1292             ilist=ilist+1;%add a line in the list of axis
1293            list{ilist,1}=num2str(hh(ifig));
1294        elseif nbaxe>1
1295            for iaxe=1:nbaxe
1296               ilist=ilist+1;%add a line in the list of axis
1297               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1298            end
1299        end
1300     end
1301end
1302list=['view_field';list];
1303set(menu_handle,'Value',1)
1304set(menu_handle,'String',list)
1305
1306
1307%-----------------------------------------------------
1308function list_fig_Callback(hObject, eventdata, handles)
1309%-----------------------------------------------------
1310list_fig=get(handles.list_fig,'String');
1311fig_val=get(handles.list_fig,'Value');
1312plot_fig=list_fig{fig_val};
1313if strcmp(plot_fig,'view_field')
1314%     huvmat=findobj(allchild(0),'name','uvmat');
1315%     if ~isempty(huvmat)
1316%         uistack(huvmat,'top')
1317%     end   
1318else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1319    sep=regexp(plot_fig,'_');
1320    if ~isempty(sep)
1321        plot_fig=plot_fig([1:sep-1]);
1322    end
1323    if ishandle(str2num(plot_fig))
1324        figure(str2num(plot_fig))% display existing figure
1325    else
1326        browse_fig(handles.list_fig); %reset the current list of figures
1327    end
1328end
1329
1330
1331%-------------------------------------------------
1332% give index numbers of the strings str in the list ListvarName
1333function VarIndex_y=name2index(cell_str,ListVarName)
1334VarIndex_y=[];
1335if ischar(cell_str)
1336    for ivar=1:length(ListVarName)
1337        varlist=ListVarName{ivar};
1338        if isequal(varlist,cell_str)
1339            VarIndex_y= ivar;
1340            break
1341        end
1342    end
1343elseif iscell(cell_str)
1344    for isel=1:length(cell_str)
1345        varsel=cell_str{isel};
1346        for ivar=1:length(ListVarName)
1347            varlist=ListVarName{ivar};
1348            if isequal(varlist,varsel)
1349                VarIndex_y=[VarIndex_y ivar];
1350            end
1351        end
1352    end
1353end
1354
1355% --------------------------------------------------------------------
1356function MenuOpen_Callback(hObject, eventdata, handles)
1357% hObject    handle to MenuOpen (see GCBO)
1358% eventdata  reserved - to be defined in a future version of MATLAB
1359% handles    structure with handles and user data (see GUIDATA)
1360
1361
1362% --------------------------------------------------------------------
1363function MenuExport_Callback(hObject, eventdata, handles)
1364% hObject    handle to MenuExport (see GCBO)
1365% eventdata  reserved - to be defined in a future version of MATLAB
1366% handles    structure with handles and user data (see GUIDATA)
1367
1368
1369% --------------------------------------------------------------------
1370function MenuBrowse_Callback(hObject, eventdata, handles)
1371
1372oldfile=get(handles.inputfile,'String');
1373testrootfile=0;
1374testsubdir=0;
1375if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1376        oldfile='';
1377        dir_perso=prefdir;
1378         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1379         if exist(profil_perso,'file')
1380              h=load (profil_perso);
1381             if isfield(h,'RootPath')
1382                  RootPath=h.RootPath;
1383             end
1384             if isfield(h,'SubDir')
1385                  SubDir=h.SubDir;
1386                  if ~isempty(SubDir)
1387                    testsubdir=1;
1388                  end
1389             end
1390             if isfield(h,'RootFile')
1391                  RootFile=h.RootFile;
1392                  if ~isempty(RootFile)
1393                    testrootfile=1;
1394                  end
1395             end
1396         end
1397end
1398if testrootfile
1399    if ~testsubdir
1400        oldfile=fullfile(RootPath,RootFile);
1401    else
1402        oldfile=fullfile(RootPath,SubDir,RootFile);
1403    end
1404end
1405[FileName, PathName] = uigetfile( ...
1406       {'*.nc', ' *.nc';...
1407       '*.cdf', ' *.cdf';...
1408        '*.*',  'All Files (*.*)'}, ...
1409        'Pick a file',oldfile);
1410
1411%global inputfile
1412fileinput=[PathName FileName];%complete file name
1413testblank=findstr(fileinput,' ');%look for blanks
1414if ~isempty(testblank)
1415    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
1416    return
1417end
1418sizf=size(fileinput);
1419if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
1420set(handles.inputfile,'String',fileinput)
1421inputfile_Callback(hObject, eventdata, handles)
1422
1423
1424%update list of recent files in the menubar
1425MenuFile_1=fileinput;
1426MenuFile_2=get(handles.MenuFile_1,'Label');
1427MenuFile_3=get(handles.MenuFile_2,'Label');
1428MenuFile_4=get(handles.MenuFile_3,'Label');
1429MenuFile_5=get(handles.MenuFile_4,'Label');
1430set(handles.MenuFile_1,'Label',MenuFile_1)
1431set(handles.MenuFile_2,'Label',MenuFile_2)
1432set(handles.MenuFile_3,'Label',MenuFile_3)
1433set(handles.MenuFile_4,'Label',MenuFile_4)
1434set(handles.MenuFile_5,'Label',MenuFile_5)
1435dir_perso=prefdir;
1436profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1437display(profil_perso)
1438if exist(profil_perso,'file')
1439    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1440else
1441    txt=ver('MATLAB');
1442    Release=txt.Release;
1443    relnumb=str2double(Release(3:4));
1444    if relnumb >= 14
1445        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1446    else
1447        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1448    end
1449end
1450
1451% --------------------------------------------------------------------
1452function MenuFile_1_Callback(hObject, eventdata, handles)
1453fileinput=get(handles.MenuFile_1,'Label');
1454set(handles.inputfile,'String',fileinput)
1455inputfile_Callback(hObject, eventdata, handles)
1456
1457% --------------------------------------------------------------------
1458function MenuFile_2_Callback(hObject, eventdata, handles)
1459fileinput=get(handles.MenuFile_2,'Label');
1460set(handles.inputfile,'String',fileinput)
1461inputfile_Callback(hObject, eventdata, handles)
1462
1463% --------------------------------------------------------------------
1464function MenuFile_3_Callback(hObject, eventdata, handles)
1465fileinput=get(handles.MenuFile_3,'Label');
1466set(handles.inputfile,'String',fileinput)
1467inputfile_Callback(hObject, eventdata, handles)
1468
1469% --------------------------------------------------------------------
1470function MenuFile_4_Callback(hObject, eventdata, handles)
1471fileinput=get(handles.MenuFile_4,'Label');
1472set(handles.inputfile,'String',fileinput)
1473inputfile_Callback(hObject, eventdata, handles)
1474
1475% --------------------------------------------------------------------
1476function MenuFile_5_Callback(hObject, eventdata, handles)
1477fileinput=get(handles.MenuFile_5,'Label');
1478set(handles.inputfile,'String',fileinput)
1479inputfile_Callback(hObject, eventdata, handles)
1480
1481% --------------------------------------------------------------------
1482function MenuExportField_Callback(hObject, eventdata, handles)
1483global Data_get_field
1484% huvmat=findobj(allchild(0),'Name','uvmat');
1485inputfile=get(handles.inputfile,'String');
1486Data_get_field=nc2struct(inputfile);
1487% Data_view_field=UvData.ProjField_2;
1488evalin('base','global Data_get_field')%make CurData global in the workspace
1489display(['content of ' inputfile ':'])
1490evalin('base','Data_get_field') %display CurData in the workspace
1491commandwindow;
1492
1493% --------------------------------------------------------------------
1494function MenuHelp_Callback(hObject, eventdata, handles)
1495% hObject    handle to MenuHelp (see GCBO)
1496% eventdata  reserved - to be defined in a future version of MATLAB
1497% handles    structure with handles and user data (see GUIDATA)
1498path_to_uvmat=which ('uvmat');% check the path of uvmat
1499pathelp=fileparts(path_to_uvmat);
1500helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1501if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1502else
1503web([helpfile '#get_field'])   
1504end
1505
Note: See TracBrowser for help on using the repository browser.