source: trunk/src/get_field.m @ 764

Last change on this file since 764 was 764, checked in by sommeria, 10 years ago

improvement of movie-pair for uvmat and introduction of a separate window SetPair? in series.

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