source: trunk/src/get_field.m @ 1086

Last change on this file since 1086 was 1084, checked in by sommeria, 4 years ago

various updates

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