Home > . > get_field.m

# get_field

## PURPOSE

'get_field': display variables and attributes from a Netcdf file, and plot selected fields

## SYNOPSIS

function varargout = get_field(varargin)

## DESCRIPTION

    'get_field': display variables and attributes from a Netcdf file, and plot selected fields
    ------------------------------------------------------------------------
    function varargout = get_field(varargin)
     associated with the GUI get_field.fig

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
         This file is part of the toolbox UVMAT.

         UVMAT is free software; you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
         the Free Software Foundation; either version 2 of the License, or
         (at your option) any later version.

         UVMAT is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
         GNU General Public License (file UVMAT/COPYING.txt) for more details.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

## CROSS-REFERENCE INFORMATION

This function calls:

- cell2tab 'cell2tab': transform a Matlab cell in a character array suitable for display in a table
- check_functions 'check_functions': check the path and modification date for all the
- find_field_indices 'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions
- msgbox_uvmat 'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
- nc2struct 'nc2struct': transform a netcdf file in a corresponding matlab structure
- peaklock 'peaklock': determines peacklocking errors from velocity histograms.
- plot_field 'plot_field': plot any field with the structure defined in the uvmat package
- read_get_field 'read_get_field': read the list of selected variables from the GUI get_field (SAME AS THE FIRST
- update_menu 'update_menu': find an input string in a menu, add it to the menu at the penultimate position if it does not exist
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

- series 'series': master function associated to the GUI series.m for analysis field series
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function get_field_OpeningFcn(hObject, eventdata, handles,filename,Field,haxes)
- function varargout = get_field_OutputFcn(hObject, eventdata, handles)
- function browse_Callback(hObject, eventdata, handles)
- function inputfile_Callback(hObject, eventdata, handles)
- function Field_input(eventdata,handles,Field)
- function abscissa_Callback(hObject, eventdata, handles)
- function ordinate_Callback(hObject, eventdata, handles)
- function vector_x_Callback(hObject, eventdata, handles)
- function vector_y_Callback(hObject, eventdata, handles)
- function scalar_Callback(hObject, eventdata, handles)
- function update_field(hObject, eventdata, handles,VarName)
- function update_UserData(handles)
- function plot_Callback(hObject, eventdata, handles)
- function PLOT(hget_field)
- function plot_histo_Callback(hObject, eventdata, handles)
- function peaklocking(handles)
- function variables_Callback(hObject, eventdata, handles)
- function check_1Dplot_Callback(hObject, eventdata, handles)
- function check_scalar_Callback(hObject, eventdata, handles)
- function check_vector_Callback(hObject, eventdata, handles)
- function mouse_up_gui(ggg,eventdata,handles)
- function ACTION_Callback(hObject, eventdata, handles)
- function HELP_Callback(hObject, eventdata, handles)
- function browse_fig(menu_handle)
- function list_fig_Callback(hObject, eventdata, handles)
- function VarIndex_y=name2index(cell_str,ListVarName)
- function vector_z_Callback(hObject, eventdata, handles)
- function coord_z_scalar_Callback(hObject, eventdata, handles)
- function coord_x_scalar_Callback(hObject, eventdata, handles)
- function coord_y_scalar_Callback(hObject, eventdata, handles)
- function coord_y_vectors_Callback(hObject, eventdata, handles)
- function coord_x_vectors_Callback(hObject, eventdata, handles)
- function vec_color_Callback(hObject, eventdata, handles)
- function MenuOpen_Callback(hObject, eventdata, handles)
- function MenuExport_Callback(hObject, eventdata, handles)
- function MenuBrowse_Callback(hObject, eventdata, handles)
- function MenuFile_1_Callback(hObject, eventdata, handles)
- function MenuFile_2_Callback(hObject, eventdata, handles)
- function MenuFile_3_Callback(hObject, eventdata, handles)
- function MenuFile_4_Callback(hObject, eventdata, handles)
- function MenuFile_5_Callback(hObject, eventdata, handles)
- function ExportField_Callback(hObject, eventdata, handles)

## SOURCE CODE

    0001 %'get_field': display variables and attributes from a Netcdf file, and plot selected fields
    0002 %------------------------------------------------------------------------
    0003 %function varargout = get_field(varargin)
    0004 % associated with the GUI get_field.fig
    0005 %
    0006 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0007 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0008 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0009 %     This file is part of the toolbox UVMAT.
    0010 %
    0011 %     UVMAT is free software; you can redistribute it and/or modify
    0012 %     it under the terms of the GNU General Public License as published by
    0013 %     the Free Software Foundation; either version 2 of the License, or
    0014 %     (at your option) any later version.
    0015 %
    0016 %     UVMAT is distributed in the hope that it will be useful,
    0017 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0018 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0019 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0020 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0021
    0022 function varargout = get_field(varargin)
    0023
    0024 % Last Modified by GUIDE v2.5 11-Nov-2009 18:59:57
    0025
    0026 % Begin initialization code - DO NOT EDIT
    0027 gui_Singleton = 0;
    0028 gui_State = struct('gui_Name',       mfilename, ...
    0029                    'gui_Singleton',  gui_Singleton, ...
    0030                    'gui_OpeningFcn', @get_field_OpeningFcn, ...
    0031                    'gui_OutputFcn',  @get_field_OutputFcn, ...
    0032                    'gui_LayoutFcn',  [] , ...
    0033                    'gui_Callback',   []);
    0034 if nargin & isstr(varargin{1})
    0035     gui_State.gui_Callback = str2func(varargin{1});
    0036 end
    0037
    0038 if nargout
    0039     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    0040 else
    0041     gui_mainfcn(gui_State, varargin{:});
    0042 end
    0043 % End initialization code - DO NOT EDIT
    0044
    0045
    0046 % --- Executes just before get_field is made visible.
    0047 function get_field_OpeningFcn(hObject, eventdata, handles,filename,Field,haxes)
    0048
    0049 set(handles.dimensions,'enable','on')% should be put by guide
    0050 browse_fig(handles.list_fig)
    0051
    0052 % Choose default command line output for get_field
    0053 handles.output = hObject;
    0054
    0055 % Update handles structure
    0056 guidata(hObject, handles);
    0057 pathuvmat=fileparts(which('uvmat'));
    0058 addpath(fullfile(pathuvmat,'FIELD_FCT'))
    0059 set(handles.attributes,'enable','on')% TO BE SET BY GUIDE
    0060 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})%set mouse click action function
    0061 if exist('filename','var')& ischar(filename)
    0062     set(handles.inputfile,'String',filename)
    0063     inputfile_Callback(hObject, eventdata, handles)
    0064 else
    0065     set(handles.inputfile,'String','')
    0066     %loads the information stored in prefdir to initiate the browser and the list of functions
    0067     menu_str={'PLOT'};%list of functions included in 'get_field.m'
    0068     %menu_str(end)=[];%remove from the list the last option 'more...'
    0069     path_get_field=which('get_field');%path of the function 'get_field'
    0070     for ilist=1:length(menu_str)
    0071         fct_path{ilist,1}=path_get_field;%paths of the fuctions buil-in in 'get_field.m'
    0072     end
    0073      dir_perso=prefdir;
    0074      profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    0075      if exist(profil_perso,'file')
    0076         % menu={'PLOT';'raw2phys';'histogram';'FFT';'peaklocking'};
    0077           h=load (profil_perso);
    0078          if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
    0079              for ilist=1:length(h.get_field_fct)
    0080                 [path,file]=fileparts(h.get_field_fct{ilist});
    0081                 fct_path=[fct_path; {path}];%concatene the list of paths
    0082                 menu_str=[menu_str; {file}];
    0083              end
    0084
    0085          end
    0086      end
    0087      menu_str=[menu_str;{'more...'}];
    0088      set(handles.ACTION,'String',menu_str)
    0089      set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
    0090      % display the GUI for the default action 'check_files'
    0091      ACTION_Callback(hObject, eventdata, handles)
    0092 end
    0093 %                  menu=[menu;h.fct_get_field];
    0094 %                  menu=[menu;{'more...'}];
    0095 %                  fct_path=h.fct_path_get_field;
    0096 %                  set(handles.ACTION,'String',menu)
    0097 %                  set(handles.ACTION,'UserData',fct_path)
    0098 %                  for ipath=1:length(fct_path)
    0099 %                      if exist(fct_path{ipath},'dir')
    0100 %                         addpath(fct_path{ipath})
    0101 %                      end
    0102 %                  end
    0103 %          end
    0104 %      end
    0105 % end
    0106 if exist('Field','var') & isstruct(Field)
    0107         Field_input(eventdata,handles,Field)
    0108         if exist('haxes','var')
    0109             Field.PlotAxes=haxes;
    0110         end
    0111     set(hObject,'UserData',Field);
    0112 end
    0113
    0114
    0115
    0116
    0117
    0118
    0119 %-----------------------------------------------------------
    0120 % --- Outputs from this function are returned to the command line.
    0121 function varargout = get_field_OutputFcn(hObject, eventdata, handles)
    0122 varargout{1} = handles.output;
    0123
    0124 %-----------------------------------------------------------
    0125 % --- Executes on button press in browse.
    0126 function browse_Callback(hObject, eventdata, handles)
    0127
    0128
    0129
    0130
    0131 %---------------------------------------------------------
    0132 function inputfile_Callback(hObject, eventdata, handles)
    0133 inputfile=get(handles.inputfile,'String');
    0134 Field=nc2struct(inputfile,[]);% reads only the lists of fields, dimensions and attributes
    0135 hfig=get(handles.inputfile,'parent');
    0136 set(hfig,'UserData',Field);
    0137 Field_input(eventdata,handles,Field);
    0138
    0139
    0140 %---------------------------------------------------------
    0141 function Field_input(eventdata,handles,Field)
    0142
    0143 if isfield(Field,'ListDimName')
    0144     Tabcell(:,1)=Field.ListDimName;
    0145     for iline=1:length(Field.ListDimName)
    0146         Tabcell{iline,2}=num2str(Field.DimValue(iline));
    0147     end
    0148     Tabchar=cell2tab(Tabcell,'=');
    0149     set(handles.dimensions,'String',Tabchar)
    0150 end
    0151 if ~isfield(Field,'ListVarName')
    0152     return
    0153 end
    0154 Txt=Field.ListVarName;
    0155 set(handles.variables,'Value',1)
    0156 set(handles.variables,'String',[{'*'} Txt])
    0157 variables_Callback(handles.variables,[], handles)
    0158 set(handles.abscissa,'String',[{''} Txt ])
    0159 set(handles.ordinate,'String',Txt)
    0160 set(handles.vector_x,'String',[Txt ])
    0161 set(handles.vector_y,'String',[Txt ])
    0162 set(handles.vector_z,'String',[{''} Txt ])
    0163 set(handles.vec_color,'String',[{''} Txt ])
    0164 set(handles.coord_x_scalar,'String',[{''} Txt ])
    0165 set(handles.coord_y_scalar,'String',[{''} Txt ])
    0166 set(handles.coord_x_vectors,'String',[{''} Txt ])
    0167 set(handles.coord_y_vectors,'String',[{''} Txt ])
    0168 set(handles.coord_z_scalar,'String',[{''} Txt ])
    0169 set(handles.coord_z_vectors,'String',[{''} Txt ])
    0170 set(handles.scalar,'Value',1)
    0171 set(handles.scalar,'String', Txt )
    0172
    0173 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
    0174 if ~isempty(errormsg)
    0175     msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_indices: ' errormsg])
    0176     return
    0177 end
    0178 [maxdim,imax]=max(NbDim);
    0179
    0180 if maxdim>=3
    0181     set(handles.vector_z,'Visible','on')
    0182     set(handles.vector_z,'String',[{''} Txt ])
    0183     set(handles.coord_z_vectors,'Visible','on')
    0184     set(handles.coord_z_vectors,'String',[{''} Txt ])
    0185     set(handles.coord_z_scalar,'Visible','on')
    0186     set(handles.coord_z_scalar,'String',[{''} Txt ])
    0187 else
    0188     set(handles.vector_z,'Visible','off')
    0189     set(handles.coord_z_vectors,'Visible','off')
    0190     set(handles.coord_z_scalar,'Visible','off')
    0191 end
    0192 if maxdim>=2
    0193     set(handles.check_1Dplot,'Value',0)
    0194     if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y)
    0195         set(handles.check_vector,'Value',1)
    0196         set(handles.vector_x,'Value',VarType{imax}.vector_x)
    0197         set(handles.vector_y,'Value',VarType{imax}.vector_y)
    0198         set(handles.check_scalar,'Value',0)
    0199     else
    0200         set(handles.check_scalar,'Value',1)
    0201         set(handles.check_vector,'Value',0)
    0202         if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1
    0203             set(handles.scalar,'Value',VarType{imax}.scalar(1))
    0204         end
    0205     end
    0206     check_1Dplot_Callback(handles.check_1Dplot, eventdata, handles)
    0207     check_scalar_Callback(handles.check_scalar, eventdata, handles)
    0208     check_vector_Callback(handles.check_vector, eventdata, handles)
    0209 end
    0210
    0211
    0212
    0213 %----------------------------------------------------------------------
    0214 % --- Executes on selection change in abscissa.
    0215 function abscissa_Callback(hObject, eventdata, handles)
    0216  hselect_field=get(handles.inputfile,'parent');
    0217  Field=get(hselect_field,'UserData');%current input field
    0218  xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
    0219 % test_2D=get(handles.check_vector,'Value');% =1 for vector fields
    0220 % test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
    0221 %if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
    0222 %     Txt=Field.ListVarName;
    0223 %     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
    0224 %     xindex=[];
    0225 % else
    0226      xlist=get(handles.abscissa,'String');%list of abscissa
    0227      xname=xlist{xdispindex}; %selected variable name
    0228      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
    0229      if ~isempty(xindex)
    0230         set(handles.variables,'Value',xindex+1)
    0231         variables_Callback(hObject, eventdata, handles)
    0232      end
    0233 %     set(handles.variables,'Value',xindex+1)%outline  in the list of variables
    0234 %     variables_Callback(hObject, eventdata, handles)  %display properties of the variable (dim, attributes)
    0235 %     if  ~test_2D &  ~test_scalar% look for possible varaibles to plot in ordinate
    0236 %         index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
    0237 %         VarIndex=[];
    0238 %         for ilist=1:length(Field.VarDimIndex)%detect
    0239 %             index_i=Field.VarDimIndex{ilist};
    0240 %             if ~isempty(index_i)
    0241 %                 if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, plot is possible
    0242 %                     VarIndex=[VarIndex ilist];
    0243 %                 end
    0244 %             end
    0245 %         end
    0246 % %         set(handles.ordinate,'Value',1)
    0247 %         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
    0248 %     end
    0249 % end
    0250 %
    0251 % update_UserData(handles)
    0252
    0253 %----------------------------------------------------------
    0254 function ordinate_Callback(hObject, eventdata, handles)
    0255 %update_field(hObject, eventdata, handles)
    0256 % A REVOIR
    0257 hselect_field=get(handles.inputfile,'parent');
    0258 Field=get(hselect_field,'UserData');
    0259 % xindex=get(handles.abscissa,'Value');
    0260 list=get(handles.ordinate,'String');
    0261 yindex=get(handles.ordinate,'Value');
    0262 yindex=name2index(list{yindex(1)},Field.ListVarName);
    0263 if ~isempty(yindex)
    0264     set(handles.variables,'Value',yindex+1)
    0265     variables_Callback(hObject, eventdata, handles)
    0266 end
    0267 [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
    0268 for icell=1:numel(CellVarIndex)
    0269     VarIndex=CellVarIndex{icell};
    0270     if ~isempty(find(VarIndex==yindex)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex))
    0271         cell_select=icell;
    0272         break
    0273     end
    0274 end
    0275
    0276 val=get(handles.abscissa,'Value');
    0277 set(handles.abscissa,'Value',min(val,2));
    0278 coord_x_index=VarType{cell_select}.coord;
    0279 coord_x_index=coord_x_index(find(coord_x_index));
    0280 set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
    0281 % Field.VarIndex.y=yindex;
    0282 % set(hselect_field,'UserData',Field);
    0283 %update_UserData(handles)
    0284
    0285 %----------------------------------------------------------
    0286 % --- Executes on selection change in vector_y.
    0287 function vector_x_Callback(hObject, eventdata, handles)
    0288 Aindex=get(handles.vector_x,'Value');
    0289 Astring=get(handles.vector_x,'String');
    0290 VarName=Astring{Aindex};
    0291 %update_field(hObject, eventdata, handles,VarName)
    0292
    0293 %----------------------------------------------------------
    0294 % --- Executes on selection change in vector_y.
    0295 function vector_y_Callback(hObject, eventdata, handles)
    0296 Aindex=get(handles.vector_y,'Value');
    0297 Astring=get(handles.vector_y,'String');
    0298 VarName=Astring{Aindex};
    0299 %update_field(hObject, eventdata, handles,VarName)
    0300
    0301 %-------------------------------------------------------
    0302 % --- Executes on selection change in vector_y.
    0303 function scalar_Callback(hObject, eventdata, handles)
    0304
    0305 Aindex=get(handles.scalar,'Value');
    0306 Astring=get(handles.scalar,'String');
    0307 VarName=Astring{Aindex};
    0308 %update_field(hObject, eventdata, handles,VarName)
    0309
    0310 %---------------------------------
    0311 function update_field(hObject, eventdata, handles,VarName)
    0312 % VarName= input variable name for scalar or vector plots
    0313 %if ischar(VarName)
    0314 hselect_field=get(handles.inputfile,'parent');
    0315 Field=get(hselect_field,'UserData');
    0316 ivar_sel=[];%default
    0317 for ivar=1:length(Field.ListVarName)%detect
    0318     if isequal(Field.ListVarName{ivar},VarName)
    0319         ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName
    0320         break
    0321     end
    0322 end
    0323 if isempty(ivar_sel)
    0324     return
    0325 end
    0326 set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed  list 'variables'
    0327 variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable
    0328
    0329 index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable
    0330 DimValue=Field.DimValue(index);%dimension values of the input variable
    0331 ind_1=find(DimValue==1);
    0332 index(ind_1)=[];%Mremove singletons
    0333
    0334
    0335 % detect possible variables for abscissa and ordinate
    0336 VarIndex=[];%initiate list of selected variable indices
    0337 ind_coordvar=[]; %initiate list of coordinate variables
    0338 for ilist=1:length(Field.VarDimIndex)
    0339     if ~isequal(ilist,ivar_sel)
    0340         index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist
    0341         if length(index_i)>1
    0342             DimValue=Field.DimValue(index_i);
    0343             ind_1=find(DimValue==1);
    0344             index_i(ind_1)=[];%Mremove singletons
    0345             if isequal(index,index_i)
    0346                 VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable
    0347             end
    0348         else
    0349             idim=find(index==index_i(1));
    0350             if ~isempty(idim)
    0351                  VarIndex=[VarIndex ilist]; %possible dimension variable
    0352                  if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist})
    0353                      ind_coordvar=[ind_coordvar length(VarIndex)];
    0354                  end
    0355             end
    0356         end
    0357     end
    0358 end
    0359 % val=get(handles.abscissa,'Value');
    0360 % if val>length(Field.ListVarName(VarIndex))+1
    0361 %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    0362 % end
    0363 % val=get(handles.ordinate,'Value');
    0364 % if val>length(Field.ListVarName(VarIndex))+1
    0365 %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    0366 % end
    0367 % val=get(handles.coord_z_vectors_scalar,'Value');
    0368 % if val>length(Field.ListVarName(VarIndex))+1
    0369 %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
    0370 % end
    0371 set(handles.abscissa,'Value',1)%default
    0372 set(handles.ordinate,'Value',1)%default
    0373 set(handles.coord_z_scalar,'Value',1)%default
    0374 set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ])
    0375 set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ])
    0376 set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ])
    0377 if length(ind_coordvar)>=1
    0378     set(handles.abscissa,'Value',ind_coordvar(1)+1)
    0379 elseif length(index)==1 && length(VarIndex)>=1
    0380     set(handles.abscissa,'Value',2)
    0381 end
    0382 if length(ind_coordvar)>=2
    0383     set(handles.ordinate,'Value',ind_coordvar(2)+1)
    0384 elseif length(index)==1 && length(VarIndex)>=2
    0385     set(handles.ordinate,'Value',3)
    0386 end
    0387 if length(ind_coordvar)>=3
    0388     set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1)
    0389 elseif length(index)==1 && length(VarIndex)>=3
    0390     set(handles.coord_z_scalar,'Value',4)
    0391 end
    0392
    0393 %---------------------------------------------------------
    0394 % update the UserData Field for use of the selected variables outsde get_field (taken from plot_Callback)
    0395 function update_UserData(handles)
    0396 %---------------------------------------------------------
    0397 return
    0398 % global SubField
    0399 hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
    0400 Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
    0401 if isfield(Field,'VarAttribute')
    0402     VarAttribute=Field.VarAttribute;
    0403 else
    0404     VarAttribute={};
    0405 end
    0406
    0407
    0408 % select the indices of field variables for 2D plots
    0409 test_check_1Dplot=get(handles.check_1Dplot,'Value');
    0410 test_scalar=get(handles.check_scalar,'Value');
    0411 test_vector=get(handles.check_vector,'Value');
    0412
    0413 %transform if needed (calibration)
    0414 list=get(handles.menu_coord,'String');
    0415 index=get(handles.menu_coord,'Value');
    0416 transform=list{index};
    0417 if ~isequal(transform,'')
    0418     Field=feval(transform,Field);
    0419 end
    0420 VarIndex.u=[];
    0421 VarIndex.v=[];
    0422 VarIndex.w=[];
    0423 VarIndex.A=[];
    0424 VarIndex_tot=[];
    0425 iuA=[];
    0426 if test_scalar
    0427     Astring=get(handles.scalar,'String');
    0428     Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
    0429     list_var=Astring(Aindex);
    0430     VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
    0431     VarIndex_tot= [VarIndex_tot VarIndex.A];
    0432     DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
    0433     DimValue=Field.DimValue(DimIndex);
    0434     ind=find(DimValue==1);
    0435     DimIndex(ind)=[];%Mremove singleton
    0436 end
    0437 if test_vector
    0438     Ustring=get(handles.vector_x,'String');
    0439     Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
    0440     list_var=Ustring{Uindex};%name of the selected scalar
    0441     VarIndex.u=name2index(list_var,Field.ListVarName);
    0442     Vstring=get(handles.vector_y,'String');
    0443     Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
    0444     list_var=Ustring{Vindex};%name of the selected scalar
    0445     VarIndex.v=name2index(list_var,Field.ListVarName);
    0446     if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
    0447         iuA=VarIndex.A; %same variable used for vector and scalar
    0448         VarIndex_tot(iuA)=[];
    0449     end
    0450     VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
    0451     %dimensions
    0452     DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
    0453     DimValue=Field.DimValue(DimIndex_u);
    0454     ind=find(DimValue==1);
    0455     DimIndex_u(ind)=[];%Mremove singleton
    0456     DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
    0457     DimValue=Field.DimValue(DimIndex_v);
    0458     ind=find(DimValue==1);
    0459     DimIndex_v(ind)=[];%Mremove singleton
    0460     if ~isequal(DimIndex_u,DimIndex_v)
    0461         warndlg_uvmat('inconsistent dimensions for u and v','ERROR')
    0462         set(handles.vector_y,'Value',1);
    0463         return
    0464     elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
    0465          warndlg_uvmat('inconsistent dimensions for vector and scalar represented as vector color','ERROR')
    0466          set(handles.scalar,'Value',1);
    0467          return
    0468     end
    0469     DimIndex=DimIndex_u;
    0470     %TODO possibility of selecting 3 times the same variable for u, v, w components
    0471 end
    0472
    0473
    0474 % select the variable  index (or indices) for z coordinates
    0475 test_grid=0;
    0476 if test_scalar | test_vector
    0477     nbdim=length(DimIndex);
    0478     if nbdim > 3
    0479         warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
    0480         return
    0481     else
    0482         perm_ind=[1:nbdim];
    0483     end
    0484     if nbdim==3
    0485         zstring=get(handles.coord_z_vectors_scalar,'String');
    0486         zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
    0487         list_var=zstring(zindex);
    0488         VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
    0489         if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
    0490             if zindex ~= 1
    0491                 set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
    0492                 return
    0493             end
    0494         else
    0495             VarIndex_tot=[VarIndex_tot VarIndex_z];
    0496             DimIndex_z=Field.VarDimIndex{VarIndex_z};
    0497             DimValue=Field.DimValue(DimIndex_z);
    0498             ind=find(DimValue==1);
    0499             DimIndex_z(ind)=[];%Mremove singleton
    0500             if isequal(DimIndex_z,DimIndex)
    0501                 VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
    0502             elseif length(DimIndex_z)==1
    0503                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
    0504                 ind_z=find(DimIndex==DimIndex_z(1));
    0505                 perm_ind(ind_z)=1;
    0506                 test_grid=1;
    0507             else
    0508                 warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
    0509                 return
    0510             end
    0511         end
    0512 %         if ~isempty(VarIndex_z)
    0513 %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable
    0514 %             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
    0515 %                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
    0516 %                 ind_z=find(DimIndex==DimIndex_z(1));
    0517 %                 perm_ind(ind_z)=1;
    0518 %                 test_grid=1;
    0519 %             end
    0520 %         end
    0521     end
    0522 end
    0523
    0524 % select the variable  index (or indices) for ordinate
    0525 ystring=get(handles.ordinate,'String');
    0526 yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
    0527 list_var=ystring(yindex);
    0528 VarIndex.y=name2index(list_var,Field.ListVarName);
    0529 if isequal(VarIndex.A,VarIndex.y)
    0530     set(handles.coord_y_scalar,'Value',1)
    0531 elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
    0532    set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
    0533 else
    0534     for ivar=1:length(VarIndex.y)
    0535         VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
    0536     end
    0537     VarIndex_tot=[VarIndex_tot VarIndex.y];
    0538 end
    0539 if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
    0540     DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
    0541     if length(DimIndex_y)==1
    0542         ind_y=find(DimIndex==DimIndex_y(1));
    0543         test_grid=1;
    0544         if nbdim==3
    0545             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    0546             perm_ind(ind_y)=2;
    0547         elseif nbdim==2
    0548             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    0549              perm_ind(ind_y)=1;
    0550         end
    0551     elseif test_grid
    0552         warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')
    0553     end
    0554 end
    0555
    0556 %select the variable index for the abscissa
    0557 xstring=get(handles.abscissa,'String');
    0558 xindex=get(handles.abscissa,'Value');
    0559 list_var=xstring(xindex);
    0560 VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
    0561 if length(VarIndex.x)==1
    0562     DimIndex_x=Field.VarDimIndex{VarIndex.x};
    0563     DimValue=Field.DimValue(DimIndex_x);
    0564     ind=find(DimValue==1);
    0565     DimIndex_x(ind)=[];%Mremove singleton
    0566     VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable
    0567 %     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
    0568     index_detect=find(VarIndex_tot==VarIndex.x);
    0569 else
    0570     index_detect=[];%coord x variable not already used
    0571 end
    0572 if isempty(index_detect)
    0573     VarIndex_tot=[VarIndex_tot VarIndex.x];
    0574 elseif ~test_check_1Dplot
    0575     VarIndex.x=[];
    0576     set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
    0577 end
    0578
    0579 if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
    0580     DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
    0581     if length(DimIndex_x)==1
    0582         ind_x=find(DimIndex==DimIndex_x(1));
    0583         if nbdim==3
    0584             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    0585             perm_ind(ind_x)=3;
    0586         elseif nbdim==2
    0587             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    0588              perm_ind(ind_x)=2;
    0589         end
    0590         if isequal(perm_ind,1:nbdim)
    0591             test_grid=0;
    0592         end
    0593         DimIndex=DimIndex(perm_ind);
    0594     elseif test_grid
    0595         warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')
    0596     end
    0597     if isequal(DimIndex_x,DimIndex)
    0598                 VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
    0599     end
    0600 end
    0601
    0602 %defined the selected sub-field SubField
    0603 SubField.ListGlobalAttribute{1}='InputFile';
    0604 SubField.InputFile=get(handles.inputfile,'String');
    0605 SubField.ListDimName=Field.ListDimName;
    0606 SubField.DimValue=Field.DimValue;
    0607 SubField.ListVarName=Field.ListVarName(VarIndex_tot);
    0608 SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
    0609
    0610 testperm=0;
    0611 testattr=0;
    0612 for ivar=VarIndex.u
    0613     VarAttribute{ivar}.Role='vector_x';
    0614     testattr=1;
    0615     if test_grid
    0616         VarDimIndex{ivar}=DimIndex; %permute dimensions
    0617         testperm=1;
    0618     end
    0619 end
    0620 for ivar=VarIndex.v
    0621     VarAttribute{ivar}.Role='vector_y';
    0622     testattr=1;
    0623      if test_grid
    0624         VarDimIndex{ivar}=DimIndex;%permute dimensions
    0625         testperm=1;
    0626     end
    0627 end
    0628 for ivar=VarIndex.A
    0629     if test_grid
    0630         VarDimIndex{ivar}=DimIndex;%permute dimensions
    0631         testperm=1;
    0632     end
    0633     if isempty(iuA)
    0634         VarAttribute{ivar}.Role='scalar';%Role =scalar
    0635         testattr=1;
    0636     else
    0637        VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
    0638        nbattr=length(VarAttribute);
    0639        VarAttribute{nbattr}.Role='scalar';
    0640        testattr=1;
    0641     end
    0642 end
    0643 if testperm
    0644     SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
    0645 end
    0646 if testattr
    0647     SubField.VarAttribute=VarAttribute(VarIndex_tot);
    0648 end
    0649 set(hselect_field,'UserData',Field)
    0650
    0651 %---------------------------------------------------------
    0652 % --- Executes on button press in plot.
    0653 function plot_Callback(hObject, eventdata, handles)
    0654 %---------------------------------------------------------
    0655 list=get(handles.ACTION,'String');
    0656 index=get(handles.ACTION,'Value');
    0657 ACTION=list{index};
    0658 hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
    0659 feval(ACTION,hselect_field);
    0660 browse_fig(handles.list_fig); %update the list of new existing figures
    0661
    0662 %---------------------------------------------------------
    0663 % --- Executes on button press in plot.
    0664 function PLOT(hget_field)
    0665 %---------------------------------------------------------
    0666 [SubField,errormsg]=read_get_field(hget_field);
    0667 handles=guidata(hget_field);
    0668 list_fig=get(handles.list_fig,'String');
    0669 val=get(handles.list_fig,'Value');
    0670 if strcmp(list_fig{val},'uvmat')
    0671     uvmat(SubField)
    0672 else
    0673 hfig=str2num(list_fig{val});% chosen figure number from tyhe GUI
    0674 if isempty(hfig)
    0675     hfig=figure;
    0676     list_fig=[list_fig;num2str(hfig)];
    0677     set(handles.list_fig,'String',list_fig);
    0678     haxes=axes;
    0679 else
    0680     figure(hfig);
    0681 end
    0682 haxes=findobj(hfig,'Type','axes');
    0683 plot_field(SubField,haxes)
    0684 end
    0685
    0686
    0687 %
    0688 % return
    0689 %  testuvmat=0;
    0690 %     if test_scalar|test_vector
    0691 %          [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
    0692 %          NbDim=max(NbDim);
    0693 %          if NbDim==3
    0694 %            testuvmat=1; %uvmat interface needed for 3D plots
    0695 %          end
    0696 %     end
    0697 %     if iscell(list_fig)
    0698 %         plot_fig=list_fig{fig_index};
    0699 %     else
    0700 %         plot_fig='new fig...';%new plotting axes must be created
    0701 %     end
    0702 %     if isequal(plot_fig,'new fig...') &  (test_scalar|test_vector)
    0703 %         plot_fig='uvmat';%use uvmat for a new fig
    0704 %     end
    0705 %     if testuvmat
    0706 %         plot_fig='uvmat';
    0707 %     end
    0708 %     if isequal(plot_fig,'uvmat')
    0709 %
    0710 %         huvmat=uvmat(SubField);
    0711 %         menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
    0712 %     else
    0713 %         test_new=1;
    0714 %         if ~isequal(plot_fig,'new fig...')
    0715 %             sep=regexp(plot_fig,'_')%look for subaxes in a fig
    0716 %             if isempty(sep)
    0717 %                 axe_index=1;
    0718 %             else
    0719 %                 axe_index=str2num(plot_fig(sep+1:end))
    0720 %                 plot_fig=plot_fig([1:sep-1])
    0721 %             end
    0722 %             if ishandle(str2num(plot_fig))
    0723 %                 haxes=findobj(str2num(plot_fig),'Type','axes')
    0724 %                 for iaxe=1:length(haxes)
    0725 %                     Tag=get(haxes(iaxe),'Tag');
    0726 %                     if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
    0727 %                        iselect(iaxe)=0;
    0728 %                     else
    0729 %                        iselect(iaxe)=1;
    0730 %                     end
    0731 %                 end
    0732 %                 haxes=haxes(find(iselect));
    0733 %                 if length(haxes)>=axe_index
    0734 %                     test_new=0
    0735 %                     haxes=haxes(axe_index);
    0736 %                     set(haxes,'NextPlot','add')
    0737 %                 end
    0738 %             end
    0739 %         end
    0740 %         if test_new
    0741 %             hfig=figure;
    0742 %             haxes=axes;
    0743 %             menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
    0744 %         end
    0745 %         plot_field(SubField,haxes)
    0746 %     end
    0747 % end
    0748 %
    0749 %
    0750 %
    0751 %
    0752 %  w components
    0753 % end
    0754 %
    0755 %
    0756 % % select the variable  index (or indices) for z coordinates
    0757 % test_grid=0;
    0758 % if test_scalar | test_vector
    0759 %     nbdim=length(DimIndex);
    0760 %     if nbdim > 3
    0761 %         warndlg_uvmat('array with more than three dimensions, not supported','ERROR')
    0762 %         return
    0763 %     else
    0764 %         perm_ind=[1:nbdim];
    0765 %     end
    0766 %     if nbdim==3
    0767 %         zstring=get(handles.coord_z_vectors_scalar,'String');
    0768 %         zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
    0769 %         list_var=zstring(zindex);
    0770 %         VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable
    0771 %         if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
    0772 %             if zindex ~= 1
    0773 %                 set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
    0774 %                 return
    0775 %             end
    0776 %         else
    0777 %             VarIndex_tot=[VarIndex_tot VarIndex_z];
    0778 %             DimIndex_z=Field.VarDimIndex{VarIndex_z};
    0779 %             DimValue=Field.DimValue(DimIndex_z);
    0780 %             ind=find(DimValue==1);
    0781 %             DimIndex_z(ind)=[];%Mremove singleton
    0782 %             if isequal(DimIndex_z,DimIndex)
    0783 %                 VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
    0784 %             elseif length(DimIndex_z)==1
    0785 %                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
    0786 %                 ind_z=find(DimIndex==DimIndex_z(1));
    0787 %                 perm_ind(ind_z)=1;
    0788 %                 test_grid=1;
    0789 %             else
    0790 %                 warndlg_uvmat('multiple dimensions for the z coordinate','ERROR')
    0791 %                 return
    0792 %             end
    0793 %         end
    0794 % %         if ~isempty(VarIndex_z)
    0795 % %             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable
    0796 % %             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
    0797 % %                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
    0798 % %                 ind_z=find(DimIndex==DimIndex_z(1));
    0799 % %                 perm_ind(ind_z)=1;
    0800 % %                 test_grid=1;
    0801 % %             end
    0802 % %         end
    0803 %     end
    0804 % end
    0805 %
    0806 % % select the variable  index (or indices) for ordinate
    0807 % ystring=get(handles.ordinate,'String');
    0808 % yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
    0809 % list_var=ystring(yindex);
    0810 % VarIndex.y=name2index(list_var,Field.ListVarName);
    0811 % if isequal(VarIndex.A,VarIndex.y)|isequal(VarIndex.u,VarIndex.y)|isequal(VarIndex.v,VarIndex.y)|isequal(VarIndex.w,VarIndex.y)
    0812 %    set(handles.ordinate,'Value',1)%ordinate cannot be the same as scalar or vector components
    0813 % else
    0814 %     for ivar=1:length(VarIndex.y)
    0815 %         VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
    0816 %     end
    0817 %     VarIndex_tot=[VarIndex_tot VarIndex.y];
    0818 % end
    0819 % if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
    0820 %     DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
    0821 %     if length(DimIndex_y)==1
    0822 %         ind_y=find(DimIndex==DimIndex_y(1));
    0823 %         test_grid=1;
    0824 %         if nbdim==3
    0825 %             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    0826 %             perm_ind(ind_y)=2;
    0827 %         elseif nbdim==2
    0828 %             VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
    0829 %              perm_ind(ind_y)=1;
    0830 %         end
    0831 %     elseif test_grid
    0832 %         warndlg_uvmat('the dimension of the y coordinate variable should be 1','ERROR')
    0833 %     end
    0834 % end
    0835 %
    0836 % %select the variable index for the abscissa
    0837 % xstring=get(handles.abscissa,'String');
    0838 % xindex=get(handles.abscissa,'Value');
    0839 % list_var=xstring(xindex);
    0840 % VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
    0841 % if length(VarIndex.x)==1
    0842 %     DimIndex_x=Field.VarDimIndex{VarIndex.x};
    0843 %     DimValue=Field.DimValue(DimIndex_x);
    0844 %     ind=find(DimValue==1);
    0845 %     DimIndex_x(ind)=[];%Mremove singleton
    0846 %     VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable
    0847 % %     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
    0848 %     index_detect=find(VarIndex_tot==VarIndex.x);
    0849 % else
    0850 %     index_detect=[];%coord x variable not already used
    0851 % end
    0852 % if isempty(index_detect)
    0853 %     VarIndex_tot=[VarIndex_tot VarIndex.x];
    0854 % else
    0855 %     VarIndex.x=[];
    0856 %     set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
    0857 % end
    0858 %
    0859 % if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
    0860 %     DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
    0861 %     if length(DimIndex_x)==1
    0862 %         ind_x=find(DimIndex==DimIndex_x(1));
    0863 %         if nbdim==3
    0864 %             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    0865 %             perm_ind(ind_x)=3;
    0866 %         elseif nbdim==2
    0867 %             %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
    0868 %              perm_ind(ind_x)=2;
    0869 %         end
    0870 %         if isequal(perm_ind,[1:nbdim])
    0871 %             test_grid=0;
    0872 %         end
    0873 %         DimIndex=DimIndex(perm_ind);
    0874 %     elseif test_grid
    0875 %         warndlg_uvmat('the dimension of the x coordinate variable should be 1','ERROR')
    0876 %     end
    0877 %     if isequal(DimIndex_x,DimIndex)
    0878 %                 VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
    0879 %     end
    0880 % end
    0881 %
    0882 % %defined the selected sub-field SubField
    0883 % SubField.ListGlobalAttribute{1}='InputFile';
    0884 % SubField.InputFile=get(handles.inputfile,'String');
    0885 % SubField.ListVarName=Field.ListVarName(VarIndex_tot);
    0886 % VarDimIndex=Field.VarDimIndex;
    0887 %
    0888 % for ivar=VarIndex.u
    0889 %     VarAttribute{ivar}.Role='vector_x';
    0890 %     if test_grid
    0891 %         VarDimIndex{ivar}=DimIndex; %permute dimensions
    0892 %     end
    0893 % end
    0894 % for ivar=VarIndex.v
    0895 %     VarAttribute{ivar}.Role='vector_y';
    0896 %      if test_grid
    0897 %         VarDimIndex{ivar}=DimIndex;%permute dimensions
    0898 %     end
    0899 % end
    0900 % for ivar=VarIndex.A
    0901 %     if test_grid
    0902 %         VarDimIndex{ivar}=DimIndex;%permute dimensions
    0903 %     end
    0904 %     if isempty(iuA)
    0905 %         VarAttribute{ivar}.Role='scalar';%Role =scalar
    0906 %     else
    0907 %        VarAttribute=[VarAttribute VarAttribute{ivar}]; %duplicate the attribute for a new variable
    0908 %        nbattr=length(VarAttribute);
    0909 %        VarAttribute{nbattr}.Role='scalar';
    0910 %     end
    0911 % end
    0912 % SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
    0913 % SubField.VarAttribute=VarAttribute(VarIndex_tot);
    0914 % % Field.SubListVarName=SubField.ListVarName;
    0915 % % Field.SubVarDimIndex=SubField.VarDimIndex;
    0916 % % Field.SubVarAttribute=SubField.VarAttribute;
    0917 % set(hselect_field,'UserData',Field);
    0918 % % copy variables on SubField
    0919 % for ivar=1:length(VarIndex_tot)
    0920 %     VarName=Field.ListVarName{VarIndex_tot(ivar)};
    0921 %     eval(['SubField.' VarName '=Field.' VarName ';'])
    0922 % end
    0923 % if test_grid
    0924 %     for ivar=1:length(VarIndex.u)
    0925 %          VarName=Field.ListVarName{VarIndex.u(ivar)};
    0926 %         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
    0927 %     end
    0928 %
    0929 %     for ivar=1:length(VarIndex.v)
    0930 %          VarName=Field.ListVarName{VarIndex.v(ivar)};
    0931 %         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
    0932 %     end
    0933 %     for ivar=1:length(VarIndex.A)
    0934 %          VarName=Field.ListVarName{VarIndex.A(ivar)};
    0935 %         eval(['SubField.' VarName '=permute(SubField.' VarName ',perm_ind);'])
    0936 %     end
    0937 % end
    0938 % if ~isempty(iuA)
    0939 %     VarName= ['A' Field.ListVarName{iuA}]; %create the new variable to distinguish the scaler form the velocity component
    0940 %     SubField.ListVarName=[SubField.ListVarName VarName];
    0941 %     SubField.VarDimIndex=[SubField.VarDimIndex Field.VarDimIndex(iuA)];
    0942 %     eval(['SubField.' VarName '=Field.'  Field.ListVarName{iuA} ';'])
    0943 % end
    0944 % % dimension of SubField
    0945 % if test_scalar|test_vector
    0946 %    % SubField.NbDim=2;
    0947 %     SubField.InputFile=get(handles.inputfile,'String');
    0948 %     SubField.get_field_handle=hselect_field;
    0949 % else
    0950 %     SubField.NbDim=1;
    0951 % end
    0952 %
    0953 % list_fig=get(handles.list_fig,'String');
    0954 % fig_index=get(handles.list_fig,'Value');
    0955 % %ACTION on SubField
    0956 % index=get(handles.ACTION,'Value');
    0957
    0958 %
    0959 % %     if (test_scalar|test_vector)
    0960 % %         plot_fig='uvmat';
    0961 % %     elseif iscell(list_fig)
    0962 %     testuvmat=0;
    0963 %     if test_scalar|test_vector
    0964 %          [DimVarIndex,CellVarIndex,NbDim]=find_field_indices(SubField);
    0965 %          NbDim=max(NbDim);
    0966 %          if NbDim==3
    0967 %            testuvmat=1; %uvmat interface needed for 3D plots
    0968 %          end
    0969 %     end
    0970 %     if iscell(list_fig)
    0971 %         plot_fig=list_fig{fig_index};
    0972 %     else
    0973 %         plot_fig='new fig...';%new plotting axes must be created
    0974 %     end
    0975 %     if isequal(plot_fig,'new fig...') &  (test_scalar|test_vector)
    0976 %         plot_fig='uvmat';%use uvmat for a new fig
    0977 %     end
    0978 %     if testuvmat
    0979 %         plot_fig='uvmat';
    0980 %     end
    0981 %     if isequal(plot_fig,'uvmat')
    0982 %
    0983 %         huvmat=uvmat(SubField);
    0984 %         menu=update_menu(handles.list_fig,'uvmat');%add the selected fct to the menu
    0985 %     else
    0986 %         test_new=1;
    0987 %         if ~isequal(plot_fig,'new fig...')
    0988 %             sep=regexp(plot_fig,'_')%look for subaxes in a fig
    0989 %             if isempty(sep)
    0990 %                 axe_index=1;
    0991 %             else
    0992 %                 axe_index=str2num(plot_fig(sep+1:end))
    0993 %                 plot_fig=plot_fig([1:sep-1])
    0994 %             end
    0995 %             if ishandle(str2num(plot_fig))
    0996 %                 haxes=findobj(str2num(plot_fig),'Type','axes')
    0997 %                 for iaxe=1:length(haxes)
    0998 %                     Tag=get(haxes(iaxe),'Tag');
    0999 %                     if isequal(Tag,'Colorbar')|isequal(Tag,'legend')
    1000 %                        iselect(iaxe)=0;
    1001 %                     else
    1002 %                        iselect(iaxe)=1;
    1003 %                     end
    1004 %                 end
    1005 %                 haxes=haxes(find(iselect));
    1006 %                 if length(haxes)>=axe_index
    1007 %                     test_new=0
    1008 %                     haxes=haxes(axe_index);
    1009 %                     set(haxes,'NextPlot','add')
    1010 %                 end
    1011 %             end
    1012 %         end
    1013 %         if test_new
    1014 %             hfig=figure;
    1015 %             haxes=axes;
    1016 %             menu=update_menu(handles.list_fig,num2str(hfig));%add the selected fct to the menu
    1017 %         end
    1018 %         plot_field(SubField,haxes)
    1019 %     end
    1020 % end
    1021 % %Field.VarIndex=VarIndex; %save for use in uvmat
    1022 % % set(hselect_field,'UserData',Field)
    1023
    1024
    1025 %------------------------------------------------
    1026 % --- Executes on button press in Plot_histo.
    1027 %plot global histograms
    1028 %-------------------------------------------------
    1029 function plot_histo_Callback(hObject, eventdata, handles)
    1030 % hObject    handle to plot (see GCBO)
    1031 % eventdata  reserved - to be defined in a future version of MATLAB
    1032 % handles    structure with handles and user data (see GUIDATA)
    1033
    1034 %time plots
    1035 leg={};
    1036 n=0;
    1037 if (get(handles.cm_switch,'Value')==1)
    1038     Uval_p=Uval_cm;
    1039     Vval_p=Vval_cm;
    1040     Uhist_p=Uhist_cm;
    1041     Vhist_p=Vhist_cm;
    1042     xlab='velocity (cm/s)';
    1043 else
    1044     Uval_p=Uval;
    1045     Vval_p=Vval;
    1046     Uhist_p=Uhist;
    1047     Vhist_p=Vhist;
    1048     xlab='velocity (pixels)';
    1049 end
    1050 if (get(handles.vector_y,'Value') == 1)
    1051    hhh=figure(2);
    1052    hold on
    1053    title([filebase ', ' strindex ', ' fieldtitle])
    1054    plot(Uval_p,Uhist_p,'b-')
    1055    n=n+1;
    1056    leg{n}='Uhist';
    1057    xlabel(xlab)
    1058 end
    1059 if (get(handles.Vhist_input,'Value') == 1)
    1060    hhh=figure(2);
    1061    hold on
    1062    title([filebase ', ' strindex ', ' fieldtitle])
    1063    plot(Vval_p,Vhist_p,'r-')
    1064    n=n+1;
    1065    leg{n}='Vhist';
    1066    xlabel(xlab);
    1067 end
    1068 if (get(handles.Chist_input,'Value') == 1)
    1069    hhhh=figure(3);
    1070    hold on
    1071    title([filebase ', ' strindex ', ' fieldtitle])
    1072    plot(Cval,Chist,'k-')
    1073    leg{1}='Chist';
    1074 end
    1075 % hold off
    1076 grid on
    1077 legend(leg);
    1078
    1079 % %-------------------------------------------------------------
    1080 % % --- Executes on button press in Save_input.
    1081 % function Save_input_Callback(hObject, eventdata, handles)
    1082 % list_str=get(handles.abscissa,'String');
    1083 % val=get(handles.abscissa,'Value');
    1084 % var=list_str{val};
    1085 % hselect_field=get(handles.Save_input,'parent')
    1086 % set(hselect_field,'UserData',var);
    1087 % set(hselect_field,'Tag','idle')
    1088
    1089 %
    1090 % %-------------------------------------------------------------
    1091 % % --- Executes on button press in save_histo.
    1092 % function save_histo_Callback(hObject, eventdata, handles)
    1093 % global filebase
    1094 %
    1095 % pathstr = fileparts(filebase)
    1096 % if (get(handles.Chist_input,'Value') == 1)
    1097 %     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
    1098 %     else
    1099
    1100 %     def = {[pathstr pathstr(1) 'vel_histo.fig']};
    1101 % end
    1102 % prompt={'save figure(2) as'}
    1103 % dlg_title = 'save figure';
    1104 % num_lines= 1;
    1105 % answer = inputdlg(prompt,dlg_title,num_lines,def)
    1106 % saveas(2,answer{1})
    1107
    1108 %
    1109 % % --- Executes on selection change in spectrum.
    1110 % function Field=FFT(Field)
    1111 % 'TESTFFT'
    1112 % Field
    1113 % nbfield=length(Field.ListVarName);
    1114 % if nbfield==0
    1115 %     warndlg_uvmat('no field selected for FFT','ERROR')
    1116 % elseif nbfield>2
    1117 %     warndlg_uvmat('select only one field for FFT','ERROR')
    1118 % end
    1119 % if nbfield==2
    1120 % % list_fields=get(handles.spectrum,'String');% list menu fields
    1121 % % index_fields=get(handles.spectrum,'Value');% selected string index
    1122 % % fields= list_fields{index_fields(1)}; % selected action
    1123 % % func=eval(fields);
    1124 %     dtmin=min(diff(time));%time step
    1125 %     time1=time(1);timend=time(end);
    1126 %     timeq=[time1:dtmin:timend];%equal time spacing
    1127 %     funcinterp=interp1(time,func,timeq); %interpolated func
    1128 % else
    1129 %     varname=Field.ListVarName{1};
    1130 %     eval(['funcinterp=Field.' varname ';'])
    1131 % end
    1132 % np=length(funcinterp);
    1133 % funcinterp=funcinterp-sum(funcinterp)/np; %substract mean
    1134 % fourier=fft(funcinterp);%take fft (complex)
    1135 % spec=abs(fourier).*abs(fourier);% take sqare of the modulus
    1136 % spec=spec([1:floor(np/2)]);%keep only the first half (the other is symmetric)
    1137 % eval(['Field.' varname '=spec;'])
    1138 % Field
    1139 % % dfreq=1/(time(end)-time(1));%frequency interval
    1140 % % freq=[0:dfreq:(floor(np/2)-1)*dfreq];
    1141 % % figure(1)
    1142 % % hold on
    1143 % % plot(freq,spec)
    1144 % % xlabel('frequency (Hz)')
    1145 % % ylabel('spectral intensity')
    1146 % % title(['spectrum of' fields]);
    1147 % % grid on
    1148
    1149
    1150
    1151
    1152
    1153 %%-------------------------------------------------------
    1154 % --- Executes on button press in peaklocking.
    1155 %-------------------------------------------------
    1156 function peaklocking(handles)
    1157 %evaluation of peacklocking errors
    1158 %use splinhist: give spline coeff cc for a smooth histo (call spline4)
    1159 %use histsmooth(x,cc): calculate the smooth histo for any value x
    1160 %use histder(x,cc): calculate the derivative of the smooth histo
    1161 global hfig1 hfig2 hfig3
    1162 global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
    1163 global xval xerror yval yerror
    1164
    1165 set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
    1166 set(handles.Vhist_input,'Value',1)
    1167 set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
    1168
    1169 %adjust the extremal values of the histogram in U with respect to integer
    1170 %values
    1171 minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins
    1172 maximU=round(max(Uval)-0.5)+0.5;
    1173 minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
    1174 maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
    1175 nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
    1176 nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
    1177 Uval=[minim_fin:(1/nbb):maxim_fin];
    1178 histu_min=zeros(nb_bin_min,1);
    1179 histu_max=zeros(nb_bin_max,1);
    1180 Uhist=[histu_min; Uhist ;histu_max]; % column vector
    1181
    1182 %adjust the extremal values of the histogram in V
    1183 minimV=round(min(Vval-0.5)+0.5);
    1184 maximV=round(max(Vval-0.5)+0.5);
    1185 minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
    1186 maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
    1187 nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
    1188 nb_bin_max=round((maxim_fin -max(Vval))*nbb);
    1189 Vval=[minim_fin:(1/nbb):maxim_fin];
    1190 histu_min=zeros(nb_bin_min,1);
    1191 histu_max=zeros(nb_bin_max,1);
    1192 Vhist=[histu_min; Vhist ;histu_max]; % column vector
    1193
    1194 % plot_histo_Callback(hObject, eventdata, handles)
    1195 % %adjust the histogram to integer values:
    1196
    1197 %histoU and V
    1198 [Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
    1199 [Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
    1200
    1201 % selection of value ranges such that histo>=10 (enough statistics)
    1202 Uval_ind=find(Uhist>=10);
    1203 ind_min=min(Uval_ind);
    1204 ind_max=max(Uval_ind);
    1205 U_min=Uval(ind_min);% minimum allowed value
    1206 U_max=Uval(ind_max);%maximum allowed value
    1207
    1208 % selection of value ranges such that histo>=10 (enough statistics)
    1209 Vval_ind=find(Vhist>=10);
    1210 ind_min=min(Vval_ind);
    1211 ind_max=max(Vval_ind);
    1212 V_min=Vval(ind_min);% minimum allowed value
    1213 V_max=Vval(ind_max);%maximum allowed value
    1214
    1215 figure(4)% plot U histogram with smoothed one
    1216 plot(Uval,Uhist,'b')
    1217 grid on
    1218 hold on
    1219 plot(Uval,Uhistinter,'r');
    1220 hold off
    1221
    1222 figure(5)% plot V histogram with smoothed one
    1223 plot(Vval,Vhist,'b')
    1224 grid on
    1225 hold on
    1226 plot(Vval,Vhistinter,'r');
    1227 hold off
    1228
    1229 figure(6)% plot pixel error in two subplots
    1230 hfig4=subplot(2,1,1);
    1231 hfig5=subplot(2,1,2);
    1232 axes(hfig4)
    1233 plot(xval,xerror)
    1234 axis([U_min U_max -0.4 0.4])
    1235 xlabel('velocity u (pix)')
    1236 ylabel('peaklocking error (pix)')
    1237 grid on
    1238 axes(hfig5)
    1239 plot(yval,yerror)
    1240 axis([V_min V_max -0.4 0.4]);
    1241 xlabel('velocity v (pix)')
    1242 ylabel('peaklocking error (pix)')
    1243 grid on
    1244
    1245
    1246 % ------------------------------------------------------------------
    1247 function variables_Callback(hObject, eventdata, handles)
    1248 Tabchar={''};%default
    1249 Tabcell=[];
    1250 hselect_field=get(handles.variables,'parent');
    1251 Field=get(hselect_field,'UserData');
    1252 index=get(handles.variables,'Value');%index in the list 'variables'
    1253 if isequal(index,1)
    1254     set(handles.attributes_txt,'String','global attributes')
    1255 % list global attribute names and values if index=1 (blank variable display) is selected
    1256     if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
    1257         for iline=1:length(Field.ListGlobalAttribute)
    1258             Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
    1259             if isfield(Field, Field.ListGlobalAttribute{iline})
    1260                 eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
    1261                 if ischar(val);
    1262                     Tabcell{iline,2}=val;
    1263                 else
    1264                     Tabcell{iline,2}=num2str(val);
    1265                 end
    1266             end
    1267         end
    1268         Tabchar=cell2tab(Tabcell,'=');
    1269     end
    1270 else
    1271 %list attribute names and values associated to the variable # injdex-1
    1272     list_var=get(handles.variables,'String');
    1273     var_select=list_var{index};
    1274     set(handles.attributes_txt,'String', ['attributes of ' var_select])
    1275     if isfield(Field,'VarAttribute')& length(Field.VarAttribute)>=index-1
    1276 %         nbline=0;
    1277         VarAttr=Field.VarAttribute{index-1};
    1278         if isstruct(VarAttr)
    1279             attr_list=fieldnames(VarAttr);
    1280             for iline=1:length(attr_list)
    1281                 Tabcell{iline,1}=attr_list{iline};
    1282                 eval(['val=VarAttr.' attr_list{iline} ';'])
    1283                 if ischar(val);
    1284                     Tabcell{iline,2}=val;
    1285                 else
    1286                      Tabcell{iline,2}=num2str(val);
    1287                 end
    1288             end
    1289         end
    1290     end
    1291
    1292 end
    1293 if ~isempty(Tabcell)
    1294     Tabchar=cell2tab(Tabcell,'=');
    1295     Tabchar=[{''};Tabchar];
    1296 end
    1297 set(handles.attributes,'String',Tabchar);
    1298
    1299 % list_var=get(handles.dimensions,'String');
    1300 % val=get(handles.dimensions,'Value');
    1301
    1302 % update dimensions;
    1303 if isfield(Field,'VarDimIndex')
    1304     Tabdim={};%default
    1305     if isequal(index,1)
    1306         dim_indices=1:length(Field.ListDimName);
    1307         set(handles.dimensions_txt,'String', 'dimensions')
    1308     else
    1309         dim_indices=Field.VarDimIndex{index-1};
    1310         set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
    1311     end
    1312     for iline=1:length(dim_indices)
    1313         Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
    1314         Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
    1315     end
    1316     Tabchar=cell2tab(Tabdim,'=');
    1317     Tabchar=[{''} ;Tabchar];
    1318     set(handles.dimensions,'String',Tabchar)
    1319 end
    1320
    1321 % --- Executes on button press in check_1Dplot.
    1322 function check_1Dplot_Callback(hObject, eventdata, handles)
    1323 val=get(handles.check_1Dplot,'Value');
    1324 if isequal(val,0)
    1325     set(handles.Panel1Dplot,'Visible','off')
    1326 %      set(handles.scalar,'Visible','off')
    1327 %     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
    1328 %     if isequal(get(handles.check_vector,'Value'),0);
    1329 %         set(handles.coord_z_vectors_scalar,'Visible','off')
    1330 %     end
    1331 else
    1332     set(handles.Panel1Dplot,'Visible','on')
    1333 %     set(handles.scalar,'Visible','on')
    1334 %     val=get(handles.ordinate,'Value');
    1335 %     val=val(1);
    1336 %     set(handles.ordinate,'Value',val);%suppress multiple ordinates
    1337 %     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
    1338 %       set(handles.coord_z_vectors_scalar,'Visible','on')
    1339 end
    1340
    1341 % --- Executes on button press in check_scalar.
    1342 function check_scalar_Callback(hObject, eventdata, handles)
    1343 val=get(handles.check_scalar,'Value');
    1344 if isequal(val,0)
    1345     set(handles.PanelScalar,'Visible','off')
    1346 %      set(handles.scalar,'Visible','off')
    1347 %     set(handles.ordinate,'Max',2.0)%allow multiple ordinate input option
    1348 %     if isequal(get(handles.check_vector,'Value'),0);
    1349 %         set(handles.coord_z_vectors_scalar,'Visible','off')
    1350 %     end
    1351 else
    1352     set(handles.PanelScalar,'Visible','on')
    1353 %     set(handles.scalar,'Visible','on')
    1354 %     val=get(handles.ordinate,'Value');
    1355 %     val=val(1);
    1356 %     set(handles.ordinate,'Value',val);%suppress multiple ordinates
    1357 %     set(handles.ordinate,'Max',1.0);%suppress multiple ordinate input option
    1358 %       set(handles.coord_z_vectors_scalar,'Visible','on')
    1359 end
    1360
    1361 %---------------------------
    1362 % --- Executes on button press in check_vector.
    1363 function check_vector_Callback(hObject, eventdata, handles)
    1364 val=get(handles.check_vector,'Value');
    1365 if isequal(val,0)
    1366     set(handles.PanelVectors,'Visible','off')
    1367 else
    1368     set(handles.PanelVectors,'Visible','on')
    1369 end
    1370
    1371
    1372
    1373 %-----------------------------
    1374 function mouse_up_gui(ggg,eventdata,handles)
    1375 if isequal(get(ggg,'SelectionType'),'alt')
    1376     message='';
    1377     global CurData
    1378     inputfield=get(handles.inputfile,'String');
    1379     if exist(inputfield,'file')
    1380         CurData=nc2struct(inputfield);
    1381     else
    1382         CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
    1383     end
    1384   %%%% TODO: put the matalb command window in front
    1385     evalin('base','global CurData')%make CurData global in the workspace
    1386     evalin('base','CurData') %display CurData in the workspace
    1387 end
    1388
    1389 %---------------------------------------------
    1390 % --- Executes on selection change in ACTION.
    1391 function ACTION_Callback(hObject, eventdata, handles)
    1392 list_ACTION=get(handles.ACTION,'String');% list menu fields
    1393 index_ACTION=get(handles.ACTION,'Value');% selected string index
    1394 ACTION= list_ACTION{index_ACTION}; % selected string
    1395 path_get_field=which('get_field');%path to series.m
    1396 list_path=get(handles.ACTION,'UserData');
    1397 nb_builtin=0;
    1398 for ilist=1:length(list_path)
    1399     if isequal(list_path{ilist},path_get_field)
    1400         nb_builtin=nb_builtin+1;
    1401     else
    1402         break
    1403     end
    1404 end
    1405 if nb_builtin==0% the path to get_field has been changed, reinitialize
    1406     get_field_OpeningFcn(hObject, eventdata, handles)
    1407     return
    1408 end
    1409
    1410 % add a new function to the menu
    1411 if isequal(ACTION,'more...')
    1412     pathfct=fileparts(path_get_field);
    1413     browse_name=fullfile(path_get_field,'FIELD_FCT');
    1414     if length(list_path)>nb_builtin
    1415         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
    1416     end
    1417 %     fct_name='';
    1418 %     dir_perso=prefdir;
    1419 %     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1420 %     display(profil_perso)
    1421 %     if exist(profil_perso,'file')
    1422 %           h=load (profil_perso);
    1423 %           if isfield(h,'get_field_fct')
    1424 %             fct_name=h.get_field_fct;
    1425 %           end
    1426 %     else
    1427 %         path_to_uvmat=which ('uvmat');% check the path of uvmat
    1428 %         pathfct=fileparts(path_to_uvmat);
    1429 %         fct_name=fullfile(pathfct,'USR_FCT');%go to UVMAT/USR_FCT by default
    1430 %     end
    1431     [FileName, PathName] = uigetfile( ...
    1432        {'*.m', ' (*.m)';
    1433         '*.m',  '.m files '; ...
    1434         '*.*', 'All Files (*.*)'}, ...
    1435         'Pick a file',browse_name);
    1436     if length(FileName)<2
    1437         return
    1438     end
    1439     ext_fct=FileName(end-1:end);
    1440     if ~isequal(ext_fct,'.m')
    1441         msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
    1442         return
    1443     end
    1444     ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
    1445
    1446     % insert the choice in the action menu
    1447    menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
    1448    index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
    1449    list_path{index_ACTION}=PathName;
    1450    if length(menu_str)>nb_builtin+5;
    1451        nbremove=length(menu_str)-nb_builtin-5;
    1452        menu_str(nb_builtin+1:end-5)=[];
    1453        list_path(nb_builtin+1:end-4)=[];
    1454        index_ACTION=index_ACTION-nbremove;
    1455        set(handles.ACTION,'Value',index_ACTION)
    1456        set(handles.ACTION,'String',menu_str)
    1457    end
    1458    list_path{index_ACTION}=PathName;
    1459    set(handles.ACTION,'UserData',list_path);
    1460    set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
    1461
    1462    %record the current menu in personal file profil_perso
    1463    dir_perso=prefdir;
    1464    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1465    for ilist=nb_builtin+1:length(menu_str)-1
    1466        get_field_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
    1467    end
    1468    if exist(profil_perso,'file')
    1469         save(profil_perso,'get_field_fct','-append')
    1470    else
    1471         txt=ver;
    1472         Release=txt(1).Release;
    1473         relnumb=str2num(Release(3:4));
    1474         if relnumb >= 14
    1475             save(profil_perso,'get_field_fct','-V6')
    1476         else
    1477             save(profil_perso, 'get_field_fct')
    1478         end
    1479    end
    1480 end
    1481
    1482    %check the current path to the selected function
    1483 PathName=list_path{index_ACTION};%current recorded path
    1484 if ~isequal(path_get_field,PathName)
    1485     CurrentPath=fileparts(which(ACTION));
    1486     if ~isequal(PathName,CurrentPath)
    1487         addpath(PathName)
    1488         errormsg=check_functions;
    1489         msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
    1490     end
    1491 end
    1492 set(handles.path_action,'String',PathName); %show the path to the senlected function
    1493
    1494
    1495 %     fct_name=fullfile(PathName, FileName);
    1496 %     if ~exist(fct_name,'file')
    1497 %            msgbox_uvmat('ERROR',['procesing fct ' fct_name ' not found'])
    1498 %     else
    1499 %        ACTION=FileName(1:end-2);%
    1500 %        menu=update_menu(handles.ACTION,ACTION);%add the selected fct to the menu
    1501 %        index_ACTION=get(handles.ACTION,'Value');% selected string index
    1502 %        list_path{index_ACTION}=PathName;
    1503 %        set(handles.ACTION,'UserData',list_path)
    1504 %        if exist(profil_perso,'file')
    1505 %             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
    1506 %         end
    1507 %     end
    1508 %
    1509 %
    1510 %     fileinput=FileName;%complete file name
    1511 %     eval(['spath=which(''' FileName ''');'])% current path to the function FileName
    1512 %     if ~isequal(spath,PathName)
    1513 %         addpath(PathName)
    1514 %     end
    1515 %     FileName([end-1:end])=[];
    1516 %
    1517 %    % insert the choice in the action menu
    1518 %     nbACTION=length(list_ACTION);
    1519 %     index=0;
    1520 %     for ilist=1:nbACTION
    1521 %        if isequal(FileName,list_ACTION{ilist})%look for the selected scalar in the fields_input menu
    1522 %             index=ilist;%
    1523 %        end
    1524 %     end
    1525 %     if index==0
    1526 %        list_ACTION{nbACTION}=FileName; %put the chosen fct at the penultimate place in the fields_input menu
    1527 %        list_path{nbACTION}=PathName;
    1528 %        index=nbACTION;
    1529 %        list_ACTION{nbACTION+1}='more...';
    1530 %        set(handles.ACTION,'String',list_ACTION)
    1531 %     end
    1532 %     set(handles.ACTION,'Value',index);% store the selected scalar type
    1533 %     set(handles.ACTION,'UserData',list_path);
    1534 %     usr_defined_fct=fct_name;
    1535 %     nbmenu=length(list_ACTION);
    1536 %     nbadd=nbmenu-5;
    1537 %     ilist=0;
    1538 %     for imenu=nbmenu-min(4,nbadd):nbmenu-1
    1539 %       ilist=ilist+1;
    1540 %       fct_get_field{ilist,1}=list_ACTION{imenu};
    1541 %       fct_path_get_field{ilist}=list_path{imenu};
    1542 %     end
    1543 %     if exist(profil_perso,'file')
    1544 %         save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-append')
    1545 %     else
    1546 %        save(profil_perso,'usr_defined_fct','fct_get_field','fct_path_get_field','-V6')
    1547 %     end
    1548 % end
    1549
    1550 % %check the current path to the selected function
    1551 % list_path
    1552 % PathName=list_path{index_ACTION}
    1553 % CurrentPath=fileparts(which(ACTION))
    1554 % if ~isequal(PathName,CurrentPath)
    1555 %     addpath(PathName)
    1556 %     errormsg=check_functions;
    1557 %     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
    1558 % end
    1559 % set(handles.path_action,'String',fullfile(PathName,' ')); %show the path to the senlected function
    1560
    1561 %default setting for the visibility of the GUI elements*
    1562 if ~isequal(ACTION,'PLOT')
    1563     varargout=feval(ACTION);% input list asked by the selected function
    1564     test_1Dplot=[];
    1565     test_scalar=[];
    1566     test_vector=[];
    1567     for ilist=1:length(varargout)-1
    1568         switch varargout{ilist}
    1569                            %RootFile always visible
    1570             case 'check_1Dplot'
    1571                  test_1Dplot=isequal(lower(varargout{ilist+1}),'y');
    1572             case 'check_scalar'
    1573                  test_scalar=isequal(lower(varargout{ilist+1}),'y');
    1574             case 'check_vector'
    1575                  test_vector=isequal(lower(varargout{ilist+1}),'y');
    1576         end
    1577     end
    1578     if test_1Dplot==0
    1579         set(handles.check_1Dplot,'Value',0);
    1580     end
    1581     if test_1Dplot==1
    1582         set(handles.check_1Dplot,'Value',1);
    1583     end
    1584     if test_scalar==0
    1585         set(handles.check_scalar,'Value',0);
    1586     end
    1587     if test_scalar==1
    1588         set(handles.check_scalar,'Value',1);
    1589     end
    1590     if test_vector==0
    1591         set(handles.check_vector,'Value',0);
    1592     end
    1593     if test_vector==1
    1594         set(handles.check_vector,'Value',1);
    1595     end
    1596     check_1Dplot_Callback(hObject, eventdata, handles)
    1597     check_scalar_Callback(hObject, eventdata, handles)
    1598     check_vector_Callback(hObject, eventdata, handles)
    1599 end
    1600 %
    1601 % % --- Executes on selection change in menu_coord.
    1602 % function menu_coord_Callback(hObject, eventdata, handles)
    1603 % hget_field=get(handles.menu_coord,'parent');
    1604 % menu=get(handles.menu_coord,'String');
    1605 % ind_coord=get(handles.menu_coord,'Value');
    1606 % coord_option=menu{ind_coord};
    1607 % if isequal(coord_option,'more...');
    1608 %     fct_name='';
    1609 %     if exist('./TMP/current_usr_fct.mat','file')% if a file is found
    1610 %         h=load('./TMP/current_usr_fct.mat');
    1611 %         if isfield(h,'fct_name');
    1612 %             fct_name=h.fct_name;
    1613 %         end
    1614 %     end
    1615 %     prompt = {'Enter the name of the transform function'};
    1616 %     dlg_title = 'user defined transform';
    1617 %     num_lines= 1;
    1618 %     [FileName, PathName, filterindex] = uigetfile( ...
    1619 %        {'*.m', ' (*.m)';
    1620 %         '*.m',  '.m files '; ...
    1621 %         '*.*', 'All Files (*.*)'}, ...
    1622 %         'Pick a file', fct_name);
    1623 %     fct_name=fullfile(PathName,FileName);
    1624 %     addpath(PathName);%add the path to the selected fct
    1625 %     [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
    1626 %     if ~exist(fct_name,'file')
    1627 %            warndlg_uvmat(['image procesing fct ' fct_name ' not found'],'WARNING')
    1628 %     else
    1629 %         transform=FileName(1:end-2);%
    1630 %         menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
    1631 % %         set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
    1632 %       save ('./TMP/current_usr_fct.mat','fct_name');
    1633 %     end
    1634 % end
    1635
    1636 % --- Executes on selection change in menu_coord.
    1637 function HELP_Callback(hObject, eventdata, handles)
    1638 path_to_uvmat=which ('uvmat');% check the path of uvmat
    1639 pathelp=fileparts(path_to_uvmat);
    1640 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    1641 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    1642 else
    1643 web([helpfile '#get_field'])
    1644 end
    1645
    1646 %-----------------------------------------------------
    1647 % --- browse existing figures
    1648 %-----------------------------------------------------
    1649 function browse_fig(menu_handle)
    1650 hh=findobj(allchild(0),'Type','figure');
    1651 ilist=0;
    1652 list={};
    1653 for ifig=1:length(hh)  %look for all existing figures
    1654     name=get(hh(ifig),'Name');
    1655      if ~isequal(name,'uvmat')%case of uvmat GUI
    1656 %         ilist=ilist+1;
    1657 %         list{ilist,1}='uvmat';
    1658 %     else        %other figures
    1659         hchild=get(hh(ifig),'children');% look for axes contained in each figure
    1660         nbaxe=0;
    1661         for ichild=1:length(hchild)
    1662             Type=get(hchild(ichild),'Type');
    1663             Tag=get(hchild(ichild),'Tag');
    1664             if isequal(Type,'axes')
    1665                 if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
    1666                      nbaxe=nbaxe+1;%count the existing axis
    1667                 end
    1668             end
    1669         end
    1670         if nbaxe==1
    1671              ilist=ilist+1;%add a line in the list of axis
    1672             list{ilist,1}=num2str(hh(ifig));
    1673         elseif nbaxe>1
    1674             for iaxe=1:nbaxe
    1675                ilist=ilist+1;%add a line in the list of axis
    1676                list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
    1677             end
    1678         end
    1679      end
    1680 end
    1681 list=['new fig...';'uvmat';list];
    1682 set(menu_handle,'Value',1)
    1683 set(menu_handle,'String',list)
    1684
    1685
    1686 %-----------------------------------------------------
    1687 function list_fig_Callback(hObject, eventdata, handles)
    1688 %-----------------------------------------------------
    1689 list_fig=get(handles.list_fig,'String');
    1690 fig_val=get(handles.list_fig,'Value');
    1691 plot_fig=list_fig{fig_val};
    1692 if isequal(plot_fig,'uvmat')
    1693     huvmat=findobj(allchild(0),'name','uvmat');
    1694     if ~isempty(huvmat)
    1695         uistack(huvmat,'top')
    1696     end
    1697 elseif ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
    1698     sep=regexp(plot_fig,'_');
    1699     if ~isempty(sep)
    1700         plot_fig=plot_fig([1:sep-1]);
    1701     end
    1702     if ishandle(str2num(plot_fig))
    1703         figure(str2num(plot_fig))% display existing figure
    1704     else
    1705         browse_fig(handles.list_fig); %reset the current list of figures
    1706     end
    1707 end
    1708
    1709
    1710 %-------------------------------------------------
    1711 % give index numbers of the strings str in the list ListvarName
    1712 function VarIndex_y=name2index(cell_str,ListVarName)
    1713 VarIndex_y=[];
    1714 if ischar(cell_str)
    1715     for ivar=1:length(ListVarName)
    1716         varlist=ListVarName{ivar};
    1717         if isequal(varlist,cell_str)
    1718             VarIndex_y= ivar;
    1719             break
    1720         end
    1721     end
    1722 elseif iscell(cell_str)
    1723     for isel=1:length(cell_str)
    1724         varsel=cell_str{isel};
    1725         for ivar=1:length(ListVarName)
    1726             varlist=ListVarName{ivar};
    1727             if isequal(varlist,varsel)
    1728                 VarIndex_y=[VarIndex_y ivar];
    1729             end
    1730         end
    1731     end
    1732 end
    1733
    1734
    1735 % --- Executes on selection change in vector_z.
    1736 function vector_z_Callback(hObject, eventdata, handles)
    1737 Aindex=get(handles.vector_z,'Value');
    1738 Astring=get(handles.vector_z,'String');
    1739 VarName=Astring{Aindex};
    1740 update_field(hObject, eventdata, handles,VarName)
    1741
    1742 % --- Executes on selection change in coord_z_scalar.
    1743 function coord_z_scalar_Callback(hObject, eventdata, handles)
    1744 hselect_field=get(handles.inputfile,'parent');
    1745 Field=get(hselect_field,'UserData');
    1746 list=get(handles.coord_z_scalar,'String');
    1747 yindex=get(handles.coord_z_scalar,'Value');
    1748 xindex=name2index(list{yindex(1)},Field.ListVarName);
    1749 if ~isempty(xindex)
    1750     set(handles.variables,'Value',xindex+1)
    1751     variables_Callback(hObject, eventdata, handles)
    1752 end
    1753 Field.VarIndex.z=xindex;
    1754 set(hselect_field,'UserData',Field);
    1755
    1756 % --- Executes on selection change in coord_x_vectors.
    1757 function coord_x_scalar_Callback(hObject, eventdata, handles)
    1758
    1759 % --- Executes on selection change in coord_x_vectors.
    1760 function coord_y_scalar_Callback(hObject, eventdata, handles)
    1761
    1762
    1763 % --- Executes on selection change in coord_y_vectors.
    1764 function coord_y_vectors_Callback(hObject, eventdata, handles)
    1765
    1766 % --- Executes on selection change in coord_x_vectors.
    1767 function coord_x_vectors_Callback(hObject, eventdata, handles)
    1768
    1769
    1770
    1771
    1772 % --- Executes on selection change in vec_color.
    1773 function vec_color_Callback(hObject, eventdata, handles)
    1774
    1775
    1776 % --------------------------------------------------------------------
    1777 function MenuOpen_Callback(hObject, eventdata, handles)
    1778 % hObject    handle to MenuOpen (see GCBO)
    1779 % eventdata  reserved - to be defined in a future version of MATLAB
    1780 % handles    structure with handles and user data (see GUIDATA)
    1781
    1782
    1783 % --------------------------------------------------------------------
    1784 function MenuExport_Callback(hObject, eventdata, handles)
    1785 % hObject    handle to MenuExport (see GCBO)
    1786 % eventdata  reserved - to be defined in a future version of MATLAB
    1787 % handles    structure with handles and user data (see GUIDATA)
    1788
    1789
    1790 % --------------------------------------------------------------------
    1791 function MenuBrowse_Callback(hObject, eventdata, handles)
    1792
    1793 oldfile=get(handles.inputfile,'String');
    1794 testrootfile=0;
    1795 testsubdir=0;
    1796 if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
    1797         oldfile='';
    1798         dir_perso=prefdir;
    1799          profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1800          if exist(profil_perso,'file')
    1801               h=load (profil_perso);
    1802              if isfield(h,'RootPath')
    1803                   RootPath=h.RootPath;
    1804              end
    1805              if isfield(h,'SubDir')
    1806                   SubDir=h.SubDir;
    1807                   if ~isempty(SubDir)
    1808                     testsubdir=1;
    1809                   end
    1810              end
    1811              if isfield(h,'RootFile')
    1812                   RootFile=h.RootFile;
    1813                   if ~isempty(RootFile)
    1814                     testrootfile=1;
    1815                   end
    1816              end
    1817          end
    1818 end
    1819 if testrootfile
    1820     if ~testsubdir
    1821         oldfile=fullfile(RootPath,RootFile);
    1822     else
    1823         oldfile=fullfile(RootPath,SubDir,RootFile);
    1824     end
    1825 end
    1826 [FileName, PathName] = uigetfile( ...
    1827        {'*.nc', ' *.nc';...
    1828        '*.cdf', ' *.cdf';...
    1829         '*.*',  'All Files (*.*)'}, ...
    1830         'Pick a file',oldfile);
    1831
    1832 %global inputfile
    1833 fileinput=[PathName FileName];%complete file name
    1834 testblank=findstr(fileinput,' ');%look for blanks
    1835 if ~isempty(testblank)
    1836     warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
    1837     return
    1838 end
    1839 sizf=size(fileinput);
    1840 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
    1841 set(handles.inputfile,'String',fileinput)
    1842 inputfile_Callback(hObject, eventdata, handles)
    1843
    1844
    1845 %update list of recent files in the menubar
    1846 MenuFile_1=fileinput;
    1847 MenuFile_2=get(handles.MenuFile_1,'Label');
    1848 MenuFile_3=get(handles.MenuFile_2,'Label');
    1849 MenuFile_4=get(handles.MenuFile_3,'Label');
    1850 MenuFile_5=get(handles.MenuFile_4,'Label');
    1851 set(handles.MenuFile_1,'Label',MenuFile_1)
    1852 set(handles.MenuFile_2,'Label',MenuFile_2)
    1853 set(handles.MenuFile_3,'Label',MenuFile_3)
    1854 set(handles.MenuFile_4,'Label',MenuFile_4)
    1855 set(handles.MenuFile_5,'Label',MenuFile_5)
    1856
    1857
    1858 % %store input file in personal file uvmat_perso.mat
    1859 % dir_perso=prefdir;
    1860 % profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    1861 % if exist(profil_perso,'file')
    1862 %     save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext','-append'); %store the root name for future opening of uvmat
    1863 % else
    1864 %    save (profil_perso,'RootPath','SubDir','RootFile','NomType', 'ext'); %store the root name for future opening of uvmat
    1865 % end
    1866
    1867
    1868 % --------------------------------------------------------------------
    1869 function MenuFile_1_Callback(hObject, eventdata, handles)
    1870 % hObject    handle to MenuFile_1 (see GCBO)
    1871 % eventdata  reserved - to be defined in a future version of MATLAB
    1872 % handles    structure with handles and user data (see GUIDATA)
    1873
    1874
    1875 % --------------------------------------------------------------------
    1876 function MenuFile_2_Callback(hObject, eventdata, handles)
    1877 % hObject    handle to MenuFile_2 (see GCBO)
    1878 % eventdata  reserved - to be defined in a future version of MATLAB
    1879 % handles    structure with handles and user data (see GUIDATA)
    1880
    1881
    1882 % --------------------------------------------------------------------
    1883 function MenuFile_3_Callback(hObject, eventdata, handles)
    1884 % hObject    handle to MenuFile_3 (see GCBO)
    1885 % eventdata  reserved - to be defined in a future version of MATLAB
    1886 % handles    structure with handles and user data (see GUIDATA)
    1887
    1888
    1889 % --------------------------------------------------------------------
    1890 function MenuFile_4_Callback(hObject, eventdata, handles)
    1891 % hObject    handle to MenuFile_4 (see GCBO)
    1892 % eventdata  reserved - to be defined in a future version of MATLAB
    1893 % handles    structure with handles and user data (see GUIDATA)
    1894
    1895
    1896 % --------------------------------------------------------------------
    1897 function MenuFile_5_Callback(hObject, eventdata, handles)
    1898 % hObject    handle to MenuFile_5 (see GCBO)
    1899 % eventdata  reserved - to be defined in a future version of MATLAB
    1900 % handles    structure with handles and user data (see GUIDATA)
    1901
    1902
    1903 % --------------------------------------------------------------------
    1904 function ExportField_Callback(hObject, eventdata, handles)
    1905 % hObject    handle to ExportField (see GCBO)
    1906 % eventdata  reserved - to be defined in a future version of MATLAB
    1907 % handles    structure with handles and user data (see GUIDATA)
    1908
    1909