source: trunk/src/get_field.m @ 54

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

field transforms put in subdir transform_field. cleaning of obsolete functions

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