source: trunk/src/get_field.m @ 56

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

uvmat: edit vector button activated
debugging and cleaning after modifications made with the windows version

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