source: trunk/src/get_field.m @ 644

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

various improvements: resize GUI uvmat, projection on lines

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