source: trunk/src/get_field.m @ 188

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

various bug repairs and cleaning

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