source: trunk/src/get_field.m @ 534

Last change on this file since 534 was 530, checked in by sommeria, 12 years ago

new conventions for find_field_cells .

File size: 69.6 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 
226for icell=1:numel(CellInfo)
227    NbDim(icell)=max(NbDim(icell),numel(CellInfo{icell}.VarIndex));
228end
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,'Value',1:numel(get_field_GUI.Panel1Dplot.ordinate))
895        set(hfield,'Value',1)
896        set(hfield,'String',[{''};{'get_field...'}])
897    end
898    if  ~check_series && strcmp(get(gcbf,'tag'),'get_field')%get_field is not called by another GUI (uvmat)
899        uvmat('run0_Callback',hObject,eventdata,hh); %refresh uvmat
900    end
901end
902delete(handles.get_field)
903
904%------------------------------------------------------------------------
905% --- Function for plotting the current subfield
906function plot_get_field(SubField,handles)
907%------------------------------------------------------------------------
908list_fig=get(handles.list_fig,'String');
909val=get(handles.list_fig,'Value');
910if strcmp(list_fig{val},'uvmat')
911    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
912    set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
913    set(handles.MenuOpen,'Visible','off')
914    set(handles.MenuExport,'Visible','off')
915    uvmat(get(handles.inputfile,'String'))
916elseif strcmp(list_fig{val},'view_field')
917    view_field(SubField)
918else
919    hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI
920    if isnan(hfig)
921        hfig=figure;
922        list_fig=[list_fig;num2str(hfig)];
923        set(handles.list_fig,'String',list_fig);
924        haxes=axes;
925    else
926        figure(hfig);
927    end
928    haxes=findobj(hfig,'Type','axes');
929    plot_field(SubField,haxes)
930end
931
932% %------------------------------------------------
933% % --- Executes on button press in Plot_histo.
934% %RUN global histograms
935% %-------------------------------------------------
936% function RUN_histo_Callback(hObject, eventdata, handles)
937% % hObject    handle to RUN (see GCBO)
938% % eventdata  reserved - to be defined in a future version of MATLAB
939% % handles    structure with handles and user data (see GUIDATA)
940%
941% %timename plots
942% leg={};
943% n=0;
944% if (get(handles.cm_switch,'Value')==1)
945%     Uval_p=Uval_cm;
946%     Vval_p=Vval_cm;
947%     Uhist_p=Uhist_cm;
948%     Vhist_p=Vhist_cm;
949%     xlab='velocity (cm/s)';
950% else
951%     Uval_p=Uval;
952%     Vval_p=Vval;
953%     Uhist_p=Uhist;
954%     Vhist_p=Vhist;
955%     xlab='velocity (pixels)';
956% end
957% if (get(handles.vector_y,'Value') == 1)
958%    hhh=figure(2);
959%    hold on
960%    title([filebase ', ' strindex ', ' fieldtitle])
961%    plot(Uval_p,Uhist_p,'b-')
962%    n=n+1;
963%    leg{n}='Uhist';
964%    xlabel(xlab)
965% end
966% if (get(handles.Vhist_input,'Value') == 1)
967%    hhh=figure(2);
968%    hold on
969%    title([filebase ', ' strindex ', ' fieldtitle])
970%    plot(Vval_p,Vhist_p,'r-')
971%    n=n+1;
972%    leg{n}='Vhist';
973%    xlabel(xlab);
974% end
975% if (get(handles.Chist_input,'Value') == 1)
976%    hhhh=figure(3);
977%    hold on
978%    title([filebase ', ' strindex ', ' fieldtitle])
979%    plot(Cval,Chist,'k-')
980%    leg{1}='Chist';
981% end
982% % hold off
983% grid on
984% legend(leg);
985
986% %-------------------------------------------------------------
987% % --- Executes on button press in Save_input.
988% function Save_input_Callback(hObject, eventdata, handles)
989% list_str=get(handles.abscissa,'String');
990% val=get(handles.abscissa,'Value');
991% var=list_str{val};
992% hselect_field=get(handles.Save_input,'parent')
993% set(hselect_field,'UserData',var);
994% set(hselect_field,'Tag','idle')
995
996%     
997% %-------------------------------------------------------------
998% % --- Executes on button press in save_histo.
999% function save_histo_Callback(hObject, eventdata, handles)
1000% global filebase
1001%
1002% pathstr = fileparts(filebase)
1003% if (get(handles.Chist_input,'Value') == 1)
1004%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
1005%     else
1006
1007%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
1008% end
1009% prompt={'save figure(2) as'}
1010% dlg_title = 'save figure';
1011% num_lines= 1;
1012% answer = inputdlg(prompt,dlg_title,num_lines,def)
1013% saveas(2,answer{1})
1014 
1015
1016%%-------------------------------------------------------
1017% --- Executes on button press in peaklocking.
1018%-------------------------------------------------
1019function peaklocking(handles)
1020%evaluation of peacklocking errors
1021%use splinhist: give spline coeff cc for a smooth histo (call spline4)
1022%use histsmooth(x,cc): calculate the smooth histo for any value x
1023%use histder(x,cc): calculate the derivative of the smooth histo
1024global hfig1 hfig2 hfig3
1025global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
1026global xval xerror yval yerror
1027
1028set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
1029set(handles.Vhist_input,'Value',1)
1030set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
1031
1032%adjust the extremal values of the histogram in U with respect to integer
1033%values
1034minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
1035maximU=round(max(Uval)-0.5)+0.5;
1036minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
1037maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
1038nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
1039nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
1040Uval=[minim_fin:(1/nbb):maxim_fin];
1041histu_min=zeros(nb_bin_min,1);
1042histu_max=zeros(nb_bin_max,1);
1043Uhist=[histu_min; Uhist ;histu_max]; % column vector
1044
1045%adjust the extremal values of the histogram in V
1046minimV=round(min(Vval-0.5)+0.5);
1047maximV=round(max(Vval-0.5)+0.5);
1048minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
1049maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
1050nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
1051nb_bin_max=round((maxim_fin -max(Vval))*nbb);
1052Vval=[minim_fin:(1/nbb):maxim_fin];
1053histu_min=zeros(nb_bin_min,1);
1054histu_max=zeros(nb_bin_max,1);
1055Vhist=[histu_min; Vhist ;histu_max]; % column vector
1056
1057% RUN_histo_Callback(hObject, eventdata, handles)
1058% %adjust the histogram to integer values:
1059
1060%histoU and V
1061[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
1062[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
1063
1064% selection of value ranges such that histo>=10 (enough statistics)
1065Uval_ind=find(Uhist>=10);
1066ind_min=min(Uval_ind);
1067ind_max=max(Uval_ind);
1068U_min=Uval(ind_min);% minimum allowed value
1069U_max=Uval(ind_max);%maximum allowed value
1070
1071% selection of value ranges such that histo>=10 (enough statistics)
1072Vval_ind=find(Vhist>=10);
1073ind_min=min(Vval_ind);
1074ind_max=max(Vval_ind);
1075V_min=Vval(ind_min);% minimum allowed value
1076V_max=Vval(ind_max);%maximum allowed value
1077
1078figure(4)% plot U histogram with smoothed one
1079plot(Uval,Uhist,'b')
1080grid on
1081hold on
1082plot(Uval,Uhistinter,'r');
1083hold off
1084
1085figure(5)% plot V histogram with smoothed one
1086plot(Vval,Vhist,'b')
1087grid on
1088hold on
1089plot(Vval,Vhistinter,'r');
1090hold off
1091
1092figure(6)% plot pixel error in two subplots
1093hfig4=subplot(2,1,1);
1094hfig5=subplot(2,1,2);
1095axes(hfig4)
1096plot(xval,xerror)
1097axis([U_min U_max -0.4 0.4])
1098xlabel('velocity u (pix)')
1099ylabel('peaklocking error (pix)')
1100grid on
1101axes(hfig5)
1102plot(yval,yerror)
1103axis([V_min V_max -0.4 0.4]);
1104xlabel('velocity v (pix)')
1105ylabel('peaklocking error (pix)')
1106grid on
1107
1108
1109% ------------------------------------------------------------------
1110function variables_Callback(hObject, eventdata, handles)
1111Tabchar={''};%default
1112Tabcell=[];
1113hselect_field=get(handles.variables,'parent');
1114Field=get(handles.get_field,'UserData');
1115index=get(handles.variables,'Value');%index in the list 'variables'
1116
1117%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
1118if isequal(index,1)
1119    set(handles.attributes_txt,'String','global attributes')
1120    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
1121        for iline=1:length(Field.ListGlobalAttribute)
1122            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
1123            if isfield(Field, Field.ListGlobalAttribute{iline})
1124                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
1125                if ischar(val);% attribute value is char string
1126                    Tabcell{iline,2}=val;
1127                elseif size(val,1)==1 %attribute value is a number or matlab vector
1128                    Tabcell{iline,2}=num2str(val);
1129                end
1130            end
1131        end
1132        Tabchar=cell2tab(Tabcell,'=');
1133    end
1134%% list Attribute names and values associated to the Variable # index-1   
1135else
1136    list_var=get(handles.variables,'String');
1137    var_select=list_var{index};
1138    set(handles.attributes_txt,'String', ['attributes of ' var_select])
1139    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
1140%         nbline=0;
1141        VarAttr=Field.VarAttribute{index-1};
1142        if isstruct(VarAttr)
1143            attr_list=fieldnames(VarAttr);
1144            for iline=1:length(attr_list)
1145                Tabcell{iline,1}=attr_list{iline};
1146                eval(['val=VarAttr.' attr_list{iline} ';'])
1147                if ischar(val);
1148                    Tabcell{iline,2}=val;
1149                else
1150                     Tabcell{iline,2}=num2str(val);
1151                end
1152            end
1153        end
1154    end
1155
1156end
1157if ~isempty(Tabcell)
1158    Tabchar=cell2tab(Tabcell,'=');
1159    Tabchar=[{''};Tabchar];
1160end
1161set(handles.attributes,'Value',1);% select the first item
1162set(handles.attributes,'String',Tabchar);
1163
1164%% update dimensions;
1165if isfield(Field,'ListDimName')
1166    Tabdim={};%default
1167    if isequal(index,1)%list all dimensions
1168        dim_indices=1:length(Field.ListDimName);
1169        set(handles.dimensions_txt,'String', 'dimensions')
1170    else
1171        DimCell=Field.VarDimName{index-1};
1172        if ischar(DimCell)
1173            DimCell={DimCell};
1174        end   
1175        dim_indices=[];
1176        for idim=1:length(DimCell)
1177            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
1178            dim_index=find(dim_index,1);
1179            dim_indices=[dim_indices dim_index];
1180        end
1181        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
1182    end
1183    for iline=1:length(dim_indices)
1184        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
1185        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
1186    end
1187    Tabchar=cell2tab(Tabdim,' = ');
1188    Tabchar=[{''} ;Tabchar];
1189    set(handles.dimensions,'Value',1)
1190    set(handles.dimensions,'String',Tabchar) 
1191end 
1192
1193%------------------------------------------------------------------------
1194% --- Executes on button press in CheckPlot1D.
1195function CheckPlot1D_Callback(hObject, eventdata, handles)
1196%------------------------------------------------------------------------
1197val=get(handles.CheckPlot1D,'Value');
1198if isequal(val,0)
1199    set(handles.Panel1Dplot,'Visible','off')
1200else
1201    set(handles.Panel1Dplot,'Visible','on')
1202    set(handles.PanelScalar,'Visible','off')
1203    set(handles.CheckScalar,'Value',0)
1204    set(handles.PanelVectors,'Visible','off')
1205    set(handles.CheckVector,'Value',0)
1206end
1207
1208%------------------------------------------------------------------------
1209% --- Executes on button press in CheckScalar.
1210function CheckScalar_Callback(hObject, eventdata, handles)
1211%------------------------------------------------------------------------
1212val=get(handles.CheckScalar,'Value');
1213if isequal(val,0)
1214    set(handles.PanelScalar,'Visible','off')
1215else
1216    set(handles.Panel1Dplot,'Visible','off')
1217    set(handles.CheckPlot1D,'Value',0)
1218    set(handles.PanelScalar,'Visible','on')
1219    set(handles.PanelVectors,'Visible','off')
1220    set(handles.CheckVector,'Value',0)
1221end
1222
1223%------------------------------------------------------------------------
1224% --- Executes on button press in CheckVector.
1225function CheckVector_Callback(hObject, eventdata, handles)
1226%------------------------------------------------------------------------
1227val=get(handles.CheckVector,'Value');
1228if isequal(val,0)
1229    set(handles.PanelVectors,'Visible','off')
1230else
1231    set(handles.Panel1Dplot,'Visible','off')
1232    set(handles.CheckPlot1D,'Value',0)
1233    set(handles.PanelScalar,'Visible','off')
1234    set(handles.CheckScalar,'Value',0)
1235    set(handles.PanelVectors,'Visible','on')
1236end
1237
1238% %------------------------------------------------------------------------
1239% function mouse_up_gui(ggg,eventdata,handles)
1240% %------------------------------------------------------------------------
1241% if isequal(get(ggg,'SelectionType'),'alt')
1242%     message=''; 
1243%     global CurData
1244%     inputfield=get(handles.inputfile,'String');
1245%     if exist(inputfield,'file')
1246%         CurData=nc2struct(inputfield);
1247%     else
1248%         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
1249%     end
1250%   %%%% TODO: put the matalb command window in front
1251%     evalin('base','global CurData')%make CurData global in the workspace
1252%     evalin('base','CurData') %display CurData in the workspace
1253% end
1254
1255%------------------------------------------------------------------------
1256% --- Executes on selection change in ACTION.
1257%------------------------------------------------------------------------
1258function ACTION_Callback(hObject, eventdata, handles)
1259global nb_builtin
1260list_ACTION=get(handles.ACTION,'String');% list menu fields
1261index_ACTION=get(handles.ACTION,'Value');% selected string index
1262ACTION= list_ACTION{index_ACTION}; % selected string
1263list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
1264ff=functions(list_func_handles{end});
1265% add a new function to the menu
1266if isequal(ACTION,'more...')
1267    [FileName, PathName] = uigetfile( ...
1268       {'*.m', ' (*.m)';
1269        '*.m',  '.m files '; ...
1270        '*.*', 'All Files (*.*)'}, ...
1271        'Pick a file',ff.file);
1272    if length(FileName)<2
1273        return
1274    end
1275    [pp,ACTION,ext_fct]=fileparts(FileName);
1276    if ~isequal(ext_fct,'.m')
1277        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1278        return
1279    end
1280
1281    % insert the choice in the action menu
1282   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1283   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1284   addpath(PathName)
1285   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
1286   set(handles.ACTION,'UserData',list_func_handles)
1287   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
1288   %list_path{index_ACTION}=PathName;
1289   if length(menu_str)>nb_builtin+5;
1290       nbremove=length(menu_str)-nb_builtin-5;
1291       menu_str(nb_builtin+1:end-5)=[];
1292       list_func_handles(nb_builtin+1:end-4)=[];
1293       index_ACTION=index_ACTION-nbremove;
1294       set(handles.ACTION,'Value',index_ACTION)
1295       set(handles.ACTION,'String',menu_str)
1296   end   
1297   %record the current menu in personal file profil_perso
1298   dir_perso=prefdir;
1299   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1300   get_field_fct={};
1301   for ilist=nb_builtin+1:length(menu_str)-1
1302       ff=functions(list_func_handles{ilist});
1303       get_field_fct{ilist-nb_builtin}=ff.file;
1304   end
1305   if exist(profil_perso,'file')
1306        save(profil_perso,'get_field_fct','-append')
1307   else
1308     txt=ver('MATLAB');
1309    Release=txt.Release;
1310       relnumb=str2num(Release(3:4));
1311        if relnumb >= 14
1312            save(profil_perso,'get_field_fct','-V6')
1313        else
1314            save(profil_perso, 'get_field_fct')
1315        end
1316   end
1317end
1318
1319%check the current path to the selected function
1320h_fun=list_func_handles{index_ACTION};
1321if isa(h_fun,'function_handle')
1322    func=functions(h_fun);
1323    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
1324    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
1325else
1326    set(handles.path_action,'String','')
1327    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
1328    return
1329end
1330
1331%prepare the GUI options for the selected ACTION
1332test_1Dplot=0;
1333test_scalar=0;
1334test_vector=0;
1335if iscell(GUI_input)
1336    for ilist=1:size(GUI_input,1)
1337        switch GUI_input{ilist,1}
1338                           %RootFile always visible
1339            case 'CheckPlot1D'   
1340                 test_1Dplot=isequal(GUI_input{ilist,2},'on');
1341            case 'CheckScalar'
1342                 test_scalar=isequal(GUI_input{ilist,2},'on');   
1343            case 'CheckVector'   
1344                 test_vector=isequal(GUI_input{ilist,2},'on');
1345        end
1346    end
1347end
1348set(handles.CheckPlot1D,'Value',test_1Dplot);
1349set(handles.CheckScalar,'Value',test_scalar);
1350set(handles.CheckVector,'Value',test_vector);
1351CheckPlot1D_Callback(hObject, eventdata, handles)
1352CheckScalar_Callback(hObject, eventdata, handles)
1353CheckVector_Callback(hObject, eventdata, handles)
1354
1355
1356%-----------------------------------------------------
1357% --- browse existing figures
1358%-----------------------------------------------------
1359function browse_fig(menu_handle)
1360hh=findobj(allchild(0),'Type','figure');
1361ilist=0;
1362list={};
1363for ifig=1:length(hh)  %look for all existing figures
1364    name=get(hh(ifig),'Name');
1365     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
1366        hchild=get(hh(ifig),'children');% look for axes contained in each figure
1367        nbaxe=0;
1368        for ichild=1:length(hchild)           
1369            Type=get(hchild(ichild),'Type');
1370            Tag=get(hchild(ichild),'Tag');
1371            if isequal(Type,'axes')
1372                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
1373                     nbaxe=nbaxe+1;%count the existing axis
1374                end
1375            end
1376        end   
1377        if nbaxe==1
1378             ilist=ilist+1;%add a line in the list of axis
1379            list{ilist,1}=num2str(hh(ifig));
1380        elseif nbaxe>1
1381            for iaxe=1:nbaxe
1382               ilist=ilist+1;%add a line in the list of axis
1383               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
1384            end
1385        end
1386     end
1387end
1388list=['uvmat';list];
1389set(menu_handle,'Value',1)
1390set(menu_handle,'String',list)
1391
1392
1393%-----------------------------------------------------
1394function list_fig_Callback(hObject, eventdata, handles)
1395%-----------------------------------------------------
1396list_fig=get(handles.list_fig,'String');
1397fig_val=get(handles.list_fig,'Value');
1398plot_fig=list_fig{fig_val};
1399if strcmp(plot_fig,'view_field')
1400%     huvmat=findobj(allchild(0),'name','uvmat');
1401%     if ~isempty(huvmat)
1402%         uistack(huvmat,'top')
1403%     end   
1404else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
1405    sep=regexp(plot_fig,'_');
1406    if ~isempty(sep)
1407        plot_fig=plot_fig([1:sep-1]);
1408    end
1409    if ishandle(str2num(plot_fig))
1410        figure(str2num(plot_fig))% display existing figure
1411    else
1412        browse_fig(handles.list_fig); %reset the current list of figures
1413    end
1414end
1415
1416
1417%-------------------------------------------------
1418% give index numbers of the strings str in the list ListvarName
1419function VarIndex_y=name2index(cell_str,ListVarName)
1420VarIndex_y=[];
1421if ischar(cell_str)
1422    for ivar=1:length(ListVarName)
1423        varlist=ListVarName{ivar};
1424        if isequal(varlist,cell_str)
1425            VarIndex_y= ivar;
1426            break
1427        end
1428    end
1429elseif iscell(cell_str)
1430    for isel=1:length(cell_str)
1431        varsel=cell_str{isel};
1432        for ivar=1:length(ListVarName)
1433            varlist=ListVarName{ivar};
1434            if isequal(varlist,varsel)
1435                VarIndex_y=[VarIndex_y ivar];
1436            end
1437        end
1438    end
1439end
1440
1441% --------------------------------------------------------------------
1442function MenuOpen_Callback(hObject, eventdata, handles)
1443% hObject    handle to MenuOpen (see GCBO)
1444% eventdata  reserved - to be defined in a future version of MATLAB
1445% handles    structure with handles and user data (see GUIDATA)
1446
1447
1448% --------------------------------------------------------------------
1449function MenuExport_Callback(hObject, eventdata, handles)
1450% hObject    handle to MenuExport (see GCBO)
1451% eventdata  reserved - to be defined in a future version of MATLAB
1452% handles    structure with handles and user data (see GUIDATA)
1453
1454
1455% --------------------------------------------------------------------
1456function MenuBrowse_Callback(hObject, eventdata, handles)
1457
1458oldfile=get(handles.inputfile,'String');
1459testrootfile=0;
1460testsubdir=0;
1461if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1462        oldfile='';
1463        dir_perso=prefdir;
1464         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1465         if exist(profil_perso,'file')
1466              h=load (profil_perso);
1467             if isfield(h,'RootPath')
1468                  RootPath=h.RootPath;
1469             end
1470             if isfield(h,'SubDir')
1471                  SubDir=h.SubDir;
1472                  if ~isempty(SubDir)
1473                    testsubdir=1;
1474                  end
1475             end
1476             if isfield(h,'RootFile')
1477                  RootFile=h.RootFile;
1478                  if ~isempty(RootFile)
1479                    testrootfile=1;
1480                  end
1481             end
1482         end
1483end
1484if testrootfile
1485    if ~testsubdir
1486        oldfile=fullfile(RootPath,RootFile);
1487    else
1488        oldfile=fullfile(RootPath,SubDir,RootFile);
1489    end
1490end
1491[FileName, PathName] = uigetfile( ...
1492       {'*.nc', ' *.nc';...
1493       '*.cdf', ' *.cdf';...
1494        '*.*',  'All Files (*.*)'}, ...
1495        'Pick a file',oldfile);
1496
1497%global inputfile
1498fileinput=[PathName FileName];%complete file name
1499sizf=size(fileinput);
1500if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1501set(handles.inputfile,'String',fileinput)
1502inputfile_Callback(hObject, eventdata, handles)
1503
1504%update list of recent files in the menubar
1505MenuFile_1=fileinput;
1506MenuFile_2=get(handles.MenuFile_1,'Label');
1507MenuFile_3=get(handles.MenuFile_2,'Label');
1508MenuFile_4=get(handles.MenuFile_3,'Label');
1509MenuFile_5=get(handles.MenuFile_4,'Label');
1510set(handles.MenuFile_1,'Label',MenuFile_1)
1511set(handles.MenuFile_2,'Label',MenuFile_2)
1512set(handles.MenuFile_3,'Label',MenuFile_3)
1513set(handles.MenuFile_4,'Label',MenuFile_4)
1514set(handles.MenuFile_5,'Label',MenuFile_5)
1515dir_perso=prefdir;
1516profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1517display(profil_perso)
1518if exist(profil_perso,'file')
1519    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1520else
1521    txt=ver('MATLAB');
1522    Release=txt.Release;
1523    relnumb=str2double(Release(3:4));
1524    if relnumb >= 14
1525        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1526    else
1527        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1528    end
1529end
1530
1531% --------------------------------------------------------------------
1532function MenuFile_1_Callback(hObject, eventdata, handles)
1533fileinput=get(handles.MenuFile_1,'Label');
1534set(handles.inputfile,'String',fileinput)
1535inputfile_Callback(hObject, eventdata, handles)
1536
1537% --------------------------------------------------------------------
1538function MenuFile_2_Callback(hObject, eventdata, handles)
1539fileinput=get(handles.MenuFile_2,'Label');
1540set(handles.inputfile,'String',fileinput)
1541inputfile_Callback(hObject, eventdata, handles)
1542
1543% -----------------------------------------------------------------------
1544function MenuFile_3_Callback(hObject, eventdata, handles)
1545% -----------------------------------------------------------------------
1546fileinput=get(handles.MenuFile_3,'Label');
1547set(handles.inputfile,'String',fileinput)
1548inputfile_Callback(hObject, eventdata, handles)
1549
1550% -----------------------------------------------------------------------
1551function MenuFile_4_Callback(hObject, eventdata, handles)
1552% -----------------------------------------------------------------------
1553fileinput=get(handles.MenuFile_4,'Label');
1554set(handles.inputfile,'String',fileinput)
1555inputfile_Callback(hObject, eventdata, handles)
1556
1557% -----------------------------------------------------------------------
1558function MenuFile_5_Callback(hObject, eventdata, handles)
1559% -----------------------------------------------------------------------
1560fileinput=get(handles.MenuFile_5,'Label');
1561set(handles.inputfile,'String',fileinput)
1562inputfile_Callback(hObject, eventdata, handles)
1563
1564%------------------------------------------------------------------------
1565function MenuExportField_Callback(hObject, eventdata, handles)
1566%------------------------------------------------------------------------
1567global Data_get_field
1568% huvmat=findobj(allchild(0),'Name','uvmat');
1569inputfile=get(handles.inputfile,'String');
1570Data_get_field=nc2struct(inputfile);
1571% Data_view_field=UvData.ProjField_2;
1572evalin('base','global Data_get_field')%make CurData global in the workspace
1573display(['content of ' inputfile ':'])
1574evalin('base','Data_get_field') %display CurData in the workspace
1575commandwindow;
1576
1577%------------------------------------------------------------------------
1578function MenuHelp_Callback(hObject, eventdata, handles)
1579%------------------------------------------------------------------------
1580path_to_uvmat=which ('uvmat');% check the path of uvmat
1581pathelp=fileparts(path_to_uvmat);
1582helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1583if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1584else
1585web([helpfile '#get_field'])   
1586end
1587
1588% -----------------------------------------------------------------------
1589function TimeName_Callback(hObject, eventdata, handles)
1590
1591scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
1592vector_x_Callback(hObject, eventdata, handles)
1593
1594%------------------------------------------------------------------------
1595% --- Executes on button press in TimeAttribute.
1596function TimeAttribute_Callback(hObject, eventdata, handles)
1597%------------------------------------------------------------------------
1598val=get(handles.TimeAttribute,'Value');
1599if val
1600    set(handles.TimeAttributeMenu,'Visible','on')
1601    Field=get(handles.get_field,'UserData');
1602    time_value=zeros(size(Field.ListGlobalAttribute));
1603    test_time=zeros(size(Field.ListGlobalAttribute));
1604    for ilist=1:numel(Field.ListGlobalAttribute)
1605        if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
1606            eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
1607            if ~isempty(time_val)
1608                time_value(ilist)=time_val;
1609                test_time(ilist)=1;
1610            end
1611        end
1612    end
1613    ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
1614    attr_index=get(handles.TimeAttributeMenu,'Value');
1615    if attr_index>numel(ListTimeAttribute)
1616        attr_index=1;
1617        set(handles.TimeAttributeMenu,'Value',1);
1618    end
1619    if isempty(ListTimeAttribute)
1620        set(handles.TimeAttributeMenu,'String',{''})
1621        set(handles.TimeValue,'Visible','off')
1622    else
1623        set(handles.TimeValue,'Visible','on')
1624        set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
1625        set(handles.TimeValue,'String',num2str(time_value(attr_index)))
1626    end
1627    set(handles.TimeDimension,'Value',0)
1628    TimeDimension_Callback(hObject, eventdata, handles)
1629    set(handles.TimeVariable,'Value',0)
1630    TimeVariable_Callback(hObject, eventdata, handles)
1631else
1632    set(handles.TimeAttributeMenu,'Visible','off')
1633    set(handles.TimeValue,'Visible','off')
1634end
1635
1636%------------------------------------------------------------------------
1637% --- Executes on selection change in TimeAttributeMenu.
1638function TimeAttributeMenu_Callback(hObject, eventdata, handles)
1639 ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
1640 index=get(handles.TimeAttributeMenu,'Value');
1641 AttrName=ListTimeAttribute{index};
1642 Field=get(handles.get_field,'UserData');
1643 eval(['time_val=Field.' AttrName ';'])
1644 set(handles.TimeValue,'String',num2str(time_val))
1645%------------------------------------------------------------------------
1646
1647%------------------------------------------------------------------------
1648% --- Executes on button press in TimeVariable.
1649function TimeDimension_Callback(hObject, eventdata, handles)
1650%------------------------------------------------------------------------
1651val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
1652if val  %if check box TimeDimension is selected
1653    Field=get(handles.get_field,'UserData');% structure describing the currently opened field
1654    previous_menu=get(handles.TimeDimensionMenu,'String');
1655    if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
1656        ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
1657        if isempty(ind_select)
1658            ind_select=1;% select the first item in the list if 'time' is not found
1659        end
1660        set(handles.TimeDimensionMenu,'Value',ind_select);
1661        set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
1662    end   
1663    set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
1664    set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
1665    TimeDimensionMenu_Callback(hObject, eventdata, handles) 
1666    set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
1667    set(handles.TimeVariable,'Value',0)
1668    TimeAttribute_Callback(hObject, eventdata, handles)
1669else
1670    set(handles.TimeDimensionMenu,'Visible','off')
1671    set(handles.TimeIndexValue,'Visible','off')
1672end
1673
1674%------------------------------------------------------------------------
1675% --- Executes on selection change in TimeDimensionMenu.
1676function TimeDimensionMenu_Callback(hObject, eventdata, handles)
1677%------------------------------------------------------------------------
1678index=get(handles.TimeDimensionMenu,'Value');
1679DimList=get(handles.TimeDimensionMenu,'String');
1680DimName=DimList{index};
1681Field=get(handles.get_field,'UserData');
1682DimIndex=find(strcmp(DimName,Field.ListDimName),1);
1683ref_index=round(Field.DimValue(DimIndex)/2);   
1684set(handles.TimeIndexValue,'String',num2str(ref_index))
1685scalar_Callback(hObject, eventdata, handles)
1686vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
1687 % look for a corresponding time variable and value
1688 time_test=zeros(size(Field.VarDimName));
1689 for ilist=1:numel(Field.VarDimName)
1690     if isequal(Field.VarDimName{ilist},{DimName})
1691         time_test(ilist)=1;
1692     end
1693 end
1694 ListVariable=Field.ListVarName(time_test==1);
1695 set(handles.TimeVariableMenu,'Value',1)
1696 if isempty(ListVariable)     
1697     set(handles.TimeVariableMenu,'String',{''})
1698     set(handles.TimeVarValue,'String','')
1699 else
1700    set(handles.TimeVariableMenu,'String',ListVariable)
1701    TimeVarName=ListVariable{1};
1702    VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
1703    inputfile=get(handles.inputfile,'String');% read the input file
1704    SubField=nc2struct(inputfile,{TimeVarName});
1705    eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
1706    set(handles.TimeVarValue,'Visible','on')
1707    set(handles.TimeVariableMenu,'Visible','on')
1708    set(handles.TimeVarValue,'String',num2str(TimeValue))
1709 end
1710
1711
1712% % -----------------------------------------------------------------------
1713% % --- Executes on button press in TimeVariable.
1714% function TimeVariable_Callback(hObject, eventdata, handles)
1715% % -----------------------------------------------------------------------
1716% val=get(handles.TimeVariable,'Value');
1717% if val
1718%     Field=get(handles.get_field,'UserData');
1719%     time_test=zeros(size(Field.VarDimName));
1720%     for ilist=1:numel(Field.VarDimName)
1721%         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
1722%             time_test(ilist)=1;
1723%         end
1724%     end
1725%     ind_test=find(time_test);
1726%     if isempty(time_test)
1727%         set(handles.TimeVariable,'Value',0)
1728%         set(handles.TimeVariableMenu,'Visible','off')
1729%         set(handles.TimeVarValue,'Visible','off')
1730%     else
1731%         set(handles.TimeVariableMenu,'Visible','on')
1732%         set(handles.TimeVarValue,'Visible','on')
1733%         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
1734%             set(handles.TimeVariableMenu,'Value',1)
1735%         end
1736%         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
1737%         TimeVariableMenu_Callback(hObject, eventdata, handles)
1738%         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
1739%         set(handles.TimeAttribute,'Value',0)
1740%         TimeAttribute_Callback(hObject, eventdata, handles)
1741%     end
1742% else
1743%     set(handles.TimeVariableMenu,'Visible','off')
1744%     set(handles.TimeVarValue,'Visible','off')
1745% end
1746
1747% -----------------------------------------------------------------------
1748% --- Executes on selection change in TimeVariableMenu.
1749function TimeVariableMenu_Callback(hObject, eventdata, handles)
1750% -----------------------------------------------------------------------
1751ListVar=get(handles.TimeVariableMenu,'String');
1752index=get(handles.TimeVariableMenu,'Value');
1753TimeVariable=ListVar{index};% name of the selected variable
1754if isempty(TimeVariable)% case of blank selection
1755    return
1756end
1757Field=get(handles.get_field,'UserData'); %index of
1758VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
1759DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
1760set(handles.TimeDimensionMenu,'Value',1)
1761set(handles.TimeDimensionMenu,'String',DimName)
1762inputfile=get(handles.inputfile,'String');% read the input file
1763SubField=nc2struct(inputfile,{TimeVariable});
1764eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
1765ref_index=round(TimeDimension/2);
1766eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
1767set(handles.TimeIndexValue,'String',num2str(ref_index))
1768set(handles.TimeVarValue,'String',num2str(TimeValue))
1769
1770
1771function TimeValue_Callback(hObject, eventdata, handles)
1772%TO suppress
1773
1774% -----------------------------------------------------------------------
1775function TimeIndexValue_Callback(hObject, eventdata, handles)
1776% -----------------------------------------------------------------------
1777TimeIndex=str2double(get(handles.TimeIndexValue,'String'));
1778TimeVarName=Field.ListVarName{time_index};
1779set(handles.TimeVariable,'Value',1)
1780set(handles.TimeName,'String',TimeVarName)
1781fileinput=get(handles.inputfile,'String');
1782SubField=nc2struct(fileinput,{TimeVarName});
1783eval(['TimeValue=SubField.' TimeVarName '(ref_index);']);
1784set(handles.TimeValue,'Visible','on')
1785set(handles.TimeValue,'String',num2str(TimeValue))
1786
1787% -----------------------------------------------------------------------
1788function SelectFigure_Callback(hObject, eventdata, handles)
1789% -----------------------------------------------------------------------
1790val=get(handles.SelectFigure,'Value');
1791if val
1792    set(handles.list_fig,'Visible','on')
1793    %% look at the existing figures in the work space
1794    browse_fig(handles.list_fig)
1795else
1796   set(handles.list_fig,'Visible','off')
1797end
1798
1799
1800function TimeVarValue_Callback(hObject, eventdata, handles)
1801
1802
1803
1804% --- Executes on button press in check_rgb.
1805function check_rgb_Callback(hObject, eventdata, handles)
Note: See TracBrowser for help on using the repository browser.