source: trunk/src/get_field.m @ 114

Last change on this file since 114 was 107, checked in by sommeria, 14 years ago

aver_stat and time_series: bug repairs for reading images, for time series, the projection of images on a line now works
get_field: various bug repairs, export field on work space activated
struct2nc and struct2nc_toolbox.m: small bug repaired
nomtype2pair: test on string input introduced to avoid error
cell2tab: test on multiline input introduced
civ: pb about cell repair (bug with recent versions of matlab)

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