source: trunk/src/get_field.m @ 1045

Last change on this file since 1045 was 1045, checked in by sommeria, 6 years ago

find field cells improved

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