source: trunk/src/get_field.m @ 874

Last change on this file since 874 was 874, checked in by sommeria, 9 years ago

merge_proj corrected + various bugs

File size: 44.7 KB
RevLine 
[581]1%'get_field': display variables and attributes from a Netcdf file, and OK selected fields
[204]2%------------------------------------------------------------------------
[674]3% GetFieldData=get_field(FileName,ParamIn)
[204]4% associated with the GUI get_field.fig
5%
[811]6% OUTPUT:
[674]7% GetFieldData: structure containing the information on the selected
8%      fields, obtained by applying the fct red_GUI to the GUI get_field
9%   .FieldOption='vectors': variables are used for vector plot
10%                  'scalar': variables are used for scalar plot,
11%                  '1Dplot': variables are used for usual x-y plot,
12%                  'civdata...': go back to automatic reading of civ data
13%   .PanelVectors: sub-structure variables used as vector components
14%   .PanelScalar:
15% INPUT:
16% FileName: name (including path) of the netcdf file to open
[809]17
18%=======================================================================
19% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
20%   http://www.legi.grenoble-inp.fr
21%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
[674]22%
[204]23%     This file is part of the toolbox UVMAT.
[809]24%
[204]25%     UVMAT is free software; you can redistribute it and/or modify
[809]26%     it under the terms of the GNU General Public License as published
27%     by the Free Software Foundation; either version 2 of the license,
28%     or (at your option) any later version.
29%
[204]30%     UVMAT is distributed in the hope that it will be useful,
31%     but WITHOUT ANY WARRANTY; without even the implied warranty of
32%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[809]33%     GNU General Public License (see LICENSE.txt) for more details.
34%=======================================================================
[204]35
36function varargout = get_field(varargin)
37
[874]38% Last Modified by GUIDE v2.5 18-Feb-2015 23:42:12
[204]39
40% Begin initialization code - DO NOT EDIT
[581]41gui_Singleton = 1;
[204]42gui_State = struct('gui_Name',       mfilename, ...
43                   'gui_Singleton',  gui_Singleton, ...
44                   'gui_OpeningFcn', @get_field_OpeningFcn, ...
45                   'gui_OutputFcn',  @get_field_OutputFcn, ...
46                   'gui_LayoutFcn',  [] , ...
47                   'gui_Callback',   []);
48if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
49    gui_State.gui_Callback = str2func(varargin{1});
50end
51
52if nargout
53    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
54else
55    gui_mainfcn(gui_State, varargin{:});
56end
57% End initialization code - DO NOT EDIT
[674]58     
[204]59%------------------------------------------------------------------------
60% --- Executes just before get_field is made visible.
[648]61%------------------------------------------------------------------------
[581]62function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn)
[204]63
[648]64%% GUI settings
[581]65handles.output = 'Cancel';
[204]66guidata(hObject, handles);
[434]67set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
[874]68set(hObject,'CloseRequestFcn',{@closefcn,handles})
[204]69
[648]70%% enter input data
[775]71if ischar(filename) % input file name
[674]72    set(handles.inputfile,'String',filename)% fill the input file name
[775]73    [Field,tild,tild,errormsg]=nc2struct(filename,[]);% reads the  field structure, without the variables
[674]74else
[775]75    msgbox_uvmat('ERROR','get_field requires a file name as input')% display error message for input file reading
76    return
[674]77end
[775]78if ~isempty(errormsg)
79    msgbox_uvmat('ERROR',['get_field/nc2struct/' errormsg])% display error message for input file reading
[648]80    return
[227]81end
[204]82if ~isfield(Field,'ListVarName')
[775]83    msgbox_uvmat('ERROR',['no variable found in ' filename])% display error message for input file reading
[204]84    return
85end
[775]86if ~exist('ParamIn','var')
87    ParamIn=[];
88end
[582]89
[648]90%% look at singletons and variables with a single dimension
91Field.Display=Field;
92Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value
[747]93NbVar=numel(Field.VarDimName);%nbre of variables in the input data
[648]94for ilist=1:NbVar
[582]95    if ischar(Field.VarDimName{ilist})
96        Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell
97    end
[648]98    NbDim=numel(Field.VarDimName{ilist});
[747]99    check_singleton=false(1,NbDim);%  check singleton, false by default
[582]100    for idim=1:NbDim
[648]101        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions
102        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton
[582]103    end
[701]104    Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)))||(~isequal(Field.VarType(ilist),4)&&~isequal(Field.VarType(ilist),5)&&~isequal(Field.VarType(ilist),6));% =1 if the variable reduces to a single value
[648]105    if ~Field.Check0D(ilist)
106    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
[582]107    end
108end
[669]109if ~isfield(Field,'VarAttribute')
110    Field.VarAttribute={};
111end
[648]112if numel(Field.VarAttribute)<NbVar% complement VarAttribute by blanjs if neded
113    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
[582]114end
[747]115% Field.Display = list of variables and corresponding properties obtained after removal of variables with a single value and singleton dimensions
116Field.Display.ListVarName=Field.ListVarName(~Field.Check0D); %list of variables available for plots, after eliminating variables with a single value
[648]117Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
118Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D);
[747]119Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);% list of non singleton dimension names
120Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);% corresponding list of non singleton dimension values
[581]121
[747]122
[648]123%% analyse the input field cells
124[CellInfo,NbDim,errormsg]=find_field_cells(Field.Display);
125if ~isempty(errormsg)
126    msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg])
127    return
128end
129[Field.MaxDim,imax]=max(NbDim);
130
[581]131%% set time mode
[646]132ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index
[582]133% look at global attributes with numerical values
[674]134check_numvalue=false(1,numel(Field.ListGlobalAttribute));
[646]135for ilist=1:numel(Field.ListGlobalAttribute)
136    Value=Field.(Field.ListGlobalAttribute{ilist});
137    check_numvalue(ilist)=isnumeric(Value);
138end
[648]139Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value
140if ~isempty(Field.Display.ListGlobalAttribute)
[646]141    ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute
[582]142end
143if Field.MaxDim>=2
[693]144    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'matrix index'}];% the time can be chosen as a dim index
[582]145end
[674]146
147%% select the Time attribute from input
148if isfield(ParamIn,'TimeAttrName')
149    time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1);
150else
[693]151    time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% look for global attribute containing name 'Time'
[674]152end
153if ~isempty(time_index)
[648]154    set(handles.SwitchVarIndexTime,'Value',2);
[674]155    set(handles.TimeName,'UserData',time_index)
[581]156else
[648]157    set(handles.SwitchVarIndexTime,'Value',1);
[581]158end
[646]159set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime)
[582]160set(handles.get_field,'UserData',Field);% record the finput field structure
[648]161SwitchVarIndexTime_Callback([], [], handles)
[581]162
[582]163%% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields
[648]164set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
165set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
[748]166set(handles.vector_z,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
[672]167set(handles.vec_color,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
[648]168set(handles.scalar,'Value',1)% fill the menu of y vector components
[747]169set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu for scalar
[648]170set(handles.ordinate,'Value',1)% fill the menu of y vector components
[747]171set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y coordinate for 1D plots
[748]172checkseries=0;
[764]173if isfield(ParamIn,'SeriesInput') && ParamIn.SeriesInput% case of call by series
[748]174    set(handles.FieldOption,'value',1)
[764]175    if isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
[771]176    set(handles.FieldOption,'String',{'scalar';'vectors';'civdata...'})
[764]177    else
[771]178       set(handles.FieldOption,'String',{'scalar';'vectors'})
[764]179    end
[748]180    checkseries=1;
181    set(handles.scalar,'Max',2)
182elseif isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
[747]183    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})% provides the possibility to come back to civdata
[748]184    set(handles.scalar,'Max',1)
[654]185else
[672]186    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'})
[748]187    set(handles.scalar,'Max',1)
[654]188end
[748]189if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields
[674]190    check_vec_input=0;
191    if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y')
192        ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1);
193        ichoice_y=find(strcmp(ParamIn.vector_y,Field.Display.ListVarName),1);
194        if ~isempty(ichoice_x)&&~isempty(ichoice_y)
195            set(handles.vector_x,'UserData',ichoice_x)
196            set(handles.vector_y,'UserData',ichoice_y)
197            check_vec_input=1;
198        end
199    end
200    if ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
201        set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1))
202        set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1))
203        check_vec_input=1;
204    end
205    if check_vec_input
[646]206        set(handles.FieldOption,'Value',3)% set vector selection option
[204]207    else
[674]208        set(handles.FieldOption,'Value',2)% set scalar selection option
[204]209    end
[582]210else % case of 1D fields
[644]211    set(handles.FieldOption,'Value',1)
[204]212end
[582]213
[648]214%% fill the general list of dimensions, variables, attributes
215if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
216    Tabcell(:,1)=Field.ListDimName;
217    for iline=1:length(Field.ListDimName)
218        Tabcell{iline,2}=num2str(Field.DimValue(iline));
219    end
220    Tabchar=cell2tab(Tabcell,' = ');
221    set(handles.dimensions,'String',Tabchar)
222end
[644]223
[648]224%% fill menus for coordinates and time
225FieldOption_Callback(handles.variables,[], handles)% list the global attributes
226
[672]227%% Make choices of coordinates from input
228if isfield(CellInfo{imax},'CoordIndex')
229    CoordIndex=CellInfo{imax}.CoordIndex;
230    if numel(CoordIndex)==2
231        YName=Field.ListVarName{CoordIndex(1)};
232        XName=Field.ListVarName{CoordIndex(2)};
233        ListCoord=get(handles.Coord_x,'String');
234        XIndex=find(strcmp(XName,ListCoord));
235        if ~isempty(XIndex)
236            set(handles.Coord_x,'Value',XIndex)
237        end
238        YIndex=find(strcmp(YName,ListCoord));
239        if ~isempty(YIndex)
240            set(handles.Coord_y,'Value',YIndex)
241        end
242    end
243end
[648]244
245%% put the GUI on the lower right of the sceen
246set(hObject,'Unit','pixel')
247pos_view_field=get(hObject,'Position');
248set(0,'Unit','pixels')
249ScreenSize=get(0,'ScreenSize');
250pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3);
251pos_view_field(2)=ScreenSize(2);
252set(hObject,'Position',pos_view_field)
253set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
[771]254if isfield(ParamIn,'Title')
255    set(hObject,'Name',ParamIn.Title)
256end
[648]257
258%% set z coordinate menu if relevant
[874]259if Field.MaxDim>=3 && prod(Field.DimValue)<10^8; % 3D field (with memory content smaller than 400 Mo)
[747]260    set(handles.Check3D,'Value',1)
[648]261else
[747]262    set(handles.Check3D,'Value',0)
[581]263end
[747]264Check3D_Callback(hObject, eventdata, handles)
[748]265set(handles.variables,'Value',1)
266set(handles.variables,'String',[{'*'} Field.ListVarName])
267variables_Callback(handles.variables,[], handles)% list the global attributes
[747]268drawnow
269uiwait(handles.get_field);
[204]270
271%------------------------------------------------------------------------
[874]272% --- Executes when user attempts to close get_field.
[648]273%------------------------------------------------------------------------
274%------------------------------------------------------------------------
[582]275
[648]276
[874]277% Use UIRESUME instead of delete because the OutputFcn needs
278% to get the updated handles structure.
[648]279
[874]280% function get_field_CloseRequestFcn(hObject, eventdata)
281% handles.output=[];
282% guidata(hObject, handles);% Update handles structure
283% %delete(handles.get_field);
284% uiresume(handles.get_field);
285%drawnow
286% if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
287%     % The GUI is still in UIWAIT, us UIRESUME
288%     uiresume(handles.get_field);
289% else
290%     % The GUI is no longer waiting, just close it
291%     delete(handles.get_field);
292% end
[648]293
[582]294% -----------------------------------------------------------------------
295% --- Activated by selection in the list of variables
[672]296% ----------------------------------------------------------------------
[582]297function variables_Callback(hObject, eventdata, handles)
[672]298
[582]299Tabchar={''};%default
300Tabcell=[];
301hselect_field=get(handles.variables,'parent');
302Field=get(handles.get_field,'UserData');
303index=get(handles.variables,'Value');%index in the list 'variables'
304
305%% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected
[672]306if isequal(index,1)
[582]307    set(handles.attributes_txt,'String','global attributes')
308    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
309        for iline=1:length(Field.ListGlobalAttribute)
[672]310            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
[582]311            if isfield(Field, Field.ListGlobalAttribute{iline})
[648]312                val=Field.(Field.ListGlobalAttribute{iline});
[582]313                if ischar(val);% attribute value is char string
314                    Tabcell{iline,2}=val;
315                elseif size(val,1)==1 %attribute value is a number or matlab vector
316                    Tabcell{iline,2}=num2str(val);
317                end
318            end
319        end
320        Tabchar=cell2tab(Tabcell,'=');
321    end
[672]322    %% list Attribute names and values associated to the Variable # index-1
[582]323else
324    list_var=get(handles.variables,'String');
[748]325    if index>numel(list_var)
326        return
327    end
[582]328    var_select=list_var{index};
329    set(handles.attributes_txt,'String', ['attributes of ' var_select])
330    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
[672]331        %         nbline=0;
[582]332        VarAttr=Field.VarAttribute{index-1};
333        if isstruct(VarAttr)
334            attr_list=fieldnames(VarAttr);
335            for iline=1:length(attr_list)
336                Tabcell{iline,1}=attr_list{iline};
[674]337                val=VarAttr.(attr_list{iline}) ;
[582]338                if ischar(val);
339                    Tabcell{iline,2}=val;
340                else
[672]341                    Tabcell{iline,2}=num2str(val);
[582]342                end
343            end
344        end
345    end
346end
347if ~isempty(Tabcell)
348    Tabchar=cell2tab(Tabcell,'=');
[672]349    %     Tabchar=[{''};Tabchar];
[582]350end
351set(handles.attributes,'Value',1);% select the first item
352set(handles.attributes,'String',Tabchar);
353
354%% update dimensions;
355if isfield(Field,'ListDimName')
356    Tabdim={};%default
357    if isequal(index,1)%list all dimensions
358        dim_indices=1:length(Field.ListDimName);
359        set(handles.dimensions_txt,'String', 'dimensions')
360    else
361        DimCell=Field.VarDimName{index-1};
362        if ischar(DimCell)
363            DimCell={DimCell};
[672]364        end
[582]365        dim_indices=[];
366        for idim=1:length(DimCell)
[672]367            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0
[582]368            dim_index=find(dim_index,1);
369            dim_indices=[dim_indices dim_index];
370        end
371        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
372    end
373    for iline=1:length(dim_indices)
374        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
375        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
376    end
377    Tabchar=cell2tab(Tabdim,' = ');
378    Tabchar=[{''} ;Tabchar];
379    set(handles.dimensions,'Value',1)
[672]380    set(handles.dimensions,'String',Tabchar)
381end
[582]382
383%------------------------------------------------------------------------
[648]384% --- Executes on selection change in FieldOption.
[582]385%------------------------------------------------------------------------
[648]386function FieldOption_Callback(hObject, eventdata, handles)
387
[672]388Field=get(handles.get_field,'UserData');
[648]389FieldList=get(handles.FieldOption,'String');
390FieldOption=FieldList{get(handles.FieldOption,'Value')};
391switch FieldOption
[672]392   
[648]393    case '1D plot'
[654]394        set(handles.Coordinates,'Visible','on')
[648]395        set(handles.PanelOrdinate,'Visible','on')
396        pos=get(handles.PanelOrdinate,'Position');
397        pos(1)=2;
398        pos_coord=get(handles.Coordinates,'Position');
399        pos(2)=pos_coord(2)-pos(4)-2;
400        set(handles.PanelOrdinate,'Position',pos)
401        set(handles.PanelScalar,'Visible','off')
402        set(handles.PanelVectors,'Visible','off')
403        set(handles.Coord_y,'Visible','off')
404        set(handles.Y_title,'Visible','off')
405        set(handles.Coord_z,'Visible','off')
406        set(handles.Z_title,'Visible','off')
407        ordinate_Callback(hObject, eventdata, handles)
[672]408       
[771]409    case {'scalar'}
[654]410        set(handles.Coordinates,'Visible','on')
[648]411        set(handles.PanelOrdinate,'Visible','off')
412        set(handles.PanelScalar,'Visible','on')
413        set(handles.PanelVectors,'Visible','off')
414        pos=get(handles.PanelScalar,'Position');
415        pos(1)=2;
416        pos_coord=get(handles.Coordinates,'Position');
417        pos(2)=pos_coord(2)-pos(4)-2;
418        set(handles.PanelScalar,'Position',pos)
419        set(handles.Coord_y,'Visible','on')
420        set(handles.Y_title,'Visible','on')
[672]421        %default scalar selection
422        test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
423        for ilist=1:numel(Field.Display.VarDimName)
424            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
425                Role=Field.Display.VarAttribute{ilist}.Role;
426                if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
427                    test_coord(ilist)=1;
428                end
429            end
430            dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
431            if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
432                test_coord(ilist)=1;
433            end
434        end
[747]435        scalar_index=find(~test_coord,1);%get the first variable not a coordinate
[672]436        if isempty(scalar_index)
437            set(handles.scalar,'Value',1)
438        else
439            set(handles.scalar,'Value',scalar_index)
440        end       
[648]441        scalar_Callback(hObject, eventdata, handles)
[674]442             
[648]443    case 'vectors'
[674]444        set(handles.PanelVectors,'Visible','on')
[654]445        set(handles.Coordinates,'Visible','on')
[648]446        set(handles.PanelOrdinate,'Visible','off')
447        set(handles.PanelScalar,'Visible','off')
448        pos=get(handles.PanelVectors,'Position');
449        pos(1)=2;
450        pos_coord=get(handles.Coordinates,'Position');
451        pos(2)=pos_coord(2)-pos(4)-2;
452        set(handles.PanelVectors,'Position',pos)
453        set(handles.Coord_y,'Visible','on')
[672]454        set(handles.Y_title,'Visible','on')
455        %default vector selection
[674]456        vector_x_value=get(handles.vector_x,'UserData');
457        vector_y_value=get(handles.vector_y,'UserData');
458        if ~isempty(vector_x_value)&&~isempty(vector_y_value)
459            set(handles.vector_x,'Value',vector_x_value)
460            set(handles.vector_y,'Value',vector_y_value)
461        else
462            test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate
463            for ilist=1:numel(Field.Display.VarDimName)
464                if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
465                    Role=Field.Display.VarAttribute{ilist}.Role;
466                    if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
467                        test_coord(ilist)=1;
468                    end
469                end
470                dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
471                if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
[672]472                    test_coord(ilist)=1;
473                end
474            end
[674]475            vector_index=find(~test_coord,2);%get the two first variables not a coordinate
476            if isempty(vector_index)
477                set(handles.vector_x,'Value',1)
478                set(handles.vector_y,'Value',2)
479            else
480                set(handles.vector_x,'Value',vector_index(1))
481                set(handles.vector_y,'Value',vector_index(2))
[672]482            end
483        end
[648]484        vector_Callback(handles)
[672]485       
[654]486    case 'civdata...'
487        set(handles.PanelOrdinate,'Visible','off')
488        set(handles.PanelScalar,'Visible','off')
489        set(handles.PanelVectors,'Visible','off')
490        set(handles.Coordinates,'Visible','off')
[582]491end
492
493%------------------------------------------------------------------------
[204]494function ordinate_Callback(hObject, eventdata, handles)
495%------------------------------------------------------------------------
[582]496Field=get(handles.get_field,'UserData');
[648]497y_index=get(handles.ordinate,'Value');
498y_menu=get(handles.ordinate,'String');
[701]499if isempty(y_menu)
500    return
501else
[648]502YName=y_menu{y_index};
[701]503end
[648]504
505%% set list of possible coordinates
506test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
507test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
508ListCoord={''};
509dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable
510
511for ilist=1:numel(Field.Display.VarDimName)
512    dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
513    if isequal(dimnames,dim_var)
514        test_component(ilist)=1;
515    elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
516        test_coord(ilist)=1;
[582]517    end
518end
[648]519var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
520var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
521ListCoord=Field.Display.ListVarName([var_component var_coord]);
[204]522
[648]523%% set default coord selection
524if numel(find(test_coord))>3
[693]525     SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
526    if numel(SwitchVarIndexTime)<3
527        SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
528        set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
529    end
[648]530    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
[693]531    SwitchVarIndexTime_Callback([], [], handles)
[582]532end
[648]533if numel(var_component)<2
534    if numel(test_coord)<2
535        ListCoord={''};
536    else
537        set(handles.Coord_x,'Value',2)
538        set(handles.Coord_y,'Value',1)
539    end
[582]540else
[648]541    coord_val=1;
542    for ilist=1:numel(var_component)
543        ivar=var_component(ilist);
544        if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
545            Role=Field.Display.VarAttribute{ivar}.Role;
546            if strcmp(Role,'coord_x')
547                coord_val=ilist;
548            end
549        end
550    end
551    set(handles.Coord_x,'Value',coord_val)
[582]552end
[648]553set(handles.Coord_x,'String',ListCoord)
[582]554
555
[648]556%% set list of time coordinates
557menu=get(handles.SwitchVarIndexTime,'String');
558TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
559switch TimeOption
560    case 'variable'
561        if numel(find(test_coord))<3
562            ListTime={''};
563        else
564            ListTime=Field.Display.ListVarName(find(test_coord,end));
565        end
566        set(handles.TimeName,'Value',1)
567        set(handles.TimeName,'String',ListTime)
[693]568    case 'matrix index'
[648]569        if numel(find(test_coord))<3
570            ListTime={''};
571        else
572            ListTime=Field.Display.VarDimName{find(test_coord,end)};
573        end
574        set(handles.TimeName,'Value',1)
575        set(handles.TimeName,'String',ListTime)
576end 
577update_field(handles,YName)
[674]578         
[582]579%------------------------------------------------------------------------
[204]580% --- Executes on selection change in scalar menu.
[648]581%------------------------------------------------------------------------
[204]582function scalar_Callback(hObject, eventdata, handles)
[648]583
[586]584Field=get(handles.get_field,'UserData');
[648]585scalar_index=get(handles.scalar,'Value');
586scalar_menu=get(handles.scalar,'String');
587ScalarName=scalar_menu{scalar_index};
[204]588
[648]589%% set list of possible coordinates
590test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
591test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
592dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
[756]593if ~get(handles.CheckDimensionX,'Value') 
[693]594    %look for coordinate variables among the other variables
595    for ilist=1:numel(Field.Display.VarDimName)
596        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
597        if isequal(dimnames,dim_var)
598            test_component(ilist)=1;% the listed variable has the same dimension as the selected scalar-> possibly chosen as unstructured coordinate
599        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var), 1))%variable ilist is a 1D array which can be coordinate variable
600            test_coord(ilist)=1;
601        end
[648]602    end
[227]603end
[672]604var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
[648]605var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
[874]606var_coord(var_coord==scalar_index)=[];
607var_component(var_component==scalar_index)=[];
608ListCoord=Field.Display.ListVarName([var_coord var_component]);
[227]609
[648]610%% set default coord selection
[750]611% if numel(find(test_coord))>3
612%     SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
613%     if numel(SwitchVarIndexTime)<3
614%         SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
615%         set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
616%     end
617%     set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
618%     SwitchVarIndexTime_Callback([], [], handles)
619% end
[747]620
[672]621coord_val=[0 0];
622% look for labelled unstructured coordinates
623for ilist=1:numel(var_component)
624    ivar=var_component(ilist);
625    if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
626        Role=Field.Display.VarAttribute{ivar}.Role;
627        if strcmp(Role,'coord_x')
628            coord_val(1)=ilist;
629        elseif strcmp(Role,'coord_y')
630            coord_val(2)=ilist;
[874]631            elseif strcmp(Role,'coord_z')
632            coord_val(3)=ilist;
[227]633        end
634    end
635end
[672]636if numel(find(coord_val))<2
[874]637    if numel(var_coord)>=3
638         coord_val=[3 2 1];
639    elseif numel(var_coord)>=2
640       % coord_val=[numel(var_component)+2 numel(var_component)+1];
641       coord_val=[2 1];
[672]642    else
643        coord_val=[1 2];
644    end
645end
[747]646if  get(handles.CheckDimensionX,'Value')
[693]647    set(handles.Coord_x,'Value',2)
648    set(handles.Coord_x,'String',dim_var')
649else
650    set(handles.Coord_x,'Value',coord_val(1))
651    set(handles.Coord_x,'String',ListCoord)
652end
[752]653if  get(handles.CheckDimensionX,'Value')
[693]654    set(handles.Coord_y,'Value',1)
655    set(handles.Coord_y,'String',dim_var')
656else
657    set(handles.Coord_y,'Value',coord_val(2))
658    set(handles.Coord_y,'String',ListCoord)
659end
[752]660if  get(handles.CheckDimensionX,'Value')
[747]661    set(handles.Coord_z,'Value',1)
662    set(handles.Coord_z,'String',dim_var')
663else
664    set(handles.Coord_z,'Value',coord_val(2))
665    set(handles.Coord_z,'String',ListCoord)
666end
[227]667
[648]668%% set list of time coordinates
669menu=get(handles.SwitchVarIndexTime,'String');
670TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
671switch TimeOption
672    case 'variable'
673        if numel(find(test_coord))<3
674            ListTime={''};
675        else
676            ListTime=Field.Display.ListVarName(find(test_coord,end));
677        end
678        set(handles.TimeName,'Value',1)
679        set(handles.TimeName,'String',ListTime)
680    case 'dim index'
681        if numel(find(test_coord))<3
682            ListTime={''};
683        else
684            ListTime=Field.Display.VarDimName{find(test_coord,end)};
685        end
686        set(handles.TimeName,'Value',1)
687        set(handles.TimeName,'String',ListTime)
688end 
689update_field(handles,ScalarName)
[582]690
[648]691% --- Executes on button press in check_rgb.
692function check_rgb_Callback(hObject, eventdata, handles)
[582]693
694
695%------------------------------------------------------------------------
[204]696% --- Executes on selection change in vector_x.
[672]697%------------------------------------------------------------------------
[204]698function vector_x_Callback(hObject, eventdata, handles)
[672]699
[648]700vector_x_menu=get(handles.vector_x,'String');
701vector_x_index=get(handles.vector_x,'Value');
702vector_x=vector_x_menu{vector_x_index};
703vector_Callback(handles)
704update_field(handles,vector_x)
[227]705
[204]706%------------------------------------------------------------------------
[648]707% --- Executes on selection change in vector_x.
[204]708function vector_y_Callback(hObject, eventdata, handles)
709%------------------------------------------------------------------------
[648]710vector_y_menu=get(handles.vector_x,'String');
711vector_y_index=get(handles.vector_x,'Value');
712vector_y=vector_y_menu{vector_y_index};
713vector_Callback(handles)
714update_field(handles,vector_y)
[204]715
716%------------------------------------------------------------------------
717% --- Executes on selection change in vector_z.
718function vector_z_Callback(hObject, eventdata, handles)
719%------------------------------------------------------------------------
[648]720vector_z_menu=get(handles.vector_z,'String');
721vector_z_index=get(handles.vector_z,'Value');
722vector_z=vector_z_menu{vector_z_index};
723vector_Callback(handles)
724update_field(handles,vector_z)
[204]725
726%------------------------------------------------------------------------
727% --- Executes on selection change in vec_color.
728function vec_color_Callback(hObject, eventdata, handles)
[227]729%------------------------------------------------------------------------
[204]730index=get(handles.vec_color,'Value');
731string=get(handles.vec_color,'String');
732VarName=string{index};
[648]733vector_Callback(handles)
734update_field(handles,VarName)
[204]735
[227]736%------------------------------------------------------------------------
[648]737% --- Executes on selection change in vector_x or vector_y
738function vector_Callback( handles)
[227]739%------------------------------------------------------------------------
[648]740Field=get(handles.get_field,'UserData');
741vector_x_index=get(handles.vector_x,'Value');
742vector_y_index=get(handles.vector_y,'Value');
743vec_color_index=get(handles.vec_color,'Value');
[204]744
[648]745%% set list of possible coordinates
746test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate
[874]747test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate
[648]748check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn
749ListCoord={''};
750dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable
751if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index})
752    check_consistent=0;
753elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index})
754    check_consistent=0;
[204]755end
[672]756% the two vector components have consistent dimensions
[648]757if check_consistent
758    for ilist=1:numel(Field.Display.VarDimName)
759        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
760        if isequal(dimnames,dim_var)
761            test_component(ilist)=1;
762        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
763            test_coord(ilist)=1;
[204]764        end
765    end
[675]766    var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
[648]767    var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
[874]768    var_component(var_component==vector_x_index|var_component==vector_y_index)=[];
769    var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components form te possible list of coordinates
770    ListCoord=Field.Display.ListVarName([var_coord var_component]);
[648]771   
772    %% set default coord selection
773    if numel(find(test_coord))>3
774        set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
[204]775    end
[648]776    if numel(var_component)<2
777        if numel(test_coord)<2
778            ListCoord={''};
779        else
[874]780            if numel(test_coord)>=3
781                set(handles.Coord_x,'Value',3)
782                set(handles.Coord_y,'Value',2)
783                set(handles.Coord_z,'Value',1)
784            else
785                set(handles.Coord_x,'Value',2)
786                set(handles.Coord_y,'Value',1)
787            end
[204]788        end
789    else
[874]790        coord_val=[0 0 0];
[648]791        for ilist=1:numel(var_component)
792            ivar=var_component(ilist);
793            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role')
794                Role=Field.Display.VarAttribute{ivar}.Role;
795                if strcmp(Role,'coord_x')
796                    coord_val(1)=ilist;
797                elseif strcmp(Role,'coord_y')
798                    coord_val(2)=ilist;
[874]799                elseif strcmp(Role,'coord_z')
800                    coord_val(3)=ilist;
[648]801                end
[526]802            end
803        end
[675]804        if isempty(find(coord_val))
[672]805            coord_val=var_coord;% case of dimension coordinates
806        end
807        if numel(find(coord_val))<2
[675]808            %coord_val=[numel(var_component)+2 numel(var_component)+1];
[874]809            coord_val=[1 2 3];
[672]810        end
[648]811        set(handles.Coord_x,'Value',coord_val(1))
812        set(handles.Coord_y,'Value',coord_val(2))
[874]813        if numel(ListCoord)>=3
814            set(handles.Coord_z,'Value',coord_val(3))
815        end
[526]816    end
[204]817end
[874]818set(handles.Coord_z,'String',ListCoord)
[648]819set(handles.Coord_y,'String',ListCoord)
820set(handles.Coord_x,'String',ListCoord)
[204]821
822
[648]823%% set list of time coordinates
824menu=get(handles.SwitchVarIndexTime,'String');
825TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')};
826switch TimeOption
827    case 'variable'
828        if numel(find(test_coord))<3
829            ListTime={''};
830        else
831            ListTime=Field.Display.ListVarName(find(test_coord,end));
[204]832        end
[648]833        set(handles.TimeName,'Value',1)
834        set(handles.TimeName,'String',ListTime)
835    case 'dim index'
836        if numel(find(test_coord))<3
837            ListTime={''};
838        else
839            ListTime=Field.Display.VarDimName{find(test_coord,end)};
[204]840        end
[648]841        set(handles.TimeName,'Value',1)
842        set(handles.TimeName,'String',ListTime)
843end 
[204]844
[227]845%------------------------------------------------------------------------
[648]846% --- Executes on selection change in SwitchVarIndexX.
[227]847%------------------------------------------------------------------------
[648]848function SwitchVarIndexX_Callback(hObject, eventdata, handles)
[227]849
850%------------------------------------------------------------------------
[648]851% --- Executes on selection change in Coord_x.
[672]852%------------------------------------------------------------------------
[648]853function Coord_x_Callback(hObject, eventdata, handles)
[672]854
[648]855index=get(handles.Coord_x,'Value');
856string=get(handles.Coord_x,'String');
857VarName=string{index};
858update_field(handles,VarName)
[227]859
860%------------------------------------------------------------------------
[648]861% --- Executes on selection change in Coord_y.
[672]862%------------------------------------------------------------------------
[648]863function Coord_y_Callback(hObject, eventdata, handles)
[672]864
[648]865index=get(handles.Coord_y,'Value');
866string=get(handles.Coord_y,'String');
867VarName=string{index};
868update_field(handles,VarName)
[227]869
[646]870%------------------------------------------------------------------------
[648]871% --- Executes on selection change in Coord_z.
[672]872%------------------------------------------------------------------------
[648]873function Coord_z_Callback(hObject, eventdata, handles)
[672]874
[648]875index=get(handles.Coord_z,'Value');
876string=get(handles.Coord_z,'String');
877VarName=string{index};
878update_field(handles,VarName)
[581]879
[646]880%------------------------------------------------------------------------
[581]881% --- Executes on selection change in SwitchVarIndexTime.
[646]882%------------------------------------------------------------------------
[747]883
[581]884function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
[672]885
[648]886Field=get(handles.get_field,'UserData');
[581]887menu=get(handles.SwitchVarIndexTime,'String');
888option=menu{get(handles.SwitchVarIndexTime,'Value')};
[648]889
[581]890switch option
891    case 'file index'
[648]892        set(handles.TimeName, 'Visible','off')% the time is taken as the file index
[581]893    case 'attribute'
[648]894        set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes
[674]895        time_index=get(handles.TimeName,'UserData');    %select the input data
896        if isempty(time_index)
897            PreviousList=get(handles.TimeName, 'String');
898            if ~isempty(PreviousList)
899                PreviousAttr=PreviousList{get(handles.TimeName, 'Value')};
900                index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes),1);
901            end
[581]902        end
[674]903        if isempty(time_index)
904            time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% index of the attributes containing the string 'Time'
905        end     
[581]906        if ~isempty(time_index)
[674]907            set(handles.TimeName,'Value',time_index)
[581]908        else
[648]909            set(handles.TimeName,'Value',1)
[581]910        end
[648]911        set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute)
[674]912
[648]913    case 'variable'% TimeName menu represents the available variables
914        set(handles.TimeName, 'Visible','on')
[747]915        VarNbDim=cellfun('length',Field.Display.VarDimName); % check the nbre of dimensions of each input variable
916        TimeVarName=Field.Display.ListVarName(VarNbDim==1);% list of variables with a single dimension (candidate for time)
917        List=get(handles.TimeName,'String');% list of names on the menu for time
918        if isempty(List)
919            ind=1;
[581]920        else
[747]921            option=List{get(handles.TimeName,'Value')};% previous selected option
922            ind=find(strcmp(option,TimeVarName)); %check whether the previous selection is available in the newlist
923            if isempty(ind)
924                ind=1;
925            end
[581]926        end
[747]927        if ~isempty(TimeVarName)
928            set(handles.TimeName, 'Value',ind);% select first value in the menu if the option is not found
929            set(handles.TimeName, 'String',TimeVarName)% update the menu for time name
930        end
931    case 'matrix index'% TimeName menu represents the available dimensions
[693]932        set(handles.TimeName, 'Visible','on')     
933        set(handles.TimeName, 'Value',1);
934        set(handles.TimeName, 'String',Field.Display.ListDimName)
[581]935end
[752]936TimeName_Callback(hObject, [], handles)
[581]937
[648]938%-----------------------------------------------------------------------
939function update_field(handles,VarName)
940%-----------------------------------------------------------------------
941Field=get(handles.get_field,'UserData');
942index=name2index(VarName,Field.ListVarName);
943if ~isempty(index)
944    set(handles.variables,'Value',index+1)
945    variables_Callback(handles.variables, [], handles)
[644]946end
[648]947
[672]948%------------------------------------------------------------------------
949% --- give index numbers of the strings str in the list ListvarName
950% -----------------------------------------------------------------------
[648]951function VarIndex_y=name2index(cell_str,ListVarName)
[672]952
[648]953VarIndex_y=[];
954if ischar(cell_str)
955    for ivar=1:length(ListVarName)
956        varlist=ListVarName{ivar};
957        if isequal(varlist,cell_str)
958            VarIndex_y= ivar;
959            break
960        end
961    end
962elseif iscell(cell_str)
963    for isel=1:length(cell_str)
964        varsel=cell_str{isel};
965        for ivar=1:length(ListVarName)
966            varlist=ListVarName{ivar};
967            if isequal(varlist,varsel)
968                VarIndex_y=[VarIndex_y ivar];
969            end
970        end
971    end
972end
[693]973
974% --- Executes on button press in CheckDimensionY.
975function CheckDimensionX_Callback(hObject, eventdata, handles)
976FieldList=get(handles.FieldOption,'String');
977FieldOption=FieldList{get(handles.FieldOption,'Value')};
978switch FieldOption
979    case '1D plot'
980       
[771]981    case {'scalar'}
[693]982       scalar_Callback(hObject, eventdata, handles)
983    case 'vectors'
984end
985
[764]986% % --- Executes on button press in CheckDimensionY.
987% function CheckDimensionY_Callback(hObject, eventdata, handles)
988% FieldList=get(handles.FieldOption,'String');
989% FieldOption=FieldList{get(handles.FieldOption,'Value')};
990% switch FieldOption
991%     case '1D plot'
992%         
993%     case {'scalar','pick variables'}
994%        scalar_Callback(hObject, eventdata, handles)
995%     case 'vectors'
996% end
997%
998%
999% % --- Executes on button press in CheckDimensionZ.
1000% function CheckDimensionZ_Callback(hObject, eventdata, handles)
1001% FieldList=get(handles.FieldOption,'String');
1002% FieldOption=FieldList{get(handles.FieldOption,'Value')};
1003% switch FieldOption
1004%     case '1D plot'
1005%         
1006%     case 'scalar'
1007%        scalar_Callback(hObject, eventdata, handles)
1008%     case 'vectors'
1009% end
[693]1010
[747]1011% --- Executes on selection change in TimeName.
1012function TimeName_Callback(hObject, eventdata, handles)
[752]1013Field=get(handles.get_field,'UserData');
[747]1014index=get(handles.SwitchVarIndexTime,'Value');
[754]1015MenuIndex=get(handles.TimeName,'Value');
1016string=get(handles.TimeName,'String');
[756]1017TimeName='';%default
1018if ~isempty(string)&&iscell(string)
[754]1019TimeName=string{MenuIndex};
[756]1020end
[752]1021switch index
1022    case 1
1023        set(handles.num_TimeDimension,'String','')
1024        set(handles.TimeUnit,'String','index')
1025    case 2
1026        set(handles.num_TimeDimension,'String','')
[754]1027        attr_index=find(strcmpi([TimeName 'Unit'],Field.ListGlobalAttribute));% look for time unit
[752]1028        if ~isempty(attr_index)
1029            AttrName=Field.ListGlobalAttribute{attr_index};
1030            set(handles.TimeUnit,'String',Field.(AttrName))
[756]1031        else
1032            set(handles.TimeUnit,'String','')
[752]1033        end
1034    case {3 ,4}
1035        if index==3  % TimeName is used to chose a variable
[754]1036            VarIndex=name2index(TimeName,Field.ListVarName);
[752]1037            DimName=Field.VarDimName{VarIndex};
1038            DimIndex=name2index(DimName,Field.ListDimName);
1039            DimValue=Field.DimValue(DimIndex);
1040            set(handles.num_TimeDimension,'String',num2str(DimValue))
1041            unit='';
1042            if isfield(Field,'VarAttribute')&& isfield(Field.VarAttribute{VarIndex},'Unit')
1043                unit=Field.VarAttribute{VarIndex}.Unit;
1044            end
1045            set(handles.TimeUnit,'String',unit)
[754]1046            update_field(handles,TimeName)
[752]1047        elseif index==4% TimeName is used to chose a dimension
1048            DimName=string{MenuIndex};
1049            DimIndex=name2index(DimName,Field.ListDimName);
1050            DimValue=Field.DimValue(DimIndex);
1051            set(handles.num_TimeDimension,'String',num2str(DimValue))
1052            set(handles.TimeUnit,'String','index')
1053        end
[747]1054end
1055
1056
1057% --- Executes on button press in Check3D.
1058function Check3D_Callback(hObject, eventdata, handles)
[874]1059if get(handles.Check3D,'Value')% 3D fields
[747]1060    status='on';
[874]1061else% fields studied as 2D
[747]1062    status='off';
[874]1063 
[747]1064end
1065set(handles.Coord_z,'Visible',status)
[752]1066% set(handles.CheckDimensionZ,'Visible',status)
[747]1067set(handles.Z_title,'Visible',status)
1068set(handles.vector_z,'Visible',status)
1069set(handles.W_title,'Visible',status)   
[874]1070   Field=get(handles.get_field,'UserData');
1071    if Field.MaxDim>=3% for 3D fields, propose to use the third variable as time
1072        menu=get(handles.SwitchVarIndexTime,'String');
1073        val=find(strcmp('variable',menu));
1074        if ~isempty(val)
1075            set(handles.SwitchVarIndexTime,'Value',val)
1076            SwitchVarIndexTime_Callback(handles.SwitchVarIndexTime,[], handles)
1077        end
1078    end
1079
1080%------------------------------------------------------------------------
1081% --- Executes on button press in OK.
1082%------------------------------------------------------------------------
1083function OK_Callback(hObject, eventdata, handles)
1084handles.output=read_GUI(handles.get_field);
1085guidata(hObject, handles);% Update handles structure
1086uiresume(handles.get_field);
1087drawnow
1088% this function then activate get_field_OutputFcn
1089
1090%------------------------------------------------------------------------
1091% --- Executes when the GUI is closed by the mouse on upper right corner.
1092%------------------------------------------------------------------------
1093function closefcn(hObject, eventdata, handles)
1094handles.output=[];
1095guidata(hObject, handles);% Update handles structure
1096uiresume(handles.get_field);
1097drawnow
1098
1099%------------------------------------------------------------------------
1100% --- Outputs from this function are returned to the command line.
1101%------------------------------------------------------------------------
1102function varargout = get_field_OutputFcn(hObject, eventdata, handles)
1103
1104varargout{1} =handles.output;
1105delete(handles.get_field)
Note: See TracBrowser for help on using the repository browser.