Home > . > series.m

series

PURPOSE ^

'series': master function associated to the GUI series.m for analysis field series

SYNOPSIS ^

function varargout = series(varargin)

DESCRIPTION ^

'series': master function associated to the GUI series.m for analysis field series  
------------------------------------------------------------------------
 function varargout = series(varargin)
 associated with the GUI series.fig

INPUT
 param: structure with input parameters (link with the GUI uvmat)
      .menu_coord_str: string for the CoordType (menu for coordinate transforms)
      .menu_coord_val: value for CoordType (menu for coordinate transforms)
      .FileName: input file name
      .FileName_1: second input file name
      .list_field: menu of input fields
      .index_fields: chosen index
      .civ1=0 or 1, .interp1,  ... : input civ field type

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: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %'series': master function associated to the GUI series.m for analysis field series
0002 %------------------------------------------------------------------------
0003 % function varargout = series(varargin)
0004 % associated with the GUI series.fig
0005 %
0006 %INPUT
0007 % param: structure with input parameters (link with the GUI uvmat)
0008 %      .menu_coord_str: string for the CoordType (menu for coordinate transforms)
0009 %      .menu_coord_val: value for CoordType (menu for coordinate transforms)
0010 %      .FileName: input file name
0011 %      .FileName_1: second input file name
0012 %      .list_field: menu of input fields
0013 %      .index_fields: chosen index
0014 %      .civ1=0 or 1, .interp1,  ... : input civ field type
0015 %
0016 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0017 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
0018 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0019 %     This file is part of the toolbox UVMAT.
0020 %
0021 %     UVMAT is free software; you can redistribute it and/or modify
0022 %     it under the terms of the GNU General Public License as published by
0023 %     the Free Software Foundation; either version 2 of the License, or
0024 %     (at your option) any later version.
0025 %
0026 %     UVMAT is distributed in the hope that it will be useful,
0027 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
0030 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0031 
0032 function varargout = series(varargin)
0033 
0034 % Begin initialization code - DO NOT EDIT
0035 gui_Singleton = 1;
0036 gui_State = struct('gui_Name',       mfilename, ...
0037                    'gui_Singleton',  gui_Singleton, ...
0038                    'gui_OpeningFcn', @series_OpeningFcn, ...
0039                    'gui_OutputFcn',  @series_OutputFcn, ...
0040                    'gui_LayoutFcn',  [] , ...
0041                    'gui_Callback',   []);
0042 if nargin & ischar(varargin{1})
0043     gui_State.gui_Callback = str2func(varargin{1});
0044 end
0045 
0046 if nargout
0047     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0048 else
0049     gui_mainfcn(gui_State, varargin{:});
0050 end
0051 % End initialization code - DO NOT EDIT
0052 
0053 %--------------------------------------------------------------------------
0054 % --- Executes just before series is made visible.
0055 %--------------------------------------------------------------------------
0056 function series_OpeningFcn(hObject, eventdata, handles,param)
0057 
0058 % Choose default command line output for series
0059 handles.output = hObject;
0060 % Update handles structure
0061 guidata(hObject, handles);
0062 %default initial parameters
0063 
0064 %load the list of previously browsed files in menus Open and Open_1
0065 dir_perso=prefdir;
0066 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0067 if exist(profil_perso,'file')
0068      h=load (profil_perso);
0069      if isfield(h,'MenuFile_1')
0070           set(handles.MenuFile_1,'Label',h.MenuFile_1);
0071           set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
0072      end
0073      if isfield(h,'MenuFile_1')
0074           set(handles.MenuFile_2,'Label',h.MenuFile_2);
0075           set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
0076      end
0077      if isfield(h,'MenuFile_1')
0078           set(handles.MenuFile_3,'Label',h.MenuFile_3);
0079           set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
0080      end
0081      if isfield(h,'MenuFile_1')
0082           set(handles.MenuFile_4,'Label',h.MenuFile_4);
0083           set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
0084      end
0085      if isfield(h,'MenuFile_1')
0086           set(handles.MenuFile_5,'Label',h.MenuFile_5);
0087           set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
0088      end
0089 end
0090 
0091 %check default input data
0092 if ~exist('param','var')
0093     param=[]; %default
0094 end
0095 
0096 %file name and browser initialisation
0097 if isfield(param,'menu_coord_str')
0098     set(handles.CoordType,'String',param.menu_coord_str)
0099 end
0100 if isfield(param,'menu_coord_val')
0101     set(handles.CoordType,'Value',param.menu_coord_val);
0102 else
0103      set(handles.CoordType,'Value',1);%default
0104 end
0105 
0106 if isfield(param,'FileName')
0107     if isfield(param,'FileName_1')
0108         update_file(hObject, eventdata, handles,param.FileName_1,0)
0109         update_file(hObject, eventdata, handles,param.FileName,1)
0110     else
0111         update_file(hObject, eventdata, handles,param.FileName,0)
0112     end
0113 end  
0114 
0115 %fields input initialisation
0116 if isfield(param,'list_fields')& isfield(param,'index_fields') &~isempty(param.list_fields) &~isempty(param.index_fields)
0117     set(handles.FieldMenu,'String',param.list_fields);% list menu fields
0118     set(handles.FieldMenu,'Value',param.index_fields);% selected string index
0119     FieldCell{1}=param.list_fields{param.index_fields};
0120 end
0121 if isfield(param,'civ1')& islogical(param.civ1) & isfield(param,'civ2')& islogical(param.civ2)&...
0122         isfield(param,'interp1')& islogical(param.interp1)&isfield(param,'interp2')& islogical(param.interp2)&...
0123         isfield(param,'filter1')& islogical(param.filter1)&isfield(param,'filter2')& islogical(param.filter2)
0124     set(handles.civ1,'Value',param.civ1);
0125     set(handles.civ2,'Value',param.civ1);
0126     set(handles.interp1,'Value',param.interp1);
0127     set(handles.interp2,'Value',param.interp2);
0128     set(handles.filter1,'Value',param.filter1);
0129     set(handles.filter2,'Value',param.filter2);
0130 end
0131 %set(hObject,'UserData', SeriesData)
0132 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles}) 
0133 NomType_Callback(hObject, eventdata, handles)
0134 %mode_Callback(hObject, eventdata, handles)
0135 
0136 %loads the information stored in prefdir to initiate the browser and the list of functions
0137 menu_str=get(handles.ACTION,'String');%list of functions included in 'series.m'
0138 menu_str(end)=[];%remove from the list the last option 'more...'
0139 path_series=which('series');%path of the function 'series'
0140 for ilist=1:length(menu_str)
0141     fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
0142 end
0143 dir_perso=prefdir;
0144 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0145 if exist(profil_perso,'file')
0146     h=load (profil_perso);
0147     if isfield(h,'series_fct') && iscell(h.series_fct)
0148          for ilist=1:length(h.series_fct)
0149              [path,file]=fileparts(h.series_fct{ilist});
0150              fct_path=[fct_path; {path}];%concatene the list of paths
0151              menu_str=[menu_str; {file}];
0152          end
0153          menu_str=[menu_str;{'more...'}];
0154          set(handles.ACTION,'String',menu_str)
0155     end
0156 end
0157 set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
0158 
0159 % display the GUI for the default action 'check_files'
0160 ACTION_Callback(hObject, eventdata, handles) 
0161 
0162 %--------------------------------------------------------------
0163 % --- Outputs from this function are returned to the command line.
0164 %-----------------------------------------------------------------
0165 function varargout = series_OutputFcn(hObject, eventdata, handles)
0166 % varargout  cell array for returning output args (see VARARGOUT);
0167 % hObject    handle to figure
0168 % eventdata  reserved - to be defined in a future version of MATLAB
0169 % handles    structure with handles and user data (see GUIDATA)
0170 % Get default command line output from handles structure
0171 varargout{1} = handles.output;
0172 
0173 
0174 % --------------------------------------------------------------------
0175 function MenuBrowse_Callback(hObject, eventdata, handles)
0176 
0177 RootPathCell=get(handles.RootPath,'String');
0178 SubDirCell=get(handles.SubDir,'String');  
0179 RootFileCell=get(handles.RootFile,'String');
0180 oldfile=''; %default
0181 if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
0182      dir_perso=prefdir;
0183      profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0184      if exist(profil_perso,'file')
0185           h=load (profil_perso);
0186          if isfield(h,'filebase')&ischar(h.filebase)
0187                  oldfile=h.filebase;
0188          end
0189          if isfield(h,'RootPath')&ischar(h.RootPath) 
0190                  oldfile=h.RootPath;
0191          end
0192      end
0193  else
0194      oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
0195  end
0196 [FileName, PathName, filterindex] = uigetfile( ...
0197        {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
0198        '*.xml',  '.xml files '; ...
0199         '*.xls',  '.xls files '; ...
0200         '*.png','.png image files'; ...
0201         '*.tif','.tif image files'; ...
0202         '*.avi;*.AVI','.avi movie files'; ...
0203         '*.nc','.netcdf files'; ...
0204         '*.*',  'All Files (*.*)'}, ...
0205         'Pick a file',oldfile);
0206 fileinput=[PathName FileName];%complete file name
0207 testblank=findstr(fileinput,' ');%look for blanks
0208 if ~isempty(testblank)
0209     errordlg('forbidden input file name: contain blanks')
0210     return
0211 end
0212 sizf=size(fileinput);
0213 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0214 [path,name,ext]=fileparts(fileinput);
0215 SeriesData=[];%dfault
0216 if isequal(ext,'.xml')
0217     errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
0218 elseif isequal(ext,'.xls')
0219     errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
0220 else
0221     update_file(hObject, eventdata, handles,fileinput,0)
0222      %update list of recent files in the menubar
0223     MenuFile_1=fileinput;
0224     MenuFile_2=get(handles.MenuFile_1,'Label');
0225     MenuFile_3=get(handles.MenuFile_2,'Label');
0226     MenuFile_4=get(handles.MenuFile_3,'Label');
0227     MenuFile_5=get(handles.MenuFile_4,'Label');
0228     set(handles.MenuFile_1,'Label',MenuFile_1)
0229     set(handles.MenuFile_2,'Label',MenuFile_2)
0230     set(handles.MenuFile_3,'Label',MenuFile_3)
0231     set(handles.MenuFile_4,'Label',MenuFile_4)
0232     set(handles.MenuFile_5,'Label',MenuFile_5)
0233     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
0234     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
0235     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
0236     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
0237     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
0238     dir_perso=prefdir;
0239     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0240     if exist(profil_perso,'file')
0241         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
0242     else
0243         txt=ver;
0244         Release=txt(1).Release;
0245         relnumb=str2num(Release(3:4));
0246         if relnumb >= 14
0247             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
0248         else
0249             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
0250         end
0251     end
0252 end
0253 % set(hseries,'UserData',SeriesData);
0254 % RootFile_Callback(hObject, eventdata, handles);
0255 % FileExt_Callback(hObject, eventdata, handles);
0256 % NomType_Callback(hObject, eventdata, handles)
0257 % mode_Callback(hObject, eventdata, handles)
0258 
0259 
0260 % --------------------------------------------------------------------
0261 function MenuFile_1_Callback(hObject, eventdata, handles)
0262 fileinput=get(handles.MenuFile_1,'Label');
0263 update_file(hObject, eventdata, handles,fileinput,0)
0264 
0265 % --------------------------------------------------------------------
0266 function MenuFile_2_Callback(hObject, eventdata, handles)
0267 fileinput=get(handles.MenuFile_2,'Label');
0268 update_file(hObject, eventdata, handles,fileinput,0)
0269 
0270 % --------------------------------------------------------------------
0271 function MenuFile_3_Callback(hObject, eventdata, handles)
0272 fileinput=get(handles.MenuFile_3,'Label');
0273 update_file(hObject, eventdata, handles,fileinput,0)
0274 
0275 % --------------------------------------------------------------------
0276 function MenuFile_4_Callback(hObject, eventdata, handles)
0277 fileinput=get(handles.MenuFile_4,'Label');
0278 update_file(hObject, eventdata, handles,fileinput,0)
0279 
0280 % --------------------------------------------------------------------
0281 function MenuFile_5_Callback(hObject, eventdata, handles)
0282 fileinput=get(handles.MenuFile_5,'Label');
0283 update_file(hObject, eventdata, handles,fileinput,0)
0284 
0285 % --------------------------------------------------------------------
0286 function MenuBrowse_insert_Callback(hObject, eventdata, handles)
0287 
0288 %hseries=get(handles.browse_root,'parent');
0289 RootPathCell=get(handles.RootPath,'String');
0290 % SubDirCell=get(handles.SubDir,'String');
0291 RootFileCell=get(handles.RootFile,'String');
0292 oldfile=''; %default
0293 if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
0294      dir_perso=prefdir;
0295      profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0296      if exist(profil_perso,'file')
0297           h=load (profil_perso);
0298          if isfield(h,'filebase')&ischar(h.filebase)
0299                  oldfile=h.filebase;
0300          end
0301          if isfield(h,'RootPath')&ischar(h.RootPath) 
0302                  oldfile=h.RootPath;
0303          end
0304      end
0305  else
0306      oldfile=fullfile(RootPathCell{1},RootFileCell{1});
0307  end
0308 [FileName, PathName, filterindex] = uigetfile( ...
0309        {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
0310        '*.xml',  '.xml files '; ...
0311         '*.xls',  '.xls files '; ...
0312         '*.png','.png image files'; ...
0313         '*.avi;*.AVI','.avi movie files'; ...
0314         '*.nc','.netcdf files'; ...
0315         '*.*',  'All Files (*.*)'}, ...
0316         'Pick a file',oldfile);
0317 fileinput=[PathName FileName];%complete file name
0318 testblank=findstr(fileinput,' ');%look for blanks
0319 if ~isempty(testblank)
0320     errordlg('forbidden input file name: contain blanks')
0321     return
0322 end
0323 sizf=size(fileinput);
0324 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
0325 [path,name,ext]=fileparts(fileinput);
0326 SeriesData=[];%dfault
0327 if isequal(ext,'.xml')
0328     errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
0329 elseif isequal(ext,'.xls')
0330     errordlg('input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
0331 else
0332     update_file(hObject, eventdata, handles,fileinput,1)
0333     %update list of recent files in the menubar
0334     MenuFile_1=fileinput;
0335     MenuFile_2=get(handles.MenuFile_1,'Label');
0336     MenuFile_3=get(handles.MenuFile_2,'Label');
0337     MenuFile_4=get(handles.MenuFile_3,'Label');
0338     MenuFile_5=get(handles.MenuFile_4,'Label');
0339     set(handles.MenuFile_1,'Label',MenuFile_1)
0340     set(handles.MenuFile_2,'Label',MenuFile_2)
0341     set(handles.MenuFile_3,'Label',MenuFile_3)
0342     set(handles.MenuFile_4,'Label',MenuFile_4)
0343     set(handles.MenuFile_5,'Label',MenuFile_5)
0344     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
0345     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
0346     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
0347     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
0348     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
0349     dir_perso=prefdir;
0350     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0351     if exist(profil_perso,'file')
0352         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
0353     else
0354         txt=ver;
0355         Release=txt(1).Release;
0356         relnumb=str2num(Release(3:4));
0357         if relnumb >= 14
0358             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
0359         else
0360             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
0361         end
0362     end
0363 end
0364 %------------------------------------------------
0365 
0366 % --------------------------------------------------------------------
0367 function MenuFile_insert_1_Callback(hObject, eventdata, handles)
0368 fileinput=get(handles.MenuFile_insert_1,'Label');
0369 update_file(hObject, eventdata, handles,fileinput,1)
0370 
0371 % --------------------------------------------------------------------
0372 function MenuFile_insert_2_Callback(hObject, eventdata, handles)
0373 fileinput=get(handles.MenuFile_insert_2,'Label');
0374 update_file(hObject, eventdata, handles,fileinput,1)
0375 
0376 % --------------------------------------------------------------------
0377 function MenuFile_insert_3_Callback(hObject, eventdata, handles)
0378 fileinput=get(handles.MenuFile_insert_3,'Label');
0379 update_file(hObject, eventdata, handles,fileinput,1)
0380 
0381 % --------------------------------------------------------------------
0382 function MenuFile_insert_4_Callback(hObject, eventdata, handles)
0383 fileinput=get(handles.MenuFile_insert_4,'Label');
0384 update_file(hObject, eventdata, handles,fileinput,1)
0385 
0386 % --------------------------------------------------------------------
0387 function MenuFile_insert_5_Callback(hObject, eventdata, handles)
0388 fileinput=get(handles.MenuFile_insert_5,'Label');
0389 update_file(hObject, eventdata, handles,fileinput,1)
0390 
0391 % --------------------------------------------------------------------
0392 % refresh the GUI data after introduction of a new file series
0393 function update_file(hObject, eventdata, handles,fileinput,addtest)
0394 hseries=get(handles.RootPath,'parent');  
0395 % refresh input root name, indices, file extension and nomenclature
0396 [RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
0397 %check for movie image files
0398 if ~isempty(imformats(FileExt(2:end)))
0399     imainfo=imfinfo(fileinput);     
0400     if length(imainfo) >1 %case of image with multiple frames
0401         NomType='*';
0402         [RootPath,RootFile]=fileparts(fileinput);
0403     end
0404 end
0405 NcType='none';%default
0406 if isequal(FileExt,'.nc')
0407    Data=nc2struct(fileinput,[]);
0408    if isfield(Data,'absolut_time_T0')
0409        NcType='civx'; % test for civx velocity fields
0410    end
0411 end
0412 
0413 set(handles.RootPath,'Value',1)
0414 set(handles.SubDir,'Value',1)
0415 set(handles.RootFile,'Value',1)
0416 set(handles.NomType,'Value',1)
0417 set(handles.FileExt,'Value',1)
0418 set(handles.nb_field,'Value',1)
0419 set(handles.nb_field2,'Value',1)
0420 if addtest
0421     SeriesData=get(hseries,'UserData');
0422     SeriesData.displ_num=[0 0 0 0;SeriesData.displ_num];
0423     SeriesData.CurrentInputFile_1=SeriesData.CurrentInputFile;
0424     RootPathCell=[{RootPath}; get(handles.RootPath,'String')] ; 
0425     SubDirCell=[{SubDir}; get(handles.SubDir,'String')];
0426     RootFileCell=[{RootFile}; get(handles.RootFile,'String')]; 
0427     NomTypeCell=[{NomType}; SeriesData.NomType];
0428     FileExtCell=[{FileExt}; get(handles.FileExt,'String')];
0429     NcTypeCell=[{NcType};SeriesData.NcType];
0430     set(handles.NomType,'String',[{};get(handles.NomType,'String')])
0431 else
0432     SeriesData=[];%re-initialisation
0433     SeriesData.displ_num=[0 0 0 0];
0434     RootPathCell={RootPath};
0435     SubDirCell={SubDir};
0436     RootFileCell={RootFile};   
0437     NomTypeCell={NomType};
0438     FileExtCell={FileExt};   
0439     NcTypeCell={NcType};
0440 end
0441 
0442 SeriesData.NomType=NomTypeCell;
0443 SeriesData.NcType=NcTypeCell;
0444 SeriesData.CurrentInputFile=fileinput;
0445 set(handles.RootPath,'String',RootPathCell);
0446 set(handles.SubDir,'String',SubDirCell);
0447 set(handles.RootFile,'String',RootFileCell);
0448 set(handles.NomType,'String',NomTypeCell);
0449 set(handles.FileExt,'String',FileExtCell);  
0450 
0451 %determine field indices
0452 ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
0453 if ~isempty(str2num(field_count))
0454     ref_i=str2num(field_count);
0455     if ~isempty(str2num(str2))
0456         ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
0457         SeriesData.browse_Di=str2num(str2)-str2num(field_count);
0458     end
0459 end
0460 set(handles.ref_i,'String',num2str(ref_i));
0461 set(handles.first_i,'String',num2str(ref_i));
0462 set(handles.last_i,'String',num2str(ref_i));
0463 ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
0464 if ~isempty(str2num(str_a))
0465     ref_j=str2num(str_a);
0466     if ~isempty(str2num(str_b))
0467         ref_j=floor((str2num(str_a)+str2num(str_b))/2);
0468         SeriesData.browse_Dj=str2num(str_b)-str2num(str_a); 
0469     end          
0470 end
0471 set(handles.ref_j,'String',num2str(ref_j)); 
0472 set(handles.first_j,'String',num2str(ref_j))
0473 set(handles.last_j,'String',num2str(ref_j)); 
0474 %set(hseries,'UserData',SeriesData);
0475 
0476 %enable other menus and uicontrols
0477 set(handles.MenuOpen_insert,'Enable','on')
0478 set(handles.MenuFile_insert_1,'Enable','on')
0479 set(handles.MenuFile_insert_2,'Enable','on')
0480 set(handles.MenuFile_insert_3,'Enable','on')
0481 set(handles.MenuFile_insert_4,'Enable','on')
0482 set(handles.MenuFile_insert_5,'Enable','on')
0483 set(handles.RUN, 'Enable','On')
0484 set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
0485 set(handles.RootPath,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
0486 drawnow
0487 
0488 % hseries=get(handles.RootFile,'parent');
0489 % SeriesData=get(hseries,'UserData');%read information set by the browser
0490 % ext_ima_read=[];
0491 % field_count=1;%default
0492 % pxcmx=1;
0493 % pxcmy=1;
0494 TimeUnit=''; %default
0495 % CoordUnit='';%default
0496 time=[];%default
0497 GeometryCalib=[];%default
0498 nb_field=[];%default
0499 nb_field2=[];%default
0500 % Heading=[];
0501 % [PD,Device]=fileparts(RootPathCell{1});
0502 SeriesData.PathCampaign=get(handles.PathCampaign,'String');
0503 
0504 % read timing and total frame number from the current file (movie files) !! may be overrid by xml file
0505 %icell=length(RootPathCell);
0506 FileBase=fullfile(RootPath,RootFile);
0507 
0508 % nb_field{icell,1}='?';%default
0509 % nb_field2{icell,1}='?';%default
0510 testima=0; %test for image input
0511 if isequal(lower(FileExt),'.avi') %.avi file
0512     testima=1;
0513     info=aviinfo([FileBase FileExt]);
0514     time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
0515     nb_field=info.NumFrames;
0516     nb_field2=1;
0517 elseif ~isempty(imformats(FileExt(2:end))) 
0518     testima=1;
0519     if isequal(NomType,'*')% multi-frame image
0520         imainfo=imfinfo([FileBase FileExt]);     
0521         if length(imainfo) >1 %case of image with multiple frames
0522             nb_field=length(imainfo);
0523             nb_field2=1;
0524         end
0525     end
0526 elseif isequal(FileExt,'.vol')
0527      testima=1;
0528 end
0529 
0530 % enable field and veltype menus
0531 testfield=isequal(get(handles.FieldMenu,'enable'),'on');
0532 testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
0533 testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
0534 testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
0535 testtransform=isequal(get(handles.CoordType,'Enable'),'on');
0536 %FieldMenu_1;
0537 testnc=0;
0538 testnc_1=0;
0539 testcivx=0;
0540 testcivx_1=0;
0541 if length(FileExtCell)==1 || length(FileExtCell)>2
0542     for iview=1:length(FileExtCell)
0543         if isequal(FileExtCell{iview},'.nc')
0544             testnc=1;
0545         end
0546         if isequal(NcTypeCell{iview},'civx')
0547             testcivx=1;
0548         end
0549     end
0550 elseif length(FileExtCell)==2
0551     testnc=isequal(FileExtCell{1},'.nc');
0552     testnc_1=isequal(FileExtCell{2},'.nc');
0553     testcivx=isequal(NcTypeCell{1},'civx');
0554     testcivx_1=isequal(NcTypeCell{2},'civx');
0555 end
0556 if testfield && testnc 
0557     view_FieldMenu(handles,'on')
0558     if testcivx
0559         menustr=get(handles.FieldMenu,'String');
0560         if isequal(menustr,{'get_field...'})
0561             set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
0562         end
0563     else
0564         set(handles.FieldMenu,'Value',1)
0565         set(handles.FieldMenu,'String',{'get_field...'}) 
0566     end
0567 else
0568     view_FieldMenu(handles,'off')
0569 end
0570 if testfield_1 && testnc_1
0571     view_FieldMenu_1(handles,'on')
0572     if testcivx_1
0573         menustr=get(handles.FieldMenu_1,'String');
0574         if isequal(menustr,{'get_field...'})
0575             set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
0576         end
0577     else
0578         set(handles.FieldMenu_1,'Value',1)
0579         set(handles.FieldMenu_1,'String',{'get_field...'}) 
0580     end
0581 else
0582     view_FieldMenu_1(handles,'off')
0583 end
0584 if testveltype && testcivx
0585     set(handles.VelTypeMenu,'Visible','on')
0586     set(handles.VelType_text,'Visible','on');
0587 else
0588     set(handles.VelTypeMenu,'Visible','off')
0589     set(handles.VelType_text,'Visible','off');
0590 end
0591 if testveltype_1 && testcivx_1
0592     set(handles.VelTypeMenu_1,'Visible','on')
0593     set(handles.VelType_text_1,'Visible','on');
0594 else
0595     set(handles.VelTypeMenu_1,'Visible','off')
0596     set(handles.VelType_text_1,'Visible','off');
0597 end
0598 if testtransform && (testcivx || testima)
0599      view_TRANSFORM(handles,'on')
0600 else
0601     view_TRANSFORM(handles,'off')
0602 end
0603 if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
0604     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
0605     return
0606 end  
0607 
0608 %%%%%%%%   read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
0609       %look for the file existence
0610 ext_imadoc='';
0611 if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
0612     ext_imadoc=FileExt;
0613 elseif exist([FileBase '.xml'],'file')
0614     ext_imadoc='.xml';
0615 elseif exist([FileBase '.civ'],'file')
0616     ext_imadoc='.civ';
0617 end
0618       %read the ImaDoc file
0619 % mode=''; %default
0620 % testheading=0;
0621 if isequal(ext_imadoc,'.xml')
0622         [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
0623         if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName')
0624             [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
0625         end
0626         if isfield(XmlData,'Time')
0627             time=XmlData.Time;
0628         end
0629         if isfield(XmlData,'Camera')
0630             if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
0631                 NbSlice=XmlData.Camera.NbSlice;
0632             end
0633             if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
0634                 TimeUnit=XmlData.Camera.TimeUnit;
0635             end
0636         end
0637 %         testheading=1;
0638 %         if error==1,
0639 %             warndlg([FileBase '.xml is not an image documentation file']);
0640 %              testheading=0;
0641 %         elseif error==1.1, warndlg_uvmat(['no element '' ImaDoc/Heading '' in ' FileBase '.xml'],'WARNING');
0642 %         elseif error==1.2, warndlg_uvmat(['no element '' ImaDoc/Camera '' in ' FileBase '.xml'],'WARNING');
0643 %         elseif error==1.21, warndlg_uvmat(['no element '' ImaDoc/Camera/BurstTiming '' in ' FileBase '.xml'],'WARNING');
0644 %         elseif error==1.211, warndlg_uvmat(['no element '' ImaDoc/Camera/BurstTiming/FrameFrequency'' in ' FileBase '.xml'],'WARNING');
0645 %         elseif error==1.212, warndlg_uvmat(['no element '' ImaDoc/Camera/BurstTiming/Time '' in ' FileBase '.xml'],'WARNING');
0646         if ~isempty(warntext)
0647             warndlg_uvmat(warntext,'WARNING')
0648         end  
0649 elseif isequal(ext_imadoc,'.civ')
0650     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
0651     time=XmlData.Time;
0652     size(time)
0653     GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
0654     GeometryCalib.Tx=0;
0655     GeometryCalib.Ty=0;
0656     GeometryCalib.Tz=1;
0657     GeometryCalib.dpx=1;
0658     GeometryCalib.dpy=1;
0659     GeometryCalib.sx=1;
0660     GeometryCalib.Cx=0;
0661     GeometryCalib.Cy=0;
0662     GeometryCalib.f=1;
0663     GeometryCalib.kappa1=0;
0664     GeometryCalib.CoordUnit='cm';
0665     XmlData.GeometryCalib=GeometryCalib;
0666     if error==2, warntext=['no file ' FileBase '.civ'];
0667     elseif error==1, warntext='inconsistent number of fields in the .civ file';
0668     end  
0669 %     set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
0670 %     set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
0671 %     set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
0672 %     set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
0673 %     set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
0674 %     set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
0675 %     set(handles.view_xml,'Visible','on')
0676 %     set(handles.view_xml,'String','view .civ')
0677 end  
0678 if addtest
0679     SeriesData.Time=[{time} SeriesData.Time];
0680 else
0681    SeriesData.Time={time};
0682 end
0683 
0684 if ~isempty(time)
0685     siztime=size(time);
0686     nb_field=siztime(1);
0687     nb_field2=siztime(2);
0688 end   
0689 set(handles.TimeUnit,'String',TimeUnit)
0690 if isempty(nb_field)
0691     nb_field_str='?';
0692     nb_field_str2='?';
0693 else
0694     nb_field_str=num2str(nb_field);
0695     nb_field_str2=num2str(nb_field2);
0696 end
0697 if addtest
0698     nb_field_cell=[{nb_field_str} ;get(handles.nb_field,'String')];
0699     nb_field2_cell=[{nb_field_str2} ;get(handles.nb_field2,'String')];
0700 else
0701     nb_field_cell={nb_field_str};
0702     nb_field2_cell={nb_field_str2};
0703 end
0704 set(handles.nb_field,'String',nb_field_cell);
0705 set(handles.nb_field2,'String',nb_field2_cell);
0706 set(hseries,'UserData',SeriesData);
0707 
0708 %number of slices
0709 if isfield(GeometryCalib,'PlanePos')
0710        siz=size(GeometryCalib.PlanePos);
0711        if siz(1)>1
0712            NbSlice=length(GeometryCalib.PlanePos);
0713        else
0714            NbSlice=1;
0715        end
0716        set(handles.NbSlice,'String',num2str(NbSlice))
0717 end
0718 
0719 % set menus of index pairs
0720 NomType_Callback(hObject, eventdata, handles)
0721 
0722 dir_perso=prefdir;
0723 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0724 % save(profil_perso, 'FileBase'); %store the root name for future opening of uvmat
0725 if exist(profil_perso,'file')
0726     save (profil_perso,'RootPath','SubDir','RootFile','NomType', '-append'); %store the root name for future opening of uvmat
0727 else
0728     txt=ver;
0729     Release=txt(1).Release;
0730     relnumb=str2num(Release(3:4));
0731     if relnumb >= 14
0732         save (profil_perso,'RootPath','SubDir','RootFile','NomType','-V6') %store the root name for future opening of uvmat
0733     else
0734         save(profil_perso,'RootPath','SubDir','RootFile','NomType')
0735     end         
0736 end
0737 set(handles.RootPath,'BackgroundColor',[1 1 1])
0738 set(handles.PathCampaign,'String',SeriesData.PathCampaign)
0739 last_j_Callback(hObject, eventdata, handles)
0740 last_i_Callback(hObject, eventdata, handles)
0741 
0742 %------------------------------------------------------------
0743 function RootPath_Callback(hObject, eventdata, handles)
0744 Val=get(handles.RootPath,'Value');
0745 synchronise_view(handles,Val)
0746 NomType_Callback(hObject, eventdata, handles)
0747 %------------------------------------------------------------
0748 
0749 function synchronise_view(handles,Val)
0750 set(handles.RootPath,'Value',Val)
0751 set(handles.SubDir,'Value',Val)
0752 set(handles.RootFile,'Value',Val)
0753 set(handles.NomType,'Value',Val)
0754 set(handles.FileExt,'Value',Val)
0755 set(handles.nb_field,'Value',Val)
0756 set(handles.nb_field2,'Value',Val)
0757 set(handles.time_first,'Value',Val)
0758 set(handles.time_last,'Value',Val)
0759 
0760 
0761 %---------------------------------------------------------
0762 % Executes on carriage return on the subdir civ1 edit window
0763 %--------------------------------------------------------
0764 function SubDir_Callback(hObject, eventdata, handles)
0765 
0766 Val=get(handles.SubDir,'Value');
0767 synchronise_view(handles,Val)
0768 NomType_Callback(hObject, eventdata, handles)
0769 
0770 %--------------------------------------------------------------
0771 %function activated when a new filebase (image series) is introduced
0772 %------------------------------------------------------------
0773 function RootFile_Callback(hObject, eventdata, handles)
0774 Val=get(handles.RootFile,'Value');
0775 synchronise_view(handles,Val)
0776 NomType_Callback(hObject, eventdata, handles)
0777 
0778 %--------------------------------------------------------------
0779 %function activated when a new filebase (image series) is introduced
0780 %------------------------------------------------------------
0781 function FileExt_Callback(hObject, eventdata, handles)
0782 Val=get(handles.FileExt,'Value');
0783 synchronise_view(handles,Val)
0784 
0785 %--------------------------------------------------------------
0786 %function activated when a new filebase (image series) is introduced
0787 %------------------------------------------------------------
0788 function nb_field_Callback(hObject, eventdata, handles)
0789 Val=get(handles.nb_field,'Value');
0790 synchronise_view(handles,Val)
0791 
0792 %--------------------------------------------------------------
0793 %function activated when a new filebase (image series) is introduced
0794 %------------------------------------------------------------
0795 function nb_field2_Callback(hObject, eventdata, handles)
0796 Val=get(handles.nb_field2,'Value');
0797 synchronise_view(handles,Val)
0798 
0799 %--------------------------------------------------------------
0800 %function activated when a new filebase (image series) is introduced
0801 %------------------------------------------------------------
0802 function time_first_Callback(hObject, eventdata, handles)
0803 Val=get(handles.time_first,'Value');
0804 synchronise_view(handles,Val)
0805 
0806 %--------------------------------------------------------------
0807 %function activated when a new filebase (image series) is introduced
0808 %------------------------------------------------------------
0809 function time_last_Callback(hObject, eventdata, handles)
0810 Val=get(handles.time_last,'Value');
0811 synchronise_view(handles,Val)
0812 
0813 %--------------------------------------------------------------
0814 %function activated by NomType
0815 %------------------------------------------------------------
0816 NomType_Callback(hObject, eventdata, handles)
0817 
0818 function NomType_Callback(hObject, eventdata, handles)
0819 hseries=get(handles.ProjObject,'Parent');
0820 SeriesData=get(hseries,'UserData');
0821 if isfield(SeriesData,'NomType')
0822     NomTypeCell=SeriesData.NomType;
0823 else
0824     NomTypeCell={};
0825 end
0826 nbfield2_cell=get(handles.nb_field2,'String');
0827 val=get(handles.nb_field2,'Value');
0828 if iscell(nbfield2_cell)
0829     nbfield2=str2num(nbfield2_cell{val});
0830 else
0831     nbfield2=str2num(nbfield2_cell);
0832 end
0833 nbfield_cell=get(handles.nb_field,'String');
0834 if iscell(nbfield_cell)
0835     nbfield=str2num(nbfield_cell{val});
0836 else
0837    nbfield=str2num(nbfield_cell);
0838 end
0839 
0840 set(handles.mode,'Visible','off') % do not show index pairs by default
0841 set(handles.list_pair_civ,'Visible','off')
0842 set(handles.ref_i,'Visible','off')
0843 set(handles.ref_i_text,'Visible','off')
0844 testpair=0;
0845 state_j='off';
0846 %set the menus of image pairs and default selection for series
0847 %list pairs if relevant
0848 Val=get(handles.NomType,'Value');
0849 synchronise_view(handles,Val)
0850 if ~isempty(NomTypeCell)
0851     NomType=NomTypeCell{Val};
0852     switch NomType  
0853             case {'_i1-i2_j', '_i1-i2'}
0854                 set(handles.mode,'String',{'series(Di)'})
0855                 set(handles.mode,'Value',1);
0856                 set(handles.mode,'Visible','on')
0857                 testpair=1;
0858             case {'#_ab'} 
0859                 set(handles.mode,'String',{'bursts'})
0860                 set(handles.mode,'Value',1);
0861                 testpair=1;
0862             case '_i_j1-j2'
0863                 set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
0864                 if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
0865                     set(handles.mode,'Value',2);
0866                 else
0867                     set(handles.mode,'Value',1);% advice 'bursts' for small bursts
0868                 end
0869                 set(handles.mode,'Visible','on')
0870                 testpair=1;
0871     end
0872     switch NomType   
0873             case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
0874                 state_j='on';
0875     end
0876 end   
0877 if testpair
0878     mode_Callback(hObject, eventdata, handles)  
0879 else
0880     set(handles.NomType,'String',NomTypeCell)
0881 end
0882 set(handles.first_j,'Visible',state_j)
0883 set(handles.incr_j,'Visible',state_j)
0884 set(handles.last_j,'Visible',state_j)
0885 set(handles.nb_field2,'Visible',state_j)
0886 
0887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
0888 % --- Executes on button press in mode.
0889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0890 function mode_Callback(hObject, eventdata, handles)
0891 hseries=get(handles.mode,'parent');
0892 SeriesData=get(hseries,'UserData');
0893 mode_list=get(handles.mode,'String');
0894 mode_value=get(handles.mode,'Value');
0895 mode=mode_list{mode_value};
0896 NomType=[];
0897 test_find_pair=0;
0898 if isfield(SeriesData,'NomType')
0899     NomTypeCell=SeriesData.NomType;
0900     Val=get(handles.NomType,'Value');
0901     NomType=NomTypeCell{Val};
0902     test_find_pair=isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')|| isequal(NomType,'#_ab');
0903 end
0904 % displ_num=[];%default
0905 % first_i=str2num(get(handles.first_i,'String'));
0906 % last_i=str2num(get(handles.last_i,'String'));
0907 time=[];
0908 if isfield(SeriesData,'Time')
0909 time=SeriesData.Time{1}; %get the set of times
0910 end
0911 siztime=size(time);
0912 nbfield=siztime(1);
0913 nbfield2=siztime(2);
0914 indchosen=1;  %%first pair selected by default
0915 if isequal(mode,'bursts')
0916     enable_i(handles,'On')
0917     enable_j(handles,'Off')    
0918 elseif  isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')
0919     enable_i(handles,'On')
0920     enable_j(handles,'On') 
0921 else
0922     enable_i(handles,'On')
0923     enable_j(handles,'Off') 
0924 end    
0925     
0926     
0927 % elseif isequal(mode,'series(Dj)')
0928 %     enable_j(handles,'On')
0929 %     if nbfield==1
0930 %         enable_i(handles,'Off')
0931 %     else
0932 %         enable_i(handles,'On')
0933 %     end
0934 % elseif isequal(mode,'series(Di)')
0935 %     if nbfield2 > 1
0936 %          enable_j(handles,'On')
0937 %     else
0938 %          enable_j(handles,'Off')
0939 %     end
0940 % end
0941 set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
0942 % SetSeries.displ_num=displ_num;
0943 set(hseries,'UserData',SeriesData)
0944 
0945 %list pairs if relevant
0946 if test_find_pair
0947      find_netcpair_civ(hObject, eventdata, handles,Val)
0948 end
0949 
0950 %-------------------------------------
0951 function enable_i(handles,state)
0952 set(handles.i_txt,'Visible',state)
0953 set(handles.first_i,'Visible',state)
0954 set(handles.last_i,'Visible',state)
0955 set(handles.incr_i,'Visible',state)
0956 set(handles.nb_field,'Visible',state)
0957 set(handles.ref_i,'Visible',state)
0958 set(handles.ref_i_text,'Visible',state)
0959 
0960 %-----------------------------------
0961 function enable_j(handles,state)
0962 set(handles.j_txt,'Visible',state)
0963 set(handles.first_j,'Visible',state)
0964 set(handles.last_j,'Visible',state)
0965 set(handles.incr_j,'Visible',state)
0966 set(handles.nb_field2,'Visible',state)
0967 set(handles.ref_j,'Visible',state)
0968 set(handles.ref_j_text,'Visible',state)
0969 
0970 %-----------------------------------
0971 function view_FieldMenu(handles,state)
0972 set(handles.FieldMenu,'Visible',state)
0973 set(handles.Field_text,'Visible',state)
0974 set(handles.Field_frame,'Visible',state)
0975 
0976 %-----------------------------------
0977 function view_FieldMenu_1(handles,state)
0978 set(handles.FieldMenu_1,'Visible',state)
0979 set(handles.Field_text_1,'Visible',state)
0980 
0981 %-----------------------------------
0982 function view_TRANSFORM(handles,state)
0983 set(handles.TRANSFORM_frame,'Visible',state)
0984 set(handles.CoordType,'Visible',state);
0985 set(handles.TRANSFORM_title,'Visible',state)
0986 
0987 %--------------------------------------------------------------
0988 % determine the menu for civ1 pairs depending on existing netcdf file at the middle of
0989 % the field series set by first_i, incr, last_i
0990 %----------------------------------------------------------------
0991 function find_netcpair_civ(hObject, eventdata, handles,Val)
0992 hseries=get(handles.list_pair_civ,'parent');
0993 SeriesData=get(hseries,'UserData'); 
0994 % NomTypeCell=get(handles.NomType,'String');
0995 NomTypeCell=SeriesData.NomType;
0996 NomType=NomTypeCell{Val};
0997   set(handles.list_pair_civ,'Visible','on')
0998 %nomenclature types
0999 RootPathCell=get(handles.RootPath,'String');
1000 filepath=RootPathCell{Val};
1001 RootFileCell=get(handles.RootFile,'String');
1002 filename=RootFileCell{Val};
1003 filebase=fullfile(filepath,filename);
1004 SubDirCell=get(handles.SubDir,'String');
1005 subdir=SubDirCell{Val};
1006 if ~exist(fullfile(filepath,subdir),'dir') 
1007          msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
1008          set(handles.list_pair_civ,'String',{''});
1009          return
1010 end
1011 mode_list=get(handles.mode,'String');
1012 mode_value=get(handles.mode,'Value');
1013 mode=mode_list{mode_value};
1014 
1015 %reads image numbers from the interface
1016 ref_i=str2num(get(handles.ref_i,'String'));
1017 ref_j=str2num(get(handles.ref_j,'String'));
1018 % time=[];
1019 % ref_time=[];
1020  ref_time=0;
1021 if isfield(SeriesData,'Time')&~isempty(SeriesData.Time{Val})&~isequal(SeriesData.Time{Val},0)
1022     time=SeriesData.Time{Val}; %get the set of times
1023     siztime=size(time);
1024     nbfield=siztime(1);
1025     nbfield2=siztime(2);
1026 %     test_imadoc=1;
1027 else
1028 %     test_imadoc=0;%no image documentation file
1029     nbfield=50;
1030     nbfield2=50;%default max number of pairs
1031 end
1032 %look for existing processed pairs involving the field at the middle of the series if civ1 will not
1033 % be performed, while the result is needed for next steps.
1034 displ_pair={''};
1035 displ_num=[];
1036 ind_exist=0;
1037 TimeUnit=get(handles.TimeUnit,'String');
1038 if length(TimeUnit)>=1
1039     dtunit=['m' TimeUnit];
1040 else
1041     dtunit='e-03';
1042 end
1043 if isequal(mode,'series(Di)') 
1044      for index=1:min(nbfield-1,50)
1045          [filename]=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
1046          select=(exist(filename,'file')==2);
1047          if select==1
1048                ind_exist=ind_exist+1;
1049                 displ_num(1,ind_exist)=0;
1050                 displ_num(2,ind_exist)=0;
1051                 displ_num(3,ind_exist)=-floor(index/2);
1052                 displ_num(4,ind_exist)=ceil(index/2);
1053                 %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1054                 [Cte,var_detect,ichoice]=nc2struct(filename,{});
1055                 if isfield(Cte,'dt2')
1056                     dt=Cte.dt2;
1057                 elseif isfield(Cte,'dt')
1058                     dt=Cte.dt;
1059                 end
1060                 if isfield(Cte,'absolut_time_TO_2')
1061                     ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1062                 elseif isfield(Cte,'absolut_time_TO')
1063                     ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1064                 elseif isfield(Cte,'Time')
1065                     ref_time(ind_exist)=Cte.Time;
1066                 end
1067                 displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1068          end
1069      end
1070      set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
1071 elseif isequal(mode,'series(Dj)')% series on the j index
1072        for index=1:min(nbfield2-1,50)
1073            [filename]=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
1074            select=(exist(filename,'file')==2);
1075            if select==1
1076                ind_exist=ind_exist+1;
1077                 displ_num(1,ind_exist)=-floor(index/2);
1078                 displ_num(2,ind_exist)=ceil(index/2);
1079                 displ_num(3,ind_exist)=0;
1080                 displ_num(4,ind_exist)=0;
1081                 %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1082                 [Cte,var_detect,ichoice]=nc2struct(nc,{});
1083                 if isfield(Cte,'dt2')
1084                     dt=Cte.dt2;
1085                 elseif isfield(Cte,'dt')
1086                     dt=Cte.dt;
1087                 end
1088                 if isfield(Cte,'absolut_time_TO_2')
1089                     ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1090                 elseif isfield(Cte,'absolut_time_TO')
1091                     ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1092                 elseif isfield(Cte,'Time')
1093                     ref_time(ind_exist)=Cte.Time;
1094                 end
1095 %                 if cte_detect(2)==1;
1096 %                     dt=cte_read(2);
1097 %                     ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
1098 %                 else
1099 %                     dt=cte_read(1);
1100 %                     ref_time(ind_exist)=cte_read(3);
1101 %                 end
1102                 displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1103            end
1104        end
1105        set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
1106 elseif isequal(mode,'bursts') %case of bursts
1107     for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
1108         for numod_b=(numod_a+1):nbfield2
1109             [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir);
1110             select=(exist(filename,'file')==2);
1111             if select==1
1112                 ind_exist=ind_exist+1;
1113                 numlist_a(ind_exist)=numod_a;
1114                 numlist_b(ind_exist)=numod_b;
1115                 Attr=nc2struct(filename,[]);
1116                 isfield(Attr,'absolut_time_T0_2')
1117                 if isfield(Attr,'dt2')
1118                    dt(ind_exist)=Attr.dt2;
1119                    ref_time(ind_exist)=Attr.absolut_time_T0_2;
1120                 elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
1121                    dt(ind_exist)=Attr.dt;
1122                    ref_time(ind_exist)=Attr.absolut_time_T0;
1123                 else
1124                    dt(ind_exist)=NaN;%no information on dt
1125                 end
1126                 %determine nom_type_ima for pair display (used in num2stra.m)
1127                 switch NomType
1128                     case {'#ab'}
1129                         nom_type_ima='#a';
1130                     case {'#AB'}
1131                         nom_type_ima='#A';
1132                     otherwise
1133                          nom_type_ima='_i_j';
1134                 end
1135                displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
1136                         ' :dt= ' num2str(dt(ind_exist)*1000)];
1137             end
1138          end
1139          set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
1140      end
1141      if exist('dt','var') & ~isempty(dt)
1142          [dtsort,indsort]=sort(dt);
1143          displ_num(1,:)=numlist_a(indsort);
1144          displ_num(2,:)=numlist_b(indsort);
1145          displ_num(3,:)=0;
1146          displ_num(4,:)=0;
1147          displ_pair=displ_pair(indsort);
1148          ref_time=ref_time(indsort);
1149      end
1150 end
1151 if ind_exist==0
1152          if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)') 
1153             msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
1154         else
1155             msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1156         end
1157         if isequal(mode,'bursts') %case of bursts
1158             set(handles.list_pair_civ,'String',{'j=*-*'});
1159         elseif isequal(mode,'series(Di)') %case of bursts
1160             set(handles.list_pair_civ,'String',{'Di=*|*'});
1161         elseif isequal(mode,'series(Dj)') %case of bursts
1162             set(handles.list_pair_civ,'String',{'Dj=*|*'});
1163         end
1164 end
1165 
1166 val=get(handles.list_pair_civ,'Value');
1167 if val > length(displ_pair)
1168     set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1169     val=1;
1170 end
1171 iview=get(handles.NomType,'Value');
1172 SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1173 SeriesData.ref_time=ref_time;
1174 set(hseries,'UserData',SeriesData)
1175 list_pair_civ_Callback(hObject, eventdata, handles)
1176 
1177 %-------------------------------------------------------------
1178 % --- Executes on selection in list_pair_civ.
1179 function list_pair_civ_Callback(hObject, eventdata, handles)
1180 %------------------------------------------------------------
1181 
1182 %update first_i and last_i according to the chosen image pairs
1183 testupdate=0;
1184 Val=get(handles.RootPath,'Value');
1185 IndexCell=get(handles.NomType,'String');
1186 hseries=get(handles.list_pair_civ,'parent');
1187 SeriesData=get(hseries,'UserData');
1188 NomType=SeriesData.NomType{Val};
1189 list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1190 index_pair=get(handles.list_pair_civ,'Value');
1191 str_pair=list_pair{index_pair};
1192 ind_equ=strfind(str_pair,'=');%find separator
1193 ind_sep=strfind(str_pair,'|');%find separator
1194 ind_com=strfind(str_pair,':');%find separator
1195 test_bursts=0;
1196 if isempty(ind_sep)
1197     ind_sep=strfind(str_pair,'-');%find separator
1198     test_bursts=1;
1199 end
1200 displ_num=[0 0 0 0]; %default
1201 if ~isempty(ind_sep)
1202     num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1203     num2_str=str_pair(ind_sep+1:ind_com-1);
1204     num1=str2double(num1_str);
1205     num2=str2double(num2_str);
1206     if isequal(num1_str(1),' ')
1207         num1_str(1)=[];
1208     end   
1209     if isequal(num2_str(end),' ')
1210         num2_str(end)=[];
1211     end
1212     switch NomType
1213        case {'_i1-i2_j'}
1214            if isequal(num1_str(1),'0')
1215                IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1216            else
1217                IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1218            end
1219            displ_num(3)=num1;
1220            displ_num(4)=num2;
1221        case {'_i1-i2'}
1222            if isequal(num1_str(1),'0')
1223                IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1224            else
1225                IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1226            end
1227            displ_num(3)=num1;
1228            displ_num(4)=num2;
1229        case '_i_j1-j2'
1230           if test_bursts
1231               IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1232           else
1233               if isequal(num1_str(1),'0')
1234                  IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1235               else
1236                  IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1237               end
1238           end
1239           displ_num(1)=num1;
1240           displ_num(2)=num2;
1241        case {'#_ab'} %TO COMPLETE
1242            IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1243 
1244     end
1245 end
1246 set(handles.NomType,'String',IndexCell)
1247 size(SeriesData.displ_num)
1248 size(displ_num)
1249 SeriesData.displ_num(Val,:)=displ_num;
1250 set(hseries,'UserData',SeriesData)
1251 % set(handles.NomType,'Value',Val)
1252 
1253 if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1254     mode_list=get(handles.mode,'String');
1255     mode_value=get(handles.mode,'Value');
1256     mode=mode_list{mode_value};
1257     if isequal(mode,'series(Di)')
1258         first_i=str2num(get(handles.first_i,'String'));
1259         last_i=str2num(get(handles.last_i,'String'));
1260         incr_i=str2num(get(handles.incr_i,'String'));
1261         num1=first_i:incr_i:last_i;
1262         lastfieldCell=get(handles.nb_field,'String');
1263         lastfield=str2num(lastfieldCell{1});
1264         if ~isempty(lastfield)
1265             ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1266             num1=num1(ind);       
1267         end
1268         set(handles.first_i,'String',num2str(num1(1)));
1269         set(handles.last_i,'String',num2str(num1(end)));
1270         testupdate=1;
1271     elseif isequal(mode,'series(Dj)')
1272         first_j=str2num(get(handles.first_j,'String'));
1273         last_j=str2num(get(handles.last_j,'String'));
1274         incr_j=str2num(get(handles.incr_j,'String'));
1275         num_j=first_j:incr_j:last_j;
1276         lastfieldCell=get(handles.nb_field2,'String');
1277         if ~isempty(lastfieldCell)
1278             lastfield2=lastfieldCell{1};
1279             ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1280                  (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1281 %             if length(num_j)>=ind
1282 %                 num1=num_j(ind);    % A REVOIR
1283 %             else
1284 %                 num1=1; %
1285 %             end
1286         end
1287 %         set(handles.first_j,'String',num2str(num1(1)));
1288 %         set(handles.last_j,'String',num2str(num1(end)));
1289         testupdate=1;
1290     end 
1291     
1292     %update the first and last times of the series
1293     if testupdate & isfield(SeriesData,'Time')
1294         if ~isempty(SeriesData.Time{1})
1295             displ_time(handles,SeriesData.Time{1});
1296         end
1297     end
1298 end
1299 %---------------------------------------------------
1300 % --- Executes on button press in RUN.
1301 %------------------------------------------------------
1302 function RUN_Callback(hObject, eventdata, handles)
1303 
1304 %.AName,..typprojObjecte of scalar (from Field menu)
1305 %.First_i, Last_i, Incr_i, First_j, Last_j, Incr_j
1306 %.CoordType : phys or px
1307 %read root name and field type
1308 set(handles.RUN,'BusyAction','queue');
1309 hseries=get(handles.RUN,'parent');
1310 set(0,'CurrentFigure',hseries)
1311 if isequal(get(handles.GetObject,'Value'),1) 
1312     Series.GetObject=1;
1313     GetObject_Callback(hObject, eventdata, handles)
1314 else
1315     Series.GetObject=0;
1316 end
1317 SeriesData=get(hseries,'UserData');
1318 if isfield(SeriesData,'sethandles')
1319     if iscell(SeriesData.sethandles)
1320         Series.sethandles=SeriesData.sethandles{1};
1321     else
1322         Series.sethandles=SeriesData.sethandles;%retrieve the handles of the set_object interface (to define projection objects)
1323     end
1324 end
1325 %reinitiate waitbar position
1326 Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1327 waitbarpos=Series.WaitbarPos;
1328 waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1329 waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1330 set(handles.waitbar,'Position',waitbarpos)
1331 % if isfield(SeriesData,'Time')&~isempty(SeriesData.Time)
1332 %     Series.Time=SeriesData.Time;
1333 % end
1334 Series.PathProject=get(handles.PathCampaign,'String');
1335 RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1336 RootFile=get(handles.RootFile,'String');% root name of the first field series
1337 %filebase=fullfile(RootPath{1},RootFile{1});% full root name with path and file
1338 SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1339 FileExt=get(handles.FileExt,'String');%file extension
1340 %Series.NomType=get(handles.NomType,'String');% nomenclature type
1341 if isempty(SeriesData)
1342     msgbox_uvmat('ERROR','no input file series')
1343     return
1344 end
1345 NomType=SeriesData.NomType;
1346 if length(RootPath)==1 %string character input for user fct
1347     Series.RootPath=RootPath{1};
1348     Series.RootFile=RootFile{1};
1349     Series.SubDir=SubDir{1};
1350     Series.FileExt=FileExt{1};
1351     Series.NomType=NomType{1};
1352 else %cell input for user fct
1353     Series.RootPath=RootPath;
1354     Series.RootFile=RootFile;
1355     Series.SubDir=SubDir;
1356     Series.FileExt=FileExt;
1357     Series.NomType=NomType;
1358 end
1359 if isequal(get(handles.FieldMenu,'Visible'),'on')
1360     FieldMenu=get(handles.FieldMenu,'String');
1361     FieldValue=get(handles.FieldMenu,'Value');
1362     Series.Field=FieldMenu(FieldValue);
1363 end
1364 menu_coord_state=get(handles.CoordType,'Visible');
1365 Series.CoordType='';%default
1366 if isequal(menu_coord_state,'on')
1367     menu_coord=get(handles.CoordType,'String');
1368     menu_index=get(handles.CoordType,'Value');
1369     Series.CoordType=menu_coord{menu_index};
1370 end
1371 Series.hseries=get(hObject,'Parent');
1372 if isequal(get(handles.ParamVal,'Visible'),'on')
1373     ParamKey=get(handles.ParamKey,'String');
1374     if ischar(ParamKey)
1375         ParamKey{1}=ParamKey;
1376     end
1377     ParamString=get(handles.ParamVal,'String');
1378     if ischar(ParamString)
1379         for ilist=1:size(ParamString,1)
1380             ParamVal{ilist}=ParamString(ilist,:);
1381         end
1382     else
1383         ParamVal=ParamString;
1384     end   
1385 end
1386 
1387 %read the set of field numbers
1388 first_i=str2num(get(handles.first_i,'String'));
1389 last_i=str2num(get(handles.last_i,'String'));
1390 incr_i=str2num(get(handles.incr_i,'String'));
1391 first_j=str2num(get(handles.first_j,'String'));
1392 last_j=str2num(get(handles.last_j,'String'));
1393 incr_j=str2num(get(handles.incr_j,'String'));
1394 if ~isequal(get(handles.first_i,'Visible'),'on')
1395    first_i=1;
1396    last_i=1;
1397    incr_i=1;
1398 end
1399 if ~isequal(get(handles.first_j,'Visible'),'on')
1400     first_j=1;
1401     last_j=1;
1402     incr_j=1;
1403 end
1404 Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1405 if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1406     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1407 if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1408     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1409 if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1410     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1411 if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1412     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1413 num_i=[first_i:incr_i:last_i];
1414 num_j=[first_j:incr_j:last_j];
1415 nbfield_cell=get(handles.nb_field,'String');
1416 nbfield=[]; %default
1417 for iview=1:length(nbfield_cell)
1418     nb=str2num(nbfield_cell{iview});
1419     if ~isempty(nb)
1420         nbfield=[nbfield nb];
1421     end
1422 end
1423 nbfield=min(nbfield);
1424 nbfield2_cell=get(handles.nb_field2,'String');
1425 nbfield2=[]; %default
1426 for iview=1:length(nbfield2_cell)
1427     nb=str2num(nbfield2_cell{iview});
1428     if ~isempty(nb)
1429         nbfield2=[nbfield2 nb];
1430     end
1431 end
1432 nbfield2=min(nbfield2);
1433 
1434 
1435 %get complementary information from the 'series' interface
1436 
1437 list_action=get(handles.ACTION,'String');% list menu action
1438 index_action=get(handles.ACTION,'Value');% selected string index
1439 action= list_action{index_action}; % selected string
1440 mode_list=get(handles.mode,'String');
1441 index_mode=get(handles.mode,'Value');
1442 mode=mode_list{index_mode};
1443 ind_shift=0;%default
1444 
1445 %determine the list of input file names
1446 nbmissing=0;
1447 for iview=1:length(RootPath)
1448     %case of pairs (.nc files)
1449     if isequal(NomType{iview},'_i_j1-j2')| isequal(NomType{iview},'_i1-i2_j')| isequal(NomType{iview},'_i1-i2')| isequal(NomType{iview},'#_ab')
1450         ind_shift=SeriesData.displ_num(iview,:);
1451         if isequal(ind_shift,[0 0 0 0]) %undefined pairs
1452             if isequal(NomType{iview},'#_ab')
1453                 mode='#_ab';
1454             end
1455             [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(fullfile(RootPath{iview},RootFile{iview}),SubDir{iview},mode,first_i,incr_i,last_i,first_j,incr_j,last_j);
1456         else    
1457             [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1458             if isempty(num_i)
1459                 warndlg_uvmat('empty set of input files chosen','ERRROR')
1460                 return
1461             end
1462             if num_i(1)>first_i
1463                set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1464                last_i_Callback(hObject, eventdata, handles)
1465             end
1466             if num_i(end)<last_i
1467                set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1468                last_i_Callback(hObject, eventdata, handles)
1469             end
1470             if num_j(1)>first_j
1471                set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1472                last_j_Callback(hObject, eventdata, handles)
1473             end
1474             if num_j(end)<last_j
1475                set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1476                last_j_Callback(hObject, eventdata, handles)
1477             end 
1478         end
1479     else%case of images
1480         [num_i1,num_j1]=meshgrid(num_i,num_j);
1481         num_i2=num_i1;
1482         num_j2=num_j1;
1483     end
1484     if length(RootPath)>1
1485         num_i1_cell{iview}=num_i1;
1486         num_i2_cell{iview}=num_i2;
1487         num_j1_cell{iview}=num_j1;
1488         num_j2_cell{iview}=num_j2;
1489     end
1490 end
1491 
1492 % RUN RUN'
1493 path_series=which('series');
1494 list_path=get(handles.ACTION,'UserData');
1495 index=get(handles.ACTION,'Value');
1496 fct_path=list_path{index}; %path stored for the function ACTION
1497 if ~isequal(fct_path,path_series)
1498     eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1499     if ~isequal(spath,fct_path)& exist(fct_path,'dir')
1500         addpath(fct_path)% add the prescribed path if not the current one
1501     end
1502 end
1503 Series.Action=action;%name of the processing programme
1504 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1505 if length(RootPath)>1
1506     feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1507 else
1508     feval(action,num_i1,num_i2,num_j1,num_j2,Series);
1509 end
1510 set(handles.RUN,'BackgroundColor',[1 0 0])
1511 
1512 % %save the current interface setting as figure namefig, append .0 to the name if it already exists
1513 % detect=1;
1514 % while detect==1
1515 %     namefigfull=[namedoc '.fig'];
1516 %     hh=dir(namefigfull);
1517 %     if ~isempty(hh)
1518 %         detect=1;
1519 %         namedoc=[namedoc '.0'];
1520 %     else
1521 %         detect=0;
1522 %     end
1523 % end
1524 % saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1525 
1526 %----------------------------------------------------
1527 function STOP_Callback(hObject, eventdata, handles)
1528 set(handles.RUN, 'BusyAction','cancel')
1529 set(handles.RUN,'BackgroundColor',[1 0 0])
1530 
1531 %----------------------------------------------
1532 
1533 %----------------------------------------------------
1534 function first_i_Callback(hObject, eventdata, handles)
1535 last_i_Callback(hObject, eventdata, handles)
1536 
1537 %----------------------------------------------
1538 function last_i_Callback(hObject, eventdata, handles)
1539     hseries=get(handles.last_i,'parent');
1540 first_i=str2num(get(handles.first_i,'String'));
1541 last_i=str2num(get(handles.last_i,'String'));
1542 ref_i=ceil((first_i+last_i)/2);
1543 set(handles.ref_i,'String', num2str(ref_i))
1544 ref_i_Callback(hObject, eventdata, handles)
1545 SeriesData=get(hseries,'UserData');
1546 if ~isfield(SeriesData,'Time')
1547     SeriesData.Time{1}=[];
1548 end
1549 displ_time(handles,SeriesData.Time{1});
1550 
1551 %-------------------------------------------------------
1552 function first_j_Callback(hObject, eventdata, handles)
1553  last_j_Callback(hObject, eventdata, handles)
1554 
1555 %-------------------------------------------------------
1556 function last_j_Callback(hObject, eventdata, handles)
1557     hseries=get(handles.last_i,'parent');
1558 first_j=str2num(get(handles.first_j,'String'));
1559 last_j=str2num(get(handles.last_j,'String'));
1560 ref_j=ceil((first_j+last_j)/2);
1561 set(handles.ref_j,'String', num2str(ref_j))
1562 
1563 ref_j_Callback(hObject, eventdata, handles)
1564 SeriesData=get(hseries,'UserData');
1565 if ~isfield(SeriesData,'Time')
1566     SeriesData.Time{1}=[];
1567 end
1568 displ_time(handles,SeriesData.Time{1});
1569 
1570 
1571 
1572 
1573 %-------------------------------------------------------
1574 function ref_i_Callback(hObject, eventdata, handles)
1575 mode_list=get(handles.mode,'String');
1576 mode_value=get(handles.mode,'Value');
1577 mode=mode_list{mode_value};
1578 hseries=get(handles.ref_i,'parent');
1579 SeriesData=get(hseries,'UserData');
1580 %NomTypeCell=get(handles.NomType,'String');
1581 NomTypeCell=SeriesData.NomType;
1582 if ~isempty(NomTypeCell)
1583 Val=get(handles.NomType,'Value');
1584 NomType=NomTypeCell{Val};
1585 % for ilist=1:length(NomType)
1586     if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1587         if isequal(mode,'series(Di)') 
1588             find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1589 %             break
1590         end
1591     end
1592 end
1593 
1594 %----------------------------------------------------
1595 function ref_j_Callback(hObject, eventdata, handles)
1596 mode_list=get(handles.mode,'String');
1597 mode_value=get(handles.mode,'Value');
1598 mode=mode_list{mode_value};
1599 hseries=get(handles.ref_i,'parent');
1600 SeriesData=get(hseries,'UserData');
1601 %NomTypeCell=get(handles.NomType,'String');
1602 NomTypeCell=SeriesData.NomType;
1603 if ~isempty(NomTypeCell)
1604 Val=get(handles.NomType,'Value');
1605 NomType=NomTypeCell{Val};
1606 % NomType=get(handles.NomType,'String');
1607     if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1608         if isequal(mode,'series(Dj)') 
1609             find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1610 %             break
1611         end
1612     end
1613 end
1614 
1615 %----------------------------------------------------
1616 % --- Executes on selection change in ACTION.
1617 function ACTION_Callback(hObject, eventdata, handles)
1618 list_ACTION=get(handles.ACTION,'String');% list menu fields
1619 index_ACTION=get(handles.ACTION,'Value');% selected string index
1620 ACTION= list_ACTION{index_ACTION}; % selected function name
1621 path_series=which('series');%path to series.m
1622 list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1623 nb_builtin=0;
1624 for ilist=1:length(list_path)
1625     if isequal(list_path{ilist},path_series)
1626         nb_builtin=nb_builtin+1;
1627     else
1628         break
1629     end
1630 end
1631 if nb_builtin==0% the path of series has been changed, reinitialize
1632     series_OpeningFcn(hObject, eventdata, handles)
1633     return
1634 end
1635 
1636 % add a new function to the menu
1637 if isequal(ACTION,'more...')
1638     pathfct=fileparts(path_series);
1639     browse_name=fullfile(path_series,'SERIES_FCT');%go to UVMAT/SERIES_FCT by default
1640     if length(list_path)>nb_builtin
1641         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
1642      end 
1643     [FileName, PathName, filterindex] = uigetfile( ...
1644        {'*.m', ' (*.m)';
1645         '*.m',  '.m files '; ...
1646         '*.*', 'All Files (*.*)'}, ...
1647         'Pick a file',browse_name);
1648     if length(FileName)<2
1649         return
1650     end
1651     ext_fct=FileName(end-1:end);
1652     if ~isequal(ext_fct,'.m')
1653         msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1654         return
1655     end
1656     ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
1657     
1658    % insert the choice in the action menu
1659    menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1660    index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1661    list_path{index_ACTION}=PathName;
1662    if length(menu_str)>nb_builtin+5;
1663        nbremove=length(menu_str)-nb_builtin-5;
1664        menu_str(nb_builtin+1:end-5)=[];
1665        list_path(nb_builtin+1:end-4)=[];
1666        index_ACTION=index_ACTION-nbremove;
1667        set(handles.ACTION,'Value',index_ACTION)
1668        set(handles.ACTION,'String',menu_str)
1669    end
1670    list_path{index_ACTION}=PathName;
1671    set(handles.ACTION,'UserData',list_path);
1672    set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1673    
1674    %record the current menu in personal file profil_perso
1675    dir_perso=prefdir;
1676    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1677    for ilist=nb_builtin+1:length(menu_str)-1
1678        series_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
1679    end
1680    if exist(profil_perso,'file')
1681         save(profil_perso,'series_fct','-append')
1682    else
1683         txt=ver;
1684         Release=txt(1).Release;
1685         relnumb=str2num(Release(3:4));
1686         if relnumb >= 14
1687             save(profil_perso,'series_fct','-V6')
1688         else
1689             save(profil_perso, 'series_fct')
1690         end
1691    end
1692 end
1693 
1694 %check the current path to the selected function
1695 PathName=list_path{index_ACTION};%current recorded path
1696 if ~isequal(path_series,PathName)
1697     CurrentPath=fileparts(which(ACTION));
1698     if ~isequal(PathName,CurrentPath)
1699         addpath(PathName) 
1700         errormsg=check_functions;
1701         msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
1702     end
1703 end
1704 set(handles.path,'String',PathName); %show the path to the senlected function
1705 
1706 %default setting for the visibility of the GUI elements
1707 %set( handles.Field,'Visible','off')%default
1708 set(handles.RootPath,'UserData','many')
1709 set(handles.SubDir,'Visible','on')
1710 set(handles.RootFile,'Visible','on')
1711 set(handles.NomType,'Visible','on')
1712 set(handles.FileExt,'Visible','on')
1713 set(handles.NbSlice,'Visible','off')
1714 set(handles.NbSlice_title,'Visible','off')
1715 set(handles.VelTypeMenu,'Visible','off');
1716 set(handles.VelType_text,'Visible','off');
1717 set(handles.VelTypeMenu_1,'Visible','off');
1718 set(handles.VelType_text_1,'Visible','off');
1719 view_FieldMenu(handles,'off')
1720 view_FieldMenu_1(handles,'off')
1721 view_TRANSFORM(handles,'off')
1722 set(handles.ProjObject_frame,'Visible','off');
1723 set(handles.GetMask,'Visible','off')
1724 set(handles.Mask,'Visible','off')
1725 set(handles.GetObject,'Visible','off');
1726 set(handles.ProjObject,'Visible','off');
1727 set(handles.OutputDir,'Visible','off');
1728 set(handles.PARAMETERS_frame,'Visible','off');
1729 set(handles.PARAMETERS_title,'Visible','off');
1730 set(handles.ParamKey,'Visible','off')
1731 set(handles.ParamVal,'Visible','off')
1732 ParamKey={};
1733 set(handles.FieldMenu,'Enable','off')
1734 set(handles.VelTypeMenu,'Enable','off')
1735 set(handles.FieldMenu_1,'Enable','off')
1736 set(handles.VelTypeMenu_1,'Enable','off')
1737 set(handles.CoordType,'Enable','off')
1738 %set the displayed GUI item needed for input parameters
1739 %list_input=feval(ACTION);% input list asked by the selected function
1740 varargout=feval(ACTION);% input list asked by the selected function
1741 Param_list={};
1742 % RootPath=get(handles.RootPath,'String');
1743 % RootFile=get(handles.RootFile,'String');
1744 
1745 %nb_series=length(RootFile);
1746 FileExt=get(handles.FileExt,'String');
1747 nb_series=length(FileExt);
1748 testima_series=1; %test for a list of images only
1749 testima=1;
1750 testima_1=1;
1751 testciv_series=1;
1752 for iview=1:nb_series
1753     ext=FileExt{iview};
1754     if length(ext)<2
1755         ext='.none';
1756     end
1757     testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1758     if ~testimaview
1759         if iview==1
1760             testima=0;
1761         end
1762         if iview==2
1763             testima_1=0;
1764         end
1765         testima_series=0;
1766     end
1767 end
1768 for ilist=1:length(varargout)-1
1769     switch varargout{ilist}
1770                        %RootFile always visible
1771          case 'RootPath'   %visible by default
1772             value=lower(varargout{ilist+1});
1773             if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1774                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1775             end
1776         case 'SubDir' %visible by default
1777             if isequal(lower(varargout{ilist+1}),'off')
1778                 set(handles.SubDir,'Visible','off')
1779             end
1780         case 'RootFile'   %visible by default
1781             value=lower(varargout{ilist+1});
1782             if isequal(value,'off')
1783                 set(handles.RootFile,'Visible','off')
1784             elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1785                 set(handles.RootFile,'Visible','on')
1786                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1787             end
1788         case 'NomType'   %visible by default
1789             if isequal(lower(varargout{ilist+1}),'off')
1790                 set(handles.NomType,'Visible','off')
1791             end 
1792         case 'FileExt'   %visible by default
1793             if isequal(lower(varargout{ilist+1}),'off')
1794                 set(handles.FileExt,'Visible','off')
1795             end
1796         case 'NbSlice'   %hidden by default
1797             if isequal(lower(varargout{ilist+1}),'on')
1798                 set(handles.NbSlice,'Visible','on')
1799                 set(handles.NbSlice_title,'Visible','on')
1800             end
1801         case 'VelTypeMenu'   %hidden by default
1802             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1803                 set(handles.VelTypeMenu,'Enable','on')
1804                 if nb_series >=1 && ~testima_series
1805                     set(handles.VelTypeMenu,'Visible','on')
1806                     set(handles.VelType_text,'Visible','on');
1807                     set(handles.Field_frame,'Visible','on')
1808                 end
1809             end
1810             if isequal(lower(varargout{ilist+1}),'two')
1811                 set(handles.VelTypeMenu_1,'Enable','on')
1812                 if nb_series >=2 && ~testima_series
1813                     set(handles.VelTypeMenu_1,'Visible','on')
1814                     set(handles.VelType_text_1,'Visible','on');
1815                 end
1816             end
1817         case 'FieldMenu'   %hidden by default
1818             if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1819                 set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1820                 if nb_series >=1 && ~testima_series
1821                     view_FieldMenu(handles,'on')
1822                 end
1823             end
1824             if isequal(lower(varargout{ilist+1}),'two')
1825                 set(handles.FieldMenu_1,'Enable','on')
1826                 if nb_series >=2 && ~testima_1
1827                     view_FieldMenu_1(handles,'on')
1828                 end
1829             end
1830         case 'CoordType'   %hidden by default
1831             if isequal(lower(varargout{ilist+1}),'on') 
1832                 set(handles.CoordType,'Enable','on')
1833                 view_TRANSFORM(handles,'on')
1834             end
1835         case 'GetObject'   %hidden by default
1836             if isequal(lower(varargout{ilist+1}),'on')   
1837                 set(handles.ProjObject_frame,'Visible','on')
1838                 set(handles.GetObject,'Visible','on');
1839             end
1840         case 'Mask'   %hidden by default
1841             if isequal(lower(varargout{ilist+1}),'on')   
1842                 set(handles.ProjObject_frame,'Visible','on')
1843                 set(handles.GetMask,'Visible','on');
1844             end
1845         case 'PARAMETER'  
1846             set(handles.PARAMETERS_frame,'Visible','on')
1847             set(handles.PARAMETERS_title,'Visible','on')
1848             set(handles.ParamKey,'Visible','on')
1849             %set(handles.ParamVal,'Visible','on')
1850             Param_str=varargout{ilist+1};
1851             Param_list=[Param_list; {Param_str}];          
1852     end
1853 end
1854 if ~isempty(Param_list)
1855     set(handles.ParamKey,'String',Param_list)
1856     set(handles.ParamVal,'Visible','on')
1857 end
1858 
1859 %-------------------------------------------------------------------
1860 % --- Executes on selection change in FieldMenu.
1861 %-------------------------------------------------------------------
1862 function FieldMenu_Callback(hObject, eventdata, handles)
1863 
1864 field_str=get(handles.FieldMenu,'String');
1865 field_index=get(handles.FieldMenu,'Value');
1866 field=field_str{field_index(1)};
1867 if isequal(field,'get_field...')    
1868      hget_field=findobj(allchild(0),'name','get_field');
1869      if ~isempty(hget_field)
1870          delete(hget_field)%delete opened versions of get_field
1871      end
1872      hseries=get(handles.FieldMenu,'parent');
1873      SeriesData=get(hseries,'UserData');
1874      filename=SeriesData.CurrentInputFile;
1875      if exist(filename,'file')
1876         get_field(filename)
1877      end
1878 elseif isequal(field,'more...')
1879     str=calc_field;
1880     [ind_answer,v] = listdlg('PromptString','Select a file:',...
1881                 'SelectionMode','single',...
1882                 'ListString',str);
1883        % edit the choice in the fields and action menu
1884      scalar=cell2mat(str(ind_answer));
1885      update_menu(handles.FieldMenu,scalar)
1886 end
1887 
1888 %------------------------------------------------------
1889 % --- Executes on selection change in FieldMenu_1.
1890 %-----------------------------------------------------
1891 function FieldMenu_1_Callback(hObject, eventdata, handles)
1892 field_str=get(handles.FieldMenu_1,'String');
1893 field_index=get(handles.FieldMenu_1,'Value');
1894 field=field_str{field_index};
1895 if isequal(field,'get_field...')    
1896      hget_field=findobj(allchild(0),'name','get_field_1');
1897      if ~isempty(hget_field)
1898          delete(hget_field)
1899      end
1900      hseries=get(handles.FieldMenu,'parent');
1901      SeriesData=get(hseries,'UserData');
1902      filename=SeriesData.CurrentInputFile_1;
1903      if exist(filename,'file')
1904         hget_field=get_field(filename);
1905         set(hget_field,'name','get_field_1')
1906      end
1907 elseif isequal(field,'more...')
1908     str=calc_field;
1909     [ind_answer,v] = listdlg('PromptString','Select a file:',...
1910                 'SelectionMode','single',...
1911                 'ListString',str);
1912        % edit the choice in the fields and action menu
1913      scalar=cell2mat(str(ind_answer));
1914      update_menu(handles.FieldMenu_1,scalar)
1915 end   
1916 
1917 
1918 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1919  %detect the chosen series of files and check their date of modification:
1920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1921 %INPUT:
1922 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
1923 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
1924 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
1925 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
1926 %OTHER INPUTS given by the structure Series
1927 function GUI_input=check_files(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
1928 
1929 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
1930 if ~exist('num_i1_cell','var')
1931     GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
1932         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
1933         'RootFile';'on';... %root input file name ('on' by default)
1934         'FileExt';'on';... %input file extension ('on' by default)
1935         'NomType';'on';...%type of file indexing ('on' by default)
1936         'NbSlice';'on'; ...%nbre of slices ('off' by default)
1937         %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..) 'off' by default)
1938         %'FieldMenu';'on';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
1939         %'CoordType';'on'...%can use a transform function 'off' by default
1940         %'GetObject';'on'...%can use projection object ,'off' by default
1941         %'GetMask';'on'...%can use mask option   ,'off' by default
1942         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
1943                ''};
1944     return %exit the function
1945 end
1946 
1947 %standard parameters for waitbar and STOP action (do not modify)
1948 hseries=guidata(Series.hseries);%handles of the GUI series
1949 WaitbarPos=get(hseries.waitbar_frame,'Position');
1950 
1951 %%%%%%%%%%%%%%%%%%%%%%%%
1952 
1953 % number of slices
1954 NbSlice=str2num(get(hseries.NbSlice,'String'));
1955 if isempty(NbSlice)
1956     NbSlice=1;
1957 end
1958 NbSlice_name=num2str(NbSlice);
1959 if isequal(NbSlice,[]),NbSlice=1; end; %default
1960 
1961 % number of views
1962 count=0; 
1963 testcell=iscell(Series.RootFile);
1964 if ~testcell
1965     Series.RootPath={Series.RootPath};
1966     Series.RootFile={Series.RootFile};
1967     Series.SubDir={Series.SubDir};
1968     Series.FileExt={Series.FileExt};
1969     Series.NomType={Series.NomType};
1970 end    
1971 nbview=length(Series.RootFile);
1972 for iview=1:nbview
1973     filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name
1974     if testcell
1975         num_i1=num_i1_cell{iview}; num_i2=num_i2_cell{iview}; num_j1=num_j1_cell{iview}; num_j2=num_j2_cell{iview};
1976     else
1977         num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell;
1978     end
1979     siz=size(num_i1);
1980     nbfield2=siz(1); %nb of consecutive fields at each level(burst
1981     nbfield=siz(1)*siz(2);
1982     nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
1983     if isequal(lower(Series.FileExt{iview}),'.avi')
1984         info=aviinfo([filebase Series.FileExt{iview}]);
1985         message{1}=info.Filename;
1986         message{2}=info.FileModDate;
1987         message{3}=[num2str(info.FramesPerSecond) ' frames/s '];
1988         message{4}=info.ImageType;
1989         message{5}=['  compression' info.VideoCompression];
1990         message{6}=[ 'quality ' num2str(info.Quality)];   
1991         Tabchar=message;
1992     else
1993         datnum=[];
1994         Tabchar={};
1995         %LOOP ON SLICES
1996         for i_slice=1:NbSlice
1997             for ifield=1:nbfield
1998                 indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
1999             end 
2000             for index=1:nbfield*nbfield2
2001                 stopstate=get(hseries.RUN,'BusyAction');
2002                 if isequal(stopstate,'queue')% enable STOP command
2003 %                     waitbarpos(4)=(index/(nbfield*nbfield2))*Series.WaitbarPos(4);
2004 %                     waitbarpos(2)=Series.WaitbarPos(4)+Series.WaitbarPos(2)-waitbarpos(4);
2005 %                     set(hwaitbar,'Position',waitbarpos)
2006                     update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
2007                     ifile=indselect(index);
2008                 
2009                     [file,idetect]=...;
2010                        name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2(ifile),num_j2(ifile),Series.SubDir{iview});
2011                   
2012                        [Path,Name,ext]=fileparts(file);
2013                     detect=exist(file,'file'); % check the existence of the file
2014                     if detect==0
2015                         count=count+1;
2016                         lastfield='not found';
2017                     else
2018                         datfile=dir(file);
2019                         datnum(ifile)=datenum(datfile.date);
2020                         filefound(ifile)={datfile.name};
2021                         lastfield='';
2022                         if isequal(Series.FileExt{iview},'.nc') || isequal(Series.FileExt{iview},'.cdf')
2023                             % check the content  netcdf file
2024                             Data=nc2struct(file,[]);       
2025 %                             lastfield='civ1'; %default
2026                             if isfield(Data,'patch2') & isequal(Data.patch2,1);
2027                                 lastfield='patch2';
2028                             elseif isfield(Data,'fix2') & isequal(Data.fix2,1);
2029                                 lastfield='fix2';
2030                             elseif isfield(Data,'civ2') & isequal(Data.civ2,1);
2031                                 lastfield='civ2';
2032                             elseif isfield(Data,'patch') & isequal(Data.patch,1);
2033                                 lastfield='patch1';
2034                             elseif isfield(Data,'fix') & isequal(Data.fix,1);
2035                                 lastfield='fix1';
2036                             elseif isfield(Data,'absolut_time_T0') & isfield(Data,'hart')
2037                                 lastfield='civ1'; 
2038                             end                          
2039                         end      
2040                     end
2041                     Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
2042                     Tabchar(index+1,i_slice)={[file '   ' lastfield]};
2043                 end
2044             end
2045         end
2046         if isempty(datnum)
2047             if NbSlice>1
2048                 message=['no set of ' num2str(NbSlice) ' (NbSlices) files found'];
2049             else
2050                  message='no file found';
2051             end
2052         else
2053             datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files
2054             [first,ind]=min(datnum);
2055             [last,indlast]=max(datnum);
2056             message={['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
2057                 ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
2058         end 
2059         if ~isempty(Tabchar)
2060           Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1);
2061         end
2062     end
2063     hfig=figure(iview);
2064     clf
2065     if iview>1
2066         pos=get(iview-1,'Position');
2067         pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
2068         set(hfig,'Position',pos)
2069     end
2070     set(hfig,'name',['view= ' num2str(iview)])
2071    
2072     h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', @ncbrowser_uvmat);
2073     hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
2074 end
2075 %----------------------------------------------------
2076 %  determine the list of index pairs of processing file
2077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2078 function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
2079 num_i1=num_i;% set of first image numbers by default
2080 num_i2=num_i;
2081 num_j1=num_j;
2082 num_j2=num_j;
2083 num_i_out=num_i;
2084 num_j_out=num_j;
2085 if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2')
2086     num_i1_line=num_i+ind_shift(3);% set of first image numbers
2087     num_i2_line=num_i+ind_shift(4);
2088     % adjust the first and last field number
2089         indsel=find(num_i1_line >= 1);
2090     num_i_out=num_i(indsel);
2091     num_i1_line=num_i1_line(indsel);
2092     num_i2_line=num_i2_line(indsel);
2093     num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2094     num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2095     [xx,num_i1]=meshgrid(num_j,num_i1_line);
2096     [xx,num_i2]=meshgrid(num_j,num_i2_line);
2097 elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
2098     if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2099         num_j1=ind_shift(1)*ones(size(num_i));
2100         num_j2=ind_shift(2)*ones(size(num_i));
2101     else
2102         num_j1_col=num_j+ind_shift(1);% set of first image numbers
2103         num_j2_col=num_j+ind_shift(2);
2104         % adjust the first field number
2105         indsel=find((num_j1_col >= 1));   
2106         num_j_out=num_j(indsel);
2107         num_j1_col=num_j1_col(indsel);
2108         num_j2_col=num_j2_col(indsel);
2109         [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2110         [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2111     end    
2112 end
2113 
2114 
2115 %----------------------------------------------------------------------
2116 % --- make average on a series of files
2117 %----------------------------------------------------------------------
2118 %INPUT:
2119 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
2120 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
2121 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
2122 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
2123 %OTHER INPUTS given by the structure Series
2124 %  Series.Time:
2125 %  Series.GeometryCalib:
2126 function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series)
2127 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
2128 if ~exist('num_i1','var')
2129     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
2130         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
2131         'RootFile';'on';... %root input file name ('on' by default)
2132         'FileExt';'on';... %input file extension ('on' by default)
2133         'NomType';'on';...%type of file indexing ('on' by default)
2134         'NbSlice';'on'; ...%nbre of slices ('off' by default)
2135         'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
2136         'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
2137         'CoordType'; 'on';...%can use a transform function
2138         'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',
2139         %'GetMask';'on'...%can use mask option
2140         %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter
2141                ''};
2142         return
2143 end
2144 
2145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2146 hseries=guidata(Series.hseries);%handles of the GUI series
2147 WaitbarPos=get(hseries.waitbar_frame,'Position');
2148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2149 
2150 %root input file and type
2151 if ~iscell(Series.RootPath)% case of a single input field series
2152     num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2};
2153     RootPath={Series.RootPath};
2154     RootFile={Series.RootFile};
2155     SubDir={Series.SubDir};
2156     FileExt={Series.FileExt};
2157     NomType={Series.NomType};
2158 else
2159     RootPath=Series.RootPath;
2160     RootFile=Series.RootFile;
2161     SubDir=Series.SubDir;
2162     NomType=Series.NomType;
2163     FileExt=Series.FileExt;
2164 end   
2165 ext=FileExt{1};
2166 form=imformats(ext([2:end]));%test valid Matlab image formats
2167 testima=0;
2168 if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol')
2169     testima(1)=1;
2170 end
2171 if length(FileExt)>=2
2172     ext_1=FileExt{2};
2173     form=imformats(ext_1([2:end]));%test valid Matlab image formats
2174     if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')
2175         testima(2)=1;
2176     end
2177     if testima(2)~=testima(1)
2178         warndlg_uvmat('images and netcdf files cannot be compared','ERROR')
2179         return
2180     end
2181 end
2182 
2183 %Number of input series: this function  accepts two input file series at most (then it operates on the difference of fields)
2184 nbview=length(RootPath);
2185 if nbview>2  
2186     RootPath=RootPath(1:2);
2187     set(hseries.RootPath,'String',RootPath)
2188     SubDir=SubDir(1:2);
2189     set(hseries.SubDir,'String',SubDir)
2190     RootFile=RootFile(1:2);
2191     set(hseries.RootFile,'String',RootFile)
2192     NomType=NomType(1:2);
2193     FileExt=FileExt(1:2);
2194     set(hseries.FileExt,'String',FileExt)
2195     nbview=2;
2196 end
2197 hhh=which('mmreader');
2198 for iview=1:nbview
2199     test_movie(iview)=0;
2200     if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
2201         if isequal(lower(FileExt{iview}),'.avi')
2202             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
2203             test_movie(iview)=1;
2204         end
2205     end 
2206 end
2207 
2208 % number of slices
2209 NbSlice=str2num(get(hseries.NbSlice,'String'));
2210 if isempty(NbSlice)
2211     NbSlice=1;
2212 end
2213 NbSlice_name=num2str(NbSlice);
2214 
2215 % Field and velocity type (the same for the two views)
2216 Field_str=get(hseries.FieldMenu,'String');
2217 FieldName=[]; %default
2218 testfield=get(hseries.FieldMenu,'Visible');
2219 if isequal(testfield,'on')
2220     val=get(hseries.FieldMenu,'Value');
2221     FieldName=Field_str(val);%the same set of fields for all views
2222     if isequal(FieldName,{'get_field...'})
2223         hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
2224         if length(hget_field)>1
2225             delete(hget_field(2:end))
2226         elseif isempty(hget_field)
2227            [filename]=...
2228                                name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
2229            get_field(filename);
2230            return
2231         end
2232         hhget_field=guidata(hget_field);%handles of GUI elements in get_field
2233         SubField=read_var_names(hhget_field); %read the names of the variables to plot in the get_field GUI
2234         if isequal(get(hhget_field.menu_coord,'Visible'),'on')
2235             list_transform=get(hhget_field.menu_coord,'String');
2236             val_list=get(hhget_field.menu_coord,'Value');
2237             transform=list_transform{val_list};
2238         end
2239     end
2240 end
2241 %detect whether the two files are 'images' or 'netcdf'
2242 testima=0;
2243 testvol=0;
2244 testcivx=0;
2245 testnc=0;
2246 FileExt=get(hseries.FileExt,'String');
2247 % test_movie=0;
2248 for iview=1:nbview
2249      ext=FileExt{iview};
2250      form=imformats(ext([2:end]));
2251      if isequal(lower(ext),'.vol')
2252          testvol=testvol+1;
2253      elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
2254          testima=testima+1;
2255      elseif isequal(ext,'.nc')
2256          testnc=testnc+1;
2257      end
2258 end
2259 if testvol
2260     warndlg_uvmat('volume images not implemented yet','ERROR')
2261     return
2262 end
2263 if testnc~=nbview && testima~=nbview && testvol~=nbview
2264     warndlg_uvmat('compare two image series or two netcdf files with the same fields as input','ERROR')
2265     return
2266 end
2267 if ~isequal(FieldName,{'get_field...'})
2268     testcivx=testnc;
2269 end
2270 
2271 if testcivx
2272     VelType_str=get(hseries.VelTypeMenu,'String');
2273     VelType_val=get(hseries.VelTypeMenu,'Value');
2274     VelType{1}=VelType_str{VelType_val};
2275     if nbview==2
2276         VelType_str=get(hseries.VelTypeMenu_1,'String');
2277         VelType_val=get(hseries.VelTypeMenu_1,'Value');
2278         VelType{2}=VelType_str{VelType_val};
2279     end
2280 end
2281 
2282 %Calibration data and timing: read the ImaDoc files
2283 mode=''; %default
2284 timecell={};
2285 itime=0;
2286 for iview=1:nbview%Loop on views
2287     XmlData{iview}=[];%default
2288     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
2289     if exist([filebase{iview} '.xml'],'file')
2290         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
2291         if isfield(XmlData{iview},'Time')
2292             itime=itime+1;
2293             timecell{itime}=XmlData{iview}.Time;
2294         end
2295     elseif exist([filebase{iview} '.civ'],'file')
2296         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
2297         itime=itime+1;
2298         timecell{itime}=time;
2299         XmlData{iview}.Time=time;
2300         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
2301         GeometryCalib.Tx=0;
2302         GeometryCalib.Ty=0;
2303         GeometryCalib.Tz=1;
2304         GeometryCalib.dpx=1;
2305         GeometryCalib.dpy=1;
2306         GeometryCalib.sx=1;
2307         GeometryCalib.Cx=0;
2308         GeometryCalib.Cy=0;
2309         GeometryCalib.f=1;
2310         GeometryCalib.kappa1=0;
2311         GeometryCalib.CoordUnit='cm';
2312         XmlData{iview}.GeometryCalib=GeometryCalib;
2313         if error==1
2314             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
2315         end
2316     end
2317 end
2318 
2319 
2320 
2321 %check coincidence in time
2322 multitime=0;
2323 if length(timecell)==0
2324     time=[];
2325 elseif length(timecell)==1
2326     time=timecell{1};
2327 elseif length(timecell)>1
2328     multitime=1;
2329     for icell=1:length(timecell)
2330         if ~isequal(size(timecell{icell}),size(timecell{1}))
2331             warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
2332             time=timecell{1};
2333             multitime=0;
2334             break
2335         end
2336     end
2337 end
2338 if multitime
2339     for icell=1:length(timecell)
2340         time(icell,:,:)=timecell{icell};
2341     end
2342     diff_time=max(max(diff(time)));
2343     if diff_time>0
2344         warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
2345     end   
2346 end
2347 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
2348     time=[];
2349 end
2350 
2351 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
2352 filebasesub=fullfile(RootPath{1},SubDir{1},RootFile{1});
2353 if isempty(SubDir{1}) % create a subdirectory '/mean'
2354     subdir_result='mean';
2355 %     filebasemean=fullfile(RootPath{1},subdir_result);
2356     if ~exist(fullfile(RootPath{1},subdir_result),'dir')
2357         dircur=pwd; %record current working directory
2358         cd(RootPath{1})% goes to the iamge directory
2359         [m1,m2,m3]=mkdir(subdir_result);
2360         if ~isequal(m2,'')
2361              msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
2362         end
2363         cd(dircur) %back to the initial working directory
2364     end
2365     filebase_out=filebase{1}; 
2366 else
2367    subdir_result=SubDir{1};
2368    filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input
2369 end
2370 %output nomtype (to generalise)
2371 NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
2372     
2373 if NbSlice==1  
2374     filebase_out=[filebasesub '_mean'];
2375 else
2376     filebase_out=[filebasesub '_' NbSlice_name 'mean'];
2377     answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
2378     if ~isequal(answeryes,'Yes')
2379         return
2380     end
2381 end
2382 
2383 % image or scalar processing programme set by user
2384 Coord_menu=get(hseries.CoordType,'String');
2385 menu_val=get(hseries.CoordType,'Value');
2386 usrfct=Coord_menu{menu_val};
2387 testfct=~isequal(usrfct,'');
2388 
2389 %slice loop
2390 siz=size(num_i1{1});
2391 lengthtot=siz(1)*siz(2);
2392 nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
2393 nbfield_slice=nbfield*siz(1);% number of fields per slice
2394 
2395 for i_slice=1:NbSlice
2396    S=0; %initiate the image sum S
2397    nbfiles=0;
2398    nbmissing=0;
2399     %averaging loop
2400    for ifile=i_slice:NbSlice:lengthtot
2401         stopstate=get(hseries.RUN,'BusyAction');
2402         if isequal(stopstate,'queue') % enable STOP command
2403              update_waitbar(hseries.waitbar,WaitbarPos,(ifile+(i_slice-1)*nbfield)/(lengthtot*NbSlice))
2404              for iview=1:nbview
2405                 [filename,idetect(iview)]=...
2406                            name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
2407                 if testima
2408                     Data{iview}.ListVarName={'A'};
2409                     Data{iview}.AName='image';
2410                     if test_movie(iview)
2411                         Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
2412                     else
2413                         Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files
2414                     end
2415                     Atype{iview}=class(Data{iview}.A);
2416                     Data{iview}.A=double(Data{iview}.A);
2417                 elseif testcivx
2418                     [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
2419                   %  [nb_coord,nb_dim,Civ,CivStage,time,Data{iview},VelTypeOut,Calib]=read_ncfield(filename,VelType{iview},FieldName,'image');
2420                 else
2421                     [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
2422                     Data{iview}.VarAttribute=SubField.VarAttribute;
2423                 end 
2424              end
2425              if ~isequal(Series.CoordType,'')
2426                 if nbview==2
2427                     [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
2428                     if isempty(Data{2})
2429                         Data(2)=[];
2430                     end
2431                 else
2432                     Data{1}=feval(Series.CoordType,Data{1},XmlData);
2433                 end
2434              end
2435             if testcivx
2436                     Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
2437             end
2438              if length(Data)==2
2439                %substract the two fields   %TODO: adapt SubField to take difference in case of two input file series, take .Time as average time
2440              end
2441              if isfield(Series,'ProjObject')
2442                 Data{1}=proj_field(Data{1},Series.ProjObject);
2443              end                                                        
2444             if min(idetect)>=1%the file(s) have been detected
2445                 %TODO: adapt SubField to take difference in case of two input file series, take .Time as average time
2446                 Field=Data{1};
2447                 nbfiles=nbfiles+1;
2448                 if nbfiles==1 %first field
2449                     time_1=[];
2450                     if isfield(Field,'Time')
2451                         time_1=Field.Time(1);
2452                     end
2453                     DataMean=Field;%default
2454                 else
2455                     for ivar=1:length(Field.ListVarName)
2456                         VarName=Field.ListVarName{ivar};
2457                         eval(['sizmean=size(DataMean.' VarName ');']);
2458                         eval(['siz=size(Field.' VarName ');']);
2459                         if ~isequal(siz,sizmean)
2460                             warndlg_uvmat(['unequal size of input field ' VarName ', need to interpolate on a grid'],'WARNING') 
2461                             nbmissing=nbmissing+1;
2462                             break
2463                         else
2464                             eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum
2465                         end
2466                     end
2467                 end
2468             else
2469                 nbmissing=nbmissing+1;
2470             end
2471         end
2472     end %end averaging loop
2473     for ivar=1:length(Field.ListVarName)
2474         VarName=Field.ListVarName{ivar};
2475         eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean
2476     end
2477     if nbmissing~=0
2478         warndlg_uvmat([num2str(nbmissing) ' input files are missing or skipted'],'WARNING')
2479     end
2480     if isempty(time) % time read from files  prevails
2481         time_end=[];
2482         if isfield(Field,'Time')
2483             time_end=Field.Time(1);%last time read
2484             if ~isempty(time_1)
2485                 DataMean.Time=time_1;
2486                 DataMean.Time_end=time_end;
2487             end
2488         end
2489     else  % time from ImaDoc prevails
2490         DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1));
2491         DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end));
2492     end
2493     
2494     %writing the result file
2495    if testima   
2496         [filemean]=name_generator(filebase_out,num_i1{1}(1,i_slice),num_j1{1}(1,1),'.png',NomTypeOut,1,num_i2{end}(end,end),num_j2{end}(end,end),subdir_result);
2497         if exist(filemean,'file')
2498             backupfile=filemean;
2499             testexist=2;
2500             while testexist==2
2501                 backupfile=[backupfile(1:end-4) '~.png'];
2502                 testexist=exist(backupfile,'file');
2503             end
2504             [success,message]=copyfile(filemean,backupfile);%make backup
2505             if ~isequal(success,1)
2506                 warndlg_uvmat(['previous file result ' filemean ' already exists, problem in backup'],'ERROR')
2507                 return
2508             end
2509         end
2510         if isequal(Atype{1},'uint16')
2511             imwrite(uint16(DataMean.A),filemean,'BitDepth',16);
2512         else
2513             imwrite(uint8(DataMean.A),filemean,'BitDepth',8);
2514         end
2515         display([filemean ' written']);
2516     else %determine global attributes
2517         DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}];
2518         ActionKey='Action';
2519         while isfield(DataMean,ActionKey)
2520             ActionKey=[ActionKey '_1'];
2521         end
2522         eval(['DataMean.' ActionKey '=Series.Action;'])
2523         DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}];
2524         if isfield(DataMean,'Time')
2525             DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}];
2526         end      
2527         [filemean]=name_generator(filebase_out,num_i1{1}(1,i_slice),num_j1{1}(1,1),'.nc',NomTypeOut,1,num_i2{end}(end,end),num_j2{end}(end,end),subdir_result);
2528         if exist(filemean,'file')
2529             backupfile=filemean;
2530             testexist=2;
2531             while testexist==2
2532                 backupfile=[backupfile(1:end-3) '~.nc'];
2533                 testexist=exist(backupfile,'file');
2534             end
2535             [success,message]=copyfile(filemean,backupfile);%make backup
2536             if ~isequal(success,1)
2537                 msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
2538                 display(['previous file result ' filemean ' already exists, problem in backup'])
2539                 return
2540             end
2541         end
2542         error=struct2nc(filemean,DataMean); %save result file
2543         if isequal(error,0)
2544             display([filemean ' written']);
2545         else
2546             warndlg_uvmat(error,'ERROR')
2547         end
2548     end
2549 % %     nc.hart=0;
2550 % %         nc.dt=1;%time interval for image correlation (put  by default)
2551 %         nc.title=scal_name;
2552 %         nc.nonciv=1;
2553 % %     nc.fix=0;
2554 %         nb_vectors=length(vec_X);
2555 %         nc('nb_vec2_patch')=nb_vectors;
2556 %         nc{'vec2_patch_X'}=ncfloat('nb_vec2_patch');
2557 %         nc{'vec2_patch_Y'}=ncfloat('nb_vec2_patch');
2558 %         scal_name=scal_type{1};
2559 %         nc{scal_name}=ncfloat('nb_vec2_patch');
2560 %         var_vec_X=ncvar('vec2_patch_X',nc);
2561 %         var_vec_Y=ncvar('vec2_patch_Y',nc);
2562 %         var_vec_A=ncvar(scal_name,nc);
2563 %         vec_Xp=vec_X';
2564 %         vec_Yp=vec_Y';
2565 %         vec_Ap=vec_A';
2566 %         var_vec_X(1:nb_vectors)=vec_Xp(1:nb_vectors);
2567 %         var_vec_Y(1:nb_vectors)=vec_Yp(1:nb_vectors);
2568 %         var_vec_A(1:nb_vectors)=vec_Ap(1:nb_vectors);
2569 %         fin=close(nc);
2570 %    end
2571 end
2572 hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
2573 delete(hget_field)
2574 uvmat(filemean)
2575 
2576 
2577 % %----------------------------------------------------------------------
2578 % % --makes a time averaged velocity field
2579 % %----------------------------------------------------------------------
2580 % function aver_vel(num_i1,num_i2,num_j1,num_j2,Series)
2581 %                           %handles of the GUI series
2582 %
2583 % hseries=guidata(Series.hseries);%handles of the GUI series
2584 % WaitbarPos=get(hseries.waitbar_frame,'Position');
2585 % Field_list=get(hseries.FieldMenu,'String');
2586 % val=get(hseries.FieldMenu,'Value');
2587 % FieldName=Field_list{val(1)};
2588 % set(hseries.FieldMenu,'Value',val(1))% select only one input field
2589 % if isequal(FieldName,'get_field...')
2590 %     hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
2591 % end
2592 % %root input file and type
2593 % RootPath=get(hseries.RootPath,'String');
2594 % SubDir=get(hseries.SubDir,'String');
2595 % RootFile=get(hseries.RootFile,'String');
2596 % %NomType=get(hseries.NomType,'String');
2597 % NomType=Series.NomType;
2598 % FileExt=get(hseries.FileExt,'String');
2599 % ext=FileExt{1};
2600 % VelType_str=get(hseries.VelTypeMenu,'String');
2601 % VelType_val=get(hseries.VelTypeMenu,'Value');
2602 % VelType{1}=VelType_str{VelType_val};
2603 %
2604 % time=0; %default
2605 % % number of slices
2606 % NbSlice=str2num(get(hseries.NbSlice,'String'));
2607 % if isempty(NbSlice)
2608 %     NbSlice=1;
2609 % end
2610 % NbSlice_name=num2str(NbSlice);
2611 % filebase=fullfile(RootPath{1},RootFile{1});
2612 % Calib=[];
2613 % if exist([filebase '.xml'],'file')
2614 %     %[error,Heading,nom_type_read,ext_ima_read,time_imadoc,TimeUnit,mode,NbSlice,npx,npy,Calib]=read_imadoc([filebase '.xml']);
2615 %     [XmlData,warntext]=imadoc2struct([filebase '.xml']);
2616 % end
2617 % if NbSlice==1
2618 %    filebase_mean=[filebase '_mean']; %root name for the result
2619 % else
2620 %    filebase_mean=[filebase '_' NbSlice_name 'mean']; %root name for the results
2621 %    answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_mean ' ...']});
2622 %     if ~isequal(answeryes,'Yes')
2623 %     return
2624 %     end
2625 % end
2626 % siz=size(num_i1);
2627 % nbfield2=siz(1); %nb of consecutive fields at each level(burst)
2628 % lengthtot=siz(1)*siz(2);
2629 % nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
2630 % nbfield_slice=nbfield*nbfield2;% number of fields per slice
2631 % %projection object
2632 % GridX=[];
2633 % GridY=[];
2634 % if isfield(Series,'sethandles')
2635 %         Series.ProjObject=read_set_object(Series.sethandles);
2636 %         if isfield(Series.ProjObject,'Style')
2637 %             answeryes=questdlg({['statistics on field series projected on ' Series.ProjObject.Style]});
2638 %             if ~isequal(answeryes,'Yes')
2639 %                 return
2640 %             end
2641 %         end
2642 % end
2643 %
2644 % %LOOP ON SLICES
2645 % for i_slice=1:NbSlice
2646 %     %select the series of image indices at the level islice
2647 %     for ifield=1:nbfield
2648 %         indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
2649 %     end
2650 %     %name of result file
2651 %     [filemean,idetect]=...
2652 %                name_generator(filebase_mean,num_i1(i_slice),num_j1(1),Series.FileExt{1},'_i1-i2_j1-j2',1,num_i2(i_slice+nbfield_slice*NbSlice-1),num_j2(end),Series.SubDir{1});
2653 %
2654 %     % field=get(handles.civ1,'UserData');%read current selected field type (civ1,civ2...)
2655 %     itime=0;
2656 %      dt=[];
2657 %      %LOOP ON FIELDS IN  A SLICE
2658 %      test_interpolate=0;%default
2659 %     for index=1:nbfield*nbfield2
2660 %             ifile=indselect(index);
2661 %         stopstate=get(hseries.RUN,'BusyAction');
2662 %         if isequal(stopstate,'queue')% enable STOP command
2663 %             update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield*nbfield2))
2664 %             %name of the current file
2665 %             [filename,idetect]=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{1},Series.NomType{1},1,num_i2(ifile),num_j2(ifile),Series.SubDir{1});
2666 %             %read input file
2667 %             itime=itime+1;
2668 %             if isequal(FieldName,'get_field...')
2669 %                 hhget_field=guidata(hget_field);%handles of GUI elements in get_field
2670 %                 hObject=0;
2671 %                 eventdata=0;
2672 %                 SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
2673 %                 [Data,var_detect]=nc2struct(filename,SubField.ListVarName); %read input data
2674 %                 time(itime)=itime;
2675 %                 dt=1;
2676 %                 Calib_read=[];
2677 %             else
2678 %                 [nb_coord,nb_dim,Civ,CivStage,timeread,Data,VelTypeOut,Calib_read]=read_ncfield(filename,VelType{1});%reading the first file
2679 %                  time(itime)=timeread;
2680 %                 if isequal(Civ,1)
2681 %                     Data.CoordType='px';%test for pixel coordinates
2682 %                     if isequal(itime,1)
2683 %                         dt=Data.dt;
2684 %                     elseif ~isequal(Data.dt,dt)
2685 %                         warndlg_uvmat('series with non constant dt, need phys coordinates','ERROR')
2686 %                         return
2687 %                     end
2688 %                 end
2689 %             end
2690 %             %increment the detected fields, skip the others
2691 %             if idetect==0
2692 %                 warndlg_uvmat(['input file ' filename ' not found'],'ERROR')
2693 %                 %A FAIRE STOCKER LE RESULT ACTUEL S'IL EXISTE
2694 %             end
2695 % %             itime=itime+1;
2696 % %             time(itime)=timeread;
2697 %
2698 %             %coordinate transform
2699 %             if isempty(Calib)
2700 %                 Calib=Calib_read;%use Calib from xml file in priority, then Calib from the current file
2701 %             end
2702 %             if ~isequal(Series.CoordType,'')
2703 %                 Data=feval(Series.CoordType,Data,Calib);
2704 %             end
2705 %             %projection on object if defined
2706 %             if isfield(Series,'ProjObject');
2707 %                 Data=proj_field(Data,Series.ProjObject);
2708 %                 if isequal(itime,1)%use the positions on the first field for the whole series, ou utiliser grille
2709 %                     if isfield(Data,'Txt')%display error message
2710 %                         warndlg(Data.Txt,'ERROR')
2711 %                         return
2712 %                     end
2713 %                 end
2714 %             else%remove false vectors and interpolate on the positions of the first field
2715 %                 Data=document_field(Data);
2716 %                 Data.Style='plane';
2717 %             end
2718 %     %%%%%%%%% initiate the average at the first iteration: check list and structure of variables
2719 %             if ifile==i_slice%first field in the slice
2720 %                 testfalse=0;
2721 %                 ListIndex={};
2722 %                 testnewcell=1;
2723 %                 %group the variables (fields of 'Data') in cells of variables with the same dimensions
2724 %                 [DimVarIndex,CellVarIndex]=find_field_indices(Data);
2725 %                 VarIndex=CellVarIndex{1}; % ONLY THE FIRST VAR GROUP IS AVERAGED
2726 %                 DimIndex=Data.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
2727 %                 MeanData=Data;%transfer heading
2728 %                 MeanData.Time=[time(1) time(end)];
2729 %                 MeanData.Action=Series.Action;%name of the processing programme
2730 %                 MeanData.ListDimName=Data.ListDimName(DimIndex);%name of dimension
2731 %                 MeanData.DimValue=Data.DimValue(DimIndex);%values of dimension (nbre of vectors)
2732 %                 MeanData.ListVarName=Data.ListVarName;
2733 %                 MeanData.VarDimIndex=Data.VarDimIndex;
2734 %                 MeanData.ListVarAttribute={'Role'};%list of variable attribute names A FAIRE: transferer les autres attributs
2735 %                 testsum=ones(size(VarIndex));
2736 %                 indexfalse=0;
2737 %                 CoordName={};
2738 %                 indexremove=[];
2739 %                 if isfield(Data,'Role') % look for coordinate and flag variables
2740 %                     for ivar=1:length(VarIndex)
2741 %                         VarName=Data.ListVarName{VarIndex(ivar)};
2742 %                         var_role=Data.Role{VarIndex(ivar)};%'role' of the variable
2743 %                         MeanData.Role{ivar}=var_role;
2744 %                         if isequal(var_role,'falseflag')
2745 %                             indexfalse=ivar; %test for false flag
2746 %                             indexremove=ivar;
2747 %                             FFName=VarName;
2748 %                             testsum(ivar)=0;
2749 %                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
2750 %                         end
2751 %                         if isequal(var_role,'warnflag')
2752 %                             testsum(ivar)=0; %do not sum warn flag
2753 %                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
2754 %                             indexremove=[indexremove ivar];
2755 %                         end
2756 %                         if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|isequal(var_role,'coord_z')
2757 %                             eval(['MeanData.' VarName '=Data.' VarName ';']);
2758 %                             testsum(ivar)=0;
2759 %                             eval(['CoordName=[CoordName ''' VarName '''];']);
2760 %                         end
2761 %                         if testsum(ivar)~=0
2762 %                            eval(['MeanData.' VarName '=zeros(size(Data.' VarName '));']);%initialise sum
2763 %                         end
2764 %                     end
2765 %                 end
2766 %                 findsum=find(testsum);
2767 %                 VarIndexSum=VarIndex(findsum);%indices of variables to sum (not coordinates nor flags)
2768 %                 if length(CoordName)==0
2769 %                     if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates, prepare histograms
2770 %                          for ilist=1:length(VarIndexSum)
2771 %                             VarName=Data.ListVarName{VarIndexSum(ilist)};
2772 %                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
2773 %                             indexremove=[indexremove ilist];
2774 %                             eval(['[MeanData.' VarName 'hist,MeanData.' VarName 'val]=hist(Data.' VarName ',100);']);%make histo
2775 %                             eval(['sizhist=size(MeanData.' VarName 'hist);'])
2776 %                             if sizhist(1)==1
2777 %                                 eval(['MeanData.' VarName 'hist=MeanData.' VarName 'hist'';'])
2778 %                             end
2779 %                             eval(['maxval=max(MeanData.' VarName 'val);']);
2780 %                             eval(['minval=min(MeanData.' VarName 'val);']);
2781 %                             dC(ilist)=(maxval-minval)/100;%size of the histogram bin
2782 %                          end
2783 %                     else
2784 % %                         icoord=0;
2785 % %                         for ilist=1:length(DimVarIndex)
2786 % %                             VarDim=Data.ListVarName{DimVarIndex(ilist)};
2787 % %                             icoord=icoord+1;
2788 % %                             % eval(['Coord{' num2str(icord) '}=[' CoordName ''' VarName ''']']);
2789 % %                              %eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
2790 % %                         end
2791 %                     end
2792 %                 end
2793 %                 if ~isempty(indexremove)
2794 %                     MeanData.ListVarName(VarIndex(indexremove))=[];
2795 %                     MeanData.VarDimIndex(VarIndex(indexremove))=[];
2796 %                     if isfield(MeanData,'Role')%generaliser aus autres attributs
2797 %                         MeanData.Role(VarIndex(indexremove))=[];
2798 %                     end
2799 %                 end
2800 %                % END OF INITIALISATION
2801 %
2802 %             end
2803 %
2804 %          % A FAIRE: regular grid if coord_x undefined
2805 %             if indexfalse~=0 %suppress false data
2806 %                  eval(['testexist=isfield(Data,''' FFName ''');'])
2807 %                 if testexist
2808 %                     eval(['indsel=find(Data.' FFName '==0);']);
2809 %                     for icoord=1:length(CoordName)
2810 %                         eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
2811 %                     end
2812 %                 end
2813 %             end
2814 %             for ilist=1:length(VarIndexSum)
2815 %                 VarName=Data.ListVarName{VarIndexSum(ilist)};
2816 %                 if indexfalse~=0 & testexist
2817 %                     eval(['Data.' VarName '=Data.' VarName '(indsel);']);
2818 %                 end
2819 %                 if length(CoordName)==0%no variable use dfor unstructured coordinates
2820 %                     if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
2821 % %                         %update histogram with the current field #ifile
2822 %                         str_left=['[MeanData.' VarName 'val,MeanData.' VarName 'hist]='];
2823 %                         str_right=['hist_update(MeanData.' VarName 'val,MeanData.' VarName 'hist,Data.' VarName ',dC(ilist));'];
2824 %                         eval([str_left str_right]);%update global histo
2825 %                     else
2826 %                        %INTERPOLER
2827 %
2828 %                         eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum%CAS x,y change
2829 %                     end
2830 %                 else
2831 %                     if length(CoordName)==2
2832 %                         eval(['test_interp= ~isequal(Data.' CoordName{1} ',MeanData.' CoordName{1} ...
2833 %                             ')|~isequal(Data.' CoordName{2} ',MeanData.' CoordName{2} ');'])
2834 %                         if test_interp
2835 %                             eval(['Data.' VarName '=griddata_uvmat(Data.' CoordName{1} ',Data.' CoordName{2}...
2836 %                                 ',Data.' VarName ',MeanData.' CoordName{1} ',MeanData.' CoordName{2} ');']);
2837 %                             test_interpolate=1;
2838 %                         end
2839 %                     end
2840 %                     eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum
2841 %                 end
2842 %             end
2843 %         end
2844 %     end
2845 %     if length(CoordName)~=0 | ~isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
2846 %         for ilist=1:length(VarIndexSum)
2847 %             VarName=Data.ListVarName{VarIndexSum(ilist)};
2848 %             eval(['MeanData.' VarName '=MeanData.' VarName '/itime;']);%normalize sum by the number of fields
2849 %         end
2850 %     else
2851 %         MeanData.NbDim=1;
2852 %         MeanData.ListDimName={};
2853 %         MeanData.DimValue=[];
2854 %         for ilist=1:length(VarIndexSum)
2855 %             VarName=Data.ListVarName{VarIndexSum(ilist)};
2856 %             MeanData.ListVarName=[MeanData.ListVarName {[VarName 'val']} {[VarName 'hist']}];
2857 %             MeanData.VarDimIndex=[MeanData.VarDimIndex {[ilist]} {[ilist]}];
2858 %             MeanData.ListDimName=[MeanData.ListDimName {[VarName 'val']}];
2859 %             eval(['MeanData.DimValue=[MeanData.DimValue length(MeanData.' VarName 'val)];']);
2860 %         end
2861 %     end
2862 %     figure
2863 %     haxes=axes;
2864 %     plot_field(MeanData,haxes)%plot the resulting average
2865 %     % change variable names for consitency with civ1 data (need to generalize these programs)
2866 %     if length(MeanData.ListVarName) >= 4 & isequal(MeanData.ListVarName(1:4), {'X'  'Y'  'U'  'V'})
2867 %        MeanData.ListGlobalAttribute={'nb_coord','nb_dim','dt','absolut_time_T0','pixcmx','pixcmy','hart','civ','fix'};
2868 %        MeanData.nb_coord=2;
2869 %        MeanData.nb_dim=2;
2870 %        MeanData.dt=1;
2871 %        MeanData.absolut_time_T0=0;
2872 %        MeanData.pixcmx=1; %pix per cm (1 by default)
2873 %        MeanData.pixcmy=1; %pix per cm (1 by default)
2874 %        MeanData.hart=0;
2875 %        if isequal(Data.CoordType,'px')
2876 %          MeanData.civ=1;
2877 %       else
2878 %          MeanData.civ=0;
2879 %        end
2880 %       MeanData.fix=0;
2881 %         MeanData.ListVarName(1:4)={'vec_X'  'vec_Y'  'vec_U'  'vec_V'};
2882 %         MeanData.vec_X=MeanData.X;
2883 %         MeanData.vec_Y=MeanData.Y;
2884 %         MeanData.vec_U=MeanData.U;
2885 %         MeanData.vec_V=MeanData.V;
2886 %     end
2887 %     error=struct2nc(filemean,MeanData); %save result file
2888 %     if isequal(error,0)
2889 %         if test_interpolate
2890 %             'fields interpolated to the positions of the first one'
2891 %         end
2892 %         [filemean ' written']
2893 %     else
2894 %         warndlg_uvmat(error,'ERROR')
2895 %     end
2896 % end
2897 
2898 %----------------------------------------------------------------------
2899 % --project fields on a projection object (e. g. a regular grid), possibly
2900 % merge several fields
2901 %----------------------------------------------------------------------
2902 %INPUT:
2903 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
2904 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
2905 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
2906 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
2907 %OTHER INPUTS given by the structure Series
2908 function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series);
2909 
2910 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
2911 if ~exist('num_i1','var')
2912     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
2913         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
2914         'RootFile';'on';... %root input file name ('on' by default)
2915         'FileExt';'on';... %input file extension ('on' by default)
2916         'NomType';'on';...%type of file indexing ('on' by default)
2917         'NbSlice';'on'; ...%nbre of slices ('off' by default)
2918         'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
2919         'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
2920         'CoordType';'on';...%can use a transform function 'off' by default
2921         'GetObject';'on';...%can use projection object ,'off' by default
2922         %'GetMask';'on'...%can use mask option   ,'off' by default
2923         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
2924                ''};
2925     return %exit the function
2926 end
2927 
2928 %-------------------------------------------------
2929 hseries=guidata(Series.hseries);%handles of the GUI series
2930 WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
2931 %-------------------------------------------------
2932 
2933 %numbers of view fields (nbre of inputs in RootPath)
2934 testcell=iscell(Series.RootFile);
2935 if ~testcell
2936     Series.RootPath={Series.RootPath};
2937     Series.RootFile={Series.RootFile};
2938     Series.SubDir={Series.SubDir};
2939     Series.FileExt={Series.FileExt};
2940     Series.NomType={Series.NomType};
2941     num_i1={num_i1};
2942     num_i2={num_i2};
2943     num_j1={num_j1};
2944     num_j2={num_j2};
2945 end 
2946 nbview=length(Series.RootFile);%number of views (file series to merge)
2947 nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series
2948 transform=Series.CoordType; %  field transform function
2949 hhh=which('mmreader');
2950 for iview=1:nbview
2951     test_movie(iview)=0;
2952     if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
2953         if isequal(lower(FileExt{iview}),'.avi')
2954             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
2955             test_movie(iview)=1;
2956         end
2957     end 
2958 end
2959 
2960 %Calibration data and timing: read the ImaDoc files
2961 mode=''; %default
2962 timecell={};
2963 itime=0;
2964 for iview=1:nbview%Loop on views
2965     XmlData{iview}=[];%default
2966     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
2967     if exist([filebase{iview} '.xml'],'file')
2968         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
2969         if isfield(XmlData{iview},'Time')
2970             itime=itime+1;
2971             timecell{itime}=XmlData{iview}.Time;
2972         end
2973     elseif exist([filebase{iview} '.civ'],'file')
2974         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
2975         itime=itime+1;
2976         timecell{itime}=time;
2977         XmlData{iview}.Time=time;
2978         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
2979         GeometryCalib.Tx=0;
2980         GeometryCalib.Ty=0;
2981         GeometryCalib.Tz=1;
2982         GeometryCalib.dpx=1;
2983         GeometryCalib.dpy=1;
2984         GeometryCalib.sx=1;
2985         GeometryCalib.Cx=0;
2986         GeometryCalib.Cy=0;
2987         GeometryCalib.f=1;
2988         GeometryCalib.kappa1=0;
2989         GeometryCalib.CoordUnit='cm';
2990         XmlData{iview}.GeometryCalib=GeometryCalib;
2991         if error==1
2992             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
2993         end
2994     end
2995 end
2996 
2997 %check coincidence in time
2998 multitime=0;
2999 if length(timecell)==0
3000     time=[];
3001 elseif length(timecell)==1
3002     time=timecell{1};
3003 elseif length(timecell)>1
3004     multitime=1;
3005     for icell=1:length(timecell)
3006         if ~isequal(size(timecell{icell}),size(timecell{1}))
3007             warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
3008             time=timecell{1};
3009             multitime=0;
3010             break
3011         end
3012     end
3013 end
3014 if multitime
3015     for icell=1:length(timecell)
3016         time(icell,:,:)=timecell{icell};
3017     end
3018     diff_time=max(max(diff(time)));
3019     if diff_time>0
3020         warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
3021     end   
3022 end
3023 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
3024     time=[];
3025 end
3026 
3027 % Field and velocity type (the same for all views)
3028 Field_str=get(hseries.FieldMenu,'String');
3029 val=get(hseries.FieldMenu,'Value');
3030 FieldName=Field_str(val);%the same set of fields for all views
3031 VelType_str=get(hseries.VelTypeMenu,'String');
3032 VelType_val=get(hseries.VelTypeMenu,'Value');
3033 VelType=VelType_str{VelType_val}; %the same for all views
3034 if isequal(FieldName,'get_field...')
3035     hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
3036     hhget_field=guidata(hget_field);%handles of GUI elements in get_field
3037     SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
3038     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
3039         list_transform=get(hhget_field.menu_coord,'String');
3040         val_list=get(hhget_field.menu_coord,'Value');
3041         transform=list_transform{val_list};
3042     end
3043 end
3044 %detect whether all the files are 'images' or 'netcdf'
3045 testima=0;
3046 testvol=0;
3047 testcivx=0;
3048 testnc=0;
3049 FileExt=get(hseries.FileExt,'String');
3050 for iview=1:nbview
3051      ext=FileExt{iview};
3052      form=imformats(ext([2:end]));
3053      if isequal(lower(ext),'.vol')
3054          testvol=testvol+1;
3055      elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
3056          testima=testima+1;
3057      elseif isequal(ext,'.nc')
3058          testnc=testnc+1;
3059      end
3060 end
3061 if testvol
3062     warndlg_uvmat('volume images not implemented yet','ERROR')
3063     return
3064 end
3065 if testnc~=nbview && testima~=nbview && testvol~=nbview
3066     warndlg_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
3067     return
3068 end
3069 if ~isequal(FieldName,'get_field...')
3070     testcivx=testnc;
3071 end
3072 %name of output files and directory:
3073 % res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']);
3074 ProjectDir=fileparts(fileparts(Series.RootPath{1}));% preoject directory (GERK)
3075 prompt={['result directory (in' ProjectDir ')']};
3076 RootPath=get(hseries.RootPath,'String');
3077 SubDir=get(hseries.SubDir,'String');
3078 if isequal(length(RootPath),1)
3079     fulldir=RootPath{1};
3080     subdir='GRID';
3081     res_subdir=fullfile(fulldir,subdir);
3082 else
3083     def={fullfile(ProjectDir,'0_RESULTS')};
3084     dlgTitle='result directory';
3085     lineNo=1;
3086     %answer=inputdlg(prompt,dlgTitle,lineNo,def,'on');
3087     answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
3088     fulldir=answer{1};
3089     subdir=[];
3090     dirlist=sort(Series.RootFile);
3091     for iview=1:nbview
3092         if ~isempty(subdir)
3093             subdir=[subdir '-'];
3094         end
3095         subdir=[subdir dirlist{iview}];
3096     end  
3097     res_subdir=fullfile(fulldir,subdir);
3098 end
3099 ext=FileExt{1};
3100 if ~exist(fulldir,'dir')
3101     warndlg_uvmat(['directory ' fulldir ' needs to be created'],'ERROR')
3102     return
3103 end
3104 if ~exist(res_subdir,'dir')
3105     dircur=pwd;
3106     cd(fulldir)
3107     error=mkdir(subdir);
3108     cd(dircur)
3109 end
3110 filebasesub=fullfile(res_subdir,Series.RootFile{1});
3111 filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
3112 
3113 %projection object
3114 if isfield(Series,'sethandles')
3115     if ishandle(Series.sethandles.set_object)
3116         Series.ProjObject=read_set_object(Series.sethandles);
3117         if ~isfield(Series.ProjObject,'Style')
3118             warndlg_uvmat('Undefined projection object style','ERROR')
3119             return
3120         end
3121         if ~isequal(Series.ProjObject.Style,'plane')
3122             warndlg_uvmat('The projection object must be a plane','ERROR')
3123             return
3124         end
3125     end
3126 end
3127 
3128     %MAIN LOOP
3129 for ifile=1:nbfield                
3130     stopstate=get(hseries.RUN,'BusyAction');
3131     if isequal(stopstate,'queue')% enable STOP command from the 'series' interface
3132          update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
3133          Amerge=0;
3134          
3135          %----------LOOP ON VIEWS----------------------
3136         nbtime=0;
3137         for iview=1:nbview
3138             %name of the current file
3139             [filename,idetect]=name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
3140             if idetect==0
3141                 warndlg_uvmat(['missing input file' filename],'ERROR')
3142                 break
3143             end
3144 
3145             %reading the current file
3146             if testima
3147                 if test_movie(iview)
3148                     Field{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
3149                 else
3150                     Field{iview}.A=read_image(filename,Series.NomType{iview},num_i1{iview}(ifile)); 
3151                 end
3152                 npxy=size(Field{iview}.A);
3153                 Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
3154                 Field{iview}.AY=[npxy(1)-0.5 0.5];
3155                 Field{iview}.CoordType='px'; 
3156                 Field{iview}.AName='image';
3157             else
3158                 if testcivx
3159                     [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
3160                 else
3161                     [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
3162                     Field{iview}.VarAttribute=SubField.VarAttribute;
3163                 end
3164                 if isfield(Field{iview},'Time')
3165                     timeread(iview)=Field{iview}.Time;
3166                     nbtime=nbtime+1;
3167                 end
3168             end
3169             % coord transform
3170             if ~isequal(transform,'')
3171                 Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested
3172             end
3173             if testcivx
3174                     Field{iview}=calc_field(FieldName,Field{iview});
3175             end
3176 
3177             %projection on object (gridded plane)
3178             if isfield(Series,'ProjObject')
3179                 Field{iview}=proj_field(Field{iview},Series.ProjObject);
3180             end
3181         end    
3182         
3183          %----------END LOOP ON VIEWS----------------------
3184          
3185         %merge the nbview fields
3186         MergeData=merge_field(Field);
3187         if isfield(MergeData,'Txt')
3188             warndlg_uvmat(MergeData.Txt,'ERROR')
3189             return
3190         end
3191         
3192         % generating the name of the merged field
3193         mergename=name_generator(filebase_merge,num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile));
3194         
3195         % time:
3196         time_i=0;%default
3197         if isempty(time)% time from ImaDoc prevails
3198             time_i=sum(timeread)/nbtime;
3199         else
3200             time_i=(time(iview,num_i1{iview}(ifile),num_j1{iview}(ifile))+time(iview,num_i2{iview}(ifile),num_j2{iview}(ifile)))/2;
3201         end
3202         
3203         % recording the merged field
3204         if testima    %in case of input images an image is produced
3205             if isa(MergeData.A,'uint8')
3206                 bitdepth=8;
3207             elseif isa(MergeData.A,'uint16')
3208                 bitdepth=16;
3209             end
3210             imwrite(MergeData.A,mergename,'BitDepth',bitdepth); 
3211             %write xml calibration file
3212             siz=size(MergeData.A);
3213             npy=siz(1);
3214             npx=siz(2);
3215             if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
3216                 Rangx=MergeData.VarAttribute{1}.Coord_2;
3217                 Rangy=MergeData.VarAttribute{1}.Coord_1;
3218             elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
3219                 Rangx=[MergeData.AX(1) MergeData.AX(end)];
3220                 Rangy=[MergeData.AY(1) MergeData.AY(end)];
3221             else
3222                 Rangx=[0.5 npx-0.5];
3223                 Rangy=[npy-0.5 0.5];%default
3224             end
3225             pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
3226             pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
3227             T_x=-pxcmx*Rangx(1)+0.5;
3228             T_y=-pxcmy*Rangy(2)+0.5;
3229             GeometryCal.focal=1;
3230             GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
3231             GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
3232             ImaDoc.GeometryCalib=GeometryCal;
3233             t=struct2xml(ImaDoc);
3234             t=set(t,1,'name','ImaDoc');
3235             save(t,[filebase_merge '.xml'])     
3236             display([filebase_merge '.xml saved'])
3237         else
3238             MergeData.ListGlobalAttribute={'Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};        
3239             MergeData.nb_coord=2;
3240             MergeData.nb_dim=2;
3241             MergeData.dt=1;
3242             MergeData.Time=time_i;
3243             error=struct2nc(mergename,MergeData); %save result file
3244             if isequal(error,0)
3245                 display(['output file= ' mergename])
3246             end
3247         end
3248     end
3249 end
3250 
3251 %--------------------------------------------------------------------------
3252 function MergeData=merge_field(Data)
3253 % initiate Matlab  structure for physical field
3254 if isempty(Data)||~iscell(Data)
3255     MergeData=[];
3256     return
3257 end
3258 MergeData=Data{1};%default
3259 error=0;
3260 nbview=length(Data);
3261 if nbview==1
3262     return
3263 end
3264 for iview=1:nbview
3265     if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName)
3266         error=1;
3267     end
3268     if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName)
3269         error=1;
3270     end
3271      if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex)
3272         error=1;
3273      end
3274 end
3275 if error
3276     MergeData.Txt='ERROR: attempt at merging fields of incompatible type';
3277     return
3278 end
3279 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
3280 %-----------------------------------------------------------------
3281 [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
3282 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
3283 % CellVarIndex=cells of variable index arrays
3284 ivar_new=0; % index of the current variable in the projected field
3285 icoord=0;
3286 for icell=1:length(CellVarIndex)
3287     if NbDim(icell)==1
3288         continue
3289     end
3290     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
3291     VarType=VarTypeCell{icell};
3292     ivar_X=VarType.coord_x;
3293     ivar_Y=VarType.coord_y;
3294     ivar_FF=VarType.errorflag;
3295     if isempty(ivar_X)
3296         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
3297     else
3298         if length(ivar_Y)~=1
3299                 warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
3300                 return
3301         end
3302         test_grid=0;
3303     end
3304     DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
3305     %case of input fields with unstructured coordinates
3306     if ~test_grid
3307         for ivar=VarIndex
3308             VarName=MergeData.ListVarName{ivar};
3309             for iview=1:nbview
3310                 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';'])
3311             end
3312         end
3313     %case of fields defined on a structured  grid
3314     else  
3315         DimValue=MergeData.DimValue(DimIndices);%set of dimension values
3316         testFF=0;
3317         for iview=2:nbview
3318             if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
3319                 MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
3320                 return
3321             end
3322             for ivar=VarIndex
3323                 VarName=MergeData.ListVarName{ivar};
3324                 if isfield(MergeData,'VarAttribute')
3325                     if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
3326                         testFF=1;
3327                     end
3328                 end
3329                 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
3330             end
3331         end
3332         if testFF
3333             nbaver=nbview-MergeData.FF;
3334             indgood=find(nbaver>0);
3335             for ivar=VarIndex
3336                 VarName=MergeData.ListVarName{ivar};
3337                 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
3338             end 
3339         else
3340             for ivar=VarIndex
3341                 VarName=MergeData.ListVarName{ivar};
3342                 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
3343             end    
3344         end
3345     end
3346 end
3347     
3348     
3349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3350  %detect the chosen series of files and check their date of modification:
3351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3352 %INPUT:
3353 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
3354 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
3355 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
3356 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
3357 %OTHER INPUTS given by the structure Series
3358 function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
3359 
3360 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
3361 if ~exist('num_i1','var')
3362     GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
3363         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
3364         %'RootFile';'on';... %root input file name ('on' by default)
3365         %'FileExt';'on';... %input file extension ('on' by default)
3366         %'NomType';'on';...%type of file indexing ('on' by default)
3367         %'NbSlice';'on'; ...%nbre of slices ('off' by default)
3368         %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
3369         %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
3370         %'CoordType';'on'...%can use a transform function 'off' by default
3371         %'GetObject';'on'...%can use projection object ,'off' by default
3372         %'GetMask';'on'...%can use mask option   ,'off' by default
3373         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
3374                ''};
3375     return %exit the function
3376 end
3377 %---------------------------------------------------------
3378 hseries=guidata(Series.hseries);%handles of the GUI series
3379 WaitbarPos=get(hseries.waitbar_frame,'Position');
3380 
3381 %%%%%%%%%%%%%%%%%%%%%%%%
3382 message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
3383 answer=msgbox_uvmat('INPUT_Y-N',message);
3384 if ~isequal(answer,'Yes')
3385     return
3386 end
3387 nbdelete=0;
3388 testcell=iscell(Series.RootFile);
3389 if ~testcell
3390     Series.RootPath={Series.RootPath};
3391     Series.RootFile={Series.RootFile};
3392     Series.SubDir={Series.SubDir};
3393     Series.FileExt={Series.FileExt};
3394     Series.NomType={Series.NomType};
3395 end 
3396 for iview=1:length(Series.RootFile)
3397     hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
3398     for ilist=1:length(hdir)
3399         update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
3400         FileName=hdir(ilist).name;
3401         [dd,ff,Ext]=fileparts(FileName);
3402         if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
3403             delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
3404             nbdelete=nbdelete+1;
3405         end
3406     end
3407 end
3408 msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
3409 
3410 
3411 
3412 
3413 
3414 %-----------------------------
3415 function mouse_up_gui(ggg,eventdata,handles)
3416 if isequal(get(ggg,'SelectionType'),'alt') 
3417     display('global CurData, UserData of GUI series')
3418     global CurData
3419     CurData=get(ggg,'UserData');
3420     evalin('base','global CurData');%make CurData global in the workspace
3421     evalin('base','CurData'); %display CurData in the workspace
3422     commandwindow
3423    % plot_text(CurData)
3424 end
3425 
3426 
3427 
3428 % %----------------------------------------------------------------------
3429 % % --- display image movie and display time average
3430 % %OBSOLETE: A SUPPRIMER
3431 % %----------------------------------------------------------------------
3432 % function movie_ima(handles,filecell,filecell_1,num1,num_a,field)
3433 %
3434 % global hfig1 hfig2 hfig3 poscolbar
3435 % global A val HIST
3436 %
3437 % A=[];aviobj=[];
3438 % % set(hfig1,'UserData','ima')% set the current field state to 'image'
3439 % set(handles.zoom,'Value',1); %put zoom on
3440 % nom_type=get(handles.file_input,'UserData');
3441 % % field=get(handles.civ1,'UserData');
3442 % % fields=field(1).fields;
3443 % set(handles.speed,'Visible','On')%show slider to set movie speed
3444 % set(handles.mo_speed_txt,'Visible','On')
3445 %
3446 % if ~isempty(filecell_1)
3447 %    file1=get(handles.file1_input,'UserData');
3448 %    field1=file1.field;
3449 %    scal_type1=field1.fields;
3450 %    vel_type1=field1.vel_type;
3451 %    filename_1=filecell_1(1);% first file name in the series
3452 % else
3453 %    filename_1=[];
3454 % end
3455 % scal_type{1}=field(1).fields;
3456 % vel_type{1}=field(1).vel_type;
3457 % % display the first field
3458 % [A,time,dt,rangx0,rangy0]=view_ima(handles,cell2mat(filecell(1)),filename_1,num1(1),num_a(1));
3459 %
3460 % % calculate the histogram of the first image
3461 % nxy=size(A);
3462 % ndim=length(nxy);
3463 % if ndim==2 % case of B/W images
3464 %     nxy(3)=1;
3465 % end
3466 % C=reshape(A,nxy(1)*nxy(2),nxy(3));
3467 % Amaxmax=double(max(max(max(A))));
3468 % Aminmin=double(min(min(min(A))));
3469 % if isa(C,'uint8')|isa(C,'uint16')
3470 %     C=double(C);
3471 %     dC=1;
3472 % else
3473 %     dC=(Amaxmax-Aminmin)/100;
3474 % end
3475 % val=[Aminmin:dC:Amaxmax];% define bins for histogram
3476 % HIST=hist(C,val);% initiate the global histogram
3477 % if ndim==2, HIST=HIST'; end;
3478 %
3479 % auto_scale=get(handles.auto_scale,'Value');
3480 % min_input=str2num(get(handles.min_input,'String'));% select the minimum
3481 % max_input=str2num(get(handles.scale_input,'String'));% select the max
3482 % zoomstate=get(handles.zoom,'Value');
3483 %
3484 % if isequal(get(handles.window_input,'String'),'avi'),
3485 %     basename=get(handles.file_input,'String');
3486 %     prompt = {'file name';'frames per second';'frame resolution ([nbpixels x y])';'axis position relative to the frame'};
3487 %     dlg_title = 'select properties of the output avi movie';
3488 %     num_lines= 1;
3489 %     def     = {[basename '_out.avi'];'5';'[1024 768]';'[0.05 0.07 0.87 0.88]'};
3490 %     answer = inputdlg(prompt,dlg_title,num_lines,def);
3491 %     aviname=answer{1};
3492 %     fps=str2num(answer{2});
3493 %     if exist(aviname,'file')==2
3494 %         delete(aviname);
3495 %     end;
3496 %     aviobj=avifile(aviname,'Compression','None','fps',fps);
3497 %
3498 %     %display first view for tests
3499 %     figure(2);
3500 %     hh=get(gcf,'CurrentAxes');
3501 %     if isempty(hh),
3502 %         hfig1=axes;
3503 %     else
3504 %         hfig1=hh;
3505 %     end;
3506 %     if isequal(filecell_1,{})
3507 %         filename_1=[];
3508 %     else
3509 %         filename_1=cell2mat(filecell_1(1));
3510 %     end
3511 %     poscolbar=[0.93 0.15 0.02 0.7];
3512 %     view_ima(handles,cell2mat(filecell(1)),filename_1,num1(1),num_a(1));% show the first field
3513 %     nbpix=eval(answer{3});
3514 %     set(gcf,'Position',[1 1 nbpix])% resolution XVGA
3515 %     set(hfig1,'Position',eval(answer{4}));
3516 %
3517 %     msgbox({'adjust figure 2 with its matlab edit menu ' ;...
3518 %             'then type any keyboard key to get the avi movie as a copy of figure 2 display'})
3519 %     pause;
3520 %     hh=colorbar;
3521 %     poscolbar=get(hh,'Position');
3522 % end
3523 %
3524 % %%%%%%%%%%%%%%%%
3525 % %mask and usrdfct
3526 % maskname=[]; %default
3527 % if isequal(get(handles.mask_test,'Value'),1)
3528 %     maskbase=get(handles.mask_test,'UserData');
3529 % end
3530 % % image or scalar processing programme set by user
3531 % % if (get(handles.usr_fct,'Value')==1)
3532 % %      usrfct=get(handles.usr_fct,'UserData');
3533 % % else
3534 % %      usrfct='';
3535 % % end
3536 % nburst=1; % nburst(1) =nbre of names in filename= nbre of bursts
3537 % set(handles.text_display_1,'String',['image movie'])
3538 % nbfield=length(filecell);
3539 % if nbfield >1
3540 % for ifile=2:nbfield
3541 %     stopstate=get(handles.run0,'BusyAction');
3542 %     if isequal(stopstate,'queue')% enable STOP command
3543 %        pausetime=1.02-get(handles.speed,'Value');
3544 %          pause(pausetime)
3545 %          if isequal(get(handles.mask_test,'Value'),1)
3546 %                 maskname=name_generator(maskbase,num1(ifile),1,'.png','png_series');
3547 %             end
3548 %             if isequal(AName{1},'image')
3549 %                 A=read_image(cell2mat(filecell(ifile)),num1(ifile),maskname);% read the first image, num2 is the counter for avi files
3550 %             else % read the first field from the netcdf file, imposing the pixel positions in the selected domain
3551 %                  [A,time(ifile),dtr,rgx,rgy,vt_out,erread]=read_scalar(filecell{ifile},vel_type,scal_type,rangx0,rangy0,nxy,maskname);
3552 %                 if erread==1;
3553 %                     errordlg({['no spatial derivative in ' filecell{ifile}]; 'run patch first'}); return
3554 %                 elseif erread==2;
3555 %                     errordlg(['no field ' vel_type{1} ' in ' filecell{ifile}]); return
3556 %                 elseif erread==3;
3557 %                     errordlg(['scalar ' scal_type{1} ' not found in' filecell{ifile}]); return
3558 %                 elseif erread==4;
3559 %                     errordlg(['all points aligned in' filecell{ifile}]); return
3560 %                 end
3561 %             end
3562 %
3563 %             % read the second image
3564 %             if ~isempty(filecell_1)
3565 %                 if isequal(scal_type{1},'image')
3566 %                     A1=read_image(cell2mat(filecell_1(ifile)),num1(ifile),maskname);% read the second image, num2 is the counter for avi files
3567 %                     Avalue_1=double(A1(indy,indx,:));
3568 %                 else % read the second field from the netcdf file, imposing the pixel positions in the selected domain
3569 %                     [Avalue_1,time1(ifile),dtr,rgx,rgy,vt_out,erread]=read_scalar(filecell_1{ifile},{vel_type1},{scal_type1},rangx0,rangy0,npxy,maskname,usrfct);
3570 %                     if erread==1;
3571 %                         errordlg({['no spatial derivative in ' filecell_1{ifile}]; 'run patch first'}); return
3572 %                     elseif erread==2;
3573 %                         errordlg(['no field ' vel_type1 ' in ' filecell_1{ifile}]); return
3574 %                     elseif erread==3;
3575 %                         errordlg(['scalar ' scal_type1 ' not found in' filecell_1{ifile}]); return
3576 %                     elseif erread==4;
3577 %                         errordlg(['all points aligned in' filecell_1{ifile}]); return
3578 %                     end
3579 %                 end
3580 %                 time(ifile)=(time(ifile)+time1(ifile))/2;
3581 %                 Avalue=Avalue-Avalue_1;
3582 %             end
3583 %         set(handles.abs_time,'String',time);
3584 %         set(handles.field_counter,'String',num2str(num1(ifile)));
3585 %         set(handles.a_input,'String',num2stra(num_a(ifile),nom_type));
3586 %         C=reshape(A,nxy(1)*nxy(2),nxy(3));% reshape in a vector
3587 %         [val,HIST]=hist_update(val,HIST,C,dC);
3588 %         [h,Amin,Amax]=plot_image(hfig1,rangx0,rangy0,1,scal_type{1},auto_scale,min_input,max_input,poscolbar,A);
3589 %         set(handles.min_input,'String',num2str(Amin));% select the minimum
3590 %         set(handles.scale_input,'String',num2str(Amax));% select the minimum
3591 %          if ~isequal(aviobj,[]),
3592 % %              mov=getframe(hfig1);
3593 %               mov=getframe(gcf);
3594 %              aviobj=addframe(aviobj,mov);end
3595 %          if (get(handles.zoom,'Value') == get(handles.zoom,'Max')),zoom on,end
3596 %          set(handles.field_counter,'String',num2str(num1(ifile)))
3597 % %     end
3598 % end
3599 % end
3600 % end
3601 % aviobj=close(aviobj);
3602 %
3603 % %plot global image histogram
3604 %         HIST=HIST/(nbfield*nxy(1)*nxy(2));% normalized by the number of points
3605 %         axes(hfig2) %in main window
3606 %         if ndim==2
3607 %             plot(val,HIST)
3608 %         else
3609 %             plot(val,HIST(:,1),'r',val,HIST(:,2),'g',val,HIST(:,3),'b')
3610 %         end
3611 %         residu=1-sum(HIST,1);
3612 %         title(['histo, residu ' num2str(residu)])
3613 %         grid on
3614 %         axes(hfig3)
3615 %         cla %clear the second histogram window
3616 %
3617 
3618 
3619 %----------------------------------------------------------------------
3620 % --- make a time series analysis
3621 %----------------------------------------------------------------------
3622 %INPUT:
3623 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
3624 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
3625 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
3626 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
3627 %OTHER INPUTS given by the structure Series
3628 function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series) 
3629 
3630 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
3631 if ~exist('num_i1','var')
3632     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
3633         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
3634         'RootFile';'on';... %root input file name ('on' by default)
3635         'FileExt';'on';... %input file extension ('on' by default)
3636         'NomType';'on';...%type of file indexing ('on' by default)
3637         'NbSlice';'on'; ...%nbre of slices ('off' by default)
3638         'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
3639         'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
3640         'CoordType';'on';...%can use a transform function 'off' by default
3641         'GetObject';'on';...%can use projection object ,'off' by default
3642         %'GetMask';'on'...%can use mask option   ,'off' by default
3643         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
3644                ''};
3645     return %exit the function
3646 end
3647 
3648 %------------------------------------------------------
3649 hseries=guidata(Series.hseries);%handles in the GUI series
3650 WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
3651 
3652 % root names
3653 if iscell(Series.RootPath)
3654     RootPath=Series.RootPath;
3655     RootFile=Series.RootFile;
3656     SubDir=Series.SubDir;
3657     FileExt=Series.FileExt;
3658     NomType=Series.NomType;
3659 else
3660     RootPath={Series.RootPath};
3661     RootFile={Series.RootFile};
3662     SubDir={Series.SubDir};
3663     FileExt={Series.FileExt};
3664     NomType={Series.NomType};
3665     num_i1={num_i1};
3666     num_i2={num_i2};
3667     num_j1={num_j1};
3668     num_j2={num_j2};
3669 end
3670 ext=FileExt{1};
3671 form=imformats(ext([2:end]));%test valid Matlab image formats
3672 testima=0;
3673 if ~isempty(form)||isequal(lower(ext),'.avi')
3674     testima=1;
3675 end
3676 nbview=length(RootPath);%number of series (1 or 2)
3677 nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
3678 
3679 %Number of input series: this function  accepts only a single input file series
3680 nbview=length(RootPath);
3681 if nbview>2  
3682     RootPath=RootPath(1:2);
3683     set(hseries.RootPath,'String',RootPath)
3684     SubDir=SubDir(1:2);
3685     set(hseries.SubDir,'String',SubDir)
3686     RootFile=RootFile(1:2);
3687     set(hseries.RootFile,'String',RootFile)
3688     NomType=NomType(1:2);
3689     %set(hseries.NomType,'String',NomType)
3690     FileExt=FileExt(1:2);
3691     set(hseries.FileExt,'String',FileExt)
3692     nbview=2;
3693 end
3694 hhh=which('mmreader');
3695 for iview=1:nbview
3696     test_movie(iview)=0;
3697     if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
3698         if isequal(lower(FileExt{iview}),'.avi')
3699             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
3700             test_movie(iview)=1;
3701         end
3702     end 
3703 end
3704 filebase{1}=fullfile(RootPath{1},RootFile{1});
3705 % FileDisplay=fullfile(RootPath{1},SubDir{1},RootFile{1});
3706 
3707 % number of slices
3708 NbSlice=str2num(get(hseries.NbSlice,'String'));
3709 if isempty(NbSlice)
3710     NbSlice=1;
3711 end
3712 NbSlice_name=num2str(NbSlice);
3713 
3714 % Field and velocity type (the same for the two views)
3715 if isfield(Series,'Field')
3716     FieldName=Series.Field;%the same set of fields for all views
3717 else
3718     FieldName={''};
3719 end
3720 if isequal(FieldName,{'get_field...'})
3721     hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
3722     if length(hget_field)>1
3723         delete(hget_field(2:end))
3724     elseif isempty(hget_field)
3725        [filename,idetect(iview)]=...
3726                            name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
3727        hget_field=get_field(filename);
3728        return
3729     end
3730     hhget_field=guidata(hget_field);%handles of GUI elements in get_field
3731     SubField=read_var_names(hhget_field); %read the names of the variables to plot in the get_field GUI
3732     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
3733         list_transform=get(hhget_field.menu_coord,'String');
3734         val_list=get(hhget_field.menu_coord,'Value');
3735         transform=list_transform{val_list};
3736     end
3737 end
3738 
3739 %detect whether the two files are 'images' or 'netcdf'
3740 testima=0;
3741 testvol=0;
3742 testcivx=0;
3743 testnc=0;
3744 FileExt=get(hseries.FileExt,'String');
3745 for iview=1:nbview
3746      ext=FileExt{iview};
3747      form=imformats(ext([2:end]));
3748      if isequal(lower(ext),'.vol')
3749          testvol=testvol+1;
3750      elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
3751          testima=testima+1;
3752      elseif isequal(ext,'.nc')
3753          testnc=testnc+1;
3754      end
3755 end
3756 if testvol
3757     warndlg_uvmat('volume images not implemented yet','ERROR')
3758     return
3759 end
3760 if testnc~=nbview && testima~=nbview && testvol~=nbview
3761     warndlg_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
3762     return
3763 end
3764 if ~isequal(FieldName,{'get_field...'})
3765     testcivx=testnc;
3766 end
3767 
3768 
3769 % Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
3770 filebasesub=fullfile(RootPath{1},RootFile{1});
3771 if NbSlice==1
3772     filebase_out=[filebasesub '_time'];
3773 else
3774     filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
3775     answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
3776     if ~isequal(answeryes,'Yes')
3777         return
3778     end
3779 end
3780 VelType_str=get(hseries.VelTypeMenu,'String');
3781 VelType_val=get(hseries.VelTypeMenu,'Value');
3782 VelType{1}=VelType_str{VelType_val};
3783 if nbview==2
3784     VelType_str=get(hseries.VelTypeMenu_1,'String');
3785     VelType_val=get(hseries.VelTypeMenu_1,'Value');
3786     VelType{2}=VelType_str{VelType_val};
3787 end
3788 
3789 %Calibration data and timing: read the ImaDoc files
3790 mode=''; %default
3791 timecell={};
3792 XmlData={};
3793 itime=0;
3794 for iview=1:nbview%Loop on views
3795     XmlData{iview}=[];%default
3796     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
3797     if exist([filebase{iview} '.xml'],'file')
3798         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
3799         if isfield(XmlData{iview},'Time')
3800             itime=itime+1;
3801             timecell{itime}=XmlData{iview}.Time;
3802         end
3803     elseif exist([filebase{iview} '.civ'],'file')
3804         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
3805         itime=itime+1;
3806         timecell{itime}=time;
3807         XmlData{iview}.Time=time;
3808         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
3809         GeometryCalib.Tx=0;
3810         GeometryCalib.Ty=0;
3811         GeometryCalib.Tz=1;
3812         GeometryCalib.dpx=1;
3813         GeometryCalib.dpy=1;
3814         GeometryCalib.sx=1;
3815         GeometryCalib.Cx=0;
3816         GeometryCalib.Cy=0;
3817         GeometryCalib.f=1;
3818         GeometryCalib.kappa1=0;
3819         GeometryCalib.CoordUnit='cm';
3820         XmlData{iview}.GeometryCalib=GeometryCalib;
3821         if error==1
3822             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
3823         end
3824     end
3825 end
3826 
3827 %check coincidence in time
3828 multitime=0;
3829 if length(timecell)==0
3830     time=[];
3831 elseif length(timecell)==1
3832     time=timecell{1};
3833 elseif length(timecell)>1
3834     multitime=1;
3835     for icell=1:length(timecell)
3836         if ~isequal(size(timecell{icell}),size(timecell{1}))
3837             warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
3838             time=timecell{1};
3839             multitime=0;
3840             break
3841         end
3842     end
3843 end
3844 if multitime
3845     for icell=1:length(timecell)
3846         time(icell,:,:)=timecell{icell};
3847     end
3848     diff_time=max(max(diff(time)));
3849     if diff_time>0
3850         warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
3851     end   
3852 end
3853 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
3854     time=[];
3855 end
3856 
3857 % image or scalar processing programme set by user
3858 Coord_menu=get(hseries.CoordType,'String');
3859 menu_val=get(hseries.CoordType,'Value');
3860 usrfct=Coord_menu{menu_val};
3861 testfct=~isequal(usrfct,'');
3862 
3863 % to update:
3864 VelType_str=get(hseries.VelTypeMenu,'String');
3865 VelType_val=get(hseries.VelTypeMenu,'Value');
3866 VelType{1}=VelType_str{VelType_val};
3867 if nbview==2
3868     VelType_str=get(hseries.VelTypeMenu_1,'String');
3869     VelType_val=get(hseries.VelTypeMenu_1,'Value');
3870     VelType{2}=VelType_str{VelType_val};
3871 end
3872 
3873 %projection object
3874 test_object=get(hseries.GetObject,'Value');
3875 if test_object%isfield(Series,'sethandles')
3876     Series.ProjObject=read_set_object(Series.sethandles);
3877     answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
3878     if ~isequal(answeryes,'Yes')
3879         return
3880     end
3881 else
3882     warndlg_uvmat('a projection object is needed','ERROR');
3883     return
3884 end
3885 
3886 %LOOP ON SLICES
3887 for i_slice=1:NbSlice
3888     %name of result file
3889     [filemean,idetect]=...
3890                name_generator(filebase_out,num_i1{1}(1,i_slice),num_j1{1}(1,1),'.nc','_i1-i2_j1-j2',1,num_i2{end}(end,end),num_j2{end}(end,end),SubDir{1});
3891      dt=[];
3892      nbmissing=0; %number of undetected files
3893      nbfiles=0;
3894     %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN  A SLICE
3895     for ifile=i_slice:NbSlice:nbfield  
3896         stopstate=get(hseries.RUN,'BusyAction');
3897         if isequal(stopstate,'queue')% enable STOP command
3898              update_waitbar(hseries.waitbar,WaitbarPos,(ifile+(i_slice-1)*nbfield)/(nbfield*NbSlice)) 
3899              for iview=1:nbview
3900                 [filename,idetect(iview)]=...
3901                            name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 
3902                 Data{iview}=[]; %default
3903                 if testima                  
3904                     Data{iview}.ListVarName={'A'};
3905                     Data{iview}.AName='image';
3906                     if test_movie(iview)
3907                         Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
3908                     else
3909                         Data{iview}.A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files
3910                     end
3911                     npy=size(Data{iview}.A,1);
3912                     npx=size(Data{iview}.A,2);
3913                     nbcolor=size(Data{iview}.A,3);
3914                     if nbcolor==3
3915                         Data{iview}.ListDimName={'coord_y','coord_x','rgb'};
3916                         Data{iview}.DimValue=[npy npx 3];
3917                         Data{iview}.VarDimIndex={[1 2 3]};
3918                     else
3919                         Data{iview}.ListDimName={'coord_y','coord_x'};  
3920                         Data{iview}.DimValue=[npy npx];
3921                         Data{iview}.VarDimIndex={[1 2]};
3922                         Data{iview}.VarAttribute{1}.Coord_1=[npy-0.5 0.5];
3923                         Data{iview}.VarAttribute{1}.Coord_2=[0.5 npx-0.5];
3924                     end   
3925                     Data{iview}.CoordType='px';
3926                 elseif testcivx
3927                     [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
3928                 else
3929                     [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
3930                     Data{iview}.VarAttribute=SubField.VarAttribute;
3931                 end
3932             end
3933             if ~isequal(Series.CoordType,'')
3934                 if nbview==2
3935                     [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
3936                     if isempty(Data{2})
3937                         Data(2)=[];
3938                     end
3939                 else
3940                     Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
3941                 end
3942             end
3943             if testcivx
3944                     Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
3945             end
3946             if length(Data)==2
3947                %substract the two fields   %TODO: adapt SubField to take difference in case of two input file series, take .Time as average time
3948             end
3949             if isfield(Series,'ProjObject')
3950                 Data{1}=proj_field(Data{1},Series.ProjObject);
3951                 if isfield(Data{1},'Txt')
3952                     msgbox_uvmat('ERROR',Data{1}.Txt)
3953                     return
3954                 end
3955             end
3956             if min(idetect)==1% the input file(s) have been detected
3957                 Field=Data{1};
3958                 nbfiles=nbfiles+1;
3959                 if nbfiles==1 %first field: initiate the time series
3960                     RecordData=Field;%default
3961                     RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots
3962                     nbvar=length(Field.ListVarName);
3963                     if nbvar==0
3964                         msgbox_uvmat('ERROR','no input variable selected in get_field')
3965                         return
3966                     end
3967                     testsum=2*ones(1,nbvar);%initiate flag for action on each variable
3968                     indexfalse=0;
3969                     CoordName={};
3970                     indexremove=[];
3971                     if isfield(Field,'VarAttribute') % look for coordinate and flag variables
3972                         for ivar=1:nbvar
3973                             if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
3974                                 var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
3975                                 if isequal(var_role,'errorflag')
3976                                     msgdlg_uvmat('ERROR','do not handle error flags in time series')
3977                                     return                                               
3978                                 end
3979                                 if isequal(var_role,'warnflag')                        
3980                                     testsum(ivar)=0;  % not recorded variable
3981                                     eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable
3982                                 end                  
3983                                 if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
3984                                     isequal(var_role,'coord_z')|isequal(var_role,'coord')
3985                                     testsum(ivar)=1; %constant coordinates, record without time evolution
3986                                 end
3987                                 % check whether the variable ivar is a dimension variable
3988                                 index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
3989                                 if length(Field.ListDimName)>=index & isequal(Field.ListVarName{ivar},Field.ListDimName{index})%detect dimension variables
3990                                    testsum(ivar)=1;
3991                                 end
3992                             end
3993                         end
3994                     end
3995                     for ivar=1:nbvar
3996                         if testsum(ivar)==2                     
3997                             eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
3998                         end
3999                     end
4000                     RecordData.ListDimName=[{'Time'} RecordData.ListDimName];%name of dimension
4001                     RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
4002                 end
4003                 for ivar=1:length(Field.ListVarName)
4004                     VarName=Field.ListVarName{ivar};
4005                     eval(['VarVal=Field.' VarName ';']);
4006                     if testsum(ivar)==2% test for recorded variable
4007                         eval(['VarVal=Field.' VarName ';']);
4008                         if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
4009                             if isempty(VarVal)
4010                                 msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
4011                                 return                             
4012                             end
4013                             VarVal=mean(VarVal,1);
4014                             dimindex=Field.VarDimIndex{ivar};
4015                             RecordData.DimValue(dimindex(1))=1;% declare corresponding dimension to 1
4016                         end
4017                         VarVal=shiftdim(VarVal,-1); %shift dimension
4018                         eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series
4019                     elseif testsum(ivar)==1% variable representing fixed coordinates
4020                         eval(['VarInit=RecordData.' VarName ';']);
4021                         if ~isequal(VarVal,VarInit)
4022                             warndlg_uvmat(['time series requires constant coordinates ' VarName],'ERROR')
4023                             return
4024                         end
4025                     end                 
4026                 end
4027                 % time:
4028                 if isempty(time)% time read in ncfiles
4029                    if isfield(Field,'Time')
4030                        RecordData.Time(nbfiles,1)=Field.Time;
4031                    else
4032                        RecordData.Time(nbfiles,1)=nbfiles;%default
4033                    end
4034                 else % time from ImaDoc prevails
4035                     RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
4036                 end
4037             else
4038                 nbmissing=nbmissing+1;
4039             end
4040         end
4041     end
4042     %remove time for global attributes if exists
4043     for iattr=1:numel(RecordData.ListGlobalAttribute) 
4044         if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
4045             RecordData.ListGlobalAttribute(iattr)=[];
4046             break
4047         end
4048     end
4049         % add time dimension and update VarDimIndex:
4050    %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
4051         for ivar=1:length(Field.VarDimIndex)
4052              vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar)
4053              if testsum(ivar)==2%variable used as time series
4054                  RecordData.VarDimIndex{ivar}=[1 vardimindex+1];
4055              elseif testsum(ivar)==1
4056                  RecordData.VarDimIndex{ivar}=[vardimindex+1];
4057              end
4058         end
4059    % end
4060     indexremove=find(~testsum);
4061     if ~isempty(indexremove)
4062         RecordData.ListVarName(1+indexremove)=[];
4063         RecordData.VarDimIndex(indexremove)=[];
4064         if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
4065             RecordData.Role(1+indexremove)=[];
4066         end
4067     end
4068     RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension
4069     %shift variable attributes
4070     if isfield(RecordData,'VarAttribute')
4071         RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
4072     end 
4073     RecordData.DimValue=[length(RecordData.Time) RecordData.DimValue];%values of dimension (nbre of vectors)
4074     RecordData.Action=Series.Action;%name of the processing programme
4075     errormsg=struct2nc(filemean,RecordData); %save result file
4076     if isempty(errormsg)
4077         display([filemean ' written'])
4078     else
4079         msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg])
4080     end
4081 end
4082 figure
4083 haxes=axes;
4084 
4085 plot_field(RecordData,haxes)
4086 hget_field=findobj(allchild(0),'name','get_field');
4087 if ~isempty(hget_field)
4088     delete(hget_field)
4089 end
4090 get_field(filemean,RecordData)
4091     
4092 %-----------------------------------------------------------------------
4093 % --- Executes on selection change in CoordType.
4094 function CoordType_Callback(hObject, eventdata, handles)
4095 menu_str=get(handles.CoordType,'String');
4096 ind_coord=get(handles.CoordType,'Value');
4097 coord_option=menu_str{ind_coord};
4098 if isequal(coord_option,'more...'); 
4099     fct_name='';
4100     if exist('./TMP/current_usr_fct.mat','file')% if a file is found
4101         h=load('./TMP/current_usr_fct.mat');
4102         if isfield(h,'fct_name'); 
4103             fct_name=h.fct_name;
4104         end
4105     end
4106     prompt = {'Enter the name of the transform function'};
4107     dlg_title = 'user defined transform';
4108     num_lines= 1;
4109     [FileName, PathName, filterindex] = uigetfile( ...
4110        {'*.m', ' (*.m)';
4111         '*.m',  '.m files '; ...
4112         '*.*', 'All Files (*.*)'}, ...
4113         'Pick a file', fct_name);
4114     fct_name=fullfile(PathName,FileName);
4115     addpath(PathName);%add the path to the selected fct
4116     [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
4117     if ~exist(fct_name,'file')
4118            warndlg(['image procesing fct ' fct_name ' not found'])
4119     else
4120         transform=FileName(1:end-2);%
4121         update_menu(handles.CoordType,transform)%add the selected fct to the menu
4122   %      set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu
4123       %save ('./TMP/current_usr_fct.mat','fct_name');
4124     end   
4125 end
4126 ind_coord=get(handles.CoordType,'Value');   
4127 
4128 %---------------------------------------------------------------------
4129 % --- Executes on selection change in ProjObject.
4130 function ProjObject_Callback(hObject, eventdata, handles)
4131 
4132 list_object=get(handles.ProjObject,'String');
4133 index=get(handles.ProjObject,'Value');
4134 hseries=get(handles.ProjObject,'Parent');
4135 SeriesData=get(hseries,'UserData');
4136 Obj=SeriesData.ProjObject{index};
4137 [SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index});
4138 set(hseries,'UserData',SeriesData);
4139 
4140 %-------------------------------------------------------------
4141 %generates a series of file names with reference numbers between range1 and
4142 %range2 with increment incr. The reference number num_ref is the image number at the middle of the
4143 %image pair. The set of first numbers num1 of the image pairs is also
4144 %given as output
4145 %------------------------------------------------------
4146 function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j)
4147 [Path,Name]=fileparts(filebase);
4148 filebasesub=fullfile(Path,subdir,Name);
4149 filecell={};%default
4150 num_i1=[];
4151 num_i2=[];
4152 num_j1=[];
4153 num_j2=[];
4154 ind0_i=first_i:incr_i:last_i;
4155 nbcolumn=length(ind0_i);
4156 ind0_j=first_j:incr_j:last_j;
4157 nbline=length(ind0_j);
4158 if isequal(mode,'#_ab')
4159     dirpair=dir([filebasesub '*_*.nc']);
4160 elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)')  
4161     dirpair=dir([filebasesub '_*_*-*.nc']);
4162 elseif isequal(mode,'series(Di)')
4163     dirpair=dir([filebasesub '_*-*_*.nc']);
4164 else
4165     errordlg('option *|* not yet implemented')
4166     return
4167 end
4168 if isempty(dirpair)
4169         errordlg('no pair detected in the selected range')
4170         return
4171 end
4172     %ind0_i=first_i:incr_i:last_i;
4173     %nbcolumn=length(ind0_i);
4174     %dirpair=dir([filebasesub '_*_*-*.nc']);
4175 if isequal(mode,'bursts')|isequal(mode,'#_ab')
4176     icount=0;
4177     for ifile=1:length(dirpair)
4178         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
4179         
4180 %         if isempty(str2num(str_1))
4181 %             dirpair(ifile).name
4182 %         end
4183         num1_r=str2num(str_1);
4184         if isequal(RootFile,Name) & ~isempty(num1_r)   
4185             num_i1(ifile)=num1_r;
4186             num_a(ifile)=stra2num(str_a);
4187             num_b(ifile)=stra2num(str_b);
4188 %             icount=icount+1;
4189         end      
4190     end
4191     length(dirpair)
4192 %     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
4193     test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
4194     ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
4195     select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
4196     ind_i=ind_i(select);%set of selected indices ind_i
4197     [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
4198     select=select(indsort);
4199     num_i1=num_i1(select);
4200     num_a=num_a(select);
4201     num_b=num_b(select);
4202     dirpair=dirpair(select);
4203     [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn); 
4204     ind_i(ind_remove)=[];
4205     num_a(ind_remove)=[];
4206     num_b(ind_remove)=[];
4207     num_j1=zeros(1,nbcolumn);%default
4208     num_j2=num_j1;
4209     num_j1(ind_i)=num_a;
4210     num_j2(ind_i)=num_b;
4211     num_i1=first_i:incr_i:last_i;
4212     num_i2=num_i1;
4213     nbmissing=nbcolumn-length(ind_i);
4214 
4215 elseif isequal(mode,'series(Di)') 
4216     %ind0_i=first_i:incr_i:last_i;
4217     %nbcolumn=length(ind0_i);
4218     %ind0_j=first_j:incr_j:last_j;
4219     %nbline=length(ind0_j);
4220     %dirpair=dir([filebasesub '_*-*_*.nc']);
4221     for ifile=1:length(dirpair)
4222         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
4223         num_i1_r(ifile)=str2num(str_1);
4224         num_i2_r(ifile)=str2num(str_2);
4225         num_j(ifile)=str2num(str_a);
4226     end
4227     num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
4228     test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
4229     ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
4230     ind_j=((num_j-first_j)/incr_j)+1;
4231     ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
4232     select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
4233     ind_ij=ind_ij(select);%set of selected indices ind_ij
4234     [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
4235     select=select(indsort);
4236     num_i1_r=num_i1_r(select);
4237     num_i2_r=num_i2_r(select);
4238 %     num_j=num_j(select);
4239     dirpair=dirpair(select);
4240     [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
4241     ind_ij(ind_remove)=[];
4242     num_i1_r(ind_remove)=[];
4243     num_i2_r(ind_remove)=[];
4244     num_i1=zeros(1,nbline*nbcolumn);%default
4245     num_i2=num_i1;
4246     num_i1(ind_ij)=num_i1_r;
4247     num_j2(ind_ij)=num_i2_r;
4248     num_i1=reshape(num_i1,nbline,nbcolumn);
4249     num_i2=reshape(num_i2,nbline,nbcolumn);
4250     num_j1=meshgrid(ind0_i,ind0_j);
4251     num_j2=num_j1;
4252     nbmissing=nbline*nbcolumn-length(ind_ij);
4253 elseif isequal(mode,'series(Dj)')
4254  %   ind0_i=first_i:incr_i:last_i;
4255  %   nbcolumn=length(ind0_i);
4256  %   ind0_j=first_j:incr_j:last_j;
4257   %  nbline=length(ind0_j);
4258   %  dirpair=dir([filebasesub '_*_*-*.nc']);
4259     for ifile=1:length(dirpair)
4260         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
4261         num_i(ifile)=str2num(str_1);
4262         num_a(ifile)=str2num(str_a);
4263         num_b(ifile)=str2num(str_b);
4264     end
4265     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
4266     test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
4267     ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
4268     ind_j=((num_j-first_j)/incr_j)+1;
4269     ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
4270     select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
4271     ind_ij=ind_ij(select);%set of selected indices ind_ij
4272     [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
4273     select=select(indsort);
4274     num_i=num_i(select);
4275     num_a=num_a(select);
4276     num_b=num_b(select);
4277     dirpair=dirpair(select);
4278     [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
4279     ind_ij(ind_remove)=[];
4280     num_a(ind_remove)=[];
4281     num_b(ind_remove)=[];
4282     num_j1=zeros(1,nbline*nbcolumn);%default
4283     num_j2=num_j1;
4284     num_j1(ind_ij)=num_a;
4285     num_j2(ind_ij)=num_b;
4286     num_j1=reshape(num_j1,nbline,nbcolumn);
4287     num_j2=reshape(num_j2,nbline,nbcolumn);
4288     num_i1=meshgrid(ind0_i,ind0_j);
4289     num_i2=num_i1;
4290     nbmissing=nbline*nbcolumn-length(ind_ij);
4291 %     for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT
4292 %         if indsel(i)==0
4293 %             filecell{i}='';
4294 %         else
4295 %             Name=dirpair(indsel(i)).name;
4296 %             filecell{i}=fullfile(Path,subdir,Name);
4297 %         end
4298 %     end
4299 %else
4300 %    errordlg('option *|* not yet implemented')
4301 %    return
4302 end
4303 
4304 %%%%%%%%%%%%%
4305 function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
4306 
4307         indsel=ind_i;
4308         indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
4309         indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
4310         if ~isempty(indiff)
4311             indiff2=diff(indiff);
4312             indiffp=[indiff2 1]; 
4313             indiffm=[1 indiff2];
4314             ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
4315             ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
4316                 %for each multiplet, select the most recent file
4317             ind_remove=[];
4318             for i=1:length(ind_multi_m)
4319                 ind_pairs=ind_multi_m(i):ind_multi_p(i);
4320                 for imulti=1:length(ind_pairs) 
4321                     datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
4322                 end
4323                 [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
4324                 ind_s=indsort2(1:end-1);%
4325                 ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
4326             end
4327         end
4328 
4329 %--------------------------------------------------------
4330 
4331  
4332 %-----------------------------------------------------------
4333 % find the times corresponding to the first and last indices of a series
4334 %
4335 function displ_time(handles,times)
4336 hseries=get(handles.last_i,'parent');
4337 SeriesData=get(hseries,'UserData');%
4338 first_i=str2num(get(handles.first_i,'String'));
4339 first_j=str2num(get(handles.first_j,'String'));
4340 last_i=str2num(get(handles.last_i,'String'));
4341 last_j=str2num(get(handles.last_j,'String'));
4342 % index_civ=get(handles.list_pair_civ,'Value');
4343 % NomType=get(handles.NomType,'String');
4344 NomType=SeriesData.NomType;
4345 mode_list=get(handles.mode,'String');
4346 index_mode=get(handles.mode,'Value');
4347 mode=mode_list{index_mode};
4348 % ind_shift=0;%default
4349 
4350 time_first=[];
4351 time_last=[];
4352 if ~isfield(SeriesData,'Time')
4353     SeriesData.Time{1}=[];
4354 end
4355 for iview=1:length(NomType)
4356     time_first_cell{iview}='?';
4357     time_last_cell{iview}='?';%default
4358     time=SeriesData.Time{iview};
4359     if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
4360         if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
4361             ind_shift=SeriesData.displ_num(iview,:);
4362             if isequal(mode,'bursts')
4363                 first_j=0;
4364                 last_j=0;
4365             end
4366             first_i1=first_i +ind_shift(3);
4367             first_i2 =first_i +ind_shift(4);
4368             first_j1 =first_j +ind_shift(1);
4369             first_j2 =first_j +ind_shift(2);
4370             last_i1=last_i +ind_shift(3);
4371             last_i2 =last_i +ind_shift(4);    
4372             last_j1 =last_j +ind_shift(1);
4373             last_j2 =last_j +ind_shift(2);
4374             siz=size(SeriesData.Time{1});
4375             if siz(1)>=last_i2 & siz(2)>=last_j2
4376                 time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
4377                 time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
4378             else%read the time in the nc files
4379                 RootPath=get(handles.RootPath,'String');
4380                 RootFile=get(handles.RootFile,'String');
4381                 SubDir=get(handles.SubDir,'String');
4382                 %VelType=get(handles.VelType,'String');
4383                 VelType_str=get(handles.VelTypeMenu,'String');
4384                 VelType_val=get(handles.VelTypeMenu,'Value');
4385                 VelType=VelType_str{VelType_val};
4386                 filebase=fullfile(RootPath{1},RootFile{1});
4387                 [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
4388                 if  exist(filefirst,'file')
4389                     Attrib=nc2struct(filefirst,[]);
4390                     if isfield(Attrib,'Time')
4391                         time_first=Attrib.Time;
4392                     else
4393                         if isfield(Attrib,'absolut_time_T0')
4394                             time_first=Attrib.absolut_time_T0;
4395                         end
4396                         if isfield(Attrib,'absolut_time_T0_2')&~(isequal(VelType,'civ1')|isequal(VelType,'interp1')|isequal(VelType,'filter1'))
4397                             time_first=Attrib.absolut_time_T0_2;
4398                         end
4399                     end 
4400                 end
4401                 [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
4402                 if exist(filelast,'file')
4403                    Attrib=nc2struct(filelast,[]);
4404                     if isfield(Attrib,'Time')
4405                         time_last=Attrib.Time;
4406                     else
4407                         if isfield(Attrib,'absolut_time_T0')
4408                             time_last=Attrib.absolut_time_T0;
4409                         end
4410                         if isfield(Attrib,'absolut_time_T0_2')&~(isequal(VelType,'civ1')|isequal(VelType,'interp1')|isequal(VelType,'filter1'))
4411                             time_last=Attrib.absolut_time_T0_2;
4412                         end
4413                     end 
4414                 end
4415             end
4416         end
4417     else
4418         siz=size(times);
4419         if siz(1)>=last_i & siz(2)>=last_j
4420             time_first=times(first_i,first_j);
4421             time_last=times(last_i,last_j); 
4422         end
4423     end
4424     time_first_cell{iview}=num2str(time_first,4);
4425     time_last_cell{iview}=num2str(time_last,4);
4426 end
4427 set(handles.time_first,'Value',1)
4428 set(handles.time_last,'Value',1)
4429 set(handles.time_first,'String',time_first_cell);
4430 set(handles.time_last,'String',time_last_cell);
4431 
4432 %--------------------------------------------------------------------
4433 % --- Executes on selection change in VelTypeMenu.
4434 function VelTypeMenu_Callback(hObject, eventdata, handles)
4435 % VelTypeList=get(handles.VelTypeMenu,'String');
4436 % VelTypeIndex=get(handles.VelTypeMenu,'Value');
4437 % VelTypeCell=get(handles.VelType,'String');
4438 % VelTypeCell{1}=VelTypeList{VelTypeIndex};
4439 % set(handles.VelType,'String',VelTypeCell)
4440 
4441 
4442 %--------------------------------------------------------------------
4443 % --- Executes on button press in GetObject.
4444 function GetObject_Callback(hObject, eventdata, handles)
4445 hseries=get(handles.GetObject,'parent');
4446 SeriesData=get(hseries,'UserData');
4447 value=get(handles.GetObject,'Value');
4448 if value
4449      set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
4450      DataInit.ParentButton=handles.GetObject;
4451      hset_object=findobj(allchild(0),'Name','set_object');%find the set_object interface handle
4452      if ishandle(hset_object)
4453          [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
4454      else
4455          DataInit.TITLE='POINTS';%default option
4456          [SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
4457      end 
4458 else
4459     set(handles.GetObject,'BackgroundColor',[0 1 0])%put activated buttons to green
4460     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
4461         close(SeriesData.hset_object)
4462     end
4463 end
4464 set(hseries,'UserData',SeriesData)
4465 
4466 %--------------------------------------------------------------
4467 function GetMask_Callback(hObject, eventdata, handles)
4468 value=get(handles.GetMask,'Value');
4469 if value
4470     errordlg('not implemented yet')
4471 end
4472 %--------------------------------------------------------------
4473 
4474 %--------------------------------------------------------------------------
4475 %'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
4476 function ncbrowser_uvmat(hObject, eventdata)
4477      bla=get(gcbo,'String');
4478      ind=get(gcbo,'Value');
4479      filename=cell2mat(bla(ind));
4480       blank=find(filename==' ');
4481       filename=filename(1:blank-1);
4482      get_field(filename)
4483 
4484 
4485 
4486 % --------------------------------------------------------------------
4487 function MenuHelp_Callback(hObject, eventdata, handles)
4488 
4489 path_to_uvmat=which ('uvmat');% check the path of uvmat
4490 pathelp=fileparts(path_to_uvmat);
4491 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
4492 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the  directory UVMAT/UVMAT_DOC')
4493 else
4494 web([helpfile '#series'])    
4495 end
4496 
4497 
4498 
4499 
4500 
4501

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003