source: trunk/src/get_field.m @ 146

Last change on this file since 146 was 144, checked in by sommeria, 14 years ago

connection between uvmat and get_field improved, cleaning of GUI get_field

File size: 56.6 KB
Line 
1%'get_field': display variables and attributes from a Netcdf file, and RUN selected fields
2%------------------------------------------------------------------------
3%function varargout = get_field(varargin)
4% associated with the GUI get_field.fig
5%
6%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%     This file is part of the toolbox UVMAT.
10%
11%     UVMAT is free software; you can redistribute it and/or modify
12%     it under the terms of the GNU General Public License as published by
13%     the Free Software Foundation; either version 2 of the License, or
14%     (at your option) any later version.
15%
16%     UVMAT is distributed in the hope that it will be useful,
17%     but WITHOUT ANY WARRANTY; without even the implied warranty of
18%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21
22function varargout = get_field(varargin)
23
24% Last Modified by GUIDE v2.5 06-Feb-2010 09:58:13
25
26% Begin initialization code - DO NOT EDIT
27gui_Singleton = 0;
28gui_State = struct('gui_Name',       mfilename, ...
29                   'gui_Singleton',  gui_Singleton, ...
30                   'gui_OpeningFcn', @get_field_OpeningFcn, ...
31                   'gui_OutputFcn',  @get_field_OutputFcn, ...
32                   'gui_LayoutFcn',  [] , ...
33                   'gui_Callback',   []);
34if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
35    gui_State.gui_Callback = str2func(varargin{1});
36end
37
38if nargout
39    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
40else
41    gui_mainfcn(gui_State, varargin{:});
42end
43% End initialization code - DO NOT EDIT
44
45%------------------------------------------------------------------------
46% --- Executes just before get_field is made visible.
47function get_field_OpeningFcn(hObject, eventdata, handles,filename,Field,haxes)
48%------------------------------------------------------------------------
49global nb_builtin
50
51%% look at the existing figues in the work space
52browse_fig(handles.list_fig)
53
54%% Choose default command line output for get_field
55handles.output = hObject;
56
57%% Update handles structure
58guidata(hObject, handles);
59
60%% activate the mouse action function: visualise the current field on work space by right click action
61set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})
62
63%% prepare the list of builtin fcts and set their paths
64menu_str={'PLOT';'FFT';'filter_band';'histogram'}; %list of functions included by default in 'get_field.m'
65nb_builtin=numel(menu_str);
66path_uvmat=fileparts(which('uvmat'));%path of the function 'uvmat'
67addpath(fullfile(path_uvmat,'get_field'))
68testexist=zeros(size(menu_str'));%default
69for ilist=1:length(menu_str)
70    if exist(menu_str{ilist},'file')
71        fct_handle{ilist,1}=str2func(menu_str{ilist});
72        testexist(ilist)=1;
73    else
74        fct_handle{ilist,1}=[];
75        testexist(ilist)=0;
76    end
77end
78rmpath(fullfile(path_uvmat,'get_field'))
79dir_perso=prefdir;
80profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
81if exist(profil_perso,'file')
82    % menu={'RUN';'raw2phys';'histogram';'FFT';'peaklocking'};
83      h=load (profil_perso);
84     if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
85         for ilist=1:length(h.get_field_fct)
86            [path,file]=fileparts(h.get_field_fct{ilist});
87            addpath(path)       
88            if exist(file,'file')
89                h_func=str2func(file);
90                testexist=[testexist 1];
91             else
92                h_func=[];
93                testexist=[testexist 0];
94             end
95             fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
96             rmpath(path)
97             menu_str=[menu_str; {file}];
98         end
99     end
100end
101menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
102fct_handle=fct_handle(testexist==1);
103menu_str=[menu_str;{'more...'}];
104set(handles.ACTION,'String',menu_str)
105set(handles.ACTION,'UserData',fct_handle)% store the list of path in UserData of ACTION
106set(handles.path_action,'String',fullfile(path_uvmat,'get_field'))
107set(handles.ACTION,'Value',1)% PLOT option selected
108
109%% settings for 'slave' mode, called by uvamt, or 'master' mode
110if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
111    set(handles.inputfile,'String',filename)% prefill the input file name
112    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
113  %  set(handles.list_fig,'Value',2)% plotting axes =uvmat selected
114  %  set(handles.list_fig,'Visible','off')%
115    set(handles.RUN,'String','REFRESH')% passive mode, get_field used to define the field for uvamt
116    set(handles.MenuOpen,'Visible','off')
117    set(handles.MenuExport,'Visible','off')
118    set(handles.MenuHelp,'Visible','off')
119    inputfile_Callback(hObject, eventdata, handles)
120else  %master mode
121    set(handles.inputfile,'String','')   
122    set(handles.RUN,'String','RUN')%
123    % load the list of previously browsed files for the upper bar menu Open
124    dir_perso=prefdir;
125    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
126    if exist(profil_perso,'file')
127        h=load (profil_perso);
128        if isfield(h,'MenuFile_1')
129            set(handles.MenuFile_1,'Label',h.MenuFile_1);
130        end
131        if isfield(h,'MenuFile_1')
132            set(handles.MenuFile_2,'Label',h.MenuFile_2);
133        end
134        if isfield(h,'MenuFile_1')
135            set(handles.MenuFile_3,'Label',h.MenuFile_3);
136        end
137        if isfield(h,'MenuFile_1')
138            set(handles.MenuFile_4,'Label',h.MenuFile_4);
139        end
140        if isfield(h,'MenuFile_1')
141            set(handles.MenuFile_5,'Label',h.MenuFile_5);
142        end
143    end
144end
145%transfer input field  in slave mode
146if exist('Field','var') && isstruct(Field)
147        Field_input(eventdata,handles,Field)
148%         if exist('haxes','var')
149%             'TESTget'
150%             get(haxes,'Tag')
151%             Field.PlotAxes=haxes;
152%         end
153    set(hObject,'UserData',Field);
154end
155
156
157
158%------------------------------------------------------------------------
159% --- Outputs from this function are returned to the command line.
160function varargout = get_field_OutputFcn(hObject, eventdata, handles)
161%------------------------------------------------------------------------
162varargout{1} = handles.output;
163
164%------------------------------------------------------------------------
165% --- Executes on button press in browse.
166function browse_Callback(hObject, eventdata, handles)
167%------------------------------------------------------------------------
168
169%------------------------------------------------------------------------
170function inputfile_Callback(hObject, eventdata, handles)
171%------------------------------------------------------------------------
172inputfile=get(handles.inputfile,'String');
173Field=nc2struct(inputfile);% reads the whole field
174set(handles.figure1,'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%---------------------------------------------------------
794figstring=get(handles.list_fig,'String');
795if isequal(figstring,{'uvmat'})
796    huvmat=findobj(allchild(0),'tag','uvmat');
797    hhuvmat=guidata(huvmat);
798    uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
799else
800    index=get(handles.ACTION,'Value');
801    list_func=get(handles.ACTION,'UserData');
802    h_fun=list_func{index};
803    set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
804    drawnow
805    SubField=h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
806    if ~isempty(SubField)
807        plot_get_field(SubField,handles)
808    end
809    browse_fig(handles.list_fig); %update the list of new existing figures
810end
811
812%------------------------------------------------------------------------
813function plot_get_field(SubField,handles)
814%------------------------------------------------------------------------
815list_fig=get(handles.list_fig,'String');
816val=get(handles.list_fig,'Value');
817if strcmp(list_fig{val},'uvmat')
818%     set(handles.figure1,'Name','uvmat_field')
819    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
820%     set(handles.list_fig,'Visible','off')%
821    set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
822    set(handles.MenuOpen,'Visible','off')
823    set(handles.MenuExport,'Visible','off')
824    uvmat(get(handles.inputfile,'String'))
825elseif strcmp(list_fig{val},'view_field')
826    view_field(SubField)
827else
828    hfig=str2num(list_fig{val});% chosen figure number from tyhe GUI
829    if isempty(hfig)
830        hfig=figure;
831        list_fig=[list_fig;num2str(hfig)];
832        set(handles.list_fig,'String',list_fig);
833        haxes=axes;
834    else
835        figure(hfig);
836    end
837    haxes=findobj(hfig,'Type','axes');
838    plot_field(SubField,haxes)
839end
840
841% %------------------------------------------------
842% % --- Executes on button press in Plot_histo.
843% %RUN global histograms
844% %-------------------------------------------------
845% function RUN_histo_Callback(hObject, eventdata, handles)
846% % hObject    handle to RUN (see GCBO)
847% % eventdata  reserved - to be defined in a future version of MATLAB
848% % handles    structure with handles and user data (see GUIDATA)
849%
850% %time plots
851% leg={};
852% n=0;
853% if (get(handles.cm_switch,'Value')==1)
854%     Uval_p=Uval_cm;
855%     Vval_p=Vval_cm;
856%     Uhist_p=Uhist_cm;
857%     Vhist_p=Vhist_cm;
858%     xlab='velocity (cm/s)';
859% else
860%     Uval_p=Uval;
861%     Vval_p=Vval;
862%     Uhist_p=Uhist;
863%     Vhist_p=Vhist;
864%     xlab='velocity (pixels)';
865% end
866% if (get(handles.vector_y,'Value') == 1)
867%    hhh=figure(2);
868%    hold on
869%    title([filebase ', ' strindex ', ' fieldtitle])
870%    plot(Uval_p,Uhist_p,'b-')
871%    n=n+1;
872%    leg{n}='Uhist';
873%    xlabel(xlab)
874% end
875% if (get(handles.Vhist_input,'Value') == 1)
876%    hhh=figure(2);
877%    hold on
878%    title([filebase ', ' strindex ', ' fieldtitle])
879%    plot(Vval_p,Vhist_p,'r-')
880%    n=n+1;
881%    leg{n}='Vhist';
882%    xlabel(xlab);
883% end
884% if (get(handles.Chist_input,'Value') == 1)
885%    hhhh=figure(3);
886%    hold on
887%    title([filebase ', ' strindex ', ' fieldtitle])
888%    plot(Cval,Chist,'k-')
889%    leg{1}='Chist';
890% end
891% % hold off
892% grid on
893% legend(leg);
894
895% %-------------------------------------------------------------
896% % --- Executes on button press in Save_input.
897% function Save_input_Callback(hObject, eventdata, handles)
898% list_str=get(handles.abscissa,'String');
899% val=get(handles.abscissa,'Value');
900% var=list_str{val};
901% hselect_field=get(handles.Save_input,'parent')
902% set(hselect_field,'UserData',var);
903% set(hselect_field,'Tag','idle')
904
905%     
906% %-------------------------------------------------------------
907% % --- Executes on button press in save_histo.
908% function save_histo_Callback(hObject, eventdata, handles)
909% global filebase
910%
911% pathstr = fileparts(filebase)
912% if (get(handles.Chist_input,'Value') == 1)
913%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
914%     else
915
916%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
917% end
918% prompt={'save figure(2) as'}
919% dlg_title = 'save figure';
920% num_lines= 1;
921% answer = inputdlg(prompt,dlg_title,num_lines,def)
922% saveas(2,answer{1})
923 
924
925%%-------------------------------------------------------
926% --- Executes on button press in peaklocking.
927%-------------------------------------------------
928function peaklocking(handles)
929%evaluation of peacklocking errors
930%use splinhist: give spline coeff cc for a smooth histo (call spline4)
931%use histsmooth(x,cc): calculate the smooth histo for any value x
932%use histder(x,cc): calculate the derivative of the smooth histo
933global hfig1 hfig2 hfig3
934global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
935global xval xerror yval yerror
936
937set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
938set(handles.Vhist_input,'Value',1)
939set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
940
941%adjust the extremal values of the histogram in U with respect to integer
942%values
943minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
944maximU=round(max(Uval)-0.5)+0.5;
945minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
946maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
947nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
948nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
949Uval=[minim_fin:(1/nbb):maxim_fin];
950histu_min=zeros(nb_bin_min,1);
951histu_max=zeros(nb_bin_max,1);
952Uhist=[histu_min; Uhist ;histu_max]; % column vector
953
954%adjust the extremal values of the histogram in V
955minimV=round(min(Vval-0.5)+0.5);
956maximV=round(max(Vval-0.5)+0.5);
957minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
958maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
959nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
960nb_bin_max=round((maxim_fin -max(Vval))*nbb);
961Vval=[minim_fin:(1/nbb):maxim_fin];
962histu_min=zeros(nb_bin_min,1);
963histu_max=zeros(nb_bin_max,1);
964Vhist=[histu_min; Vhist ;histu_max]; % column vector
965
966% RUN_histo_Callback(hObject, eventdata, handles)
967% %adjust the histogram to integer values:
968
969%histoU and V
970[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
971[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
972
973% selection of value ranges such that histo>=10 (enough statistics)
974Uval_ind=find(Uhist>=10);
975ind_min=min(Uval_ind);
976ind_max=max(Uval_ind);
977U_min=Uval(ind_min);% minimum allowed value
978U_max=Uval(ind_max);%maximum allowed value
979
980% selection of value ranges such that histo>=10 (enough statistics)
981Vval_ind=find(Vhist>=10);
982ind_min=min(Vval_ind);
983ind_max=max(Vval_ind);
984V_min=Vval(ind_min);% minimum allowed value
985V_max=Vval(ind_max);%maximum allowed value
986
987figure(4)% plot U histogram with smoothed one
988plot(Uval,Uhist,'b')
989grid on
990hold on
991plot(Uval,Uhistinter,'r');
992hold off
993
994figure(5)% plot V histogram with smoothed one
995plot(Vval,Vhist,'b')
996grid on
997hold on
998plot(Vval,Vhistinter,'r');
999hold off
1000
1001figure(6)% plot pixel error in two subplots
1002hfig4=subplot(2,1,1);
1003hfig5=subplot(2,1,2);
1004axes(hfig4)
1005plot(xval,xerror)
1006axis([U_min U_max -0.4 0.4])
1007xlabel('velocity u (pix)')
1008ylabel('peaklocking error (pix)')
1009grid on
1010axes(hfig5)
1011plot(yval,yerror)
1012axis([V_min V_max -0.4 0.4]);
1013xlabel('velocity v (pix)')
1014ylabel('peaklocking error (pix)')
1015grid on
1016
1017
1018% ------------------------------------------------------------------
1019function variables_Callback(hObject, eventdata, handles)
1020Tabchar={''};%default
1021Tabcell=[];
1022hselect_field=get(handles.variables,'parent');
1023Field=get(hselect_field,'UserData');
1024index=get(handles.variables,'Value');%index in the list 'variables'
1025if isequal(index,1)
1026    set(handles.attributes_txt,'String','global attributes')
1027% list global attribute names and values if index=1 (blank variable display) is selected
1028    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
1029        for iline=1:length(Field.ListGlobalAttribute)
1030            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
1031            if isfield(Field, Field.ListGlobalAttribute{iline})
1032                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
1033                if ischar(val);% attribute value is char string
1034                    Tabcell{iline,2}=val;
1035                elseif size(val,1)==1 %attribute value is a number or matlab vector
1036                    Tabcell{iline,2}=num2str(val);
1037                end
1038            end
1039        end
1040        Tabchar=cell2tab(Tabcell,'=');
1041    end
1042else
1043%list attribute names and values associated to the variable # injdex-1   
1044    list_var=get(handles.variables,'String');
1045    var_select=list_var{index};
1046    set(handles.attributes_txt,'String', ['attributes of ' var_select])
1047    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
1048%         nbline=0;
1049        VarAttr=Field.VarAttribute{index-1};
1050        if isstruct(VarAttr)
1051            attr_list=fieldnames(VarAttr);
1052            for iline=1:length(attr_list)
1053                Tabcell{iline,1}=attr_list{iline};
1054                eval(['val=VarAttr.' attr_list{iline} ';'])
1055                if ischar(val);
1056                    Tabcell{iline,2}=val;
1057                else
1058                     Tabcell{iline,2}=num2str(val);
1059                end
1060            end
1061        end
1062    end
1063
1064end
1065if ~isempty(Tabcell)
1066    Tabchar=cell2tab(Tabcell,'=');
1067    Tabchar=[{''};Tabchar];
1068end
1069set(handles.attributes,'Value',1);% select the first item
1070set(handles.attributes,'String',Tabchar);
1071
1072% list_var=get(handles.dimensions,'String');
1073% val=get(handles.dimensions,'Value');
1074
1075% update dimensions;
1076if isfield(Field,'ListDimName')
1077    Field.ListDimName
1078    Tabdim={};%default
1079    if isequal(index,1)%list all dimensions
1080        dim_indices=1:length(Field.ListDimName);
1081        set(handles.dimensions_txt,'String', 'dimensions')
1082    else
1083        DimCell=Field.VarDimName{index-1};
1084        if ischar(DimCell)
1085            DimCell={DimCell};
1086        end   
1087        dim_indices=[];
1088        for idim=1:length(DimCell)
1089            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
1090            dim_index=find(dim_index,1);
1091            dim_indices=[dim_indices dim_index];
1092        end
1093        %dim_indices=find(dim_list) %removes 0 values
1094        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1095    end
1096    for iline=1:length(dim_indices)
1097        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1098        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1099    end
1100    Tabchar=cell2tab(Tabdim,'=');
1101    Tabchar=[{''} ;Tabchar];
1102    set(handles.dimensions,'String',Tabchar) 
1103end 
1104
1105% --- Executes on button press in check_1Dplot.
1106function check_1Dplot_Callback(hObject, eventdata, handles)
1107val=get(handles.check_1Dplot,'Value');
1108if isequal(val,0)
1109    set(handles.Panel1Dplot,'Visible','off')
1110%      set(handles.scalar,'Visible','off')
1111%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1112%     if isequal(get(handles.check_vector,'Value'),0);
1113%         set(handles.coord_z_vectors_scalar,'Visible','off')
1114%     end
1115else
1116    set(handles.Panel1Dplot,'Visible','on')
1117%     set(handles.scalar,'Visible','on')
1118%     val=get(handles.ordinate,'Value');
1119%     val=val(1);
1120%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1121%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1122%       set(handles.coord_z_vectors_scalar,'Visible','on')
1123end
1124
1125% --- Executes on button press in check_scalar.
1126function check_scalar_Callback(hObject, eventdata, handles)
1127val=get(handles.check_scalar,'Value');
1128if isequal(val,0)
1129    set(handles.PanelScalar,'Visible','off')
1130else
1131    set(handles.PanelScalar,'Visible','on')
1132end
1133
1134%---------------------------
1135% --- Executes on button press in check_vector.
1136function check_vector_Callback(hObject, eventdata, handles)
1137val=get(handles.check_vector,'Value');
1138if isequal(val,0)
1139    set(handles.PanelVectors,'Visible','off')
1140else
1141    set(handles.PanelVectors,'Visible','on')
1142end
1143
1144%-----------------------------
1145function mouse_up_gui(ggg,eventdata,handles)
1146if isequal(get(ggg,'SelectionType'),'alt')
1147    message=''; 
1148    global CurData
1149    inputfield=get(handles.inputfile,'String');
1150    if exist(inputfield,'file')
1151        CurData=nc2struct(inputfield);
1152    else
1153        CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1154    end
1155  %%%% TODO: put the matalb command window in front
1156    evalin('base','global CurData')%make CurData global in the workspace
1157    evalin('base','CurData') %display CurData in the workspace
1158end
1159
1160%---------------------------------------------
1161% --- Executes on selection change in ACTION.
1162function ACTION_Callback(hObject, eventdata, handles)
1163global nb_builtin
1164list_ACTION=get(handles.ACTION,'String');% list menu fields
1165index_ACTION=get(handles.ACTION,'Value');% selected string index
1166ACTION= list_ACTION{index_ACTION}; % selected string
1167list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
1168ff=functions(list_func_handles{end});
1169% add a new function to the menu
1170if isequal(ACTION,'more...')
1171%     pathfct=fileparts(path_get_field);
1172%     browse_name=fullfile(path_get_field,'FIELD_FCT');
1173%     if length(list_path)>nb_builtin
1174%         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
1175%     end
1176    [FileName, PathName] = uigetfile( ...
1177       {'*.m', ' (*.m)';
1178        '*.m',  '.m files '; ...
1179        '*.*', 'All Files (*.*)'}, ...
1180        'Pick a file',ff.file);
1181    if length(FileName)<2
1182        return
1183    end
1184    [pp,ACTION,ext_fct]=fileparts(FileName);
1185    if ~isequal(ext_fct,'.m')
1186        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1187        return
1188    end
1189
1190    % insert the choice in the action menu
1191   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1192   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1193   addpath(PathName)
1194   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
1195   set(handles.ACTION,'UserData',list_func_handles)
1196   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1197   %list_path{index_ACTION}=PathName;
1198   if length(menu_str)>nb_builtin+5;
1199       nbremove=length(menu_str)-nb_builtin-5;
1200       menu_str(nb_builtin+1:end-5)=[];
1201       list_func_handles(nb_builtin+1:end-4)=[];
1202       index_ACTION=index_ACTION-nbremove;
1203       set(handles.ACTION,'Value',index_ACTION)
1204       set(handles.ACTION,'String',menu_str)
1205   end   
1206   %record the current menu in personal file profil_perso
1207   dir_perso=prefdir;
1208   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1209   for ilist=nb_builtin+1:length(menu_str)-1
1210       ff=functions(list_func_handles{ilist});
1211       get_field_fct{ilist-nb_builtin}=ff.file;
1212   end
1213   if exist(profil_perso,'file')
1214        save(profil_perso,'get_field_fct','-append')
1215   else
1216        txt=ver;
1217        Release=txt(1).Release;
1218        relnumb=str2num(Release(3:4));
1219        if relnumb >= 14
1220            save(profil_perso,'get_field_fct','-V6')
1221        else
1222            save(profil_perso, 'get_field_fct')
1223        end
1224   end
1225end
1226
1227%check the current path to the selected function
1228h_fun=list_func_handles{index_ACTION};
1229if isa(h_fun,'function_handle')
1230    func=functions(h_fun);
1231    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
1232    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
1233else
1234    set(handles.path_action,'String','')
1235    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
1236    return
1237end
1238
1239%prepare the GUI options for the selected ACTION
1240test_1Dplot=0;
1241test_scalar=0;
1242test_vector=0;
1243if iscell(GUI_input)
1244    for ilist=1:length(GUI_input)
1245        switch GUI_input{ilist}
1246                           %RootFile always visible
1247            case 'check_1Dplot'   
1248                 test_1Dplot=1;
1249            case 'check_scalar'
1250                 test_scalar=1;   
1251            case 'check_vector'   
1252                 test_vector=1;
1253        end
1254    end
1255end
1256set(handles.check_1Dplot,'Value',test_1Dplot);
1257set(handles.check_scalar,'Value',test_scalar);
1258set(handles.check_vector,'Value',test_vector);
1259check_1Dplot_Callback(hObject, eventdata, handles)
1260check_scalar_Callback(hObject, eventdata, handles)
1261check_vector_Callback(hObject, eventdata, handles)
1262
1263
1264%-----------------------------------------------------
1265% --- browse existing figures
1266%-----------------------------------------------------
1267function browse_fig(menu_handle)
1268hh=findobj(allchild(0),'Type','figure');
1269ilist=0;
1270list={};
1271for ifig=1:length(hh)  %look for all existing figures
1272    name=get(hh(ifig),'Name');
1273     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
1274        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1275        nbaxe=0;
1276        for ichild=1:length(hchild)           
1277            Type=get(hchild(ichild),'Type');
1278            Tag=get(hchild(ichild),'Tag');
1279            if isequal(Type,'axes')
1280                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1281                     nbaxe=nbaxe+1;%count the existing axis
1282                end
1283            end
1284        end   
1285        if nbaxe==1
1286             ilist=ilist+1;%add a line in the list of axis
1287            list{ilist,1}=num2str(hh(ifig));
1288        elseif nbaxe>1
1289            for iaxe=1:nbaxe
1290               ilist=ilist+1;%add a line in the list of axis
1291               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1292            end
1293        end
1294     end
1295end
1296list=['view_field';list];
1297set(menu_handle,'Value',1)
1298set(menu_handle,'String',list)
1299
1300
1301%-----------------------------------------------------
1302function list_fig_Callback(hObject, eventdata, handles)
1303%-----------------------------------------------------
1304list_fig=get(handles.list_fig,'String');
1305fig_val=get(handles.list_fig,'Value');
1306plot_fig=list_fig{fig_val};
1307if strcmp(plot_fig,'view_field')
1308%     huvmat=findobj(allchild(0),'name','uvmat');
1309%     if ~isempty(huvmat)
1310%         uistack(huvmat,'top')
1311%     end   
1312else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1313    sep=regexp(plot_fig,'_');
1314    if ~isempty(sep)
1315        plot_fig=plot_fig([1:sep-1]);
1316    end
1317    if ishandle(str2num(plot_fig))
1318        figure(str2num(plot_fig))% display existing figure
1319    else
1320        browse_fig(handles.list_fig); %reset the current list of figures
1321    end
1322end
1323
1324
1325%-------------------------------------------------
1326% give index numbers of the strings str in the list ListvarName
1327function VarIndex_y=name2index(cell_str,ListVarName)
1328VarIndex_y=[];
1329if ischar(cell_str)
1330    for ivar=1:length(ListVarName)
1331        varlist=ListVarName{ivar};
1332        if isequal(varlist,cell_str)
1333            VarIndex_y= ivar;
1334            break
1335        end
1336    end
1337elseif iscell(cell_str)
1338    for isel=1:length(cell_str)
1339        varsel=cell_str{isel};
1340        for ivar=1:length(ListVarName)
1341            varlist=ListVarName{ivar};
1342            if isequal(varlist,varsel)
1343                VarIndex_y=[VarIndex_y ivar];
1344            end
1345        end
1346    end
1347end
1348
1349% --------------------------------------------------------------------
1350function MenuOpen_Callback(hObject, eventdata, handles)
1351% hObject    handle to MenuOpen (see GCBO)
1352% eventdata  reserved - to be defined in a future version of MATLAB
1353% handles    structure with handles and user data (see GUIDATA)
1354
1355
1356% --------------------------------------------------------------------
1357function MenuExport_Callback(hObject, eventdata, handles)
1358% hObject    handle to MenuExport (see GCBO)
1359% eventdata  reserved - to be defined in a future version of MATLAB
1360% handles    structure with handles and user data (see GUIDATA)
1361
1362
1363% --------------------------------------------------------------------
1364function MenuBrowse_Callback(hObject, eventdata, handles)
1365
1366oldfile=get(handles.inputfile,'String');
1367testrootfile=0;
1368testsubdir=0;
1369if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1370        oldfile='';
1371        dir_perso=prefdir;
1372         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1373         if exist(profil_perso,'file')
1374              h=load (profil_perso);
1375             if isfield(h,'RootPath')
1376                  RootPath=h.RootPath;
1377             end
1378             if isfield(h,'SubDir')
1379                  SubDir=h.SubDir;
1380                  if ~isempty(SubDir)
1381                    testsubdir=1;
1382                  end
1383             end
1384             if isfield(h,'RootFile')
1385                  RootFile=h.RootFile;
1386                  if ~isempty(RootFile)
1387                    testrootfile=1;
1388                  end
1389             end
1390         end
1391end
1392if testrootfile
1393    if ~testsubdir
1394        oldfile=fullfile(RootPath,RootFile);
1395    else
1396        oldfile=fullfile(RootPath,SubDir,RootFile);
1397    end
1398end
1399[FileName, PathName] = uigetfile( ...
1400       {'*.nc', ' *.nc';...
1401       '*.cdf', ' *.cdf';...
1402        '*.*',  'All Files (*.*)'}, ...
1403        'Pick a file',oldfile);
1404
1405%global inputfile
1406fileinput=[PathName FileName];%complete file name
1407testblank=findstr(fileinput,' ');%look for blanks
1408if ~isempty(testblank)
1409    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
1410    return
1411end
1412sizf=size(fileinput);
1413if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
1414set(handles.inputfile,'String',fileinput)
1415inputfile_Callback(hObject, eventdata, handles)
1416
1417
1418%update list of recent files in the menubar
1419MenuFile_1=fileinput;
1420MenuFile_2=get(handles.MenuFile_1,'Label');
1421MenuFile_3=get(handles.MenuFile_2,'Label');
1422MenuFile_4=get(handles.MenuFile_3,'Label');
1423MenuFile_5=get(handles.MenuFile_4,'Label');
1424set(handles.MenuFile_1,'Label',MenuFile_1)
1425set(handles.MenuFile_2,'Label',MenuFile_2)
1426set(handles.MenuFile_3,'Label',MenuFile_3)
1427set(handles.MenuFile_4,'Label',MenuFile_4)
1428set(handles.MenuFile_5,'Label',MenuFile_5)
1429dir_perso=prefdir;
1430profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1431display(profil_perso)
1432if exist(profil_perso,'file')
1433    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1434else
1435    txt=ver;
1436    Release=txt(1).Release;
1437    relnumb=str2double(Release(3:4));
1438    if relnumb >= 14
1439        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1440    else
1441        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1442    end
1443end
1444
1445% --------------------------------------------------------------------
1446function MenuFile_1_Callback(hObject, eventdata, handles)
1447fileinput=get(handles.MenuFile_1,'Label');
1448set(handles.inputfile,'String',fileinput)
1449inputfile_Callback(hObject, eventdata, handles)
1450
1451% --------------------------------------------------------------------
1452function MenuFile_2_Callback(hObject, eventdata, handles)
1453fileinput=get(handles.MenuFile_2,'Label');
1454set(handles.inputfile,'String',fileinput)
1455inputfile_Callback(hObject, eventdata, handles)
1456
1457% --------------------------------------------------------------------
1458function MenuFile_3_Callback(hObject, eventdata, handles)
1459fileinput=get(handles.MenuFile_3,'Label');
1460set(handles.inputfile,'String',fileinput)
1461inputfile_Callback(hObject, eventdata, handles)
1462
1463% --------------------------------------------------------------------
1464function MenuFile_4_Callback(hObject, eventdata, handles)
1465fileinput=get(handles.MenuFile_4,'Label');
1466set(handles.inputfile,'String',fileinput)
1467inputfile_Callback(hObject, eventdata, handles)
1468
1469% --------------------------------------------------------------------
1470function MenuFile_5_Callback(hObject, eventdata, handles)
1471fileinput=get(handles.MenuFile_5,'Label');
1472set(handles.inputfile,'String',fileinput)
1473inputfile_Callback(hObject, eventdata, handles)
1474
1475% --------------------------------------------------------------------
1476function MenuExportField_Callback(hObject, eventdata, handles)
1477global Data_get_field
1478% huvmat=findobj(allchild(0),'Name','uvmat');
1479inputfile=get(handles.inputfile,'String');
1480Data_get_field=nc2struct(inputfile);
1481% Data_view_field=UvData.ProjField_2;
1482evalin('base','global Data_get_field')%make CurData global in the workspace
1483display(['content of ' inputfile ':'])
1484evalin('base','Data_get_field') %display CurData in the workspace
1485commandwindow;
1486
1487% --------------------------------------------------------------------
1488function MenuHelp_Callback(hObject, eventdata, handles)
1489% hObject    handle to MenuHelp (see GCBO)
1490% eventdata  reserved - to be defined in a future version of MATLAB
1491% handles    structure with handles and user data (see GUIDATA)
1492path_to_uvmat=which ('uvmat');% check the path of uvmat
1493pathelp=fileparts(path_to_uvmat);
1494helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1495if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1496else
1497web([helpfile '#get_field'])   
1498end
1499
Note: See TracBrowser for help on using the repository browser.