source: trunk/src/get_field.m @ 227

Last change on this file since 227 was 227, checked in by sommeria, 13 years ago

add function sub_field_series to apply the sub_field operation to a series of fileds (for instance subtracting a background to an image series)

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