source: trunk/src/get_field.m @ 446

Last change on this file since 446 was 436, checked in by sommeria, 12 years ago

improvement of the get_field GUI

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