source: trunk/src/get_field.m @ 59

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

upgrade and cleaning in uvmat: run min plus does not modify the field counters in case of error
nomtype2pair: comments added
get_field: minor cleaning

File size: 56.3 KB
RevLine 
[2]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
[12]24% Last Modified by GUIDE v2.5 06-Feb-2010 09:58:13
[2]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
[34]45%------------------------------------------------------------------------
[2]46% --- Executes just before get_field is made visible.
47function get_field_OpeningFcn(hObject, eventdata, handles,filename,Field,haxes)
[34]48%------------------------------------------------------------------------
49global nb_builtin
[2]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);
[34]57%pathuvmat=fileparts(which('uvmat'));
58%addpath(fullfile(pathuvmat,'FIELD_FCT'))
59%loads the information stored in prefdir to initiate the browser and the list of functions
60menu_str={'PLOT';'FFT';'filter_band';'histogram'}; %list of functions included in 'get_field.m'
61nb_builtin=numel(menu_str)-1;
62%menu_str(end)=[];%remove from the list the last option 'more...'
63path_get_field=fileparts(which('get_field'));%path of the function 'get_field'
64for ilist=1:length(menu_str)
65    fct_path{ilist,1}=fullfile(path_get_field,'get_field');%paths of the fuctions buil-in in 'get_field.m'
66end
67dir_perso=prefdir;
68profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
69if exist(profil_perso,'file')
70    % menu={'RUN';'raw2phys';'histogram';'FFT';'peaklocking'};
71      h=load (profil_perso);
72     if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
73         for ilist=1:length(h.get_field_fct)
74            [path,file]=fileparts(h.get_field_fct{ilist});
75            fct_path=[fct_path; {path}];%concatene the list of paths
76            menu_str=[menu_str; {file}];
77         end
78     end
79end
80menu_str=[menu_str;{'more...'}];
81set(handles.ACTION,'String',menu_str)
82set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION 
83ACTION_Callback(hObject, eventdata, handles)
[2]84set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})%set mouse click action function
85if exist('filename','var')& ischar(filename)
86    set(handles.inputfile,'String',filename)
87    inputfile_Callback(hObject, eventdata, handles)
88else
[34]89    set(handles.inputfile,'String','')   
[2]90end
91if exist('Field','var') & isstruct(Field)
92        Field_input(eventdata,handles,Field)
93        if exist('haxes','var')
94            Field.PlotAxes=haxes;
95        end
96    set(hObject,'UserData',Field);
97end
98
[34]99%load the list of previously browsed files in menus Open
100 dir_perso=prefdir;
101 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
102 if exist(profil_perso,'file')
103      h=load (profil_perso);
104      if isfield(h,'MenuFile_1')
105          set(handles.MenuFile_1,'Label',h.MenuFile_1);
106      end
107      if isfield(h,'MenuFile_1')
108          set(handles.MenuFile_2,'Label',h.MenuFile_2);
109      end
110      if isfield(h,'MenuFile_1')
111          set(handles.MenuFile_3,'Label',h.MenuFile_3);
112      end
113      if isfield(h,'MenuFile_1')
114          set(handles.MenuFile_4,'Label',h.MenuFile_4);
115      end
116      if isfield(h,'MenuFile_1')
117          set(handles.MenuFile_5,'Label',h.MenuFile_5);
118     end
119 end
[2]120
[34]121%------------------------------------------------------------------------
[2]122% --- Outputs from this function are returned to the command line.
123function varargout = get_field_OutputFcn(hObject, eventdata, handles)
[34]124%------------------------------------------------------------------------
[2]125varargout{1} = handles.output;
126
[34]127%------------------------------------------------------------------------
[2]128% --- Executes on button press in browse.
129function browse_Callback(hObject, eventdata, handles)
[34]130%------------------------------------------------------------------------
[2]131
[34]132%------------------------------------------------------------------------
[2]133function inputfile_Callback(hObject, eventdata, handles)
[34]134%------------------------------------------------------------------------
[2]135inputfile=get(handles.inputfile,'String');
[56]136Field=nc2struct(inputfile);% reads the whole field
[2]137hfig=get(handles.inputfile,'parent');
138set(hfig,'UserData',Field);
139Field_input(eventdata,handles,Field);
140
[34]141%------------------------------------------------------------------------
[2]142function Field_input(eventdata,handles,Field)
[34]143%------------------------------------------------------------------------
[2]144if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
145    Tabcell(:,1)=Field.ListDimName;
146    for iline=1:length(Field.ListDimName)
147        Tabcell{iline,2}=num2str(Field.DimValue(iline));
148    end
149    Tabchar=cell2tab(Tabcell,'=');
150    set(handles.dimensions,'String',Tabchar)
151end
152if ~isfield(Field,'ListVarName')
153    return
154end
155Txt=Field.ListVarName;
156set(handles.variables,'Value',1)
157set(handles.variables,'String',[{'*'} Txt])
158variables_Callback(handles.variables,[], handles)
159set(handles.abscissa,'String',[{''} Txt ])
160set(handles.ordinate,'String',Txt)
161set(handles.vector_x,'String',[Txt ])
162set(handles.vector_y,'String',[Txt ])
163set(handles.vector_z,'String',[{''} Txt ])
164set(handles.vec_color,'String',[{''} Txt ])
165set(handles.coord_x_scalar,'String',[{''} Txt ])
166set(handles.coord_y_scalar,'String',[{''} Txt ])
167set(handles.coord_x_vectors,'String',[{''} Txt ])
168set(handles.coord_y_vectors,'String',[{''} Txt ])
169set(handles.coord_z_scalar,'String',[{''} Txt ])
170set(handles.coord_z_vectors,'String',[{''} Txt ])
171set(handles.scalar,'Value',1)
172set(handles.scalar,'String', Txt )
173[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
[34]211%------------------------------------------------------------------------
[2]212function ordinate_Callback(hObject, eventdata, handles)
[34]213%------------------------------------------------------------------------
[2]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};
[55]229    if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex))
[2]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;
[55]238coord_x_index=coord_x_index(coord_x_index~=0);
[2]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
[34]244%------------------------------------------------------------------------
[2]245% --- Executes on selection change in abscissa.
246function abscissa_Callback(hObject, eventdata, handles)
[34]247%------------------------------------------------------------------------
[2]248 hselect_field=get(handles.inputfile,'parent');
249 Field=get(hselect_field,'UserData');%current input field
250 xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
251% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
252% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
253%if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
254%     Txt=Field.ListVarName;
255%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
256%     xindex=[];
257% else
258     xlist=get(handles.abscissa,'String');%list of abscissa
259     VarName=xlist{xdispindex}; %selected variable name
260     update_field(hObject, eventdata, handles,VarName)
261%      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
262%      if ~isempty(xindex)
263%         set(handles.variables,'Value',xindex+1)
264%         variables_Callback(hObject, eventdata, handles)
265%      end
266%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
267%     variables_Callback(hObject, eventdata, handles)  %display properties of the variable (dim, attributes)
268%     if  ~test_2D &  ~test_scalar% look for possible varaibles to RUN in ordinate   
269%         index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
270%         VarIndex=[];
271%         for ilist=1:length(Field.VarDimIndex)%detect
272%             index_i=Field.VarDimIndex{ilist};
273%             if ~isempty(index_i)
274%                 if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible
275%                     VarIndex=[VarIndex ilist];
276%                 end
277%             end
278%         end
279% %         set(handles.ordinate,'Value',1)
280%         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
281%     end
282% end
283%
284% update_UserData(handles)
285
286%-------------------------------------------------------
287% --- Executes on selection change in scalar menu.
288function scalar_Callback(hObject, eventdata, handles)
289%-------------------------------------------------------
290Aindex=get(handles.scalar,'Value');
291Astring=get(handles.scalar,'String');
292VarName=Astring{Aindex};
293update_field(hObject, eventdata, handles,VarName)
294
295%-------------------------------------------------------
296% --- Executes on selection change in coord_x_scalar.
297function coord_x_scalar_Callback(hObject, eventdata, handles)
298%-------------------------------------------------------
299index=get(handles.coord_x_scalar,'Value');
300string=get(handles.coord_x_scalar,'String');
301VarName=string{index};
302update_field(hObject, eventdata, handles,VarName)
303
304%-------------------------------------------------------
305% --- Executes on selection change in coord_y_scalar.
306function coord_y_scalar_Callback(hObject, eventdata, handles)
307%-------------------------------------------------------
308index=get(handles.coord_y_scalar,'Value');
309string=get(handles.coord_y_scalar,'String');
310VarName=string{index};
311update_field(hObject, eventdata, handles,VarName)
312
313%-------------------------------------------------------
314% --- Executes on selection change in coord_z_scalar.
315function coord_z_scalar_Callback(hObject, eventdata, handles)
316%-------------------------------------------------------
317index=get(handles.coord_z_scalar,'Value');
318string=get(handles.coord_z_scalar,'String');
319VarName=string{index};
320update_field(hObject, eventdata, handles,VarName)
321
322%-------------------------------------------------------
323% --- Executes on selection change in vector_x.
324function vector_x_Callback(hObject, eventdata, handles)
325%-------------------------------------------------------
326index=get(handles.vector_x,'Value');
327string=get(handles.vector_x,'String');
328VarName=string{index};
329update_field(hObject, eventdata, handles,VarName)
330
331%-------------------------------------------------------
332% --- Executes on selection change in vector_y.
333function vector_y_Callback(hObject, eventdata, handles)
334%-------------------------------------------------------
335index=get(handles.vector_y,'Value');
336string=get(handles.vector_y,'String');
337VarName=string{index};
338update_field(hObject, eventdata, handles,VarName)
339
340%-------------------------------------------------------
341% --- Executes on selection change in vector_z.
342function vector_z_Callback(hObject, eventdata, handles)
343%-------------------------------------------------------
344index=get(handles.vector_z,'Value');
345string=get(handles.vector_z,'String');
346VarName=Astring{index};
347update_field(hObject, eventdata, handles,VarName)
348
349%-------------------------------------------------------
350% --- Executes on selection change in coord_x_vectors.
351function coord_x_vectors_Callback(hObject, eventdata, handles)
352%-------------------------------------------------------
353index=get(handles.coord_x_vectors,'Value');
354string=get(handles.coord_x_vectors,'String');
355VarName=string{index};
356update_field(hObject, eventdata, handles,VarName)
357
358%-------------------------------------------------------
359% --- Executes on selection change in coord_y_vectors.
360%-------------------------------------------------------
361function coord_y_vectors_Callback(hObject, eventdata, handles)
362index=get(handles.coord_y_vectors,'Value');
363string=get(handles.coord_y_vectors,'String');
364VarName=string{index};
365update_field(hObject, eventdata, handles,VarName)
366
367%-------------------------------------------------------
368% --- Executes on selection change in coord_z_scalar.
369function coord_z_vectors_Callback(hObject, eventdata, handles)
370%-------------------------------------------------------
371index=get(handles.coord_z_vectors,'Value');
372string=get(handles.coord_z_vectors,'String');
373VarName=string{index};
374update_field(hObject, eventdata, handles,VarName)
375
376%-------------------------------------------------------
377% --- Executes on selection change in vec_color.
378function vec_color_Callback(hObject, eventdata, handles)
379%-------------------------------------------------------
380index=get(handles.vec_color,'Value');
381string=get(handles.vec_color,'String');
382VarName=string{index};
383update_field(hObject, eventdata, handles,VarName)
384
385%---------------------------------
386function update_field(hObject, eventdata, handles,VarName)
387% VarName= input variable name for scalar or vector plots
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)
[38]544        msgbox_uvmat('ERROR','inconsistent dimensions for u and v')
[2]545        set(handles.vector_y,'Value',1);
546        return
547    elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
[38]548         msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color')
[2]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
[38]562        msgbox_uvmat('ERROR','array with more than three dimensions, not supported')
[2]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
[38]591                msgbox_uvmat('ERROR','multiple dimensions for the z coordinate')
[2]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
[38]635        msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1')   
[2]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
[38]678        msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1')   
[2]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%---------------------------------------------------------
[34]738path_get_field=fileparts(which('get_field'));
[2]739list=get(handles.ACTION,'String');
740index=get(handles.ACTION,'Value');
741ACTION=list{index};
[34]742list_path=get(handles.ACTION,'UserData');
743%hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
744fct_path=list_path{index}; %path stored for the function ACTION
745if ~isequal(fct_path,path_get_field)
746%     eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
747%     if ~isequal(spath,fct_path)& exist(fct_path,'dir')
748        addpath(fct_path)% add the prescribed path if not the current one
749%     end
[2]750end
[34]751% fct_path
752eval(['h_fun=@' ACTION ';'])
753if ~isequal(fct_path,path_get_field)
754        rmpath(fct_path)% add the prescribed path if not the current one   
[2]755end
756
[34]757set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
758drawnow
759h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
760browse_fig(handles.list_fig); %update the list of new existing figures
[2]761
762
763%------------------------------------------------
764% --- Executes on button press in Plot_histo.
765%RUN global histograms
766%-------------------------------------------------
767function RUN_histo_Callback(hObject, eventdata, handles)
768% hObject    handle to RUN (see GCBO)
769% eventdata  reserved - to be defined in a future version of MATLAB
770% handles    structure with handles and user data (see GUIDATA)
771
772%time plots
773leg={};
774n=0;
775if (get(handles.cm_switch,'Value')==1)
776    Uval_p=Uval_cm;
777    Vval_p=Vval_cm;
778    Uhist_p=Uhist_cm;
779    Vhist_p=Vhist_cm;
780    xlab='velocity (cm/s)';
781else
782    Uval_p=Uval;
783    Vval_p=Vval;
784    Uhist_p=Uhist;
785    Vhist_p=Vhist;
786    xlab='velocity (pixels)';
787end
788if (get(handles.vector_y,'Value') == 1)
789   hhh=figure(2);
790   hold on
791   title([filebase ', ' strindex ', ' fieldtitle])
792   plot(Uval_p,Uhist_p,'b-')
793   n=n+1;
794   leg{n}='Uhist';
795   xlabel(xlab)
796end
797if (get(handles.Vhist_input,'Value') == 1)
798   hhh=figure(2);
799   hold on
800   title([filebase ', ' strindex ', ' fieldtitle])
801   plot(Vval_p,Vhist_p,'r-')
802   n=n+1;
803   leg{n}='Vhist';
804   xlabel(xlab);
805end
806if (get(handles.Chist_input,'Value') == 1)
807   hhhh=figure(3);
808   hold on
809   title([filebase ', ' strindex ', ' fieldtitle])
810   plot(Cval,Chist,'k-')
811   leg{1}='Chist';
812end
813% hold off
814grid on
815legend(leg);
816
817% %-------------------------------------------------------------
818% % --- Executes on button press in Save_input.
819% function Save_input_Callback(hObject, eventdata, handles)
820% list_str=get(handles.abscissa,'String');
821% val=get(handles.abscissa,'Value');
822% var=list_str{val};
823% hselect_field=get(handles.Save_input,'parent')
824% set(hselect_field,'UserData',var);
825% set(hselect_field,'Tag','idle')
826
827%     
828% %-------------------------------------------------------------
829% % --- Executes on button press in save_histo.
830% function save_histo_Callback(hObject, eventdata, handles)
831% global filebase
832%
833% pathstr = fileparts(filebase)
834% if (get(handles.Chist_input,'Value') == 1)
835%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
836%     else
837
838%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
839% end
840% prompt={'save figure(2) as'}
841% dlg_title = 'save figure';
842% num_lines= 1;
843% answer = inputdlg(prompt,dlg_title,num_lines,def)
844% saveas(2,answer{1})
845 
846
847%%-------------------------------------------------------
848% --- Executes on button press in peaklocking.
849%-------------------------------------------------
850function peaklocking(handles)
851%evaluation of peacklocking errors
852%use splinhist: give spline coeff cc for a smooth histo (call spline4)
853%use histsmooth(x,cc): calculate the smooth histo for any value x
854%use histder(x,cc): calculate the derivative of the smooth histo
855global hfig1 hfig2 hfig3
856global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
857global xval xerror yval yerror
858
859set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
860set(handles.Vhist_input,'Value',1)
861set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
862
863%adjust the extremal values of the histogram in U with respect to integer
864%values
865minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
866maximU=round(max(Uval)-0.5)+0.5;
867minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
868maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
869nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
870nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
871Uval=[minim_fin:(1/nbb):maxim_fin];
872histu_min=zeros(nb_bin_min,1);
873histu_max=zeros(nb_bin_max,1);
874Uhist=[histu_min; Uhist ;histu_max]; % column vector
875
876%adjust the extremal values of the histogram in V
877minimV=round(min(Vval-0.5)+0.5);
878maximV=round(max(Vval-0.5)+0.5);
879minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
880maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
881nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
882nb_bin_max=round((maxim_fin -max(Vval))*nbb);
883Vval=[minim_fin:(1/nbb):maxim_fin];
884histu_min=zeros(nb_bin_min,1);
885histu_max=zeros(nb_bin_max,1);
886Vhist=[histu_min; Vhist ;histu_max]; % column vector
887
888% RUN_histo_Callback(hObject, eventdata, handles)
889% %adjust the histogram to integer values:
890
891%histoU and V
892[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
893[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
894
895% selection of value ranges such that histo>=10 (enough statistics)
896Uval_ind=find(Uhist>=10);
897ind_min=min(Uval_ind);
898ind_max=max(Uval_ind);
899U_min=Uval(ind_min);% minimum allowed value
900U_max=Uval(ind_max);%maximum allowed value
901
902% selection of value ranges such that histo>=10 (enough statistics)
903Vval_ind=find(Vhist>=10);
904ind_min=min(Vval_ind);
905ind_max=max(Vval_ind);
906V_min=Vval(ind_min);% minimum allowed value
907V_max=Vval(ind_max);%maximum allowed value
908
909figure(4)% plot U histogram with smoothed one
910plot(Uval,Uhist,'b')
911grid on
912hold on
913plot(Uval,Uhistinter,'r');
914hold off
915
916figure(5)% plot V histogram with smoothed one
917plot(Vval,Vhist,'b')
918grid on
919hold on
920plot(Vval,Vhistinter,'r');
921hold off
922
923figure(6)% plot pixel error in two subplots
924hfig4=subplot(2,1,1);
925hfig5=subplot(2,1,2);
926axes(hfig4)
927plot(xval,xerror)
928axis([U_min U_max -0.4 0.4])
929xlabel('velocity u (pix)')
930ylabel('peaklocking error (pix)')
931grid on
932axes(hfig5)
933plot(yval,yerror)
934axis([V_min V_max -0.4 0.4]);
935xlabel('velocity v (pix)')
936ylabel('peaklocking error (pix)')
937grid on
938
939
940% ------------------------------------------------------------------
941function variables_Callback(hObject, eventdata, handles)
942Tabchar={''};%default
943Tabcell=[];
944hselect_field=get(handles.variables,'parent');
945Field=get(hselect_field,'UserData');
946index=get(handles.variables,'Value');%index in the list 'variables'
947if isequal(index,1)
948    set(handles.attributes_txt,'String','global attributes')
949% list global attribute names and values if index=1 (blank variable display) is selected
950    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
951        for iline=1:length(Field.ListGlobalAttribute)
952            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
953            if isfield(Field, Field.ListGlobalAttribute{iline})
954                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
955                if ischar(val);
956                    Tabcell{iline,2}=val;
957                else
958                    Tabcell{iline,2}=num2str(val);
959                end
960            end
961        end
962        Tabchar=cell2tab(Tabcell,'=');
963    end
964else
965%list attribute names and values associated to the variable # injdex-1   
966    list_var=get(handles.variables,'String');
967    var_select=list_var{index};
968    set(handles.attributes_txt,'String', ['attributes of ' var_select])
969    if isfield(Field,'VarAttribute')& length(Field.VarAttribute)>=index-1
970%         nbline=0;
971        VarAttr=Field.VarAttribute{index-1};
972        if isstruct(VarAttr)
973            attr_list=fieldnames(VarAttr);
974            for iline=1:length(attr_list)
975                Tabcell{iline,1}=attr_list{iline};
976                eval(['val=VarAttr.' attr_list{iline} ';'])
977                if ischar(val);
978                    Tabcell{iline,2}=val;
979                else
980                     Tabcell{iline,2}=num2str(val);
981                end
982            end
983        end
984    end
985
986end
987if ~isempty(Tabcell)
988    Tabchar=cell2tab(Tabcell,'=');
989    Tabchar=[{''};Tabchar];
990end
991set(handles.attributes,'String',Tabchar);
992
993% list_var=get(handles.dimensions,'String');
994% val=get(handles.dimensions,'Value');
995
996% update dimensions;
997if isfield(Field,'VarDimIndex')
998    Tabdim={};%default
999    if isequal(index,1)
1000        dim_indices=1:length(Field.ListDimName);
1001        set(handles.dimensions_txt,'String', 'dimensions')
1002    else
1003        dim_indices=Field.VarDimIndex{index-1};
1004        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1005    end
1006    for iline=1:length(dim_indices)
1007        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1008        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1009    end
1010    Tabchar=cell2tab(Tabdim,'=');
1011    Tabchar=[{''} ;Tabchar];
1012    set(handles.dimensions,'String',Tabchar) 
1013end 
1014
1015% --- Executes on button press in check_1Dplot.
1016function check_1Dplot_Callback(hObject, eventdata, handles)
1017val=get(handles.check_1Dplot,'Value');
1018if isequal(val,0)
1019    set(handles.Panel1Dplot,'Visible','off')
1020%      set(handles.scalar,'Visible','off')
1021%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1022%     if isequal(get(handles.check_vector,'Value'),0);
1023%         set(handles.coord_z_vectors_scalar,'Visible','off')
1024%     end
1025else
1026    set(handles.Panel1Dplot,'Visible','on')
1027%     set(handles.scalar,'Visible','on')
1028%     val=get(handles.ordinate,'Value');
1029%     val=val(1);
1030%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1031%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1032%       set(handles.coord_z_vectors_scalar,'Visible','on')
1033end
1034
1035% --- Executes on button press in check_scalar.
1036function check_scalar_Callback(hObject, eventdata, handles)
1037val=get(handles.check_scalar,'Value');
1038if isequal(val,0)
1039    set(handles.PanelScalar,'Visible','off')
1040%      set(handles.scalar,'Visible','off')
1041%     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
1042%     if isequal(get(handles.check_vector,'Value'),0);
1043%         set(handles.coord_z_vectors_scalar,'Visible','off')
1044%     end
1045else
1046    set(handles.PanelScalar,'Visible','on')
1047%     set(handles.scalar,'Visible','on')
1048%     val=get(handles.ordinate,'Value');
1049%     val=val(1);
1050%     set(handles.ordinate,'Value',val);%suppress multiple ordinates
1051%     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
1052%       set(handles.coord_z_vectors_scalar,'Visible','on')
1053end
1054
1055%---------------------------
1056% --- Executes on button press in check_vector.
1057function check_vector_Callback(hObject, eventdata, handles)
1058val=get(handles.check_vector,'Value');
1059if isequal(val,0)
1060    set(handles.PanelVectors,'Visible','off')
1061else
1062    set(handles.PanelVectors,'Visible','on')
1063end
1064
1065
1066
1067%-----------------------------
1068function mouse_up_gui(ggg,eventdata,handles)
1069if isequal(get(ggg,'SelectionType'),'alt')
1070    message=''; 
1071    global CurData
1072    inputfield=get(handles.inputfile,'String');
1073    if exist(inputfield,'file')
1074        CurData=nc2struct(inputfield);
1075    else
1076        CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1077    end
1078  %%%% TODO: put the matalb command window in front
1079    evalin('base','global CurData')%make CurData global in the workspace
1080    evalin('base','CurData') %display CurData in the workspace
1081end
1082
1083%---------------------------------------------
1084% --- Executes on selection change in ACTION.
1085function ACTION_Callback(hObject, eventdata, handles)
[34]1086global nb_builtin
[2]1087list_ACTION=get(handles.ACTION,'String');% list menu fields
1088index_ACTION=get(handles.ACTION,'Value');% selected string index
1089ACTION= list_ACTION{index_ACTION}; % selected string
1090path_get_field=which('get_field');%path to series.m
1091list_path=get(handles.ACTION,'UserData');
1092
[34]1093% nb_builtin=0;
1094% if iscell(list_path)
1095%     for ilist=1:length(list_path)
1096%         if isequal(list_path{ilist},path_get_field)
1097%             nb_builtin=nb_builtin+1;
1098%         else
1099%             break
1100%         end
1101%     end
1102% end
1103% if nb_builtin==0% the path to get_field has been changed, reinitialize
1104%     get_field_OpeningFcn(hObject, eventdata, handles)
1105%     return
1106% end
1107
[2]1108% add a new function to the menu
1109if isequal(ACTION,'more...')
1110    pathfct=fileparts(path_get_field);
1111    browse_name=fullfile(path_get_field,'FIELD_FCT');
1112    if length(list_path)>nb_builtin
1113        browse_name=list_path{end};% initialize browser with  the path of the last introduced function
1114    end
1115    [FileName, PathName] = uigetfile( ...
1116       {'*.m', ' (*.m)';
1117        '*.m',  '.m files '; ...
1118        '*.*', 'All Files (*.*)'}, ...
1119        'Pick a file',browse_name);
1120    if length(FileName)<2
1121        return
1122    end
[34]1123    [pp,ACTION,ext_fct]=fileparts(FileName);
[2]1124    if ~isequal(ext_fct,'.m')
1125        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1126        return
1127    end
[34]1128%     ACTION=FileName(1:end-2);% ACTION choice updated by the selected item 
[2]1129    % insert the choice in the action menu
1130   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1131   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1132   list_path{index_ACTION}=PathName;
1133   if length(menu_str)>nb_builtin+5;
1134       nbremove=length(menu_str)-nb_builtin-5;
1135       menu_str(nb_builtin+1:end-5)=[];
1136       list_path(nb_builtin+1:end-4)=[];
1137       index_ACTION=index_ACTION-nbremove;
1138       set(handles.ACTION,'Value',index_ACTION)
1139       set(handles.ACTION,'String',menu_str)
1140   end
1141   list_path{index_ACTION}=PathName;
1142   set(handles.ACTION,'UserData',list_path);
1143   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1144   
1145   %record the current menu in personal file profil_perso
1146   dir_perso=prefdir;
1147   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1148   for ilist=nb_builtin+1:length(menu_str)-1
1149       get_field_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
1150   end
1151   if exist(profil_perso,'file')
1152        save(profil_perso,'get_field_fct','-append')
1153   else
1154        txt=ver;
1155        Release=txt(1).Release;
1156        relnumb=str2num(Release(3:4));
1157        if relnumb >= 14
1158            save(profil_perso,'get_field_fct','-V6')
1159        else
1160            save(profil_perso, 'get_field_fct')
1161        end
1162   end
1163end
1164
1165   %check the current path to the selected function
1166PathName=list_path{index_ACTION};%current recorded path
[34]1167% if ~isequal(path_get_field,PathName)
1168%     CurrentPath=fileparts(which(ACTION));
1169%     if ~isequal(CurrentPath,PathName)%&&~isequal(CurrentPath,fullfile(PathName,'private'))
1170%         addpath(PathName)
1171%         errormsg=check_functions;
1172%         msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
1173%     end
1174% end
[2]1175set(handles.path_action,'String',PathName); %show the path to the senlected function
1176   
1177   
1178%     fct_name=fullfile(PathName, FileName);
1179%     if ~exist(fct_name,'file')
1180%            msgbox_uvmat('ERROR',['procesing fct ' fct_name ' not found'])
1181%     else
1182%        ACTION=FileName(1:end-2);%
1183%        menu=update_menu(handles.ACTION,ACTION);%add the selected fct to the menu
1184%        index_ACTION=get(handles.ACTION,'Value');% selected string index
1185%        list_path{index_ACTION}=PathName;
1186%        set(handles.ACTION,'UserData',list_path)
1187%        if exist(profil_perso,'file')
1188%             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
1189%         end
1190%     end   
1191%     
1192%     
1193%     fileinput=FileName;%complete file name
1194%     eval(['spath=which(''' FileName ''');'])% current path to the function FileName
1195%     if ~isequal(spath,PathName)
1196%         addpath(PathName)
1197%     end
1198%     FileName([end-1:end])=[];
1199%     
1200%    % insert the choice in the action menu
1201%     nbACTION=length(list_ACTION);
1202%     index=0;
1203%     for ilist=1:nbACTION
1204%        if isequal(FileName,list_ACTION{ilist})%look for the selected scalar in the fields_input menu
1205%             index=ilist;%
1206%        end
1207%     end
1208%     if index==0
1209%        list_ACTION{nbACTION}=FileName; %put the chosen fct at the penultimate place in the fields_input menu
1210%        list_path{nbACTION}=PathName;
1211%        index=nbACTION;
1212%        list_ACTION{nbACTION+1}='more...';
1213%        set(handles.ACTION,'String',list_ACTION)
1214%     end
1215%     set(handles.ACTION,'Value',index);% store the selected scalar type
1216%     set(handles.ACTION,'UserData',list_path);
1217%     usr_defined_fct=fct_name;
1218%     nbmenu=length(list_ACTION);
1219%     nbadd=nbmenu-5;
1220%     ilist=0;
1221%     for imenu=nbmenu-min(4,nbadd):nbmenu-1
1222%       ilist=ilist+1;
1223%       fct_get_field{ilist,1}=list_ACTION{imenu};
1224%       fct_path_get_field{ilist}=list_path{imenu};
1225%     end
1226%     if exist(profil_perso,'file')
1227%         save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-append')
1228%     else
1229%        save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-V6')
1230%     end
1231% end
1232
1233% %check the current path to the selected function
1234% list_path
1235% PathName=list_path{index_ACTION}
1236% CurrentPath=fileparts(which(ACTION))
1237% if ~isequal(PathName,CurrentPath)
1238%     addpath(PathName)
1239%     errormsg=check_functions;
1240%     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
1241% end
1242% set(handles.path_action,'String',fullfile(PathName,' ')); %show the path to the senlected function
1243
1244%default setting for the visibility of the GUI elements*
1245if ~isequal(ACTION,'PLOT')
[55]1246    varargout=feval(ACTION);% input list asked by the selected function
[2]1247    test_1Dplot=[];
1248    test_scalar=[];
1249    test_vector=[];
[12]1250    for ilist=1:length(varargout)
1251        switch varargout{ilist,1}
[2]1252                           %RootFile always visible
1253            case 'check_1Dplot'   
[55]1254                 test_1Dplot=isequal(lower(varargout{ilist,2}),'y');
[2]1255            case 'check_scalar'
[55]1256                 test_scalar=isequal(lower(varargout{ilist,2}),'y');   
[2]1257            case 'check_vector'   
[55]1258                 test_vector=isequal(lower(varargout{ilist,2}),'y');
[2]1259        end
1260    end
1261    if test_1Dplot==0
1262        set(handles.check_1Dplot,'Value',0);
1263    end
1264    if test_1Dplot==1
1265        set(handles.check_1Dplot,'Value',1);
1266    end
1267    if test_scalar==0
1268        set(handles.check_scalar,'Value',0);
1269    end
1270    if test_scalar==1
1271        set(handles.check_scalar,'Value',1);
1272    end
1273    if test_vector==0
1274        set(handles.check_vector,'Value',0);
1275    end
1276    if test_vector==1
1277        set(handles.check_vector,'Value',1);
1278    end
1279    check_1Dplot_Callback(hObject, eventdata, handles)
1280    check_scalar_Callback(hObject, eventdata, handles)
1281    check_vector_Callback(hObject, eventdata, handles)
1282end
1283
1284%-----------------------------------------------------
1285% --- browse existing figures
1286%-----------------------------------------------------
1287function browse_fig(menu_handle)
1288hh=findobj(allchild(0),'Type','figure');
1289ilist=0;
1290list={};
1291for ifig=1:length(hh)  %look for all existing figures
1292    name=get(hh(ifig),'Name');
1293     if ~isequal(name,'uvmat')%case of uvmat GUI
1294        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1295        nbaxe=0;
1296        for ichild=1:length(hchild)           
1297            Type=get(hchild(ichild),'Type');
1298            Tag=get(hchild(ichild),'Tag');
1299            if isequal(Type,'axes')
1300                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1301                     nbaxe=nbaxe+1;%count the existing axis
1302                end
1303            end
1304        end   
1305        if nbaxe==1
1306             ilist=ilist+1;%add a line in the list of axis
1307            list{ilist,1}=num2str(hh(ifig));
1308        elseif nbaxe>1
1309            for iaxe=1:nbaxe
1310               ilist=ilist+1;%add a line in the list of axis
1311               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1312            end
1313        end
1314     end
1315end
1316list=['new fig...';'uvmat';list];
1317set(menu_handle,'Value',1)
1318set(menu_handle,'String',list)
1319
1320
1321%-----------------------------------------------------
1322function list_fig_Callback(hObject, eventdata, handles)
1323%-----------------------------------------------------
1324list_fig=get(handles.list_fig,'String');
1325fig_val=get(handles.list_fig,'Value');
1326plot_fig=list_fig{fig_val};
1327if isequal(plot_fig,'uvmat')
1328    huvmat=findobj(allchild(0),'name','uvmat');
1329    if ~isempty(huvmat)
1330        uistack(huvmat,'top')
1331    end   
1332elseif ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1333    sep=regexp(plot_fig,'_');
1334    if ~isempty(sep)
1335        plot_fig=plot_fig([1:sep-1]);
1336    end
1337    if ishandle(str2num(plot_fig))
1338        figure(str2num(plot_fig))% display existing figure
1339    else
1340        browse_fig(handles.list_fig); %reset the current list of figures
1341    end
1342end
1343
1344
1345%-------------------------------------------------
1346% give index numbers of the strings str in the list ListvarName
1347function VarIndex_y=name2index(cell_str,ListVarName)
1348VarIndex_y=[];
1349if ischar(cell_str)
1350    for ivar=1:length(ListVarName)
1351        varlist=ListVarName{ivar};
1352        if isequal(varlist,cell_str)
1353            VarIndex_y= ivar;
1354            break
1355        end
1356    end
1357elseif iscell(cell_str)
1358    for isel=1:length(cell_str)
1359        varsel=cell_str{isel};
1360        for ivar=1:length(ListVarName)
1361            varlist=ListVarName{ivar};
1362            if isequal(varlist,varsel)
1363                VarIndex_y=[VarIndex_y ivar];
1364            end
1365        end
1366    end
1367end
1368
1369% --------------------------------------------------------------------
1370function MenuOpen_Callback(hObject, eventdata, handles)
1371% hObject    handle to MenuOpen (see GCBO)
1372% eventdata  reserved - to be defined in a future version of MATLAB
1373% handles    structure with handles and user data (see GUIDATA)
1374
1375
1376% --------------------------------------------------------------------
1377function MenuExport_Callback(hObject, eventdata, handles)
1378% hObject    handle to MenuExport (see GCBO)
1379% eventdata  reserved - to be defined in a future version of MATLAB
1380% handles    structure with handles and user data (see GUIDATA)
1381
1382
1383% --------------------------------------------------------------------
1384function MenuBrowse_Callback(hObject, eventdata, handles)
1385
1386oldfile=get(handles.inputfile,'String');
1387testrootfile=0;
1388testsubdir=0;
1389if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1390        oldfile='';
1391        dir_perso=prefdir;
1392         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1393         if exist(profil_perso,'file')
1394              h=load (profil_perso);
1395             if isfield(h,'RootPath')
1396                  RootPath=h.RootPath;
1397             end
1398             if isfield(h,'SubDir')
1399                  SubDir=h.SubDir;
1400                  if ~isempty(SubDir)
1401                    testsubdir=1;
1402                  end
1403             end
1404             if isfield(h,'RootFile')
1405                  RootFile=h.RootFile;
1406                  if ~isempty(RootFile)
1407                    testrootfile=1;
1408                  end
1409             end
1410         end
1411end
1412if testrootfile
1413    if ~testsubdir
1414        oldfile=fullfile(RootPath,RootFile);
1415    else
1416        oldfile=fullfile(RootPath,SubDir,RootFile);
1417    end
1418end
1419[FileName, PathName] = uigetfile( ...
1420       {'*.nc', ' *.nc';...
1421       '*.cdf', ' *.cdf';...
1422        '*.*',  'All Files (*.*)'}, ...
1423        'Pick a file',oldfile);
1424
1425%global inputfile
1426fileinput=[PathName FileName];%complete file name
1427testblank=findstr(fileinput,' ');%look for blanks
1428if ~isempty(testblank)
[12]1429    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
[2]1430    return
1431end
1432sizf=size(fileinput);
1433if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
1434set(handles.inputfile,'String',fileinput)
1435inputfile_Callback(hObject, eventdata, handles)
1436
1437
1438%update list of recent files in the menubar
1439MenuFile_1=fileinput;
1440MenuFile_2=get(handles.MenuFile_1,'Label');
1441MenuFile_3=get(handles.MenuFile_2,'Label');
1442MenuFile_4=get(handles.MenuFile_3,'Label');
1443MenuFile_5=get(handles.MenuFile_4,'Label');
1444set(handles.MenuFile_1,'Label',MenuFile_1)
1445set(handles.MenuFile_2,'Label',MenuFile_2)
1446set(handles.MenuFile_3,'Label',MenuFile_3)
1447set(handles.MenuFile_4,'Label',MenuFile_4)
1448set(handles.MenuFile_5,'Label',MenuFile_5)
[34]1449dir_perso=prefdir;
[55]1450profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1451display(profil_perso)
[34]1452if exist(profil_perso,'file')
1453    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1454else
1455    txt=ver;
1456    Release=txt(1).Release;
1457    relnumb=str2double(Release(3:4));
1458    if relnumb >= 14
1459        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1460    else
1461        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1462    end
1463end
[2]1464
1465% %store input file in personal file uvmat_perso.mat
1466% dir_perso=prefdir;
1467% profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1468% if exist(profil_perso,'file')
1469%     save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext','-append'); %store the root name for future opening of uvmat
1470% else
1471%    save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext'); %store the root name for future opening of uvmat
1472% end   
1473
1474
1475% --------------------------------------------------------------------
1476function MenuFile_1_Callback(hObject, eventdata, handles)
[12]1477fileinput=get(handles.MenuFile_1,'Label');
1478set(handles.inputfile,'String',fileinput)
1479inputfile_Callback(hObject, eventdata, handles)
[2]1480
1481% --------------------------------------------------------------------
1482function MenuFile_2_Callback(hObject, eventdata, handles)
[12]1483fileinput=get(handles.MenuFile_2,'Label');
1484set(handles.inputfile,'String',fileinput)
1485inputfile_Callback(hObject, eventdata, handles)
[2]1486
1487% --------------------------------------------------------------------
1488function MenuFile_3_Callback(hObject, eventdata, handles)
[12]1489fileinput=get(handles.MenuFile_3,'Label');
1490set(handles.inputfile,'String',fileinput)
1491inputfile_Callback(hObject, eventdata, handles)
[2]1492
1493% --------------------------------------------------------------------
1494function MenuFile_4_Callback(hObject, eventdata, handles)
[12]1495fileinput=get(handles.MenuFile_4,'Label');
1496set(handles.inputfile,'String',fileinput)
1497inputfile_Callback(hObject, eventdata, handles)
[2]1498
1499% --------------------------------------------------------------------
1500function MenuFile_5_Callback(hObject, eventdata, handles)
[12]1501fileinput=get(handles.MenuFile_5,'Label');
1502set(handles.inputfile,'String',fileinput)
1503inputfile_Callback(hObject, eventdata, handles)
[2]1504
[12]1505% --------------------------------------------------------------------
1506function MenuExportField_Callback(hObject, eventdata, handles)
[2]1507
[12]1508
[2]1509% --------------------------------------------------------------------
[12]1510function MenuHelp_Callback(hObject, eventdata, handles)
1511% hObject    handle to MenuHelp (see GCBO)
[2]1512% eventdata  reserved - to be defined in a future version of MATLAB
1513% handles    structure with handles and user data (see GUIDATA)
[12]1514path_to_uvmat=which ('uvmat');% check the path of uvmat
1515pathelp=fileparts(path_to_uvmat);
1516helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1517if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1518else
1519web([helpfile '#get_field'])   
1520end
1521
Note: See TracBrowser for help on using the repository browser.