source: trunk/src/get_field.m @ 1040

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

get_field improved to select variables, uvmat rationalized with respect to input file types

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