source: trunk/src/get_field.m @ 106

Last change on this file since 106 was 89, checked in by sommeria, 14 years ago

many bug corrections and cleaning. Activation of the BW option in uvmat. Improvement of the interaction of get_field with uvmat.

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