source: trunk/src/get_field.m @ 205

Last change on this file since 205 was 204, checked in by sommeria, 14 years ago

put back deleted files

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