source: trunk/src/get_field.m @ 630

Last change on this file since 630 was 630, checked in by sommeria, 8 years ago

generalisation of update_imadoc, improverment of the GUI get_field

File size: 59.5 KB
Line 
1%'get_field': display variables and attributes from a Netcdf file, and OK 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 05-May-2013 23:54:32
25
26% Begin initialization code - DO NOT EDIT
27gui_Singleton = 1;
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,ParamIn)
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
52handles.output = 'Cancel';
53
54%% Update handles structure
55guidata(hObject, handles);
56set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
57
58%% settings for 'slave' mode, called by uvmat, or 'master' mode
59if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
60    set(handles.inputfile,'String',filename)% prefill the input file name
61    Field=nc2struct(filename,[]);% reads the  field structure, without the variables
62    if isfield(Field,'Txt')
63        msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt])
64    else
65        if ~exist('ParamIn','var')
66            ParamIn=[];
67        end
68        Field_input(handles,Field,ParamIn);
69    end
70else  %master mode
71    set(handles.inputfile,'String','')
72end
73
74%% put the GUI on the lower right of the sceen
75set(hObject,'Unit','pixel')
76pos_view_field=get(hObject,'Position');
77ScreenSize=get(0,'ScreenSize');
78pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
79pos_view_field(2)=ScreenSize(2);
80set(hObject,'Position',pos_view_field)
81set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
82drawnow
83uiwait(handles.get_field);
84
85%------------------------------------------------------------------------
86% --- update the display when a new field is introduced.
87function Field_input(handles,Field,ParamIn)
88%------------------------------------------------------------------------
89
90%% fill the list and values of dimensions
91if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
92    Tabcell(:,1)=Field.ListDimName;
93    for iline=1:length(Field.ListDimName)
94        Tabcell{iline,2}=num2str(Field.DimValue(iline));
95    end
96    Tabchar=cell2tab(Tabcell,' = ');
97    set(handles.dimensions,'String',Tabchar)
98end
99if ~isfield(Field,'ListVarName')
100    return
101end
102
103%% fill the list of variables
104Txt=Field.ListVarName;
105set(handles.variables,'Value',1)
106set(handles.variables,'String',[{'*'} Txt])
107variables_Callback(handles.variables,[], handles)
108
109% set(handles.abscissa,'String',[{''} Txt ])
110set(handles.ordinate,'String',Txt)
111set(handles.vector_x,'String',[Txt ])
112set(handles.vector_y,'String',[Txt ])
113set(handles.vector_z,'String',[{''} Txt ])
114set(handles.vec_color,'String',[{''} Txt ])
115set(handles.XVarName,'String',[{''} Txt ])
116set(handles.YVarName,'String',[{''} Txt ])
117set(handles.ZVarName,'String',[{''} Txt ])
118% set(handles.coord_x_vectors,'String',[{''} Txt ])
119% set(handles.coord_y_vectors,'String',[{''} Txt ])
120% set(handles.YVarName,'String',[{''} Txt ])
121% set(handles.TimeVarName,'String',[{''} Txt ])
122set(handles.scalar,'Value',1)
123set(handles.scalar,'String', Txt )
124
125%% ananlyse the input field cells
126[CellInfo,NbDim,errormsg]=find_field_cells(Field);
127if ~isempty(errormsg) 
128    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
129    return
130end 
131[Field.MaxDim,imax]=max(NbDim);
132% look at variables with a single dimension
133for ilist=1:numel(Field.VarDimName)
134    if ischar(Field.VarDimName{ilist})
135        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
136    end
137    NbDim=numel(Field.VarDimName{ilist});% TODO eliminate singleton dimensions
138    check_singleton=false(1,NbDim);
139    for idim=1:NbDim
140        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);
141        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);
142    end
143    Field.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);
144    Field.NbDim(ilist)=numel(Field.VarDimName{ilist});
145    if Field.NbDim(ilist)==1
146        Field.VarDimName{ilist}=cell2mat(Field.VarDimName{ilist});
147    end
148end
149SingleVarName=Field.ListVarName(Field.NbDim==1);%list of variables with a single dim
150MultiVarName=Field.ListVarName(Field.NbDim>1);
151check_dim=zeros(size(Field.VarDimName));
152for ilist=1:numel(Field.VarDimName);
153    if iscell(Field.VarDimName{ilist})% exclude single dim
154        for idim=1:numel(Field.VarDimName{ilist})
155            check_dim=check_dim|strcmp(Field.VarDimName{ilist}{idim},Field.VarDimName);
156        end
157    end
158end
159Field.SingleVarName=Field.ListVarName(find(check_dim));%list of variables with a single dim
160Field.SingleDimName=Field.VarDimName(find(check_dim));% corresponding list of dimensions for variables with a single dim
161Field.MaxDim=max(Field.NbDim);
162
163%% set time mode
164ListSwitchVarIndexTime={'file index'};
165% look at global attributes with numerical values
166check_numvalue=false;
167check_time=false;
168    for ilist=1:numel(Field.ListGlobalAttribute)
169        Value=Field.(Field.ListGlobalAttribute{ilist});
170        check_numvalue(ilist)=isnumeric(Value);
171        check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1));
172    end 
173Field.ListNumAttributes=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
174if ~isempty(Field.ListNumAttributes)
175ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];
176end
177nboption=numel(ListSwitchVarIndexTime);
178if Field.MaxDim>=2
179    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];
180end
181if Field.MaxDim>=4
182        option=nboption+1;
183elseif ~isempty(find(check_time, 1))
184    option=2;
185else
186    option=1;
187end
188set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
189set(handles.SwitchVarIndexTime,'Value',option)
190set(handles.get_field,'UserData',Field);% record the finput field structure
191SwitchVarIndexTime_Callback([],[], handles)
192
193%% set z coordinate menu if relevant
194if Field.MaxDim>=3
195    set(handles.vector_z,'Visible','on')
196    set(handles.vector_z,'String',[{''} Txt ])
197        set(handles.ZVarName,'Visible','on')
198    set(handles.SwitchVarIndexZ,'Visible','on')
199    set(handles.Z_title,'Visible','on')
200else
201    set(handles.vector_z,'Visible','off')
202    set(handles.ZVarName,'Visible','off')
203    set(handles.SwitchVarIndexZ,'Visible','off')
204    set(handles.Z_title,'Visible','off')
205end
206
207%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
208if Field.MaxDim>=2 % case of 2D (or 3D) fields
209    set(handles.CheckPlot1D,'Value',0)
210    if isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
211        set(handles.CheckVector,'Value',1)
212        set(handles.CheckScalar,'Value',0)
213        set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1))
214        set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1))
215    else
216        set(handles.CheckScalar,'Value',1)
217        set(handles.CheckVector,'Value',0)
218    end
219else % case of 1D fields
220    set(handles.CheckPlot1D,'Value',1)
221    set(handles.CheckScalar,'Value',0)
222    set(handles.CheckVector,'Value',0)
223end
224
225%% Make choices in menus from input
226if exist('ParamIn','var')&&~isempty(ParamIn)
227    fill_GUI(ParamIn,handles.get_field);
228end
229CheckPlot1D_Callback(handles.CheckPlot1D, [], handles)
230CheckScalar_Callback(handles.CheckScalar, [], handles)
231CheckVector_Callback(handles.CheckVector, [], handles)
232
233%------------------------------------------------------------------------
234% --- Outputs from this function are returned to the command line.
235function varargout = get_field_OutputFcn(hObject, eventdata, handles)
236%------------------------------------------------------------------------
237varargout{1} = handles.output;
238delete(handles.get_field)
239
240
241% -----------------------------------------------------------------------
242% --- Activated by selection in the list of variables
243function variables_Callback(hObject, eventdata, handles)
244% -----------------------------------------------------------------------
245Tabchar={''};%default
246Tabcell=[];
247hselect_field=get(handles.variables,'parent');
248Field=get(handles.get_field,'UserData');
249index=get(handles.variables,'Value');%index in the list 'variables'
250
251%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
252if isequal(index,1)
253    set(handles.attributes_txt,'String','global attributes')
254    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
255        for iline=1:length(Field.ListGlobalAttribute)
256            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
257            if isfield(Field, Field.ListGlobalAttribute{iline})
258                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
259                if ischar(val);% attribute value is char string
260                    Tabcell{iline,2}=val;
261                elseif size(val,1)==1 %attribute value is a number or matlab vector
262                    Tabcell{iline,2}=num2str(val);
263                end
264            end
265        end
266        Tabchar=cell2tab(Tabcell,'=');
267    end
268%% list Attribute names and values associated to the Variable # index-1   
269else
270    list_var=get(handles.variables,'String');
271    var_select=list_var{index};
272    set(handles.attributes_txt,'String', ['attributes of ' var_select])
273    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
274%         nbline=0;
275        VarAttr=Field.VarAttribute{index-1};
276        if isstruct(VarAttr)
277            attr_list=fieldnames(VarAttr);
278            for iline=1:length(attr_list)
279                Tabcell{iline,1}=attr_list{iline};
280                eval(['val=VarAttr.' attr_list{iline} ';'])
281                if ischar(val);
282                    Tabcell{iline,2}=val;
283                else
284                     Tabcell{iline,2}=num2str(val);
285                end
286            end
287        end
288    end
289
290end
291if ~isempty(Tabcell)
292    Tabchar=cell2tab(Tabcell,'=');
293    Tabchar=[{''};Tabchar];
294end
295set(handles.attributes,'Value',1);% select the first item
296set(handles.attributes,'String',Tabchar);
297
298%% update dimensions;
299if isfield(Field,'ListDimName')
300    Tabdim={};%default
301    if isequal(index,1)%list all dimensions
302        dim_indices=1:length(Field.ListDimName);
303        set(handles.dimensions_txt,'String', 'dimensions')
304    else
305        DimCell=Field.VarDimName{index-1};
306        if ischar(DimCell)
307            DimCell={DimCell};
308        end   
309        dim_indices=[];
310        for idim=1:length(DimCell)
311            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
312            dim_index=find(dim_index,1);
313            dim_indices=[dim_indices dim_index];
314        end
315        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
316    end
317    for iline=1:length(dim_indices)
318        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
319        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
320    end
321    Tabchar=cell2tab(Tabdim,' = ');
322    Tabchar=[{''} ;Tabchar];
323    set(handles.dimensions,'Value',1)
324    set(handles.dimensions,'String',Tabchar) 
325end 
326
327
328
329%------------------------------------------------------------------------
330% --- Executes on button press in CheckPlot1D.
331function CheckPlot1D_Callback(hObject, eventdata, handles)
332%------------------------------------------------------------------------
333val=get(handles.CheckPlot1D,'Value');
334if isequal(val,0)
335    set(handles.Panel1Dplot,'Visible','off')
336else
337    set(handles.Panel1Dplot,'Visible','on')
338    set(handles.PanelScalar,'Visible','off')
339    set(handles.CheckScalar,'Value',0)
340    set(handles.PanelVectors,'Visible','off')
341    set(handles.CheckVector,'Value',0)
342    set(handles.XVarName,'Visible','on')
343    set(handles.SwitchVarIndexX,'Visible','on')
344    set(handles.X_title,'Visible','on')
345    set(handles.YVarName,'Visible','off')
346    set(handles.SwitchVarIndexY,'Visible','off')
347    set(handles.Y_title,'Visible','off')
348    set(handles.ZVarName,'Visible','off')
349    set(handles.SwitchVarIndexZ,'Visible','off')
350    set(handles.Z_title,'Visible','off')
351    ordinate_Callback(hObject, eventdata, handles)
352end
353
354%------------------------------------------------------------------------
355function ordinate_Callback(hObject, eventdata, handles)
356%------------------------------------------------------------------------
357Field=get(handles.get_field,'UserData');
358list=get(handles.ordinate,'String');
359yindex=get(handles.ordinate,'Value');
360yindex=name2index(list{yindex(1)},Field.ListVarName);
361if ~isempty(yindex)
362    set(handles.variables,'Value',yindex+1)
363    variables_Callback(hObject, eventdata, handles)
364end
365[CellInfo,NbDim,errormsg]=find_field_cells(Field);
366%[CellVarIndex,NbDim,VarRole,errormsg]=find_field_cells(Field);
367for icell=1:numel(CellInfo)
368    VarIndex=CellInfo{icell}.VarIndex;
369    if ~isempty(find(VarIndex==yindex,1)) && (isempty(CellInfo{icell}.VarIndex_coord_x)||~isequal(CellInfo{icell}.VarIndex_coord_x,VarIndex))
370        cell_select=icell;
371        break
372    end
373end
374val=get(handles.abscissa,'Value');
375set(handles.abscissa,'Value',min(val,2));
376coord_x_index=CellInfo{cell_select}.VarIndex_coord_x;
377coord_x_index=coord_x_index(coord_x_index~=0);
378set(handles.XVarName,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
379
380%------------------------------------------------------------------------
381% --- Executes on button press in CheckScalar.
382function CheckScalar_Callback(hObject, eventdata, handles)
383%------------------------------------------------------------------------
384val=get(handles.CheckScalar,'Value');
385if isequal(val,0)
386    set(handles.PanelScalar,'Visible','off')
387else
388    set(handles.Panel1Dplot,'Visible','off')
389    set(handles.CheckPlot1D,'Value',0)
390    set(handles.PanelScalar,'Visible','on')
391    set(handles.PanelVectors,'Visible','off')
392    set(handles.CheckVector,'Value',0)
393end
394
395%------------------------------------------------------------------------
396% --- Executes on button press in CheckVector.
397function CheckVector_Callback(hObject, eventdata, handles)
398%------------------------------------------------------------------------
399val=get(handles.CheckVector,'Value');
400if isequal(val,0)
401    set(handles.PanelVectors,'Visible','off')
402else
403    set(handles.Panel1Dplot,'Visible','off')
404    set(handles.CheckPlot1D,'Value',0)
405    set(handles.PanelScalar,'Visible','off')
406    set(handles.CheckScalar,'Value',0)
407    set(handles.PanelVectors,'Visible','on')
408    set(handles.XVarName,'Visible','on')
409    set(handles.YVarName,'Visible','on')
410    set(handles.X_title,'Visible','on')
411    set(handles.Y_title,'Visible','on')
412end
413
414
415%------------------------------------------------------------------------
416% --- Executes on selection change in scalar menu.
417function scalar_Callback(hObject, eventdata, handles)
418%------------------------------------------------------------------------
419Field=get(handles.get_field,'UserData');
420index=get(handles.scalar,'Value');
421string=get(handles.scalar,'String');
422VarName=string{index};
423update_field(hObject, eventdata, handles,VarName)
424
425%eliminate time
426TimeDimName='';%default
427SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
428TimeVarOption=SwitchVarIndexTime{get(handles.SwitchVarIndexTime,'Value')};
429if strcmp(TimeVarOption,'variable')
430    List=get(handles.TimeVarName,'String');
431    TimeVarName=List{get(handles.TimeVarName,'Value')};
432elseif  strcmp(TimeVarOption,'dim index')
433    List=get(handles.TimeVarName,'String');
434    TimeDimName=List{get(handles.TimeVarName,'Value')};
435end
436% A completer
437% if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on')
438%     TimeDimList=get(handles.TimeDimensionMenu,'String');
439%     TimeDimIndex=get(handles.TimeDimensionMenu,'Value');
440%     TimeDimName=TimeDimList{TimeDimIndex};
441% end
442
443%check possible coordinates
444Field=get(handles.get_field,'UserData');
445dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar
446test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
447for ilist=1:numel(Field.VarDimName)
448    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
449    if isequal(dimnames,TimeDimName)
450        test_coord(ilist)=0;%mark time variables fo elimination
451    end
452    if ischar(dimnames)
453        dimnames={dimnames};
454    end
455    for idim=1:numel(dimnames)
456        if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable
457            test_coord(ilist)=0;
458            break
459        end
460    end
461end
462test_coord(index)=0;%the coordinate variable must be different from the scalar
463
464string_coord=[{''};string(test_coord==1)];
465val=get(handles.XVarName,'Value');
466if val>numel(string_coord)
467    set(handles.XVarName,'Value',1)
468end
469set(handles.XVarName,'String',string_coord);
470val=get(handles.ZVarName,'Value');
471if val>numel(string_coord)
472    set(handles.ZVarName,'Value',1)
473end
474set(handles.ZVarName,'String',string_coord);
475val=get(handles.ZVarName,'Value');
476if val>numel(string_coord)
477    set(handles.ZVarName,'Value',1)
478end
479set(handles.YVarName,'String',string_coord);
480
481
482%------------------------------------------------------------------------
483% --- Executes on selection change in abscissa.
484function abscissa_Callback(hObject, eventdata, handles)
485%------------------------------------------------------------------------
486 hselect_field=get(handles.inputfile,'parent');
487 Field=get(hselect_field,'UserData');%current input field
488 xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
489% test_2D=get(handles.CheckVector,'Value');% =1 for vector fields
490% test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields
491%if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa
492%     Txt=Field.ListVarName;
493%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
494%     xindex=[];
495% else
496     xlist=get(handles.abscissa,'String');%list of abscissa
497     VarName=xlist{xdispindex}; %selected variable name
498     update_field(hObject, eventdata, handles,VarName)
499%      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
500%      if ~isempty(xindex)
501%         set(handles.variables,'Value',xindex+1)
502%         variables_Callback(hObject, eventdata, handles)
503%      end
504%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
505%     variables_Callback(hObject, eventdata, handles)  %display properties of the TimeVariable (dim, attributes)
506%     if  ~test_2D &  ~test_scalar% look for possible varaibles to OK in ordinate   
507%         index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa
508%         VarIndex=[];
509%         for ilist=1:length(Field.VarDimIndex)%detect
510%             index_i=Field.VarDimIndex{ilist};
511%             if ~isempty(index_i)
512%                 if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, OK is possible
513%                     VarIndex=[VarIndex ilist];
514%                 end
515%             end
516%         end
517% %         set(handles.ordinate,'Value',1)
518%         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
519%     end
520% end
521%
522% update_UserData(handles)
523
524
525
526%------------------------------------------------------------------------
527% --- Executes on selection change in XVarName.
528function XVarName_Callback(hObject, eventdata, handles)
529%------------------------------------------------------------------------
530index=get(handles.XVarName,'Value');
531string=get(handles.XVarName,'String');
532VarName=string{index};
533update_field(hObject, eventdata, handles,VarName)
534
535%------------------------------------------------------------------------
536% --- Executes on selection change in ZVarName.
537function ZVarName_Callback(hObject, eventdata, handles)
538%------------------------------------------------------------------------
539index=get(handles.ZVarName,'Value');
540string=get(handles.ZVarName,'String');
541VarName=string{index};
542update_field(hObject, eventdata, handles,VarName)
543
544%------------------------------------------------------------------------
545% --- Executes on selection change in YVarName.
546function YVarName_Callback(hObject, eventdata, handles)
547%------------------------------------------------------------------------
548index=get(handles.YVarName,'Value');
549string=get(handles.YVarName,'String');
550VarName=string{index};
551update_field(hObject, eventdata, handles,VarName)
552
553%------------------------------------------------------------------------
554% --- Executes on selection change in vector_x.
555function vector_x_Callback(hObject, eventdata, handles)
556%------------------------------------------------------------------------
557index=get(handles.vector_x,'Value');
558string=get(handles.vector_x,'String');
559VarName=string{index};
560
561%check possible coordinates
562Field=get(handles.get_field,'UserData');
563dim_var=Field.VarDimName{index};%list of dimensions of the selected variable
564test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate
565test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component
566for ilist=1:numel(Field.VarDimName)
567    dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist
568    if ~isequal(dimnames,dim_var)
569        test_component(ilist)=0;
570    end
571    for idim=1:numel(dimnames)
572        if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable
573            test_coord(ilist)=0;
574            break
575        end
576    end
577end
578%eliminate time
579if get(handles.TimeVariable,'Value')
580    TimeName=get(handles.TimeName,'String');
581    index_time=find(strcmp( TimeName,Field.ListVarName));
582    test_coord(index_time)=0;
583end
584vlength=numel(string(test_component==1));
585val=get(handles.vector_y,'Value');
586if val>vlength
587    set(handles.vector_y,'Value',1)
588end
589set(handles.vector_y,'String',[string(test_component==1)])
590val=get(handles.vector_z,'Value');
591if val>vlength+1
592    set(handles.vector_z,'Value',1)
593end
594set(handles.vector_z,'String',[{''};string(test_component==1)])
595val=get(handles.vec_color,'Value');
596if val>vlength+1
597    set(handles.vec_color,'Value',1)
598end
599set(handles.vec_color,'String',[{''};string(test_component==1)])
600string_coord=[{''};string(test_coord==1)];
601val=get(handles.XVarName,'Value');
602if val>numel(string_coord)
603    set(handles.XVarName,'Value',1)
604end
605set(handles.XVarName,'Visible','on');
606set(handles.XVarName,'String',string_coord);
607val=get(handles.YVarName,'Value');
608if val>numel(string_coord)
609    set(handles.YVarName,'Value',1)
610end
611set(handles.YVarName,'Visible','on');
612set(handles.YVarName,'String',string_coord);
613val=get(handles.TimeVarName,'Value');
614if val>numel(string_coord)
615    set(handles.TimeVarName,'Value',1)
616end
617set(handles.TimeVarName,'String',string_coord);
618
619update_field(hObject, eventdata, handles,VarName)
620
621%------------------------------------------------------------------------
622% --- Executes on selection change in vector_y.
623function vector_y_Callback(hObject, eventdata, handles)
624%------------------------------------------------------------------------
625index=get(handles.vector_y,'Value');
626string=get(handles.vector_y,'String');
627VarName=string{index};
628update_field(hObject, eventdata, handles,VarName)
629
630%------------------------------------------------------------------------
631% --- Executes on selection change in vector_z.
632function vector_z_Callback(hObject, eventdata, handles)
633%------------------------------------------------------------------------
634index=get(handles.vector_z,'Value');
635string=get(handles.vector_z,'String');
636VarName=Astring{index};
637update_field(hObject, eventdata, handles,VarName)
638
639%------------------------------------------------------------------------
640% --- Executes on selection change in coord_x_vectors.
641function coord_x_vectors_Callback(hObject, eventdata, handles)
642%------------------------------------------------------------------------
643index=get(handles.coord_x_vectors,'Value');
644string=get(handles.coord_x_vectors,'String');
645VarName=string{index};
646update_field(hObject, eventdata, handles,VarName)
647
648%------------------------------------------------------------------------
649% --- Executes on selection change in coord_y_vectors.
650function coord_y_vectors_Callback(hObject, eventdata, handles)
651%------------------------------------------------------------------------
652index=get(handles.coord_y_vectors,'Value');
653string=get(handles.coord_y_vectors,'String');
654VarName=string{index};
655update_field(hObject, eventdata, handles,VarName)
656
657%------------------------------------------------------------------------
658% --- Executes on selection change in YVarName.
659function TimeVarName_Callback(hObject, eventdata, handles)
660%------------------------------------------------------------------------
661index=get(handles.TimeVarName,'Value');
662string=get(handles.TimeVarName,'String');
663VarName=string{index};
664update_field(hObject, eventdata, handles,VarName)
665
666%------------------------------------------------------------------------
667% --- Executes on selection change in vec_color.
668function vec_color_Callback(hObject, eventdata, handles)
669%------------------------------------------------------------------------
670index=get(handles.vec_color,'Value');
671string=get(handles.vec_color,'String');
672VarName=string{index};
673update_field(hObject, eventdata, handles,VarName)
674
675%-----------------------------------------------------------------------
676function update_field(hObject, eventdata, handles,VarName)
677%-----------------------------------------------------------------------
678Field=get(handles.get_field,'UserData');
679index=name2index(VarName,Field.ListVarName);
680if ~isempty(index)
681    set(handles.variables,'Value',index+1)
682    variables_Callback(hObject, eventdata, handles)
683end
684
685%------------------------------------------------------------------------
686% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
687function update_UserData(handles)
688%------------------------------------------------------------------------
689return
690% global SubField
691hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
692Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
693if isfield(Field,'VarAttribute')
694    VarAttribute=Field.VarAttribute;
695else
696    VarAttribute={};
697end
698
699
700% select the indices of field variables for 2D plots
701test_CheckPlot1D=get(handles.CheckPlot1D,'Value');
702test_scalar=get(handles.CheckScalar,'Value');
703test_vector=get(handles.CheckVector,'Value');
704
705%transform if needed (calibration)
706list=get(handles.menu_coord,'String');
707index=get(handles.menu_coord,'Value');
708transform=list{index};
709if ~isequal(transform,'')
710    Field=feval(transform,Field);
711end
712VarIndex.u=[];
713VarIndex.v=[];
714VarIndex.w=[];
715VarIndex.A=[];
716VarIndex_tot=[];
717iuA=[];
718if test_scalar
719    Astring=get(handles.scalar,'String');
720    Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
721    list_var=Astring(Aindex);
722    VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
723    VarIndex_tot= [VarIndex_tot VarIndex.A];
724    DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
725    DimValue=Field.DimValue(DimIndex);
726    ind=find(DimValue==1);
727    DimIndex(ind)=[];%Mremove singleton
728end
729if test_vector
730    Ustring=get(handles.vector_x,'String');
731    Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
732    list_var=Ustring{Uindex};%name of the selected scalar
733    VarIndex.u=name2index(list_var,Field.ListVarName);
734    Vstring=get(handles.vector_y,'String');
735    Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
736    list_var=Ustring{Vindex};%name of the selected scalar
737    VarIndex.v=name2index(list_var,Field.ListVarName);
738    if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
739        iuA=VarIndex.A; %same variable used for vector and scalar
740        VarIndex_tot(iuA)=[];
741    end
742    VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
743    %dimensions
744    DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
745    DimValue=Field.DimValue(DimIndex_u);
746    ind=find(DimValue==1);
747    DimIndex_u(ind)=[];%Mremove singleton
748    DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
749    DimValue=Field.DimValue(DimIndex_v);
750    ind=find(DimValue==1);
751    DimIndex_v(ind)=[];%Mremove singleton
752    if ~isequal(DimIndex_u,DimIndex_v)
753        msgbox_uvmat('ERROR','inconsistent dimensions for u and v')
754        set(handles.vector_y,'Value',1);
755        return
756    elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
757         msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color')
758         set(handles.scalar,'Value',1);
759         return
760    end
761    DimIndex=DimIndex_u;
762    %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components
763end
764
765
766% select the TimeVariable  index (or indices) for z coordinates
767test_grid=0;
768if test_scalar | test_vector
769    nbdim=length(DimIndex);
770    if nbdim > 3
771        msgbox_uvmat('ERROR','array with more than three dimensions, not supported')
772        return
773    else
774        perm_ind=1:nbdim;
775    end
776    if nbdim==3
777        zstring=get(handles.coord_z_vectors_scalar,'String');
778        zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
779        list_var=zstring(zindex);
780        VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
781        if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
782            if zindex ~= 1
783                set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
784                return
785            end
786        else
787            VarIndex_tot=[VarIndex_tot VarIndex_z];
788            DimIndex_z=Field.VarDimIndex{VarIndex_z};
789            DimValue=Field.DimValue(DimIndex_z);
790            ind=find(DimValue==1);         
791            DimIndex_z(ind)=[];%Mremove singleton
792            if isequal(DimIndex_z,DimIndex)
793                VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
794            elseif length(DimIndex_z)==1
795                VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
796                ind_z=find(DimIndex==DimIndex_z(1));
797                perm_ind(ind_z)=1;
798                test_grid=1;
799            else
800                msgbox_uvmat('ERROR','multiple dimensions for the z coordinate')
801                return
802            end
803        end
804%         if ~isempty(VarIndex_z)
805%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable   
806%             if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable
807%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
808%                 ind_z=find(DimIndex==DimIndex_z(1));
809%                 perm_ind(ind_z)=1;
810%                 test_grid=1;
811%             end
812%         end
813    end
814end
815
816% select the TimeVariable  index (or indices) for ordinate
817ystring=get(handles.ordinate,'String');
818yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
819list_var=ystring(yindex);
820VarIndex.y=name2index(list_var,Field.ListVarName);
821if isequal(VarIndex.A,VarIndex.y)
822    set(handles.ZVarName,'Value',1)
823elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
824   set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
825else
826    for ivar=1:length(VarIndex.y)
827        VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
828    end
829    VarIndex_tot=[VarIndex_tot VarIndex.y];
830end
831if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
832    DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
833    if length(DimIndex_y)==1
834        ind_y=find(DimIndex==DimIndex_y(1));
835        test_grid=1;
836        if nbdim==3
837            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
838            perm_ind(ind_y)=2;
839        elseif nbdim==2
840            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
841             perm_ind(ind_y)=1;
842        end
843    elseif test_grid
844        msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1')   
845    end
846end
847
848%select the TimeVariable index for the abscissa
849xstring=get(handles.abscissa,'String');
850xindex=get(handles.abscissa,'Value');
851list_var=xstring(xindex);
852VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
853if length(VarIndex.x)==1   
854    DimIndex_x=Field.VarDimIndex{VarIndex.x};
855    DimValue=Field.DimValue(DimIndex_x);
856    ind=find(DimValue==1);         
857    DimIndex_x(ind)=[];%Mremove singleton                     
858    VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
859%     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
860    index_detect=find(VarIndex_tot==VarIndex.x);
861else
862    index_detect=[];%coord x variable not already used
863end
864if isempty(index_detect)
865    VarIndex_tot=[VarIndex_tot VarIndex.x];
866elseif ~test_CheckPlot1D
867    VarIndex.x=[];
868    set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
869end
870
871if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
872    DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
873    if length(DimIndex_x)==1
874        ind_x=find(DimIndex==DimIndex_x(1));
875        if nbdim==3
876            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
877            perm_ind(ind_x)=3;
878        elseif nbdim==2
879            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
880             perm_ind(ind_x)=2;
881        end
882        if isequal(perm_ind,1:nbdim)
883            test_grid=0;
884        end
885        DimIndex=DimIndex(perm_ind);
886    elseif test_grid
887        msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1')   
888    end
889    if isequal(DimIndex_x,DimIndex)
890                VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
891    end
892end
893
894%defined the selected sub-field SubField
895SubField.ListGlobalAttribute{1}='InputFile';
896SubField.InputFile=get(handles.inputfile,'String');
897SubField.ListDimName=Field.ListDimName;
898SubField.DimValue=Field.DimValue;
899SubField.ListVarName=Field.ListVarName(VarIndex_tot);
900SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
901
902testperm=0;
903testattr=0;
904for ivar=VarIndex.u
905    VarAttribute{ivar}.Role='vector_x';
906    testattr=1;
907    if test_grid
908        VarDimIndex{ivar}=DimIndex; %permute dimensions
909        testperm=1;
910    end
911end
912for ivar=VarIndex.v
913    VarAttribute{ivar}.Role='vector_y';
914    testattr=1;
915     if test_grid
916        VarDimIndex{ivar}=DimIndex;%permute dimensions
917        testperm=1;
918    end
919end
920for ivar=VarIndex.A
921    if test_grid
922        VarDimIndex{ivar}=DimIndex;%permute dimensions
923        testperm=1;
924    end
925    if isempty(iuA)
926        VarAttribute{ivar}.Role='scalar';%Role =scalar
927        testattr=1;
928    else
929       VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
930       nbattr=length(VarAttribute);
931       VarAttribute{nbattr}.Role='scalar';
932       testattr=1;
933    end
934end
935if testperm
936    SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
937end
938if testattr
939    SubField.VarAttribute=VarAttribute(VarIndex_tot);
940end
941set(hselect_field,'UserData',Field)
942
943%---------------------------------------------------------
944% --- Executes on button press in OK.
945
946function OK_Callback(hObject, eventdata, handles)
947%---------------------------------------------------------
948
949handles.output=read_GUI(handles.get_field);
950guidata(hObject, handles);% Update handles structure
951uiresume(handles.get_field);
952drawnow
953return
954
955%%%% SKIPPED %%%%
956hfield=[];
957huvmat=findobj(allchild(0),'tag','uvmat');
958hseries=findobj(allchild(0),'tag','series');
959check_series=0;
960% look for the status of the GUI uvmat
961if ~isempty(huvmat)
962    hh=guidata(huvmat);
963    FieldMenu=get(hh.FieldName,'String');
964    FieldName=FieldMenu{get(hh.FieldName,'Value')};
965    if strcmp(FieldName,'get_field...')
966        hfield=hh.FieldName; %FieldName on uvmat
967    elseif strcmp(get(hh.FieldName_1,'Visible'),'on')
968        FieldMenu=get(hh.FieldName_1,'String');
969        if ~isempty(FieldMenu)
970            FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
971            if strcmp(FieldName,'get_field...')
972                hfield=hh.FieldName_1; %FieldName_1 on uvmat
973            end
974        end
975    end
976end
977% if no filed data is concerned on uvmat, look at the GUI series
978if isempty(hfield) && ~isempty(hseries)
979    check_series=1;
980    hh=guidata(hseries);
981    FieldMenu=get(hh.FieldName,'String');
982    FieldName=FieldMenu{get(hh.FieldName,'Value')};
983    if strcmp(FieldName,'get_field...')
984        hfield=hh.FieldName; %FieldName on series
985    else
986       FieldMenu=get(hh.FieldName_1,'String');
987       FieldName=FieldMenu{get(hh.FieldName_1,'Value')};
988       if strcmp(FieldName,'get_field...')
989            hfield=hh.FieldName_1; %FieldName_1 on series
990       end
991    end
992end
993if ~isempty(hfield)
994    get_field_GUI=read_GUI(handles.get_field);
995    if isfield(get_field_GUI,'PanelVectors')
996        set(hh.Coord_x,'value',1)
997        set(hh.Coord_y,'value',1)
998        set(hh.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors})
999        set(hh.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors})
1000        UName=get_field_GUI.PanelVectors.vector_x;
1001        VName=get_field_GUI.PanelVectors.vector_y;
1002        menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}];
1003        menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}];
1004        set(hfield,'Value',1)
1005        set(hfield,'String',menu_str)
1006        if ~check_series
1007            ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color));
1008            if ~isempty(ind_menu)
1009                set(hh.ColorScalar,'Value',ind_menu)
1010            else
1011                set(hh.ColorScalar,'Value',1)
1012            end
1013            set(hh.ColorScalar,'String',menu_color)
1014        end
1015    elseif isfield(get_field_GUI,'PanelScalar')
1016        set(hh.Coord_x,'value',1)
1017        set(hh.Coord_y,'value',1)
1018        set(hh.Coord_x,'String',{get_field_GUI.PanelScalar.coord_x_scalar})
1019        set(hh.Coord_y,'String',{get_field_GUI.PanelScalar.coord_y_scalar})
1020        AName=get_field_GUI.PanelScalar.scalar;
1021        menu=get(hfield,'String');
1022        ind_select=find(strcmp(AName,menu));
1023        if isempty(ind_select)
1024            menu=[menu(1:end-1);{AName};{'get_field...'}];
1025            ind_select=numel(menu)-1;
1026        end
1027        set(hfield,'Value',ind_select);
1028        set(hfield,'String',menu);
1029    elseif isfield(get_field_GUI,'Panel1Dplot')
1030        set(hh.Coord_x,'Value',1)
1031        set(hh.Coord_x,'String',{get_field_GUI.Panel1Dplot.abscissa})
1032        set(hh.Coord_y,'String',get_field_GUI.Panel1Dplot.ordinate)
1033        set(hh.Coord_y,'Max', numel(get_field_GUI.Panel1Dplot.ordinate))
1034        set(hh.Coord_y,'Value',1:numel(get_field_GUI.Panel1Dplot.ordinate))
1035        set(hfield,'Value',1)
1036        set(hfield,'String',[{''};{'get_field...'}])
1037    end
1038    if  ~check_series && strcmp(get(gcbf,'tag'),'get_field')%get_field is not called by another GUI (uvmat)
1039        uvmat('run0_Callback',hObject,eventdata,hh); %refresh uvmat
1040    end
1041end
1042delete(handles.get_field)
1043
1044
1045
1046%-------------------------------------------------
1047% give index numbers of the strings str in the list ListvarName
1048function VarIndex_y=name2index(cell_str,ListVarName)
1049VarIndex_y=[];
1050if ischar(cell_str)
1051    for ivar=1:length(ListVarName)
1052        varlist=ListVarName{ivar};
1053        if isequal(varlist,cell_str)
1054            VarIndex_y= ivar;
1055            break
1056        end
1057    end
1058elseif iscell(cell_str)
1059    for isel=1:length(cell_str)
1060        varsel=cell_str{isel};
1061        for ivar=1:length(ListVarName)
1062            varlist=ListVarName{ivar};
1063            if isequal(varlist,varsel)
1064                VarIndex_y=[VarIndex_y ivar];
1065            end
1066        end
1067    end
1068end
1069
1070% --------------------------------------------------------------------
1071function MenuOpen_Callback(hObject, eventdata, handles)
1072% hObject    handle to MenuOpen (see GCBO)
1073% eventdata  reserved - to be defined in a future version of MATLAB
1074% handles    structure with handles and user data (see GUIDATA)
1075
1076
1077% --------------------------------------------------------------------
1078function MenuExport_Callback(hObject, eventdata, handles)
1079% hObject    handle to MenuExport (see GCBO)
1080% eventdata  reserved - to be defined in a future version of MATLAB
1081% handles    structure with handles and user data (see GUIDATA)
1082
1083
1084% --------------------------------------------------------------------
1085function MenuBrowse_Callback(hObject, eventdata, handles)
1086
1087oldfile=get(handles.inputfile,'String');
1088testrootfile=0;
1089testsubdir=0;
1090if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
1091        oldfile='';
1092        dir_perso=prefdir;
1093         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1094         if exist(profil_perso,'file')
1095              h=load (profil_perso);
1096             if isfield(h,'RootPath')
1097                  RootPath=h.RootPath;
1098             end
1099             if isfield(h,'SubDir')
1100                  SubDir=h.SubDir;
1101                  if ~isempty(SubDir)
1102                    testsubdir=1;
1103                  end
1104             end
1105             if isfield(h,'RootFile')
1106                  RootFile=h.RootFile;
1107                  if ~isempty(RootFile)
1108                    testrootfile=1;
1109                  end
1110             end
1111         end
1112end
1113if testrootfile
1114    if ~testsubdir
1115        oldfile=fullfile(RootPath,RootFile);
1116    else
1117        oldfile=fullfile(RootPath,SubDir,RootFile);
1118    end
1119end
1120[FileName, PathName] = uigetfile( ...
1121       {'*.nc', ' *.nc';...
1122       '*.cdf', ' *.cdf';...
1123        '*.*',  'All Files (*.*)'}, ...
1124        'Pick a file',oldfile);
1125
1126%global inputfile
1127fileinput=[PathName FileName];%complete file name
1128sizf=size(fileinput);
1129if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1130set(handles.inputfile,'String',fileinput)
1131inputfile_Callback(hObject, eventdata, handles)
1132
1133%update list of recent files in the menubar
1134MenuFile_1=fileinput;
1135MenuFile_2=get(handles.MenuFile_1,'Label');
1136MenuFile_3=get(handles.MenuFile_2,'Label');
1137MenuFile_4=get(handles.MenuFile_3,'Label');
1138MenuFile_5=get(handles.MenuFile_4,'Label');
1139set(handles.MenuFile_1,'Label',MenuFile_1)
1140set(handles.MenuFile_2,'Label',MenuFile_2)
1141set(handles.MenuFile_3,'Label',MenuFile_3)
1142set(handles.MenuFile_4,'Label',MenuFile_4)
1143set(handles.MenuFile_5,'Label',MenuFile_5)
1144dir_perso=prefdir;
1145profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1146display(profil_perso)
1147if exist(profil_perso,'file')
1148    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
1149else
1150    txt=ver('MATLAB');
1151    Release=txt.Release;
1152    relnumb=str2double(Release(3:4));
1153    if relnumb >= 14
1154        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
1155    else
1156        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
1157    end
1158end
1159
1160% --------------------------------------------------------------------
1161function MenuFile_1_Callback(hObject, eventdata, handles)
1162fileinput=get(handles.MenuFile_1,'Label');
1163set(handles.inputfile,'String',fileinput)
1164inputfile_Callback(hObject, eventdata, handles)
1165
1166% --------------------------------------------------------------------
1167function MenuFile_2_Callback(hObject, eventdata, handles)
1168fileinput=get(handles.MenuFile_2,'Label');
1169set(handles.inputfile,'String',fileinput)
1170inputfile_Callback(hObject, eventdata, handles)
1171
1172% -----------------------------------------------------------------------
1173function MenuFile_3_Callback(hObject, eventdata, handles)
1174% -----------------------------------------------------------------------
1175fileinput=get(handles.MenuFile_3,'Label');
1176set(handles.inputfile,'String',fileinput)
1177inputfile_Callback(hObject, eventdata, handles)
1178
1179% -----------------------------------------------------------------------
1180function MenuFile_4_Callback(hObject, eventdata, handles)
1181% -----------------------------------------------------------------------
1182fileinput=get(handles.MenuFile_4,'Label');
1183set(handles.inputfile,'String',fileinput)
1184inputfile_Callback(hObject, eventdata, handles)
1185
1186% -----------------------------------------------------------------------
1187function MenuFile_5_Callback(hObject, eventdata, handles)
1188% -----------------------------------------------------------------------
1189fileinput=get(handles.MenuFile_5,'Label');
1190set(handles.inputfile,'String',fileinput)
1191inputfile_Callback(hObject, eventdata, handles)
1192
1193%------------------------------------------------------------------------
1194function MenuExportField_Callback(hObject, eventdata, handles)
1195%------------------------------------------------------------------------
1196global Data_get_field
1197% huvmat=findobj(allchild(0),'Name','uvmat');
1198inputfile=get(handles.inputfile,'String');
1199Data_get_field=nc2struct(inputfile);
1200% Data_view_field=UvData.ProjField_2;
1201evalin('base','global Data_get_field')%make CurData global in the workspace
1202display(['content of ' inputfile ':'])
1203evalin('base','Data_get_field') %display CurData in the workspace
1204commandwindow;
1205
1206%------------------------------------------------------------------------
1207function MenuHelp_Callback(hObject, eventdata, handles)
1208%------------------------------------------------------------------------
1209path_to_uvmat=which ('uvmat');% check the path of uvmat
1210pathelp=fileparts(path_to_uvmat);
1211helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
1212if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
1213else
1214web([helpfile '#get_field'])   
1215end
1216
1217% -----------------------------------------------------------------------
1218function TimeName_Callback(hObject, eventdata, handles)
1219
1220scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates
1221vector_x_Callback(hObject, eventdata, handles)
1222
1223%------------------------------------------------------------------------
1224% --- Executes on button press in TimeAttribute.
1225function TimeAttribute_Callback(hObject, eventdata, handles)
1226%------------------------------------------------------------------------
1227val=get(handles.TimeAttribute,'Value');
1228if val
1229    set(handles.TimeAttributeMenu,'Visible','on')
1230    Field=get(handles.get_field,'UserData');
1231    time_value=zeros(size(Field.ListGlobalAttribute));
1232    test_time=zeros(size(Field.ListGlobalAttribute));
1233    for ilist=1:numel(Field.ListGlobalAttribute)
1234        if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}]))
1235            eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';'])
1236            if ~isempty(time_val)
1237                time_value(ilist)=time_val;
1238                test_time(ilist)=1;
1239            end
1240        end
1241    end
1242    ListTimeAttribute=Field.ListGlobalAttribute(test_time==1);
1243    attr_index=get(handles.TimeAttributeMenu,'Value');
1244    if attr_index>numel(ListTimeAttribute)
1245        attr_index=1;
1246        set(handles.TimeAttributeMenu,'Value',1);
1247    end
1248    if isempty(ListTimeAttribute)
1249        set(handles.TimeAttributeMenu,'String',{''})
1250        set(handles.TimeValue,'Visible','off')
1251    else
1252        set(handles.TimeValue,'Visible','on')
1253        set(handles.TimeAttributeMenu,'String',ListTimeAttribute)
1254        set(handles.TimeValue,'String',num2str(time_value(attr_index)))
1255    end
1256    set(handles.TimeDimension,'Value',0)
1257    TimeDimension_Callback(hObject, eventdata, handles)
1258    set(handles.TimeVariable,'Value',0)
1259    TimeVariable_Callback(hObject, eventdata, handles)
1260else
1261    set(handles.TimeAttributeMenu,'Visible','off')
1262    set(handles.TimeValue,'Visible','off')
1263end
1264
1265%------------------------------------------------------------------------
1266% --- Executes on selection change in TimeAttributeMenu.
1267function TimeAttributeMenu_Callback(hObject, eventdata, handles)
1268 ListTimeAttribute=get(handles.TimeAttributeMenu,'String');
1269 index=get(handles.TimeAttributeMenu,'Value');
1270 AttrName=ListTimeAttribute{index};
1271 Field=get(handles.get_field,'UserData');
1272 eval(['time_val=Field.' AttrName ';'])
1273 set(handles.TimeValue,'String',num2str(time_val))
1274%------------------------------------------------------------------------
1275
1276%------------------------------------------------------------------------
1277% --- Executes on button press in TimeVariable.
1278function TimeDimension_Callback(hObject, eventdata, handles)
1279%------------------------------------------------------------------------
1280val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected
1281if val  %if check box TimeDimension is selected
1282    Field=get(handles.get_field,'UserData');% structure describing the currently opened field
1283    previous_menu=get(handles.TimeDimensionMenu,'String');
1284    if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu
1285        ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time'
1286        if isempty(ind_select)
1287            ind_select=1;% select the first item in the list if 'time' is not found
1288        end
1289        set(handles.TimeDimensionMenu,'Value',ind_select);
1290        set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu
1291    end   
1292    set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible
1293    set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible
1294    TimeDimensionMenu_Callback(hObject, eventdata, handles) 
1295    set(handles.TimeAttribute,'Value',0) %deselect alternative options for time
1296    set(handles.TimeVariable,'Value',0)
1297    TimeAttribute_Callback(hObject, eventdata, handles)
1298else
1299    set(handles.TimeDimensionMenu,'Visible','off')
1300    set(handles.TimeIndexValue,'Visible','off')
1301end
1302%
1303% %------------------------------------------------------------------------
1304% % --- Executes on selection change in TimeDimensionMenu.
1305% function TimeDimensionMenu_Callback(hObject, eventdata, handles)
1306% %------------------------------------------------------------------------
1307% index=get(handles.TimeDimensionMenu,'Value');
1308% DimList=get(handles.TimeDimensionMenu,'String');
1309% DimName=DimList{index};
1310% Field=get(handles.get_field,'UserData');
1311% DimIndex=find(strcmp(DimName,Field.ListDimName),1);
1312% ref_index=round(Field.DimValue(DimIndex)/2);   
1313% set(handles.TimeIndexValue,'String',num2str(ref_index))
1314% scalar_Callback(hObject, eventdata, handles)
1315% vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time)
1316%  % look for a corresponding time variable and value
1317%  time_test=zeros(size(Field.VarDimName));
1318%  for ilist=1:numel(Field.VarDimName)
1319%      if isequal(Field.VarDimName{ilist},{DimName})
1320%          time_test(ilist)=1;
1321%      end
1322%  end
1323%  ListVariable=Field.ListVarName(time_test==1);
1324%  set(handles.TimeVariableMenu,'Value',1)
1325%  if isempty(ListVariable)     
1326%      set(handles.TimeVariableMenu,'String',{''})
1327%      set(handles.TimeVarValue,'String','')
1328%  else
1329%     set(handles.TimeVariableMenu,'String',ListVariable)
1330%     TimeVarName=ListVariable{1};
1331%     VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables
1332%     inputfile=get(handles.inputfile,'String');% read the input file
1333%     SubField=nc2struct(inputfile,{TimeVarName});
1334%     eval(['TimeValue=SubField.' TimeVarName '(ref_index);'])
1335%     set(handles.TimeVarValue,'Visible','on')
1336%     set(handles.TimeVariableMenu,'Visible','on')
1337%     set(handles.TimeVarValue,'String',num2str(TimeValue))
1338%  end
1339%
1340%
1341% % % -----------------------------------------------------------------------
1342% % % --- Executes on button press in TimeVariable.
1343% % function TimeVariable_Callback(hObject, eventdata, handles)
1344% % % -----------------------------------------------------------------------
1345% % val=get(handles.TimeVariable,'Value');
1346% % if val
1347% %     Field=get(handles.get_field,'UserData');
1348% %     time_test=zeros(size(Field.VarDimName));
1349% %     for ilist=1:numel(Field.VarDimName)
1350% %         if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension
1351% %             time_test(ilist)=1;
1352% %         end
1353% %     end
1354% %     ind_test=find(time_test);
1355% %     if isempty(time_test)
1356% %         set(handles.TimeVariable,'Value',0)
1357% %         set(handles.TimeVariableMenu,'Visible','off')
1358% %         set(handles.TimeVarValue,'Visible','off')
1359% %     else
1360% %         set(handles.TimeVariableMenu,'Visible','on')
1361% %         set(handles.TimeVarValue,'Visible','on')
1362% %         if get(handles.TimeVariableMenu,'Value')>numel(ind_test)
1363% %             set(handles.TimeVariableMenu,'Value',1)
1364% %         end
1365% %         set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test))
1366% %         TimeVariableMenu_Callback(hObject, eventdata, handles)
1367% %         set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time
1368% %         set(handles.TimeAttribute,'Value',0)
1369% %         TimeAttribute_Callback(hObject, eventdata, handles)
1370% %     end
1371% % else
1372% %     set(handles.TimeVariableMenu,'Visible','off')
1373% %     set(handles.TimeVarValue,'Visible','off')
1374% % end
1375%
1376% % -----------------------------------------------------------------------
1377% % --- Executes on selection change in TimeVariableMenu.
1378% function TimeVariableMenu_Callback(hObject, eventdata, handles)
1379% % -----------------------------------------------------------------------
1380% ListVar=get(handles.TimeVariableMenu,'String');
1381% index=get(handles.TimeVariableMenu,'Value');
1382% TimeVariable=ListVar{index};% name of the selected variable
1383% if isempty(TimeVariable)% case of blank selection
1384%     return
1385% end
1386% Field=get(handles.get_field,'UserData'); %index of
1387% VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables
1388% DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable
1389% set(handles.TimeDimensionMenu,'Value',1)
1390% set(handles.TimeDimensionMenu,'String',DimName)
1391% inputfile=get(handles.inputfile,'String');% read the input file
1392% SubField=nc2struct(inputfile,{TimeVariable});
1393% eval(['TimeDimension=numel(SubField.' TimeVariable ');'])
1394% ref_index=round(TimeDimension/2);
1395% eval(['TimeValue=SubField.' TimeVariable '(ref_index);'])
1396% set(handles.TimeIndexValue,'String',num2str(ref_index))
1397% set(handles.TimeVarValue,'String',num2str(TimeValue))
1398
1399
1400% --- Executes on button press in check_rgb.
1401function check_rgb_Callback(hObject, eventdata, handles)
1402
1403
1404% --- Executes when user attempts to close get_field.
1405function get_field_CloseRequestFcn(hObject, eventdata, handles)
1406if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
1407    % The GUI is still in UIWAIT, us UIRESUME
1408    uiresume(handles.get_field);
1409else
1410    % The GUI is no longer waiting, just close it
1411    delete(handles.get_field);
1412end
1413
1414
1415
1416
1417
1418% --- Executes on selection change in listbox30.
1419function listbox30_Callback(hObject, eventdata, handles)
1420% hObject    handle to listbox30 (see GCBO)
1421% eventdata  reserved - to be defined in a future version of MATLAB
1422% handles    structure with handles and user data (see GUIDATA)
1423
1424% Hints: contents = cellstr(get(hObject,'String')) returns listbox30 contents as cell array
1425%        contents{get(hObject,'Value')} returns selected item from listbox30
1426
1427
1428% --- Executes on selection change in SwitchVarIndexX.
1429function SwitchVarIndexX_Callback(hObject, eventdata, handles)
1430% hObject    handle to SwitchVarIndexX (see GCBO)
1431% eventdata  reserved - to be defined in a future version of MATLAB
1432% handles    structure with handles and user data (see GUIDATA)
1433
1434% Hints: contents = cellstr(get(hObject,'String')) returns SwitchVarIndexX contents as cell array
1435%        contents{get(hObject,'Value')} returns selected item from SwitchVarIndexX
1436
1437
1438% --- Executes on selection change in SwitchVarIndexTime.
1439function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
1440menu=get(handles.SwitchVarIndexTime,'String');
1441option=menu{get(handles.SwitchVarIndexTime,'Value')};
1442Field=get(handles.get_field,'UserData');
1443switch option
1444    case 'file index'
1445        set(handles.TimeVarName, 'Visible','off')
1446    case 'attribute'
1447        set(handles.TimeVarName, 'Visible','on')
1448        time_index=[];
1449        PreviousList=get(handles.TimeVarName, 'String');
1450         index=[];
1451        if ~isempty(PreviousList)
1452        PreviousAttr=PreviousList{get(handles.TimeVarName, 'Value')};
1453        index=find(strcmp(PreviousAttr,Field.ListNumAttributes));
1454        end
1455        if isempty(index)
1456            time_index=find(~cellfun('isempty',regexp(Field.ListNumAttributes,'Time')));% index of the attributes containing the string 'Time'
1457        end
1458        if ~isempty(time_index)
1459            set(handles.TimeVarName,'Value',time_index(1))
1460        else
1461            set(handles.TimeVarName,'Value',1)
1462        end
1463        set(handles.TimeVarName, 'String',Field.ListNumAttributes)
1464    case 'variable'
1465        set(handles.TimeVarName, 'Visible','on')
1466        TimeVarName=Field.SingleVarName;
1467        List=get(handles.TimeVarName,'String');
1468        option=List{get(handles.TimeVarName,'Value')};
1469        ind=find(strcmp(option,TimeVarName));
1470        if isempty(ind)
1471            set(handles.TimeVarName, 'Value',1);
1472        else
1473            set(handles.TimeVarName, 'Value',ind);
1474        end
1475        set(handles.TimeVarName, 'String',TimeVarName)
1476    case 'dim index'
1477        set(handles.TimeVarName, 'Visible','on')
1478        TimeVarName=Field.SingleDimName;
1479        List=get(handles.TimeVarName,'String');
1480        option=List{get(handles.TimeVarName,'Value')};
1481        ind=find(strcmp(option,TimeVarName));
1482        if isempty(ind)
1483            set(handles.TimeVarName, 'Value',1);
1484        else
1485            set(handles.TimeVarName, 'Value',ind);
1486        end
1487        set(handles.TimeVarName, 'String',TimeVarName)
1488end
1489
1490
1491% --- Executes on button press in CheckScalar.
1492function checkbox22_Callback(hObject, eventdata, handles)
1493% hObject    handle to CheckScalar (see GCBO)
1494% eventdata  reserved - to be defined in a future version of MATLAB
1495% handles    structure with handles and user data (see GUIDATA)
1496
1497% Hint: get(hObject,'Value') returns toggle state of CheckScalar
1498
1499
1500% --- Executes on button press in checkbox23.
1501function checkbox23_Callback(hObject, eventdata, handles)
1502% hObject    handle to checkbox23 (see GCBO)
1503% eventdata  reserved - to be defined in a future version of MATLAB
1504% handles    structure with handles and user data (see GUIDATA)
1505
1506% Hint: get(hObject,'Value') returns toggle state of checkbox23
Note: See TracBrowser for help on using the repository browser.