source: trunk/src/get_field.m @ 854

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