source: trunk/src/get_field.m @ 17

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

possibilite de créer une grille physique dans geometry_calib (le faire apres avoir introduit les points sur l'image avec la souris)
petites corrections mineures sur les autres fichiers

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