source: trunk/src/get_field.m @ 581

Last change on this file since 581 was 581, checked in by sommeria, 11 years ago

clean the transform field functions

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