source: trunk/src/get_field.m @ 3

Last change on this file since 3 was 3, checked in by gostiaux, 11 years ago

Sous-dossier FIELD_FCT deja dans le path

File size: 70.9 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 13-Nov-2009 22:14:18
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
49set(handles.dimensions,'enable','on')% should be put by guide
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);
57pathuvmat=fileparts(which('uvmat'));
58% addpath(fullfile(pathuvmat,'FIELD_FCT'))
59set(handles.attributes,'enable','on')% TO BE SET BY GUIDE
60set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})%set mouse click action function
61if exist('filename','var')& ischar(filename)
62    set(handles.inputfile,'String',filename)
63    inputfile_Callback(hObject, eventdata, handles)
64else
65    set(handles.inputfile,'String','')
66    %loads the information stored in prefdir to initiate the browser and the list of functions
67    menu_str={'PLOT'};%list of functions included in 'get_field.m'
68    %menu_str(end)=[];%remove from the list the last option 'more...'
69    path_get_field=which('get_field');%path of the function 'get_field'
70    for ilist=1:length(menu_str)
71        fct_path{ilist,1}=path_get_field;%paths of the fuctions buil-in in 'get_field.m'
72    end
73     dir_perso=prefdir;
74     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
75     if exist(profil_perso,'file')
76        % menu={'RUN';'raw2phys';'histogram';'FFT';'peaklocking'};
77          h=load (profil_perso);
78         if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
79             for ilist=1:length(h.get_field_fct)
80                [path,file]=fileparts(h.get_field_fct{ilist});
81                fct_path=[fct_path; {path}];%concatene the list of paths
82                menu_str=[menu_str; {file}];
83             end
84             
85         end
86     end
87     menu_str=[menu_str;{'more...'}];
88     set(handles.ACTION,'String',menu_str)
89     set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION 
90     % display the GUI for the default action 'check_files'
91     ACTION_Callback(hObject, eventdata, handles)
92end
93%                  menu=[menu;h.fct_get_field];
94%                  menu=[menu;{'more...'}];
95%                  fct_path=h.fct_path_get_field;
96%                  set(handles.ACTION,'String',menu)
97%                  set(handles.ACTION,'UserData',fct_path)
98%                  for ipath=1:length(fct_path)
99%                      if exist(fct_path{ipath},'dir')
100%                         addpath(fct_path{ipath})
101%                      end
102%                  end
103%          end
104%      end
105% end
106if exist('Field','var') & isstruct(Field)
107        Field_input(eventdata,handles,Field)
108        if exist('haxes','var')
109            Field.PlotAxes=haxes;
110        end
111    set(hObject,'UserData',Field);
112end
113
114
115
116
117
118
119%-----------------------------------------------------------
120% --- Outputs from this function are returned to the command line.
121function varargout = get_field_OutputFcn(hObject, eventdata, handles)
122varargout{1} = handles.output;
123
124%-----------------------------------------------------------
125% --- Executes on button press in browse.
126function browse_Callback(hObject, eventdata, handles)
127
128
129
130
131%---------------------------------------------------------
132function inputfile_Callback(hObject, eventdata, handles)
133inputfile=get(handles.inputfile,'String');
134Field=nc2struct(inputfile,[]);% reads only the lists of fields, dimensions and attributes
135hfig=get(handles.inputfile,'parent');
136set(hfig,'UserData',Field);
137Field_input(eventdata,handles,Field);
138
139
140%---------------------------------------------------------
141function Field_input(eventdata,handles,Field)
142
143if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
144    Tabcell(:,1)=Field.ListDimName;
145    for iline=1:length(Field.ListDimName)
146        Tabcell{iline,2}=num2str(Field.DimValue(iline));
147    end
148    Tabchar=cell2tab(Tabcell,'=');
149    set(handles.dimensions,'String',Tabchar)
150end
151if ~isfield(Field,'ListVarName')
152    return
153end
154Txt=Field.ListVarName;
155set(handles.variables,'Value',1)
156set(handles.variables,'String',[{'*'} Txt])
157variables_Callback(handles.variables,[], handles)
158set(handles.abscissa,'String',[{''} Txt ])
159set(handles.ordinate,'String',Txt)
160set(handles.vector_x,'String',[Txt ])
161set(handles.vector_y,'String',[Txt ])
162set(handles.vector_z,'String',[{''} Txt ])
163set(handles.vec_color,'String',[{''} Txt ])
164set(handles.coord_x_scalar,'String',[{''} Txt ])
165set(handles.coord_y_scalar,'String',[{''} Txt ])
166set(handles.coord_x_vectors,'String',[{''} Txt ])
167set(handles.coord_y_vectors,'String',[{''} Txt ])
168set(handles.coord_z_scalar,'String',[{''} Txt ])
169set(handles.coord_z_vectors,'String',[{''} Txt ])
170set(handles.scalar,'Value',1)
171set(handles.scalar,'String', Txt )
172
173[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
174if ~isempty(errormsg) 
175    msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_indices: ' errormsg])
176    return
177end 
178[maxdim,imax]=max(NbDim);
179   
180if maxdim>=3
181    set(handles.vector_z,'Visible','on')
182    set(handles.vector_z,'String',[{''} Txt ])
183    set(handles.coord_z_vectors,'Visible','on')
184    set(handles.coord_z_vectors,'String',[{''} Txt ])
185    set(handles.coord_z_scalar,'Visible','on')
186    set(handles.coord_z_scalar,'String',[{''} Txt ])
187else
188    set(handles.vector_z,'Visible','off')
189    set(handles.coord_z_vectors,'Visible','off')
190    set(handles.coord_z_scalar,'Visible','off')
191end
192if maxdim>=2
193    set(handles.check_1Dplot,'Value',0)
194    if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y)     
195        set(handles.check_vector,'Value',1)
196        set(handles.vector_x,'Value',VarType{imax}.vector_x)
197        set(handles.vector_y,'Value',VarType{imax}.vector_y)
198        set(handles.check_scalar,'Value',0)
199    else
200        set(handles.check_scalar,'Value',1)
201        set(handles.check_vector,'Value',0)
202        if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1
203            set(handles.scalar,'Value',VarType{imax}.scalar(1))
204        end
205    end
206    check_1Dplot_Callback(handles.check_1Dplot, eventdata, handles)
207    check_scalar_Callback(handles.check_scalar, eventdata, handles)
208    check_vector_Callback(handles.check_vector, eventdata, handles)
209end
210
211
212%----------------------------------------------------------
213function ordinate_Callback(hObject, eventdata, handles)
214%update_field(hObject, eventdata, handles)
215% A REVOIR
216hselect_field=get(handles.inputfile,'parent');
217Field=get(hselect_field,'UserData');
218% xindex=get(handles.abscissa,'Value');
219list=get(handles.ordinate,'String');
220yindex=get(handles.ordinate,'Value');
221yindex=name2index(list{yindex(1)},Field.ListVarName);
222if ~isempty(yindex)
223    set(handles.variables,'Value',yindex+1)
224    variables_Callback(hObject, eventdata, handles)
225end
226[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
227for icell=1:numel(CellVarIndex)
228    VarIndex=CellVarIndex{icell};
229    if ~isempty(find(VarIndex==yindex)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex))
230        cell_select=icell;
231        break
232    end
233end
234
235val=get(handles.abscissa,'Value');
236set(handles.abscissa,'Value',min(val,2));
237coord_x_index=VarType{cell_select}.coord;
238coord_x_index=coord_x_index(find(coord_x_index));
239set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
240% Field.VarIndex.y=yindex;
241% set(hselect_field,'UserData',Field);
242%update_UserData(handles)
243
244%----------------------------------------------------------------------
245% --- Executes on selection change in abscissa.
246function abscissa_Callback(hObject, eventdata, handles)
247 hselect_field=get(handles.inputfile,'parent');
248 Field=get(hselect_field,'UserData');%current input field
249 xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
250% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
251% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
252%if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
253%     Txt=Field.ListVarName;
254%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
255%     xindex=[];
256% else
257     xlist=get(handles.abscissa,'String');%list of abscissa
258     VarName=xlist{xdispindex}; %selected variable name
259     update_field(hObject, eventdata, handles,VarName)
260%      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
261%      if ~isempty(xindex)
262%         set(handles.variables,'Value',xindex+1)
263%         variables_Callback(hObject, eventdata, handles)
264%      end
265%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
266%     variables_Callback(hObject, eventdata, handles)  %display properties of the variable (dim, attributes)
267%     if  ~test_2D &  ~test_scalar% look for possible varaibles to RUN in ordinate   
268%         index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
269%         VarIndex=[];
270%         for ilist=1:length(Field.VarDimIndex)%detect
271%             index_i=Field.VarDimIndex{ilist};
272%             if ~isempty(index_i)
273%                 if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible
274%                     VarIndex=[VarIndex ilist];
275%                 end
276%             end
277%         end
278% %         set(handles.ordinate,'Value',1)
279%         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
280%     end
281% end
282%
283% update_UserData(handles)
284
285%-------------------------------------------------------
286% --- Executes on selection change in scalar menu.
287function scalar_Callback(hObject, eventdata, handles)
288%-------------------------------------------------------
289Aindex=get(handles.scalar,'Value');
290Astring=get(handles.scalar,'String');
291VarName=Astring{Aindex};
292update_field(hObject, eventdata, handles,VarName)
293
294%-------------------------------------------------------
295% --- Executes on selection change in coord_x_scalar.
296function coord_x_scalar_Callback(hObject, eventdata, handles)
297%-------------------------------------------------------
298index=get(handles.coord_x_scalar,'Value');
299string=get(handles.coord_x_scalar,'String');
300VarName=string{index};
301update_field(hObject, eventdata, handles,VarName)
302
303%-------------------------------------------------------
304% --- Executes on selection change in coord_y_scalar.
305function coord_y_scalar_Callback(hObject, eventdata, handles)
306%-------------------------------------------------------
307index=get(handles.coord_y_scalar,'Value');
308string=get(handles.coord_y_scalar,'String');
309VarName=string{index};
310update_field(hObject, eventdata, handles,VarName)
311
312%-------------------------------------------------------
313% --- Executes on selection change in coord_z_scalar.
314function coord_z_scalar_Callback(hObject, eventdata, handles)
315%-------------------------------------------------------
316index=get(handles.coord_z_scalar,'Value');
317string=get(handles.coord_z_scalar,'String');
318VarName=string{index};
319update_field(hObject, eventdata, handles,VarName)
320
321%-------------------------------------------------------
322% --- Executes on selection change in vector_x.
323function vector_x_Callback(hObject, eventdata, handles)
324%-------------------------------------------------------
325index=get(handles.vector_x,'Value');
326string=get(handles.vector_x,'String');
327VarName=string{index};
328update_field(hObject, eventdata, handles,VarName)
329
330%-------------------------------------------------------
331% --- Executes on selection change in vector_y.
332function vector_y_Callback(hObject, eventdata, handles)
333%-------------------------------------------------------
334index=get(handles.vector_y,'Value');
335string=get(handles.vector_y,'String');
336VarName=string{index};
337update_field(hObject, eventdata, handles,VarName)
338
339%-------------------------------------------------------
340% --- Executes on selection change in vector_z.
341function vector_z_Callback(hObject, eventdata, handles)
342%-------------------------------------------------------
343index=get(handles.vector_z,'Value');
344string=get(handles.vector_z,'String');
345VarName=Astring{index};
346update_field(hObject, eventdata, handles,VarName)
347
348%-------------------------------------------------------
349% --- Executes on selection change in coord_x_vectors.
350function coord_x_vectors_Callback(hObject, eventdata, handles)
351%-------------------------------------------------------
352index=get(handles.coord_x_vectors,'Value');
353string=get(handles.coord_x_vectors,'String');
354VarName=string{index};
355update_field(hObject, eventdata, handles,VarName)
356
357%-------------------------------------------------------
358% --- Executes on selection change in coord_y_vectors.
359%-------------------------------------------------------
360function coord_y_vectors_Callback(hObject, eventdata, handles)
361index=get(handles.coord_y_vectors,'Value');
362string=get(handles.coord_y_vectors,'String');
363VarName=string{index};
364update_field(hObject, eventdata, handles,VarName)
365
366%-------------------------------------------------------
367% --- Executes on selection change in coord_z_scalar.
368function coord_z_vectors_Callback(hObject, eventdata, handles)
369%-------------------------------------------------------
370index=get(handles.coord_z_vectors,'Value');
371string=get(handles.coord_z_vectors,'String');
372VarName=string{index};
373update_field(hObject, eventdata, handles,VarName)
374
375%-------------------------------------------------------
376% --- Executes on selection change in vec_color.
377function vec_color_Callback(hObject, eventdata, handles)
378%-------------------------------------------------------
379index=get(handles.vec_color,'Value');
380string=get(handles.vec_color,'String');
381VarName=string{index};
382update_field(hObject, eventdata, handles,VarName)
383
384%---------------------------------
385function update_field(hObject, eventdata, handles,VarName)
386% VarName= input variable name for scalar or vector plots
387%if ischar(VarName)
388hselect_field=get(handles.inputfile,'parent');
389Field=get(hselect_field,'UserData');
390index=name2index(VarName,Field.ListVarName);
391if ~isempty(index)
392    set(handles.variables,'Value',index+1)
393    variables_Callback(hObject, eventdata, handles)
394end
395%
396%
397% hselect_field=get(handles.inputfile,'parent');
398% Field=get(hselect_field,'UserData');
399% ivar_sel=[];%default
400% for ivar=1:length(Field.ListVarName)%detect
401%     if isequal(Field.ListVarName{ivar},VarName)
402%         ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName
403%         break
404%     end
405% end
406% if isempty(ivar_sel)
407%     return
408% end
409% set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed  list 'variables'
410% variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable
411%
412% index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable
413% DimValue=Field.DimValue(index);%dimension values of the input variable
414% ind_1=find(DimValue==1);
415% index(ind_1)=[];%Mremove singletons
416%
417%
418% % detect possible variables for abscissa and ordinate
419% VarIndex=[];%initiate list of selected variable indices
420% ind_coordvar=[]; %initiate list of coordinate variables
421% for ilist=1:length(Field.VarDimIndex)
422%     if ~isequal(ilist,ivar_sel)       
423%         index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist
424%         if length(index_i)>1
425%             DimValue=Field.DimValue(index_i);
426%             ind_1=find(DimValue==1);
427%             index_i(ind_1)=[];%Mremove singletons
428%             if isequal(index,index_i)
429%                 VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable
430%             end
431%         else
432%             idim=find(index==index_i(1));
433%             if ~isempty(idim)
434%                  VarIndex=[VarIndex ilist]; %possible dimension variable
435%                  if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist})
436%                      ind_coordvar=[ind_coordvar length(VarIndex)];
437%                  end
438%             end
439%         end
440%     end
441% end
442% % val=get(handles.abscissa,'Value');
443% % if val>length(Field.ListVarName(VarIndex))+1
444% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
445% % end
446% % val=get(handles.ordinate,'Value');
447% % if val>length(Field.ListVarName(VarIndex))+1
448% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
449% % end
450% % val=get(handles.coord_z_vectors_scalar,'Value');
451% % if val>length(Field.ListVarName(VarIndex))+1
452% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
453% % end
454% set(handles.abscissa,'Value',1)%default
455% set(handles.ordinate,'Value',1)%default
456% set(handles.coord_z_scalar,'Value',1)%default
457% set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ])
458% set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ])
459% set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ])
460% if length(ind_coordvar)>=1
461%     set(handles.abscissa,'Value',ind_coordvar(1)+1)
462% elseif length(index)==1 && length(VarIndex)>=1
463%     set(handles.abscissa,'Value',2)
464% end
465% if length(ind_coordvar)>=2
466%     set(handles.ordinate,'Value',ind_coordvar(2)+1)
467% elseif length(index)==1 && length(VarIndex)>=2
468%     set(handles.ordinate,'Value',3)
469% end
470% if length(ind_coordvar)>=3
471%     set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1)
472% elseif length(index)==1 && length(VarIndex)>=3
473%     set(handles.coord_z_scalar,'Value',4)
474% end
475
476%---------------------------------------------------------
477% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
478function update_UserData(handles)
479%---------------------------------------------------------
480return
481% global SubField
482hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
483Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
484if isfield(Field,'VarAttribute')
485    VarAttribute=Field.VarAttribute;
486else
487    VarAttribute={};
488end
489
490
491% select the indices of field variables for 2D plots
492test_check_1Dplot=get(handles.check_1Dplot,'Value');
493test_scalar=get(handles.check_scalar,'Value');
494test_vector=get(handles.check_vector,'Value');
495
496%transform if needed (calibration)
497list=get(handles.menu_coord,'String');
498index=get(handles.menu_coord,'Value');
499transform=list{index};
500if ~isequal(transform,'')
501    Field=feval(transform,Field);
502end
503VarIndex.u=[];
504VarIndex.v=[];
505VarIndex.w=[];
506VarIndex.A=[];
507VarIndex_tot=[];
508iuA=[];
509if test_scalar
510    Astring=get(handles.scalar,'String');
511    Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
512    list_var=Astring(Aindex);
513    VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
514    VarIndex_tot= [VarIndex_tot VarIndex.A];
515    DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
516    DimValue=Field.DimValue(DimIndex);
517    ind=find(DimValue==1);
518    DimIndex(ind)=[];%Mremove singleton
519end
520if test_vector
521    Ustring=get(handles.vector_x,'String');
522    Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
523    list_var=Ustring{Uindex};%name of the selected scalar
524    VarIndex.u=name2index(list_var,Field.ListVarName);
525    Vstring=get(handles.vector_y,'String');
526    Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
527    list_var=Ustring{Vindex};%name of the selected scalar
528    VarIndex.v=name2index(list_var,Field.ListVarName);
529    if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
530        iuA=VarIndex.A; %same variable used for vector and scalar
531        VarIndex_tot(iuA)=[];
532    end
533    VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
534    %dimensions
535    DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
536    DimValue=Field.DimValue(DimIndex_u);
537    ind=find(DimValue==1);
538    DimIndex_u(ind)=[];%Mremove singleton
539    DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
540    DimValue=Field.DimValue(DimIndex_v);
541    ind=find(DimValue==1);
542    DimIndex_v(ind)=[];%Mremove singleton
543    if ~isequal(DimIndex_u,DimIndex_v)
544        warndlg_uvmat('inconsistent dimensions for u and v','ERROR')
545        set(handles.vector_y,'Value',1);
546        return
547    elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
548         warndlg_uvmat('inconsistent dimensions for vector and scalar represented as vector color','ERROR')
549         set(handles.scalar,'Value',1);
550         return
551    end
552    DimIndex=DimIndex_u;
553    %TODO possibility of selecting 3 times the same variable for u, v, w components
554end
555
556
557% select the variable  index (or indices) for z coordinates
558test_grid=0;
559if test_scalar | test_vector
560    nbdim=length(DimIndex);
561    if nbdim > 3
562        warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
563        return
564    else
565        perm_ind=[1:nbdim];
566    end
567    if nbdim==3
568        zstring=get(handles.coord_z_vectors_scalar,'String');
569        zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
570        list_var=zstring(zindex);
571        VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
572        if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
573            if zindex ~= 1
574                set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
575                return
576            end
577        else
578            VarIndex_tot=[VarIndex_tot VarIndex_z];
579            DimIndex_z=Field.VarDimIndex{VarIndex_z};
580            DimValue=Field.DimValue(DimIndex_z);
581            ind=find(DimValue==1);         
582            DimIndex_z(ind)=[];%Mremove singleton
583            if isequal(DimIndex_z,DimIndex)
584                VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
585            elseif length(DimIndex_z)==1
586                VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
587                ind_z=find(DimIndex==DimIndex_z(1));
588                perm_ind(ind_z)=1;
589                test_grid=1;
590            else
591                warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
592                return
593            end
594        end
595%         if ~isempty(VarIndex_z)
596%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable   
597%             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
598%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
599%                 ind_z=find(DimIndex==DimIndex_z(1));
600%                 perm_ind(ind_z)=1;
601%                 test_grid=1;
602%             end
603%         end
604    end
605end
606
607% select the variable  index (or indices) for ordinate
608ystring=get(handles.ordinate,'String');
609yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
610list_var=ystring(yindex);
611VarIndex.y=name2index(list_var,Field.ListVarName);
612if isequal(VarIndex.A,VarIndex.y)
613    set(handles.coord_y_scalar,'Value',1)
614elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
615   set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
616else
617    for ivar=1:length(VarIndex.y)
618        VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
619    end
620    VarIndex_tot=[VarIndex_tot VarIndex.y];
621end
622if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
623    DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
624    if length(DimIndex_y)==1
625        ind_y=find(DimIndex==DimIndex_y(1));
626        test_grid=1;
627        if nbdim==3
628            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
629            perm_ind(ind_y)=2;
630        elseif nbdim==2
631            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
632             perm_ind(ind_y)=1;
633        end
634    elseif test_grid
635        warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')   
636    end
637end
638
639%select the variable index for the abscissa
640xstring=get(handles.abscissa,'String');
641xindex=get(handles.abscissa,'Value');
642list_var=xstring(xindex);
643VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
644if length(VarIndex.x)==1   
645    DimIndex_x=Field.VarDimIndex{VarIndex.x};
646    DimValue=Field.DimValue(DimIndex_x);
647    ind=find(DimValue==1);         
648    DimIndex_x(ind)=[];%Mremove singleton                     
649    VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
650%     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
651    index_detect=find(VarIndex_tot==VarIndex.x);
652else
653    index_detect=[];%coord x variable not already used
654end
655if isempty(index_detect)
656    VarIndex_tot=[VarIndex_tot VarIndex.x];
657elseif ~test_check_1Dplot
658    VarIndex.x=[];
659    set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
660end
661
662if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
663    DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
664    if length(DimIndex_x)==1
665        ind_x=find(DimIndex==DimIndex_x(1));
666        if nbdim==3
667            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
668            perm_ind(ind_x)=3;
669        elseif nbdim==2
670            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
671             perm_ind(ind_x)=2;
672        end
673        if isequal(perm_ind,1:nbdim)
674            test_grid=0;
675        end
676        DimIndex=DimIndex(perm_ind);
677    elseif test_grid
678        warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')   
679    end
680    if isequal(DimIndex_x,DimIndex)
681                VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
682    end
683end
684
685%defined the selected sub-field SubField
686SubField.ListGlobalAttribute{1}='InputFile';
687SubField.InputFile=get(handles.inputfile,'String');
688SubField.ListDimName=Field.ListDimName;
689SubField.DimValue=Field.DimValue;
690SubField.ListVarName=Field.ListVarName(VarIndex_tot);
691SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
692
693testperm=0;
694testattr=0;
695for ivar=VarIndex.u
696    VarAttribute{ivar}.Role='vector_x';
697    testattr=1;
698    if test_grid
699        VarDimIndex{ivar}=DimIndex; %permute dimensions
700        testperm=1;
701    end
702end
703for ivar=VarIndex.v
704    VarAttribute{ivar}.Role='vector_y';
705    testattr=1;
706     if test_grid
707        VarDimIndex{ivar}=DimIndex;%permute dimensions
708        testperm=1;
709    end
710end
711for ivar=VarIndex.A
712    if test_grid
713        VarDimIndex{ivar}=DimIndex;%permute dimensions
714        testperm=1;
715    end
716    if isempty(iuA)
717        VarAttribute{ivar}.Role='scalar';%Role =scalar
718        testattr=1;
719    else
720       VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
721       nbattr=length(VarAttribute);
722       VarAttribute{nbattr}.Role='scalar';
723       testattr=1;
724    end
725end
726if testperm
727    SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
728end
729if testattr
730    SubField.VarAttribute=VarAttribute(VarIndex_tot);
731end
732set(hselect_field,'UserData',Field)
733
734%---------------------------------------------------------
735% --- Executes on button press in RUN.
736function RUN_Callback(hObject, eventdata, handles)
737%---------------------------------------------------------
738list=get(handles.ACTION,'String');
739index=get(handles.ACTION,'Value');
740ACTION=list{index};
741hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
742feval(ACTION,hselect_field);
743browse_fig(handles.list_fig); %update the list of new existing figures
744
745%---------------------------------------------------------
746% --- Executes on button press in RUN.
747function PLOT(hget_field)
748%---------------------------------------------------------
749[SubField,errormsg]=read_get_field(hget_field);
750if ~isempty(errormsg)
751    msgbox_uvmat('ERROR',['error in get_field/PLOT input:' errormsg])
752    return
753end
754handles=guidata(hget_field);
755list_fig=get(handles.list_fig,'String');
756val=get(handles.list_fig,'Value');
757if strcmp(list_fig{val},'uvmat')
758    uvmat(SubField)
759else
760hfig=str2num(list_fig{val});% chosen figure number from tyhe GUI
761if isempty(hfig)
762    hfig=figure;
763    list_fig=[list_fig;num2str(hfig)];
764    set(handles.list_fig,'String',list_fig);
765    haxes=axes;
766else
767    figure(hfig);
768end
769haxes=findobj(hfig,'Type','axes');
770
771plot_field(SubField,haxes)
772end
773
774
775%
776% return
777%  testuvmat=0;
778%     if test_scalar|test_vector
779%          [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
780%          NbDim=max(NbDim);
781%          if NbDim==3
782%            testuvmat=1; %uvmat interface needed for 3D plots
783%          end
784%     end
785%     if iscell(list_fig)
786%         RUN_fig=list_fig{fig_index};
787%     else
788%         RUN_fig='new fig...';%new plotting axes must be created
789%     end
790%     if isequal(RUN_fig,'new fig...') &  (test_scalar|test_vector)
791%         RUN_fig='uvmat';%use uvmat for a new fig
792%     end
793%     if testuvmat
794%         RUN_fig='uvmat';
795%     end
796%     if isequal(RUN_fig,'uvmat')
797%         
798%         huvmat=uvmat(SubField);
799%         menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
800%     else
801%         test_new=1;
802%         if ~isequal(RUN_fig,'new fig...')
803%             sep=regexp(RUN_fig,'_')%look for subaxes in a fig
804%             if isempty(sep)
805%                 axe_index=1;
806%             else
807%                 axe_index=str2num(RUN_fig(sep+1:end))
808%                 RUN_fig=RUN_fig([1:sep-1])             
809%             end
810%             if ishandle(str2num(RUN_fig))
811%                 haxes=findobj(str2num(RUN_fig),'Type','axes')
812%                 for iaxe=1:length(haxes)
813%                     Tag=get(haxes(iaxe),'Tag');
814%                     if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
815%                        iselect(iaxe)=0;
816%                     else
817%                        iselect(iaxe)=1;
818%                     end
819%                 end
820%                 haxes=haxes(find(iselect));   
821%                 if length(haxes)>=axe_index
822%                     test_new=0
823%                     haxes=haxes(axe_index);
824%                     set(haxes,'NextPlot','add')
825%                 end
826%             end
827%         end
828%         if test_new
829%             hfig=figure;
830%             haxes=axes;
831%             menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
832%         end 
833%         RUN_field(SubField,haxes)       
834%     end
835% end
836%
837%
838%
839%
840%  w components
841% end
842%
843%
844% % select the variable  index (or indices) for z coordinates
845% test_grid=0;
846% if test_scalar | test_vector
847%     nbdim=length(DimIndex);
848%     if nbdim > 3
849%         warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
850%         return
851%     else
852%         perm_ind=[1:nbdim];
853%     end
854%     if nbdim==3
855%         zstring=get(handles.coord_z_vectors_scalar,'String');
856%         zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
857%         list_var=zstring(zindex);
858%         VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
859%         if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
860%             if zindex ~= 1
861%                 set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
862%                 return
863%             end
864%         else
865%             VarIndex_tot=[VarIndex_tot VarIndex_z];
866%             DimIndex_z=Field.VarDimIndex{VarIndex_z};
867%             DimValue=Field.DimValue(DimIndex_z);
868%             ind=find(DimValue==1);         
869%             DimIndex_z(ind)=[];%Mremove singleton
870%             if isequal(DimIndex_z,DimIndex)
871%                 VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
872%             elseif length(DimIndex_z)==1
873%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
874%                 ind_z=find(DimIndex==DimIndex_z(1));
875%                 perm_ind(ind_z)=1;
876%                 test_grid=1;
877%             else
878%                 warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
879%                 return
880%             end
881%         end
882% %         if ~isempty(VarIndex_z)
883% %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable   
884% %             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
885% %                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
886% %                 ind_z=find(DimIndex==DimIndex_z(1));
887% %                 perm_ind(ind_z)=1;
888% %                 test_grid=1;
889% %             end
890% %         end
891%     end
892% end
893%
894% % select the variable  index (or indices) for ordinate
895% ystring=get(handles.ordinate,'String');
896% yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
897% list_var=ystring(yindex);
898% VarIndex.y=name2index(list_var,Field.ListVarName);
899% if isequal(VarIndex.A,VarIndex.y)|isequal(VarIndex.u,VarIndex.y)|isequal(VarIndex.v,VarIndex.y)|isequal(VarIndex.w,VarIndex.y)
900%    set(handles.ordinate,'Value',1)%ordinate cannot be the same as scalar or vector components
901% else
902%     for ivar=1:length(VarIndex.y)
903%         VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
904%     end
905%     VarIndex_tot=[VarIndex_tot VarIndex.y];
906% end
907% if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
908%     DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
909%     if length(DimIndex_y)==1
910%         ind_y=find(DimIndex==DimIndex_y(1));
911%         test_grid=1;
912%         if nbdim==3
913%             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
914%             perm_ind(ind_y)=2;
915%         elseif nbdim==2
916%             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
917%              perm_ind(ind_y)=1;
918%         end
919%     elseif test_grid
920%         warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')   
921%     end
922% end
923%
924% %select the variable index for the abscissa
925% xstring=get(handles.abscissa,'String');
926% xindex=get(handles.abscissa,'Value');
927% list_var=xstring(xindex);
928% VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
929% if length(VarIndex.x)==1   
930%     DimIndex_x=Field.VarDimIndex{VarIndex.x};
931%     DimValue=Field.DimValue(DimIndex_x);
932%     ind=find(DimValue==1);         
933%     DimIndex_x(ind)=[];%Mremove singleton                     
934%     VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
935% %     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
936%     index_detect=find(VarIndex_tot==VarIndex.x);
937% else
938%     index_detect=[];%coord x variable not already used
939% end
940% if isempty(index_detect)
941%     VarIndex_tot=[VarIndex_tot VarIndex.x];
942% else
943%     VarIndex.x=[];
944%     set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
945% end
946%
947% if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
948%     DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
949%     if length(DimIndex_x)==1
950%         ind_x=find(DimIndex==DimIndex_x(1));
951%         if nbdim==3
952%             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
953%             perm_ind(ind_x)=3;
954%         elseif nbdim==2
955%             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
956%              perm_ind(ind_x)=2;
957%         end
958%         if isequal(perm_ind,[1:nbdim])
959%             test_grid=0;
960%         end
961%         DimIndex=DimIndex(perm_ind);
962%     elseif test_grid
963%         warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')   
964%     end
965%     if isequal(DimIndex_x,DimIndex)
966%                 VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
967%     end
968% end
969%
970% %defined the selected sub-field SubField
971% SubField.ListGlobalAttribute{1}='InputFile';
972% SubField.InputFile=get(handles.inputfile,'String');
973% SubField.ListVarName=Field.ListVarName(VarIndex_tot);
974% VarDimIndex=Field.VarDimIndex;
975%
976% for ivar=VarIndex.u
977%     VarAttribute{ivar}.Role='vector_x';
978%     if test_grid
979%         VarDimIndex{ivar}=DimIndex; %permute dimensions
980%     end
981% end
982% for ivar=VarIndex.v
983%     VarAttribute{ivar}.Role='vector_y';
984%      if test_grid
985%         VarDimIndex{ivar}=DimIndex;%permute dimensions
986%     end
987% end
988% for ivar=VarIndex.A
989%     if test_grid
990%         VarDimIndex{ivar}=DimIndex;%permute dimensions
991%     end
992%     if isempty(iuA)
993%         VarAttribute{ivar}.Role='scalar';%Role =scalar
994%     else
995%        VarAttribute=[VarAttribute VarAttribute{ivar}]; %duplicate the attribute for a new variable
996%        nbattr=length(VarAttribute);
997%        VarAttribute{nbattr}.Role='scalar';
998%     end
999% end
1000% SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
1001% SubField.VarAttribute=VarAttribute(VarIndex_tot);
1002% % Field.SubListVarName=SubField.ListVarName;
1003% % Field.SubVarDimIndex=SubField.VarDimIndex;
1004% % Field.SubVarAttribute=SubField.VarAttribute;
1005% set(hselect_field,'UserData',Field);
1006% % copy variables on SubField
1007% for ivar=1:length(VarIndex_tot)
1008%     VarName=Field.ListVarName{VarIndex_tot(ivar)};
1009%     eval(['SubField.' VarName '=Field.' VarName ';'])
1010% end
1011% if test_grid
1012%     for ivar=1:length(VarIndex.u)
1013%          VarName=Field.ListVarName{VarIndex.u(ivar)};
1014%         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
1015%     end
1016%
1017%     for ivar=1:length(VarIndex.v)
1018%          VarName=Field.ListVarName{VarIndex.v(ivar)};
1019%         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
1020%     end
1021%     for ivar=1:length(VarIndex.A)
1022%          VarName=Field.ListVarName{VarIndex.A(ivar)};
1023%         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
1024%     end   
1025% end   
1026% if ~isempty(iuA)
1027%     VarName= ['A' Field.ListVarName{iuA}]; %create the new variable to distinguish the scaler form the velocity component
1028%     SubField.ListVarName=[SubField.ListVarName VarName];
1029%     SubField.VarDimIndex=[SubField.VarDimIndex Field.VarDimIndex(iuA)];
1030%     eval(['SubField.' VarName '=Field.'  Field.ListVarName{iuA} ';'])
1031% end
1032% % dimension of SubField
1033% if test_scalar|test_vector
1034%    % SubField.NbDim=2;
1035%     SubField.InputFile=get(handles.inputfile,'String');
1036%     SubField.get_field_handle=hselect_field;
1037% else
1038%     SubField.NbDim=1;
1039% end
1040%
1041% list_fig=get(handles.list_fig,'String');
1042% fig_index=get(handles.list_fig,'Value');
1043% %ACTION on SubField
1044% index=get(handles.ACTION,'Value');
1045
1046
1047% %     if (test_scalar|test_vector)
1048% %         RUN_fig='uvmat';
1049% %     elseif iscell(list_fig)
1050%     testuvmat=0;
1051%     if test_scalar|test_vector
1052%          [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
1053%          NbDim=max(NbDim);
1054%          if NbDim==3
1055%            testuvmat=1; %uvmat interface needed for 3D plots
1056%          end
1057%     end
1058%     if iscell(list_fig)
1059%         RUN_fig=list_fig{fig_index};
1060%     else
1061%         RUN_fig='new fig...';%new plotting axes must be created
1062%     end
1063%     if isequal(RUN_fig,'new fig...') &  (test_scalar|test_vector)
1064%         RUN_fig='uvmat';%use uvmat for a new fig
1065%     end
1066%     if testuvmat
1067%         RUN_fig='uvmat';
1068%     end
1069%     if isequal(RUN_fig,'uvmat')
1070%         
1071%         huvmat=uvmat(SubField);
1072%         menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
1073%     else
1074%         test_new=1;
1075%         if ~isequal(RUN_fig,'new fig...')
1076%             sep=regexp(RUN_fig,'_')%look for subaxes in a fig
1077%             if isempty(sep)
1078%                 axe_index=1;
1079%             else
1080%                 axe_index=str2num(RUN_fig(sep+1:end))
1081%                 RUN_fig=RUN_fig([1:sep-1])             
1082%             end
1083%             if ishandle(str2num(RUN_fig))
1084%                 haxes=findobj(str2num(RUN_fig),'Type','axes')
1085%                 for iaxe=1:length(haxes)
1086%                     Tag=get(haxes(iaxe),'Tag');
1087%                     if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
1088%                        iselect(iaxe)=0;
1089%                     else
1090%                        iselect(iaxe)=1;
1091%                     end
1092%                 end
1093%                 haxes=haxes(find(iselect));   
1094%                 if length(haxes)>=axe_index
1095%                     test_new=0
1096%                     haxes=haxes(axe_index);
1097%                     set(haxes,'NextPlot','add')
1098%                 end
1099%             end
1100%         end
1101%         if test_new
1102%             hfig=figure;
1103%             haxes=axes;
1104%             menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
1105%         end 
1106%         RUN_field(SubField,haxes)       
1107%     end
1108% end
1109% %Field.VarIndex=VarIndex; %save for use in uvmat
1110% % set(hselect_field,'UserData',Field)
1111
1112
1113%------------------------------------------------
1114% --- Executes on button press in Plot_histo.
1115%RUN global histograms
1116%-------------------------------------------------
1117function RUN_histo_Callback(hObject, eventdata, handles)
1118% hObject    handle to RUN (see GCBO)
1119% eventdata  reserved - to be defined in a future version of MATLAB
1120% handles    structure with handles and user data (see GUIDATA)
1121
1122%time plots
1123leg={};
1124n=0;
1125if (get(handles.cm_switch,'Value')==1)
1126    Uval_p=Uval_cm;
1127    Vval_p=Vval_cm;
1128    Uhist_p=Uhist_cm;
1129    Vhist_p=Vhist_cm;
1130    xlab='velocity (cm/s)';
1131else
1132    Uval_p=Uval;
1133    Vval_p=Vval;
1134    Uhist_p=Uhist;
1135    Vhist_p=Vhist;
1136    xlab='velocity (pixels)';
1137end
1138if (get(handles.vector_y,'Value') == 1)
1139   hhh=figure(2);
1140   hold on
1141   title([filebase ', ' strindex ', ' fieldtitle])
1142   plot(Uval_p,Uhist_p,'b-')
1143   n=n+1;
1144   leg{n}='Uhist';
1145   xlabel(xlab)
1146end
1147if (get(handles.Vhist_input,'Value') == 1)
1148   hhh=figure(2);
1149   hold on
1150   title([filebase ', ' strindex ', ' fieldtitle])
1151   plot(Vval_p,Vhist_p,'r-')
1152   n=n+1;
1153   leg{n}='Vhist';
1154   xlabel(xlab);
1155end
1156if (get(handles.Chist_input,'Value') == 1)
1157   hhhh=figure(3);
1158   hold on
1159   title([filebase ', ' strindex ', ' fieldtitle])
1160   plot(Cval,Chist,'k-')
1161   leg{1}='Chist';
1162end
1163% hold off
1164grid on
1165legend(leg);
1166
1167% %-------------------------------------------------------------
1168% % --- Executes on button press in Save_input.
1169% function Save_input_Callback(hObject, eventdata, handles)
1170% list_str=get(handles.abscissa,'String');
1171% val=get(handles.abscissa,'Value');
1172% var=list_str{val};
1173% hselect_field=get(handles.Save_input,'parent')
1174% set(hselect_field,'UserData',var);
1175% set(hselect_field,'Tag','idle')
1176
1177%     
1178% %-------------------------------------------------------------
1179% % --- Executes on button press in save_histo.
1180% function save_histo_Callback(hObject, eventdata, handles)
1181% global filebase
1182%
1183% pathstr = fileparts(filebase)
1184% if (get(handles.Chist_input,'Value') == 1)
1185%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
1186%     else
1187
1188%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
1189% end
1190% prompt={'save figure(2) as'}
1191% dlg_title = 'save figure';
1192% num_lines= 1;
1193% answer = inputdlg(prompt,dlg_title,num_lines,def)
1194% saveas(2,answer{1})
1195 
1196%
1197% % --- Executes on selection change in spectrum.
1198% function Field=FFT(Field)
1199% 'TESTFFT'
1200% Field
1201% nbfield=length(Field.ListVarName);
1202% if nbfield==0
1203%     warndlg_uvmat('no field selected for FFT','ERROR')
1204% elseif nbfield>2
1205%     warndlg_uvmat('select only one field for FFT','ERROR')
1206% end
1207% if nbfield==2
1208% % list_fields=get(handles.spectrum,'String');% list menu fields
1209% % index_fields=get(handles.spectrum,'Value');% selected string index
1210% % fields= list_fields{index_fields(1)}; % selected action
1211% % func=eval(fields);
1212%     dtmin=min(diff(time));%time step
1213%     time1=time(1);timend=time(end);
1214%     timeq=[time1:dtmin:timend];%equal time spacing
1215%     funcinterp=interp1(time,func,timeq); %interpolated func
1216% else
1217%     varname=Field.ListVarName{1};
1218%     eval(['funcinterp=Field.' varname ';'])
1219% end
1220% np=length(funcinterp);
1221% funcinterp=funcinterp-sum(funcinterp)/np; %substract mean
1222% fourier=fft(funcinterp);%take fft (complex)
1223% spec=abs(fourier).*abs(fourier);% take sqare of the modulus
1224% spec=spec([1:floor(np/2)]);%keep only the first half (the other is symmetric)
1225% eval(['Field.' varname '=spec;'])
1226% Field
1227% % dfreq=1/(time(end)-time(1));%frequency interval
1228% % freq=[0:dfreq:(floor(np/2)-1)*dfreq];
1229% % figure(1)
1230% % hold on
1231% % RUN(freq,spec)
1232% % xlabel('frequency (Hz)')
1233% % ylabel('spectral intensity')
1234% % title(['spectrum of' fields]);
1235% % grid on
1236
1237
1238
1239
1240
1241%%-------------------------------------------------------
1242% --- Executes on button press in peaklocking.
1243%-------------------------------------------------
1244function peaklocking(handles)
1245%evaluation of peacklocking errors
1246%use splinhist: give spline coeff cc for a smooth histo (call spline4)
1247%use histsmooth(x,cc): calculate the smooth histo for any value x
1248%use histder(x,cc): calculate the derivative of the smooth histo
1249global hfig1 hfig2 hfig3
1250global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
1251global xval xerror yval yerror
1252
1253set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
1254set(handles.Vhist_input,'Value',1)
1255set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
1256
1257%adjust the extremal values of the histogram in U with respect to integer
1258%values
1259minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
1260maximU=round(max(Uval)-0.5)+0.5;
1261minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
1262maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
1263nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
1264nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
1265Uval=[minim_fin:(1/nbb):maxim_fin];
1266histu_min=zeros(nb_bin_min,1);
1267histu_max=zeros(nb_bin_max,1);
1268Uhist=[histu_min; Uhist ;histu_max]; % column vector
1269
1270%adjust the extremal values of the histogram in V
1271minimV=round(min(Vval-0.5)+0.5);
1272maximV=round(max(Vval-0.5)+0.5);
1273minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
1274maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
1275nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
1276nb_bin_max=round((maxim_fin -max(Vval))*nbb);
1277Vval=[minim_fin:(1/nbb):maxim_fin];
1278histu_min=zeros(nb_bin_min,1);
1279histu_max=zeros(nb_bin_max,1);
1280Vhist=[histu_min; Vhist ;histu_max]; % column vector
1281
1282% RUN_histo_Callback(hObject, eventdata, handles)
1283% %adjust the histogram to integer values:
1284
1285%histoU and V
1286[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
1287[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
1288
1289% selection of value ranges such that histo>=10 (enough statistics)
1290Uval_ind=find(Uhist>=10);
1291ind_min=min(Uval_ind);
1292ind_max=max(Uval_ind);
1293U_min=Uval(ind_min);% minimum allowed value
1294U_max=Uval(ind_max);%maximum allowed value
1295
1296% selection of value ranges such that histo>=10 (enough statistics)
1297Vval_ind=find(Vhist>=10);
1298ind_min=min(Vval_ind);
1299ind_max=max(Vval_ind);
1300V_min=Vval(ind_min);% minimum allowed value
1301V_max=Vval(ind_max);%maximum allowed value
1302
1303figure(4)% plot U histogram with smoothed one
1304plot(Uval,Uhist,'b')
1305grid on
1306hold on
1307plot(Uval,Uhistinter,'r');
1308hold off
1309
1310figure(5)% plot V histogram with smoothed one
1311plot(Vval,Vhist,'b')
1312grid on
1313hold on
1314plot(Vval,Vhistinter,'r');
1315hold off
1316
1317figure(6)% plot pixel error in two subplots
1318hfig4=subplot(2,1,1);
1319hfig5=subplot(2,1,2);
1320axes(hfig4)
1321plot(xval,xerror)
1322axis([U_min U_max -0.4 0.4])
1323xlabel('velocity u (pix)')
1324ylabel('peaklocking error (pix)')
1325grid on
1326axes(hfig5)
1327plot(yval,yerror)
1328axis([V_min V_max -0.4 0.4]);
1329xlabel('velocity v (pix)')
1330ylabel('peaklocking error (pix)')
1331grid on
1332
1333
1334% ------------------------------------------------------------------
1335function variables_Callback(hObject, eventdata, handles)
1336Tabchar={''};%default
1337Tabcell=[];
1338hselect_field=get(handles.variables,'parent');
1339Field=get(hselect_field,'UserData');
1340index=get(handles.variables,'Value');%index in the list 'variables'
1341if isequal(index,1)
1342    set(handles.attributes_txt,'String','global attributes')
1343% list global attribute names and values if index=1 (blank variable display) is selected
1344    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
1345        for iline=1:length(Field.ListGlobalAttribute)
1346            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
1347            if isfield(Field, Field.ListGlobalAttribute{iline})
1348                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
1349                if ischar(val);
1350                    Tabcell{iline,2}=val;
1351                else
1352                    Tabcell{iline,2}=num2str(val);
1353                end
1354            end
1355        end
1356        Tabchar=cell2tab(Tabcell,'=');
1357    end
1358else
1359%list attribute names and values associated to the variable # injdex-1   
1360    list_var=get(handles.variables,'String');
1361    var_select=list_var{index};
1362    set(handles.attributes_txt,'String', ['attributes of ' var_select])
1363    if isfield(Field,'VarAttribute')& length(Field.VarAttribute)>=index-1
1364%         nbline=0;
1365        VarAttr=Field.VarAttribute{index-1};
1366        if isstruct(VarAttr)
1367            attr_list=fieldnames(VarAttr);
1368            for iline=1:length(attr_list)
1369                Tabcell{iline,1}=attr_list{iline};
1370                eval(['val=VarAttr.' attr_list{iline} ';'])
1371                if ischar(val);
1372                    Tabcell{iline,2}=val;
1373                else
1374                     Tabcell{iline,2}=num2str(val);
1375                end
1376            end
1377        end
1378    end
1379
1380end
1381if ~isempty(Tabcell)
1382    Tabchar=cell2tab(Tabcell,'=');
1383    Tabchar=[{''};Tabchar];
1384end
1385set(handles.attributes,'String',Tabchar);
1386
1387% list_var=get(handles.dimensions,'String');
1388% val=get(handles.dimensions,'Value');
1389
1390% update dimensions;
1391if isfield(Field,'VarDimIndex')
1392    Tabdim={};%default
1393    if isequal(index,1)
1394        dim_indices=1:length(Field.ListDimName);
1395        set(handles.dimensions_txt,'String', 'dimensions')
1396    else
1397        dim_indices=Field.VarDimIndex{index-1};
1398        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1399    end
1400    for iline=1:length(dim_indices)
1401        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1402        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1403    end
1404    Tabchar=cell2tab(Tabdim,'=');
1405    Tabchar=[{''} ;Tabchar];
1406    set(handles.dimensions,'String',Tabchar) 
1407end 
1408
1409% --- Executes on button press in check_1Dplot.
1410function check_1Dplot_Callback(hObject, eventdata, handles)
1411val=get(handles.check_1Dplot,'Value');
1412if isequal(val,0)
1413    set(handles.Panel1Dplot,'Visible','off')
1414%      set(handles.scalar,'Visible','off')
1415%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1416%     if isequal(get(handles.check_vector,'Value'),0);
1417%         set(handles.coord_z_vectors_scalar,'Visible','off')
1418%     end
1419else
1420    set(handles.Panel1Dplot,'Visible','on')
1421%     set(handles.scalar,'Visible','on')
1422%     val=get(handles.ordinate,'Value');
1423%     val=val(1);
1424%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1425%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1426%       set(handles.coord_z_vectors_scalar,'Visible','on')
1427end
1428
1429% --- Executes on button press in check_scalar.
1430function check_scalar_Callback(hObject, eventdata, handles)
1431val=get(handles.check_scalar,'Value');
1432if isequal(val,0)
1433    set(handles.PanelScalar,'Visible','off')
1434%      set(handles.scalar,'Visible','off')
1435%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1436%     if isequal(get(handles.check_vector,'Value'),0);
1437%         set(handles.coord_z_vectors_scalar,'Visible','off')
1438%     end
1439else
1440    set(handles.PanelScalar,'Visible','on')
1441%     set(handles.scalar,'Visible','on')
1442%     val=get(handles.ordinate,'Value');
1443%     val=val(1);
1444%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1445%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1446%       set(handles.coord_z_vectors_scalar,'Visible','on')
1447end
1448
1449%---------------------------
1450% --- Executes on button press in check_vector.
1451function check_vector_Callback(hObject, eventdata, handles)
1452val=get(handles.check_vector,'Value');
1453if isequal(val,0)
1454    set(handles.PanelVectors,'Visible','off')
1455else
1456    set(handles.PanelVectors,'Visible','on')
1457end
1458
1459
1460
1461%-----------------------------
1462function mouse_up_gui(ggg,eventdata,handles)
1463if isequal(get(ggg,'SelectionType'),'alt')
1464    message=''; 
1465    global CurData
1466    inputfield=get(handles.inputfile,'String');
1467    if exist(inputfield,'file')
1468        CurData=nc2struct(inputfield);
1469    else
1470        CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1471    end
1472  %%%% TODO: put the matalb command window in front
1473    evalin('base','global CurData')%make CurData global in the workspace
1474    evalin('base','CurData') %display CurData in the workspace
1475end
1476
1477%---------------------------------------------
1478% --- Executes on selection change in ACTION.
1479function ACTION_Callback(hObject, eventdata, handles)
1480list_ACTION=get(handles.ACTION,'String');% list menu fields
1481index_ACTION=get(handles.ACTION,'Value');% selected string index
1482ACTION= list_ACTION{index_ACTION}; % selected string
1483path_get_field=which('get_field');%path to series.m
1484list_path=get(handles.ACTION,'UserData');
1485nb_builtin=0;
1486list_path
1487if iscell(list_path)
1488for ilist=1:length(list_path)
1489    if isequal(list_path{ilist},path_get_field)
1490        nb_builtin=nb_builtin+1;
1491    else
1492        break
1493    end
1494end
1495end
1496if nb_builtin==0% the path to get_field has been changed, reinitialize
1497    get_field_OpeningFcn(hObject, eventdata, handles)
1498    return
1499end
1500
1501% add a new function to the menu
1502if isequal(ACTION,'more...')
1503    pathfct=fileparts(path_get_field);
1504    browse_name=fullfile(path_get_field,'FIELD_FCT');
1505    if length(list_path)>nb_builtin
1506        browse_name=list_path{end};% initialize browser with  the path of the last introduced function
1507    end
1508%     fct_name='';
1509%     dir_perso=prefdir;
1510%     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1511%     display(profil_perso)
1512%     if exist(profil_perso,'file')
1513%           h=load (profil_perso);
1514%           if isfield(h,'get_field_fct')
1515%             fct_name=h.get_field_fct;
1516%           end
1517%     else
1518%         path_to_uvmat=which ('uvmat');% check the path of uvmat
1519%         pathfct=fileparts(path_to_uvmat);
1520%         fct_name=fullfile(pathfct,'USR_FCT');%go to UVMAT/USR_FCT by default
1521%     end
1522    [FileName, PathName] = uigetfile( ...
1523       {'*.m', ' (*.m)';
1524        '*.m',  '.m files '; ...
1525        '*.*', 'All Files (*.*)'}, ...
1526        'Pick a file',browse_name);
1527    if length(FileName)<2
1528        return
1529    end
1530    ext_fct=FileName(end-1:end);
1531    if ~isequal(ext_fct,'.m')
1532        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1533        return
1534    end
1535    ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
1536   
1537    % insert the choice in the action menu
1538   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1539   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1540   list_path{index_ACTION}=PathName;
1541   if length(menu_str)>nb_builtin+5;
1542       nbremove=length(menu_str)-nb_builtin-5;
1543       menu_str(nb_builtin+1:end-5)=[];
1544       list_path(nb_builtin+1:end-4)=[];
1545       index_ACTION=index_ACTION-nbremove;
1546       set(handles.ACTION,'Value',index_ACTION)
1547       set(handles.ACTION,'String',menu_str)
1548   end
1549   list_path{index_ACTION}=PathName;
1550   set(handles.ACTION,'UserData',list_path);
1551   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1552   
1553   %record the current menu in personal file profil_perso
1554   dir_perso=prefdir;
1555   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1556   for ilist=nb_builtin+1:length(menu_str)-1
1557       get_field_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
1558   end
1559   if exist(profil_perso,'file')
1560        save(profil_perso,'get_field_fct','-append')
1561   else
1562        txt=ver;
1563        Release=txt(1).Release;
1564        relnumb=str2num(Release(3:4));
1565        if relnumb >= 14
1566            save(profil_perso,'get_field_fct','-V6')
1567        else
1568            save(profil_perso, 'get_field_fct')
1569        end
1570   end
1571end
1572
1573   %check the current path to the selected function
1574PathName=list_path{index_ACTION};%current recorded path
1575if ~isequal(path_get_field,PathName)
1576    CurrentPath=fileparts(which(ACTION));
1577    if ~isequal(PathName,CurrentPath)
1578        addpath(PathName)
1579        errormsg=check_functions;
1580        msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
1581    end
1582end
1583set(handles.path_action,'String',PathName); %show the path to the senlected function
1584   
1585   
1586%     fct_name=fullfile(PathName, FileName);
1587%     if ~exist(fct_name,'file')
1588%            msgbox_uvmat('ERROR',['procesing fct ' fct_name ' not found'])
1589%     else
1590%        ACTION=FileName(1:end-2);%
1591%        menu=update_menu(handles.ACTION,ACTION);%add the selected fct to the menu
1592%        index_ACTION=get(handles.ACTION,'Value');% selected string index
1593%        list_path{index_ACTION}=PathName;
1594%        set(handles.ACTION,'UserData',list_path)
1595%        if exist(profil_perso,'file')
1596%             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
1597%         end
1598%     end   
1599%     
1600%     
1601%     fileinput=FileName;%complete file name
1602%     eval(['spath=which(''' FileName ''');'])% current path to the function FileName
1603%     if ~isequal(spath,PathName)
1604%         addpath(PathName)
1605%     end
1606%     FileName([end-1:end])=[];
1607%     
1608%    % insert the choice in the action menu
1609%     nbACTION=length(list_ACTION);
1610%     index=0;
1611%     for ilist=1:nbACTION
1612%        if isequal(FileName,list_ACTION{ilist})%look for the selected scalar in the fields_input menu
1613%             index=ilist;%
1614%        end
1615%     end
1616%     if index==0
1617%        list_ACTION{nbACTION}=FileName; %put the chosen fct at the penultimate place in the fields_input menu
1618%        list_path{nbACTION}=PathName;
1619%        index=nbACTION;
1620%        list_ACTION{nbACTION+1}='more...';
1621%        set(handles.ACTION,'String',list_ACTION)
1622%     end
1623%     set(handles.ACTION,'Value',index);% store the selected scalar type
1624%     set(handles.ACTION,'UserData',list_path);
1625%     usr_defined_fct=fct_name;
1626%     nbmenu=length(list_ACTION);
1627%     nbadd=nbmenu-5;
1628%     ilist=0;
1629%     for imenu=nbmenu-min(4,nbadd):nbmenu-1
1630%       ilist=ilist+1;
1631%       fct_get_field{ilist,1}=list_ACTION{imenu};
1632%       fct_path_get_field{ilist}=list_path{imenu};
1633%     end
1634%     if exist(profil_perso,'file')
1635%         save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-append')
1636%     else
1637%        save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-V6')
1638%     end
1639% end
1640
1641% %check the current path to the selected function
1642% list_path
1643% PathName=list_path{index_ACTION}
1644% CurrentPath=fileparts(which(ACTION))
1645% if ~isequal(PathName,CurrentPath)
1646%     addpath(PathName)
1647%     errormsg=check_functions;
1648%     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
1649% end
1650% set(handles.path_action,'String',fullfile(PathName,' ')); %show the path to the senlected function
1651
1652%default setting for the visibility of the GUI elements*
1653if ~isequal(ACTION,'PLOT')
1654    varargout=feval(ACTION);% input list asked by the selected function
1655    test_1Dplot=[];
1656    test_scalar=[];
1657    test_vector=[];
1658    for ilist=1:length(varargout)-1
1659        switch varargout{ilist}
1660                           %RootFile always visible
1661            case 'check_1Dplot'   
1662                 test_1Dplot=isequal(lower(varargout{ilist+1}),'y');
1663            case 'check_scalar'
1664                 test_scalar=isequal(lower(varargout{ilist+1}),'y');   
1665            case 'check_vector'   
1666                 test_vector=isequal(lower(varargout{ilist+1}),'y');
1667        end
1668    end
1669    if test_1Dplot==0
1670        set(handles.check_1Dplot,'Value',0);
1671    end
1672    if test_1Dplot==1
1673        set(handles.check_1Dplot,'Value',1);
1674    end
1675    if test_scalar==0
1676        set(handles.check_scalar,'Value',0);
1677    end
1678    if test_scalar==1
1679        set(handles.check_scalar,'Value',1);
1680    end
1681    if test_vector==0
1682        set(handles.check_vector,'Value',0);
1683    end
1684    if test_vector==1
1685        set(handles.check_vector,'Value',1);
1686    end
1687    check_1Dplot_Callback(hObject, eventdata, handles)
1688    check_scalar_Callback(hObject, eventdata, handles)
1689    check_vector_Callback(hObject, eventdata, handles)
1690end
1691%
1692% % --- Executes on selection change in menu_coord.
1693% function menu_coord_Callback(hObject, eventdata, handles)
1694% hget_field=get(handles.menu_coord,'parent');
1695% menu=get(handles.menu_coord,'String');
1696% ind_coord=get(handles.menu_coord,'Value');
1697% coord_option=menu{ind_coord};
1698% if isequal(coord_option,'more...');
1699%     fct_name='';
1700%     if exist('./TMP/current_usr_fct.mat','file')% if a file is found
1701%         h=load('./TMP/current_usr_fct.mat');
1702%         if isfield(h,'fct_name');
1703%             fct_name=h.fct_name;
1704%         end
1705%     end
1706%     prompt = {'Enter the name of the transform function'};
1707%     dlg_title = 'user defined transform';
1708%     num_lines= 1;
1709%     [FileName, PathName, filterindex] = uigetfile( ...
1710%        {'*.m', ' (*.m)';
1711%         '*.m',  '.m files '; ...
1712%         '*.*', 'All Files (*.*)'}, ...
1713%         'Pick a file', fct_name);
1714%     fct_name=fullfile(PathName,FileName);
1715%     addpath(PathName);%add the path to the selected fct
1716%     [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
1717%     if ~exist(fct_name,'file')
1718%            warndlg_uvmat(['image procesing fct ' fct_name ' not found'],'WARNING')
1719%     else
1720%         transform=FileName(1:end-2);%
1721%         menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
1722% %         set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
1723%       save ('./TMP/current_usr_fct.mat','fct_name');
1724%     end   
1725% end
1726
1727% --- Executes on selection change in menu_coord.
1728function HELP_Callback(hObject, eventdata, handles)
1729path_to_uvmat=which ('uvmat');% check the path of uvmat
1730pathelp=fileparts(path_to_uvmat);
1731helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1732if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1733else
1734web([helpfile '#get_field'])   
1735end
1736
1737%-----------------------------------------------------
1738% --- browse existing figures
1739%-----------------------------------------------------
1740function browse_fig(menu_handle)
1741hh=findobj(allchild(0),'Type','figure');
1742ilist=0;
1743list={};
1744for ifig=1:length(hh)  %look for all existing figures
1745    name=get(hh(ifig),'Name');
1746     if ~isequal(name,'uvmat')%case of uvmat GUI
1747%         ilist=ilist+1;
1748%         list{ilist,1}='uvmat';
1749%     else        %other figures
1750        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1751        nbaxe=0;
1752        for ichild=1:length(hchild)           
1753            Type=get(hchild(ichild),'Type');
1754            Tag=get(hchild(ichild),'Tag');
1755            if isequal(Type,'axes')
1756                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1757                     nbaxe=nbaxe+1;%count the existing axis
1758                end
1759            end
1760        end   
1761        if nbaxe==1
1762             ilist=ilist+1;%add a line in the list of axis
1763            list{ilist,1}=num2str(hh(ifig));
1764        elseif nbaxe>1
1765            for iaxe=1:nbaxe
1766               ilist=ilist+1;%add a line in the list of axis
1767               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1768            end
1769        end
1770     end
1771end
1772list=['new fig...';'uvmat';list];
1773set(menu_handle,'Value',1)
1774set(menu_handle,'String',list)
1775
1776
1777%-----------------------------------------------------
1778function list_fig_Callback(hObject, eventdata, handles)
1779%-----------------------------------------------------
1780list_fig=get(handles.list_fig,'String');
1781fig_val=get(handles.list_fig,'Value');
1782plot_fig=list_fig{fig_val};
1783if isequal(plot_fig,'uvmat')
1784    huvmat=findobj(allchild(0),'name','uvmat');
1785    if ~isempty(huvmat)
1786        uistack(huvmat,'top')
1787    end   
1788elseif ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1789    sep=regexp(plot_fig,'_');
1790    if ~isempty(sep)
1791        plot_fig=plot_fig([1:sep-1]);
1792    end
1793    if ishandle(str2num(plot_fig))
1794        figure(str2num(plot_fig))% display existing figure
1795    else
1796        browse_fig(handles.list_fig); %reset the current list of figures
1797    end
1798end
1799
1800
1801%-------------------------------------------------
1802% give index numbers of the strings str in the list ListvarName
1803function VarIndex_y=name2index(cell_str,ListVarName)
1804VarIndex_y=[];
1805if ischar(cell_str)
1806    for ivar=1:length(ListVarName)
1807        varlist=ListVarName{ivar};
1808        if isequal(varlist,cell_str)
1809            VarIndex_y= ivar;
1810            break
1811        end
1812    end
1813elseif iscell(cell_str)
1814    for isel=1:length(cell_str)
1815        varsel=cell_str{isel};
1816        for ivar=1:length(ListVarName)
1817            varlist=ListVarName{ivar};
1818            if isequal(varlist,varsel)
1819                VarIndex_y=[VarIndex_y ivar];
1820            end
1821        end
1822    end
1823end
1824
1825% --------------------------------------------------------------------
1826function MenuOpen_Callback(hObject, eventdata, handles)
1827% hObject    handle to MenuOpen (see GCBO)
1828% eventdata  reserved - to be defined in a future version of MATLAB
1829% handles    structure with handles and user data (see GUIDATA)
1830
1831
1832% --------------------------------------------------------------------
1833function MenuExport_Callback(hObject, eventdata, handles)
1834% hObject    handle to MenuExport (see GCBO)
1835% eventdata  reserved - to be defined in a future version of MATLAB
1836% handles    structure with handles and user data (see GUIDATA)
1837
1838
1839% --------------------------------------------------------------------
1840function MenuBrowse_Callback(hObject, eventdata, handles)
1841
1842oldfile=get(handles.inputfile,'String');
1843testrootfile=0;
1844testsubdir=0;
1845if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1846        oldfile='';
1847        dir_perso=prefdir;
1848         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1849         if exist(profil_perso,'file')
1850              h=load (profil_perso);
1851             if isfield(h,'RootPath')
1852                  RootPath=h.RootPath;
1853             end
1854             if isfield(h,'SubDir')
1855                  SubDir=h.SubDir;
1856                  if ~isempty(SubDir)
1857                    testsubdir=1;
1858                  end
1859             end
1860             if isfield(h,'RootFile')
1861                  RootFile=h.RootFile;
1862                  if ~isempty(RootFile)
1863                    testrootfile=1;
1864                  end
1865             end
1866         end
1867end
1868if testrootfile
1869    if ~testsubdir
1870        oldfile=fullfile(RootPath,RootFile);
1871    else
1872        oldfile=fullfile(RootPath,SubDir,RootFile);
1873    end
1874end
1875[FileName, PathName] = uigetfile( ...
1876       {'*.nc', ' *.nc';...
1877       '*.cdf', ' *.cdf';...
1878        '*.*',  'All Files (*.*)'}, ...
1879        'Pick a file',oldfile);
1880
1881%global inputfile
1882fileinput=[PathName FileName];%complete file name
1883testblank=findstr(fileinput,' ');%look for blanks
1884if ~isempty(testblank)
1885    warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
1886    return
1887end
1888sizf=size(fileinput);
1889if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
1890set(handles.inputfile,'String',fileinput)
1891inputfile_Callback(hObject, eventdata, handles)
1892
1893
1894%update list of recent files in the menubar
1895MenuFile_1=fileinput;
1896MenuFile_2=get(handles.MenuFile_1,'Label');
1897MenuFile_3=get(handles.MenuFile_2,'Label');
1898MenuFile_4=get(handles.MenuFile_3,'Label');
1899MenuFile_5=get(handles.MenuFile_4,'Label');
1900set(handles.MenuFile_1,'Label',MenuFile_1)
1901set(handles.MenuFile_2,'Label',MenuFile_2)
1902set(handles.MenuFile_3,'Label',MenuFile_3)
1903set(handles.MenuFile_4,'Label',MenuFile_4)
1904set(handles.MenuFile_5,'Label',MenuFile_5)
1905
1906
1907% %store input file in personal file uvmat_perso.mat
1908% dir_perso=prefdir;
1909% profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1910% if exist(profil_perso,'file')
1911%     save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext','-append'); %store the root name for future opening of uvmat
1912% else
1913%    save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext'); %store the root name for future opening of uvmat
1914% end   
1915
1916
1917% --------------------------------------------------------------------
1918function MenuFile_1_Callback(hObject, eventdata, handles)
1919% hObject    handle to MenuFile_1 (see GCBO)
1920% eventdata  reserved - to be defined in a future version of MATLAB
1921% handles    structure with handles and user data (see GUIDATA)
1922
1923
1924% --------------------------------------------------------------------
1925function MenuFile_2_Callback(hObject, eventdata, handles)
1926% hObject    handle to MenuFile_2 (see GCBO)
1927% eventdata  reserved - to be defined in a future version of MATLAB
1928% handles    structure with handles and user data (see GUIDATA)
1929
1930
1931% --------------------------------------------------------------------
1932function MenuFile_3_Callback(hObject, eventdata, handles)
1933% hObject    handle to MenuFile_3 (see GCBO)
1934% eventdata  reserved - to be defined in a future version of MATLAB
1935% handles    structure with handles and user data (see GUIDATA)
1936
1937
1938% --------------------------------------------------------------------
1939function MenuFile_4_Callback(hObject, eventdata, handles)
1940% hObject    handle to MenuFile_4 (see GCBO)
1941% eventdata  reserved - to be defined in a future version of MATLAB
1942% handles    structure with handles and user data (see GUIDATA)
1943
1944
1945% --------------------------------------------------------------------
1946function MenuFile_5_Callback(hObject, eventdata, handles)
1947% hObject    handle to MenuFile_5 (see GCBO)
1948% eventdata  reserved - to be defined in a future version of MATLAB
1949% handles    structure with handles and user data (see GUIDATA)
1950
1951
1952% --------------------------------------------------------------------
1953function ExportField_Callback(hObject, eventdata, handles)
1954% hObject    handle to ExportField (see GCBO)
1955% eventdata  reserved - to be defined in a future version of MATLAB
1956% handles    structure with handles and user data (see GUIDATA)
1957
1958
Note: See TracBrowser for help on using the repository browser.