source: trunk/src/get_field.m @ 568

Last change on this file since 568 was 538, checked in by sommeria, 12 years ago

bug corrected in get_field to get multiple curves in 1D mode

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