source: trunk/src/get_field.m @ 1199

Last change on this file since 1199 was 1197, checked in by sommeria, 9 days ago

bugs repaired

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