source: trunk/src/series.m @ 246

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

thin plate shell (patch) introduced

File size: 91.8 KB
Line 
1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
8%      .menu_coord_str: string for the transform_fct (menu for coordinate transforms)
9%      .menu_coord_val: value for transform_fct (menu for coordinate transforms)
10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
32function varargout = series(varargin)
33
34% Begin initialization code - DO NOT EDIT
35gui_Singleton = 1;
36gui_State = struct('gui_Name',       mfilename, ...
37                   'gui_Singleton',  gui_Singleton, ...
38                   'gui_OpeningFcn', @series_OpeningFcn, ...
39                   'gui_OutputFcn',  @series_OutputFcn, ...
40                   'gui_LayoutFcn',  [] , ...
41                   'gui_Callback',   []);
42if nargin && ischar(varargin{1})
43    gui_State.gui_Callback = str2func(varargin{1});
44end
45
46if nargout
47    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
48else
49    gui_mainfcn(gui_State, varargin{:});
50end
51% End initialization code - DO NOT EDIT
52
53%--------------------------------------------------------------------------
54% --- Executes just before series is made visible.
55%--------------------------------------------------------------------------
56function series_OpeningFcn(hObject, eventdata, handles,param)
57global nb_builtin_ACTION nb_builtin_transform
58% Choose default command line output for series
59handles.output = hObject;
60% Update handles structure
61guidata(hObject, handles);
62%default initial parameters
63drawnow
64set(hObject,'Units','pixels')
65% set(0,'Units','pixels')
66% screensize=get(0,'ScreenSize'); %screen size in pixels
67set(hObject,'Position',[150 100 1000 600] );%position and size in pixels (get adjusted to the screen size in case of excess)
68%load the list of previously browsed files in menus Open and Open_1
69dir_perso=prefdir;
70test_profil_perso=0;
71profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
72if exist(profil_perso,'file')
73     h=load (profil_perso);
74     test_profil_perso=1;
75     if isfield(h,'MenuFile_1')
76          set(handles.MenuFile_1,'Label',h.MenuFile_1);
77          set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
78     end
79     if isfield(h,'MenuFile_1')
80          set(handles.MenuFile_2,'Label',h.MenuFile_2);
81          set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
82     end
83     if isfield(h,'MenuFile_1')
84          set(handles.MenuFile_3,'Label',h.MenuFile_3);
85          set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
86     end
87     if isfield(h,'MenuFile_1')
88          set(handles.MenuFile_4,'Label',h.MenuFile_4);
89          set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
90     end
91     if isfield(h,'MenuFile_1')
92          set(handles.MenuFile_5,'Label',h.MenuFile_5);
93          set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
94     end
95end
96
97%check default input data
98if ~exist('param','var')
99    param=[]; %default
100end
101
102%file name and browser initialisation
103if isfield(param,'menu_coord_str')
104    set(handles.transform_fct,'String',param.menu_coord_str)
105end
106if isfield(param,'menu_coord_val')
107    set(handles.transform_fct,'Value',param.menu_coord_val);
108else
109     set(handles.transform_fct,'Value',1);%default
110end
111
112if isfield(param,'FileName')
113    if isfield(param,'FileName_1')
114        update_file(hObject, eventdata, handles,param.FileName_1,0)
115        update_file(hObject, eventdata, handles,param.FileName,1)
116    else
117        update_file(hObject, eventdata, handles,param.FileName,0)
118    end
119end 
120
121%fields input initialisation
122if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
123    set(handles.FieldMenu,'String',param.list_fields);% list menu fields
124    set(handles.FieldMenu,'Value',param.index_fields);% selected string index
125    FieldCell{1}=param.list_fields{param.index_fields};
126end
127% if isfield(param,'velTypeMenu')&&isfield(param,'velTypeIndex')
128%     set(handles.VelTypeMenu,'Value',param.VelTypeIndex)
129%     set(handles.VelTypeMenu,'String',param.VelTypeMenu)
130% end 
131set(hObject,'WindowButtonUpFcn',{'mouse_up_gui',handles})
132NomType_Callback(hObject, eventdata, handles)
133
134%loads the information stored in prefdir to initiate  the list of ACTION functions
135fct_menu={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
136transform_menu={'';'phys';'px';'phys_polar'};
137nb_builtin_ACTION=numel(fct_menu); %number of functions
138nb_transform=numel(transform_menu);
139[path_series,name,ext]=fileparts(which('series'));
140path_series=fullfile(path_series,'series');%path of the function 'series'
141path_transform=fullfile(path_series,'transform_field');%path of the field transform functions
142for ilist=1:length(fct_menu)
143    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
144end
145
146%TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
147menu_str={'';'phys';'px';'phys_polar'};
148nb_builtin_transform=numel(menu_str); %number of functions
149[path_uvmat,name,ext]=fileparts(which('uvmat'));
150addpath(fullfile(path_uvmat,'transform_field'))
151fct_handle{1,1}=[];
152testexist(1)=1;
153for ilist=2:length(menu_str)
154    if exist(menu_str{ilist},'file')
155        fct_handle{ilist,1}=str2func(menu_str{ilist});
156        testexist(ilist)=1;
157    else
158        testexist(ilist)=0;
159    end
160end
161rmpath(fullfile(path_uvmat,'transform_field'))
162
163% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
164if test_profil_perso
165    if isfield(h,'series_fct') && iscell(h.series_fct)
166         for ilist=1:length(h.series_fct)
167             [path,file]=fileparts(h.series_fct{ilist});
168             fct_path=[fct_path; {path}];%concatene the list of paths
169             fct_menu=[fct_menu; {file}];
170         end
171    end
172    if isfield(h,'transform_fct') && iscell(h.transform_fct)
173        for ilist=1:length(h.transform_fct);
174             [path,file]=fileparts(h.transform_fct{ilist});
175             addpath(path)
176             if exist(file,'file')
177                h_func=str2func(file);
178                testexist=[testexist 1];
179             else
180                h_func=[];
181                testexist=[testexist 0];
182             end
183             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
184             rmpath(path)
185             menu_str=[menu_str; {file}];
186        end
187    end
188end
189fct_menu=[fct_menu;{'more...'}];
190set(handles.ACTION,'String',fct_menu)
191set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
192
193menu_str=menu_str(find(testexist));
194fct_handle=fct_handle(find(testexist));
195menu_str=[menu_str;{'more...'}];
196set(handles.transform_fct,'String',menu_str)
197set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
198
199% display the GUI for the default action 'check_files'
200ACTION_Callback(hObject, eventdata, handles)
201
202%--------------------------------------------------------------
203% --- Outputs from this function are returned to the command line.
204%-----------------------------------------------------------------
205function varargout = series_OutputFcn(hObject, eventdata, handles)
206% varargout  cell array for returning output args (see VARARGOUT);
207% hObject    handle to figure
208% eventdata  reserved - to be defined in a future version of MATLAB
209% handles    structure with handles and user data (see GUIDATA)
210% Get default command line output from handles structure
211varargout{1} = handles.output;
212
213
214% --------------------------------------------------------------------
215function MenuBrowse_Callback(hObject, eventdata, handles)
216
217RootPathCell=get(handles.RootPath,'String');
218SubDirCell=get(handles.SubDir,'String'); 
219RootFileCell=get(handles.RootFile,'String');
220oldfile=''; %default
221if isempty(RootPathCell)|isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
222     dir_perso=prefdir;
223     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
224     if exist(profil_perso,'file')
225          h=load (profil_perso);
226         if isfield(h,'filebase')&ischar(h.filebase)
227                 oldfile=h.filebase;
228         end
229         if isfield(h,'RootPath')&ischar(h.RootPath)
230                 oldfile=h.RootPath;
231         end
232     end
233 else
234     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
235 end
236[FileName, PathName, filterindex] = uigetfile( ...
237       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
238       '*.xml',  '.xml files '; ...
239        '*.xls',  '.xls files '; ...
240        '*.png','.png image files'; ...
241        '*.tif','.tif image files'; ...
242        '*.avi;*.AVI','.avi movie files'; ...
243        '*.nc','.netcdf files'; ...
244        '*.*',  'All Files (*.*)'}, ...
245        'Pick a file',oldfile);
246fileinput=[PathName FileName];%complete file name
247%testblank=findstr(fileinput,' ');%look for blanks
248% if ~isempty(testblank)
249%     errordlg('forbidden input file name: contain blanks')
250%     return
251% end
252sizf=size(fileinput);
253if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
254[path,name,ext]=fileparts(fileinput);
255SeriesData=[];%dfault
256if isequal(ext,'.xml')
257    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
258elseif isequal(ext,'.xls')
259    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
260else
261    update_file(hObject, eventdata, handles,fileinput,0)
262     %update list of recent files in the menubar
263    MenuFile_1=fileinput;
264    MenuFile_2=get(handles.MenuFile_1,'Label');
265    MenuFile_3=get(handles.MenuFile_2,'Label');
266    MenuFile_4=get(handles.MenuFile_3,'Label');
267    MenuFile_5=get(handles.MenuFile_4,'Label');
268    set(handles.MenuFile_1,'Label',MenuFile_1)
269    set(handles.MenuFile_2,'Label',MenuFile_2)
270    set(handles.MenuFile_3,'Label',MenuFile_3)
271    set(handles.MenuFile_4,'Label',MenuFile_4)
272    set(handles.MenuFile_5,'Label',MenuFile_5)
273    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
274    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
275    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
276    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
277    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
278    dir_perso=prefdir;
279    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
280    if exist(profil_perso,'file')
281        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
282    else
283    txt=ver('MATLAB');
284    Release=txt.Release;
285        relnumb=str2num(Release(3:4));
286        if relnumb >= 14
287            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
288        else
289            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
290        end
291    end
292end
293
294
295% --------------------------------------------------------------------
296function MenuFile_1_Callback(hObject, eventdata, handles)
297fileinput=get(handles.MenuFile_1,'Label');
298update_file(hObject, eventdata, handles,fileinput,0)
299
300% --------------------------------------------------------------------
301function MenuFile_2_Callback(hObject, eventdata, handles)
302fileinput=get(handles.MenuFile_2,'Label');
303update_file(hObject, eventdata, handles,fileinput,0)
304
305% --------------------------------------------------------------------
306function MenuFile_3_Callback(hObject, eventdata, handles)
307fileinput=get(handles.MenuFile_3,'Label');
308update_file(hObject, eventdata, handles,fileinput,0)
309
310% --------------------------------------------------------------------
311function MenuFile_4_Callback(hObject, eventdata, handles)
312fileinput=get(handles.MenuFile_4,'Label');
313update_file(hObject, eventdata, handles,fileinput,0)
314
315% --------------------------------------------------------------------
316function MenuFile_5_Callback(hObject, eventdata, handles)
317fileinput=get(handles.MenuFile_5,'Label');
318update_file(hObject, eventdata, handles,fileinput,0)
319
320% --------------------------------------------------------------------
321function MenuBrowse_insert_Callback(hObject, eventdata, handles)
322
323RootPathCell=get(handles.RootPath,'String');
324RootFileCell=get(handles.RootFile,'String');
325oldfile=''; %default
326if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
327     dir_perso=prefdir;
328     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
329     if exist(profil_perso,'file')
330          h=load (profil_perso);
331         if isfield(h,'filebase')&ischar(h.filebase)
332                 oldfile=h.filebase;
333         end
334         if isfield(h,'RootPath')&ischar(h.RootPath)
335                 oldfile=h.RootPath;
336         end
337     end
338 else
339     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
340 end
341[FileName, PathName, filterindex] = uigetfile( ...
342       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
343       '*.xml',  '.xml files '; ...
344        '*.xls',  '.xls files '; ...
345        '*.png','.png image files'; ...
346        '*.avi;*.AVI','.avi movie files'; ...
347        '*.nc','.netcdf files'; ...
348        '*.*',  'All Files (*.*)'}, ...
349        'Pick a file',oldfile);
350fileinput=[PathName FileName];%complete file name
351% testblank=findstr(fileinput,' ');%look for blanks
352% if ~isempty(testblank)
353%     errordlg('forbidden input file name: contain blanks')
354%     return
355% end
356sizf=size(fileinput);
357if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
358[path,name,ext]=fileparts(fileinput);
359SeriesData=[];%dfault
360if isequal(ext,'.xml')
361    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
362elseif isequal(ext,'.xls')
363    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
364else
365    update_file(hObject, eventdata, handles,fileinput,1)
366    %update list of recent files in the menubar
367    MenuFile_1=fileinput;
368    MenuFile_2=get(handles.MenuFile_1,'Label');
369    MenuFile_3=get(handles.MenuFile_2,'Label');
370    MenuFile_4=get(handles.MenuFile_3,'Label');
371    MenuFile_5=get(handles.MenuFile_4,'Label');
372    set(handles.MenuFile_1,'Label',MenuFile_1)
373    set(handles.MenuFile_2,'Label',MenuFile_2)
374    set(handles.MenuFile_3,'Label',MenuFile_3)
375    set(handles.MenuFile_4,'Label',MenuFile_4)
376    set(handles.MenuFile_5,'Label',MenuFile_5)
377    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
378    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
379    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
380    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
381    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
382    dir_perso=prefdir;
383    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
384    if exist(profil_perso,'file')
385        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
386    else
387    txt=ver('MATLAB');
388    Release=txt.Release;
389        relnumb=str2num(Release(3:4));
390        if relnumb >= 14
391            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
392        else
393            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
394        end
395    end
396end
397%------------------------------------------------
398
399% --------------------------------------------------------------------
400function MenuFile_insert_1_Callback(hObject, eventdata, handles)
401fileinput=get(handles.MenuFile_insert_1,'Label');
402update_file(hObject, eventdata, handles,fileinput,1)
403
404% --------------------------------------------------------------------
405function MenuFile_insert_2_Callback(hObject, eventdata, handles)
406fileinput=get(handles.MenuFile_insert_2,'Label');
407update_file(hObject, eventdata, handles,fileinput,1)
408
409% --------------------------------------------------------------------
410function MenuFile_insert_3_Callback(hObject, eventdata, handles)
411fileinput=get(handles.MenuFile_insert_3,'Label');
412update_file(hObject, eventdata, handles,fileinput,1)
413
414% --------------------------------------------------------------------
415function MenuFile_insert_4_Callback(hObject, eventdata, handles)
416fileinput=get(handles.MenuFile_insert_4,'Label');
417update_file(hObject, eventdata, handles,fileinput,1)
418
419% --------------------------------------------------------------------
420function MenuFile_insert_5_Callback(hObject, eventdata, handles)
421fileinput=get(handles.MenuFile_insert_5,'Label');
422update_file(hObject, eventdata, handles,fileinput,1)
423
424%------------------------------------------------------------------------
425% ---  refresh the GUI data after introduction of a new file series
426function update_file(hObject, eventdata, handles,fileinput,addtest)
427%------------------------------------------------------------------------ 
428if ~exist(fileinput,'file')
429    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
430    return
431end
432
433% refresh input root name, indices, file extension and nomenclature
434[RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
435
436%check for movie image files
437if ~isempty(FileExt)
438    if ~isempty(imformats(FileExt(2:end)))
439        imainfo=imfinfo(fileinput);
440        if length(imainfo) >1 %case of image with multiple frames
441            NomType='*';
442            [RootPath,RootFile]=fileparts(fileinput);
443        end
444    end
445end
446NcType='none';%default
447if isequal(FileExt,'.nc')
448   Data=nc2struct(fileinput,[]);
449   if isfield(Data,'absolut_time_T0')
450       NcType='civx'; % test for civx velocity fields
451   end
452end
453
454set(handles.RootPath,'Value',1)
455set(handles.SubDir,'Value',1)
456set(handles.RootFile,'Value',1)
457set(handles.NomType,'Value',1)
458set(handles.FileExt,'Value',1)
459set(handles.nb_field,'Value',1)
460set(handles.nb_field2,'Value',1)
461if addtest
462    SeriesData=get(handles.figure1,'UserData');
463    SeriesData.displ_num=[0 0 0 0;SeriesData.displ_num];
464    SeriesData.CurrentInputFile_1=SeriesData.CurrentInputFile;
465    RootPathCell=[{RootPath}; get(handles.RootPath,'String')] ;
466    SubDirCell=[{SubDir}; get(handles.SubDir,'String')];
467    RootFileCell=[{RootFile}; get(handles.RootFile,'String')];
468    NomTypeCell=[{NomType}; SeriesData.NomType];
469    FileExtCell=[{FileExt}; get(handles.FileExt,'String')];
470    NcTypeCell=[{NcType};SeriesData.NcType];
471    set(handles.NomType,'String',[{};get(handles.NomType,'String')])
472else
473    SeriesData=[];%re-initialisation
474    SeriesData.displ_num=[0 0 0 0];
475    RootPathCell={RootPath};
476    SubDirCell={SubDir};
477    RootFileCell={RootFile};   
478    NomTypeCell={NomType};
479    FileExtCell={FileExt};   
480    NcTypeCell={NcType};
481end
482
483SeriesData.NomType=NomTypeCell;
484SeriesData.NcType=NcTypeCell;
485SeriesData.CurrentInputFile=fileinput;
486set(handles.RootPath,'String',RootPathCell);
487set(handles.SubDir,'String',SubDirCell);
488set(handles.RootFile,'String',RootFileCell);
489set(handles.NomType,'String',NomTypeCell);
490set(handles.FileExt,'String',FileExtCell); 
491
492%determine field indices
493ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
494if ~isempty(str2num(field_count))
495    ref_i=str2num(field_count);
496    if ~isempty(str2num(str2))
497        ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
498        SeriesData.browse_Di=str2num(str2)-str2num(field_count);
499    end
500end
501set(handles.ref_i,'String',num2str(ref_i));
502set(handles.first_i,'String',num2str(ref_i));
503set(handles.last_i,'String',num2str(ref_i));
504ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
505if ~isempty(str2num(str_a))
506    ref_j=str2num(str_a);
507    if ~isempty(str2num(str_b))
508        ref_j=floor((str2num(str_a)+str2num(str_b))/2);
509        SeriesData.browse_Dj=str2num(str_b)-str2num(str_a);
510    end         
511end
512set(handles.ref_j,'String',num2str(ref_j));
513set(handles.first_j,'String',num2str(ref_j))
514set(handles.last_j,'String',num2str(ref_j));
515
516%enable other menus and uicontrols
517set(handles.MenuOpen_insert,'Enable','on')
518set(handles.MenuFile_insert_1,'Enable','on')
519set(handles.MenuFile_insert_2,'Enable','on')
520set(handles.MenuFile_insert_3,'Enable','on')
521set(handles.MenuFile_insert_4,'Enable','on')
522set(handles.MenuFile_insert_5,'Enable','on')
523set(handles.RUN, 'Enable','On')
524set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
525set(handles.RootPath,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
526drawnow
527
528TimeUnit=''; %default
529time=[];%default
530GeometryCalib=[];%default
531nb_field=NaN;%default
532nb_field2=NaN;%default
533SeriesData.PathCampaign=get(handles.PathCampaign,'String');
534
535% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
536FileBase=fullfile(RootPath,RootFile);
537
538testima=0; %test for image input
539if isequal(lower(FileExt),'.avi') %.avi file
540    testima=1;
541    info=aviinfo([FileBase FileExt]);
542    time=(0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond)';
543    nb_field=info.NumFrames;
544    nb_field2=1;
545elseif ~isempty(imformats(FileExt(2:end)))
546    testima=1;
547    if isequal(NomType,'*')% multi-frame image
548        imainfo=imfinfo([FileBase FileExt]);     
549        if length(imainfo) >1 %case of image with multiple frames
550            nb_field=length(imainfo);
551            nb_field2=1;
552        end
553    end
554elseif isequal(FileExt,'.vol')
555     testima=1;
556end
557
558% enable field and veltype menus
559testfield=isequal(get(handles.FieldMenu,'enable'),'on');
560testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
561testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
562testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
563testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
564testnc=0;
565testnc_1=0;
566testcivx=0;
567testcivx_1=0;
568if length(FileExtCell)==1 || length(FileExtCell)>2
569    for iview=1:length(FileExtCell)
570        if isequal(FileExtCell{iview},'.nc')
571            testnc=1;
572        end
573        if isequal(NcTypeCell{iview},'civx')
574            testcivx=1;
575        end
576    end
577elseif length(FileExtCell)==2
578    testnc=isequal(FileExtCell{1},'.nc');
579    testnc_1=isequal(FileExtCell{2},'.nc');
580    testcivx=isequal(NcTypeCell{1},'civx');
581    testcivx_1=isequal(NcTypeCell{2},'civx');
582end
583if testfield && testnc
584    view_FieldMenu(handles,'on')
585    if testcivx
586        menustr=get(handles.FieldMenu,'String');
587        if isequal(menustr,{'get_field...'})
588            set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
589        end
590    else
591        set(handles.FieldMenu,'Value',1)
592        set(handles.FieldMenu,'String',{'get_field...'})
593    end
594else
595    view_FieldMenu(handles,'off')
596end
597if testfield_1 && testnc_1
598    view_FieldMenu_1(handles,'on')
599    if testcivx_1
600        menustr=get(handles.FieldMenu_1,'String');
601        if isequal(menustr,{'get_field...'})
602            set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
603        end
604    else
605        set(handles.FieldMenu_1,'Value',1)
606        set(handles.FieldMenu_1,'String',{'get_field...'})
607    end
608else
609    view_FieldMenu_1(handles,'off')
610end
611if testveltype && testcivx
612    set(handles.VelTypeMenu,'Visible','on')
613    set(handles.VelType_text,'Visible','on');
614else
615    set(handles.VelTypeMenu,'Visible','off')
616    set(handles.VelType_text,'Visible','off');
617end
618if testveltype_1 && testcivx_1
619    set(handles.VelTypeMenu_1,'Visible','on')
620    set(handles.VelType_text_1,'Visible','on');
621else
622    set(handles.VelTypeMenu_1,'Visible','off')
623    set(handles.VelType_text_1,'Visible','off');
624end
625if testtransform && (testcivx || testima)
626     view_TRANSFORM(handles,'on')
627else
628    view_TRANSFORM(handles,'off')
629end
630if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
631    msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
632    return
633end 
634
635%%%%%%%%   read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
636      %look for the file existence
637ext_imadoc='';
638if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
639    ext_imadoc=FileExt;
640elseif exist([FileBase '.xml'],'file')
641    ext_imadoc='.xml';
642elseif exist([FileBase '.civ'],'file')
643    ext_imadoc='.civ';
644end
645      %read the ImaDoc file
646XmlData=[];
647NbSlice_calib={};
648if isequal(ext_imadoc,'.xml')
649        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
650        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
651            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
652        end
653        if isfield(XmlData,'Time')
654            time=XmlData.Time;
655        end
656        if isfield(XmlData,'Camera')
657            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
658                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
659                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
660                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
661                end
662            end
663            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
664                TimeUnit=XmlData.Camera.TimeUnit;
665            end
666        end
667        if ~isempty(warntext)
668            msgbox_uvmat('WARNING',warntext)
669        end 
670elseif isequal(ext_imadoc,'.civ')
671    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
672    time=XmlData.Time;
673    if error==2, warntext=['no file ' FileBase '.civ'];
674    elseif error==1, warntext='inconsistent number of fields in the .civ file';
675    end 
676end 
677if addtest
678    SeriesData.Time=[{time} SeriesData.Time];
679else
680   SeriesData.Time={time};
681end
682
683
684% if ~isempty(time)
685%     siztime=size(time);
686%     nb_field=siztime(1);
687%     nb_field2=siztime(2);
688% end   
689set(handles.TimeUnit,'String',TimeUnit)
690%look for max indices
691if ~strcmp(NomType,'*')
692    [num_i1,num_i2,num_j1,num_j2]=find_indexseries(fileinput);
693    nb_field=max(floor((max(num_i1)+max(num_i2))/2));
694    nb_field2=max(floor((max(num_j1)+max(num_j2))/2));
695end
696if isnan(nb_field)
697    nb_field_str='?';
698    nb_field_str2='?';
699else
700    nb_field_str=num2str(nb_field);
701    nb_field_str2=num2str(nb_field2);
702end
703if addtest
704    nb_field_cell=[{nb_field_str} ;get(handles.nb_field,'String')];
705    nb_field2_cell=[{nb_field_str2} ;get(handles.nb_field2,'String')];
706else
707    nb_field_cell={nb_field_str};
708    nb_field2_cell={nb_field_str2};
709end
710set(handles.nb_field,'String',nb_field_cell);
711set(handles.nb_field2,'String',nb_field2_cell);
712set(handles.figure1,'UserData',SeriesData);
713
714%number of slices
715if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
716       siz=size(XmlData.GeometryCalib.SliceCoord);
717       if siz(1)>1
718           NbSlice=siz(1);
719       else
720           NbSlice=1;
721       end
722       set(handles.NbSlice,'String',num2str(NbSlice))
723end
724
725% set menus of index pairs
726NomType_Callback(hObject, eventdata, handles)
727
728%store the root name for future opening of uvmat
729dir_perso=prefdir;
730profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
731if exist(profil_perso,'file')
732    save (profil_perso,'RootPath','SubDir','RootFile','NomType', '-append'); %store the root name for future opening of uvmat
733else
734    txt=ver('MATLAB');
735    Release=txt.Release;
736    relnumb=str2num(Release(3:4));
737    if relnumb >= 14
738        save (profil_perso,'RootPath','SubDir','RootFile','NomType','-V6') %store the root name for future opening of uvmat
739    else
740        save(profil_perso,'RootPath','SubDir','RootFile','NomType')
741    end         
742end
743set(handles.RootPath,'BackgroundColor',[1 1 1])
744set(handles.PathCampaign,'String',SeriesData.PathCampaign)
745last_j_Callback(hObject, eventdata, handles)
746last_i_Callback(hObject, eventdata, handles)
747
748%------------------------------------------------------------
749function RootPath_Callback(hObject, eventdata, handles)
750Val=get(handles.RootPath,'Value');
751synchronise_view(handles,Val)
752NomType_Callback(hObject, eventdata, handles)
753%------------------------------------------------------------
754
755function synchronise_view(handles,Val)
756set(handles.RootPath,'Value',Val)
757set(handles.SubDir,'Value',Val)
758set(handles.RootFile,'Value',Val)
759set(handles.NomType,'Value',Val)
760set(handles.FileExt,'Value',Val)
761set(handles.nb_field,'Value',Val)
762set(handles.nb_field2,'Value',Val)
763set(handles.time_first,'Value',Val)
764set(handles.time_last,'Value',Val)
765
766
767%---------------------------------------------------------
768% Executes on carriage return on the subdir civ1 edit window
769%--------------------------------------------------------
770function SubDir_Callback(hObject, eventdata, handles)
771
772Val=get(handles.SubDir,'Value');
773synchronise_view(handles,Val)
774NomType_Callback(hObject, eventdata, handles)
775
776%--------------------------------------------------------------
777%function activated when a new filebase (image series) is introduced
778%------------------------------------------------------------
779function RootFile_Callback(hObject, eventdata, handles)
780Val=get(handles.RootFile,'Value');
781synchronise_view(handles,Val)
782NomType_Callback(hObject, eventdata, handles)
783
784%--------------------------------------------------------------
785%function activated when a new filebase (image series) is introduced
786%------------------------------------------------------------
787function FileExt_Callback(hObject, eventdata, handles)
788Val=get(handles.FileExt,'Value');
789synchronise_view(handles,Val)
790
791%--------------------------------------------------------------
792%function activated when a new filebase (image series) is introduced
793%------------------------------------------------------------
794function nb_field_Callback(hObject, eventdata, handles)
795Val=get(handles.nb_field,'Value');
796synchronise_view(handles,Val)
797
798%--------------------------------------------------------------
799%function activated when a new filebase (image series) is introduced
800%------------------------------------------------------------
801function nb_field2_Callback(hObject, eventdata, handles)
802Val=get(handles.nb_field2,'Value');
803synchronise_view(handles,Val)
804
805%--------------------------------------------------------------
806%function activated when a new filebase (image series) is introduced
807%------------------------------------------------------------
808function time_first_Callback(hObject, eventdata, handles)
809Val=get(handles.time_first,'Value');
810synchronise_view(handles,Val)
811
812%--------------------------------------------------------------
813%function activated when a new filebase (image series) is introduced
814%------------------------------------------------------------
815function time_last_Callback(hObject, eventdata, handles)
816Val=get(handles.time_last,'Value');
817synchronise_view(handles,Val)
818
819%--------------------------------------------------------------
820%function activated by NomType
821%------------------------------------------------------------
822NomType_Callback(hObject, eventdata, handles)
823
824%------------------------------------------------------------------------
825function NomType_Callback(hObject, eventdata, handles)
826%------------------------------------------------------------------------
827hseries=get(handles.ProjObject,'Parent');
828SeriesData=get(hseries,'UserData');
829if isfield(SeriesData,'NomType')
830    NomTypeCell=SeriesData.NomType;
831else
832    NomTypeCell={};
833end
834nbfield2_cell=get(handles.nb_field2,'String');
835val=get(handles.nb_field2,'Value');
836if iscell(nbfield2_cell)
837    nbfield2=str2num(nbfield2_cell{val});
838else
839    nbfield2=str2num(nbfield2_cell);
840end
841nbfield_cell=get(handles.nb_field,'String');
842if iscell(nbfield_cell)
843    nbfield=str2num(nbfield_cell{val});
844else
845   nbfield=str2num(nbfield_cell);
846end
847
848set(handles.mode,'Visible','off') % do not show index pairs by default
849set(handles.list_pair_civ,'Visible','off')
850set(handles.ref_i,'Visible','off')
851set(handles.ref_i_text,'Visible','off')
852testpair=0;
853state_j='off';
854%set the menus of image pairs and default selection for series
855%list pairs if relevant
856Val=get(handles.NomType,'Value');
857synchronise_view(handles,Val)
858if ~isempty(NomTypeCell)
859    NomType=NomTypeCell{Val};
860    switch NomType 
861            case {'_i1-i2_j', '_i1-i2'}
862                set(handles.mode,'String',{'series(Di)'})
863                set(handles.mode,'Value',1);
864                set(handles.mode,'Visible','on')
865                testpair=1;
866            case {'#_ab'}
867                set(handles.mode,'String',{'bursts'})
868                set(handles.mode,'Value',1);
869                testpair=1;
870            case '_i_j1-j2'
871                set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
872                if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
873                    set(handles.mode,'Value',2);
874                else
875                    set(handles.mode,'Value',1);% advice 'bursts' for small bursts
876                end
877                set(handles.mode,'Visible','on')
878                testpair=1;
879    end
880    switch NomType   
881            case {'_1_1','_i_j1-j2','_i1-i2_j','1_ab','01_ab'},% two navigation indices
882                state_j='on';
883    end
884end
885if testpair
886    mode_Callback(hObject, eventdata, handles) 
887else
888    set(handles.NomType,'String',NomTypeCell)
889    set(handles.first_j,'Visible',state_j)
890    set(handles.incr_j,'Visible',state_j)
891    set(handles.last_j,'Visible',state_j)
892    set(handles.nb_field2,'Visible',state_j)
893end
894
895
896%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
897% --- Executes on button press in mode.
898%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899function mode_Callback(hObject, eventdata, handles)
900%hseries=get(handles.mode,'parent');
901hseries=handles.figure1;
902SeriesData=get(hseries,'UserData');
903mode_list=get(handles.mode,'String');
904mode_value=get(handles.mode,'Value');
905mode=mode_list{mode_value};
906NomType=[];
907test_find_pair=0;
908if isfield(SeriesData,'NomType')
909    NomTypeCell=SeriesData.NomType;
910    Val=get(handles.NomType,'Value');
911    NomType=NomTypeCell{Val};
912    test_find_pair=isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')|| isequal(NomType,'#_ab');
913end
914time=[];
915if isfield(SeriesData,'Time')
916time=SeriesData.Time{1}; %get the set of times
917end
918siztime=size(time);
919nbfield=siztime(1);
920nbfield2=siztime(2);
921indchosen=1;  %%first pair selected by default
922if isequal(mode,'bursts')
923    enable_i(handles,'On')
924    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice) 
925elseif  isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')
926    enable_i(handles,'On')
927    enable_j(handles,'On') % allow both i and j index scanning
928else
929    enable_i(handles,'On')
930    enable_j(handles,'Off')
931end   
932set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
933set(hseries,'UserData',SeriesData)
934
935%list pairs if relevant
936if test_find_pair
937     find_netcpair_civ(hObject, eventdata, handles,Val)
938end
939
940%-------------------------------------
941function enable_i(handles,state)
942set(handles.i_txt,'Visible',state)
943set(handles.first_i,'Visible',state)
944set(handles.last_i,'Visible',state)
945set(handles.incr_i,'Visible',state)
946set(handles.nb_field,'Visible',state)
947set(handles.ref_i,'Visible',state)
948set(handles.ref_i_text,'Visible',state)
949
950%-----------------------------------
951function enable_j(handles,state)
952set(handles.j_txt,'Visible',state)
953set(handles.first_j,'Visible',state)
954set(handles.last_j,'Visible',state)
955set(handles.incr_j,'Visible',state)
956set(handles.nb_field2,'Visible',state)
957set(handles.ref_j,'Visible',state)
958set(handles.ref_j_text,'Visible',state)
959
960%-----------------------------------
961function view_FieldMenu(handles,state)
962set(handles.FieldMenu,'Visible',state)
963set(handles.Field_text,'Visible',state)
964set(handles.Field_frame,'Visible',state)
965
966%-----------------------------------
967function view_FieldMenu_1(handles,state)
968set(handles.FieldMenu_1,'Visible',state)
969set(handles.Field_text_1,'Visible',state)
970
971%-----------------------------------
972function view_TRANSFORM(handles,state)
973set(handles.TRANSFORM_frame,'Visible',state)
974set(handles.transform_fct,'Visible',state);
975set(handles.TRANSFORM_title,'Visible',state)
976
977%--------------------------------------------------------------
978% determine the menu for civ1 pairs depending on existing netcdf files
979% with the reference indices ref_i and ref_j
980%----------------------------------------------------------------
981function find_netcpair_civ(hObject, eventdata, handles,Val)
982%hseries=get(handles.list_pair_civ,'parent');
983SeriesData=get(handles.figure1,'UserData');
984% NomTypeCell=get(handles.NomType,'String');
985NomTypeCell=SeriesData.NomType;
986NomType=NomTypeCell{Val};
987  set(handles.list_pair_civ,'Visible','on')
988%nomenclature types
989RootPathCell=get(handles.RootPath,'String');
990filepath=RootPathCell{Val};
991RootFileCell=get(handles.RootFile,'String');
992filename=RootFileCell{Val};
993filebase=fullfile(filepath,filename);
994SubDirCell=get(handles.SubDir,'String');
995subdir=SubDirCell{Val};
996if ~exist(fullfile(filepath,subdir),'dir')
997         msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
998         set(handles.list_pair_civ,'String',{''});
999         return
1000end
1001mode_list=get(handles.mode,'String');
1002mode_value=get(handles.mode,'Value');
1003mode=mode_list{mode_value};
1004
1005%reads image numbers from the interface
1006ref_i=str2num(get(handles.ref_i,'String'));
1007ref_j=str2num(get(handles.ref_j,'String'));
1008ref_time=0;
1009nbfield=50;
1010nbfield2=50;%default max number of pairs
1011
1012%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1013% be performed, while the result is needed for next steps.
1014displ_pair={''};
1015displ_num=[];
1016ind_exist=0;
1017TimeUnit=get(handles.TimeUnit,'String');
1018if length(TimeUnit)>=1
1019    dtunit=['m' TimeUnit];
1020else
1021    dtunit='e-03';
1022end
1023if strcmp(mode,'series(Di)')
1024     for index=1:min(nbfield-1,50)
1025         filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
1026         select=(exist(filename,'file')==2);
1027         if select==1
1028               ind_exist=ind_exist+1;
1029                displ_num(1,ind_exist)=0;
1030                displ_num(2,ind_exist)=0;
1031                displ_num(3,ind_exist)=-floor(index/2);
1032                displ_num(4,ind_exist)=ceil(index/2);
1033                %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1034                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1035                if isfield(Cte,'dt2')
1036                    dt=Cte.dt2;
1037                elseif isfield(Cte,'dt')
1038                    dt=Cte.dt;
1039                end
1040                if isfield(Cte,'absolut_time_TO_2')
1041                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1042                elseif isfield(Cte,'absolut_time_TO')
1043                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1044                elseif isfield(Cte,'Time')
1045                    ref_time(ind_exist)=Cte.Time;
1046                end
1047                displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1048         end
1049     end
1050     set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
1051elseif isequal(mode,'series(Dj)')% series on the j index
1052       for index=1:min(nbfield2-1,50)
1053           filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
1054           select=(exist(filename,'file')==2);
1055           if select==1
1056               ind_exist=ind_exist+1;
1057                displ_num(1,ind_exist)=-floor(index/2);
1058                displ_num(2,ind_exist)=ceil(index/2);
1059                displ_num(3,ind_exist)=0;
1060                displ_num(4,ind_exist)=0;
1061                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1062                if isfield(Cte,'dt2')
1063                    dt=Cte.dt2;
1064                elseif isfield(Cte,'dt')
1065                    dt=Cte.dt;
1066                end
1067                if isfield(Cte,'absolut_time_TO_2')
1068                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1069                elseif isfield(Cte,'absolut_time_TO')
1070                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1071                elseif isfield(Cte,'Time')
1072                    ref_time(ind_exist)=Cte.Time;
1073                end
1074%                 if cte_detect(2)==1;
1075%                     dt=cte_read(2);
1076%                     ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
1077%                 else
1078%                     dt=cte_read(1);
1079%                     ref_time(ind_exist)=cte_read(3);
1080%                 end
1081                displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1082           end
1083       end
1084       set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
1085elseif isequal(mode,'bursts') %case of bursts
1086    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
1087        for numod_b=(numod_a+1):nbfield2
1088            [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir);
1089            select=(exist(filename,'file')==2);
1090            if select==1
1091                ind_exist=ind_exist+1;
1092                numlist_a(ind_exist)=numod_a;
1093                numlist_b(ind_exist)=numod_b;
1094                Attr=nc2struct(filename,[]);
1095                isfield(Attr,'absolut_time_T0_2')
1096                if isfield(Attr,'dt2')
1097                   dt(ind_exist)=Attr.dt2;
1098                   ref_time(ind_exist)=Attr.absolut_time_T0_2;
1099                elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
1100                   dt(ind_exist)=Attr.dt;
1101                   ref_time(ind_exist)=Attr.absolut_time_T0;
1102                else
1103                   dt(ind_exist)=NaN;%no information on dt
1104                end
1105                %determine nom_type_ima for pair display (used in num2stra.m)
1106                switch NomType
1107                    case {'#ab'}
1108                        nom_type_ima='#a';
1109                    case {'#AB'}
1110                        nom_type_ima='#A';
1111                    otherwise
1112                         nom_type_ima='_i_j';
1113                end
1114               displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
1115                        ' :dt= ' num2str(dt(ind_exist)*1000)];
1116            end
1117         end
1118         set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
1119     end
1120     if exist('dt','var') & ~isempty(dt)
1121         [dtsort,indsort]=sort(dt);
1122         displ_num(1,:)=numlist_a(indsort);
1123         displ_num(2,:)=numlist_b(indsort);
1124         displ_num(3,:)=0;
1125         displ_num(4,:)=0;
1126         displ_pair=displ_pair(indsort);
1127         ref_time=ref_time(indsort);
1128     end
1129end
1130if ind_exist==0
1131         if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1132            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
1133        else
1134            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1135        end
1136        if isequal(mode,'bursts') %case of bursts
1137            set(handles.list_pair_civ,'String',{'j=*-*'});
1138        elseif isequal(mode,'series(Di)') %case of bursts
1139            set(handles.list_pair_civ,'String',{'Di=*|*'});
1140        elseif isequal(mode,'series(Dj)') %case of bursts
1141            set(handles.list_pair_civ,'String',{'Dj=*|*'});
1142        end
1143end
1144
1145val=get(handles.list_pair_civ,'Value');
1146if val > length(displ_pair)
1147    set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1148    val=1;
1149end
1150iview=get(handles.NomType,'Value');
1151SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1152SeriesData.ref_time=ref_time;
1153set(handles.figure1,'UserData',SeriesData)
1154list_pair_civ_Callback(hObject, eventdata, handles)
1155
1156%-------------------------------------------------------------
1157% --- Executes on selection in list_pair_civ.
1158function list_pair_civ_Callback(hObject, eventdata, handles)
1159%------------------------------------------------------------
1160
1161%update first_i and last_i according to the chosen image pairs
1162testupdate=0;
1163Val=get(handles.RootPath,'Value');
1164IndexCell=get(handles.NomType,'String');
1165%hseries=get(handles.list_pair_civ,'parent');
1166SeriesData=get(handles.figure1,'UserData');
1167NomType=SeriesData.NomType{Val};
1168list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1169index_pair=get(handles.list_pair_civ,'Value');
1170str_pair=list_pair{index_pair};
1171ind_equ=strfind(str_pair,'=');%find '='
1172ind_sep=strfind(str_pair,'|');%find pair separator '|'
1173ind_com=strfind(str_pair,':');%find ':'
1174test_bursts=0;
1175if isempty(ind_sep)
1176    ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
1177    test_bursts=1;% we are in the case of bursts
1178end
1179displ_num=[0 0 0 0]; %default
1180if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
1181    num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1182    num2_str=str_pair(ind_sep+1:ind_com-1);
1183    num1=str2double(num1_str);
1184    num2=str2double(num2_str);
1185    if isequal(num1_str(1),' ')
1186        num1_str(1)=[];
1187    end   
1188    if isequal(num2_str(end),' ')
1189        num2_str(end)=[];
1190    end
1191    switch NomType
1192       case {'_i1-i2_j'}
1193           if isequal(num1_str(1),'0')
1194               IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1195           else
1196               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1197           end
1198           displ_num(3)=num1;
1199           displ_num(4)=num2;
1200       case {'_i1-i2'}
1201           if isequal(num1_str(1),'0')
1202               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1203           else
1204               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1205           end
1206           displ_num(3)=num1;
1207           displ_num(4)=num2;
1208       case '_i_j1-j2'
1209          if test_bursts
1210              IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1211          else
1212              if isequal(num1_str(1),'0')
1213                 IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1214              else
1215                 IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1216              end
1217          end
1218          displ_num(1)=num1;
1219          displ_num(2)=num2;
1220       case {'#_ab'} %TO COMPLETE
1221           IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1222
1223    end
1224end
1225set(handles.NomType,'String',IndexCell)
1226SeriesData.displ_num(Val,:)=displ_num;
1227set(handles.figure1,'UserData',SeriesData)
1228% set(handles.NomType,'Value',Val)
1229
1230if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1231        mode_list=get(handles.mode,'String');
1232    mode_value=get(handles.mode,'Value');
1233    mode=mode_list{mode_value};
1234        if isequal(mode,'series(Di)')
1235        first_i=str2num(get(handles.first_i,'String'));
1236        last_i=str2num(get(handles.last_i,'String'));
1237        incr_i=str2num(get(handles.incr_i,'String'));
1238        num1=first_i:incr_i:last_i;
1239        lastfieldCell=get(handles.nb_field,'String');
1240        lastfield=str2num(lastfieldCell{1});
1241        if ~isempty(lastfield)
1242            ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1243            num1=num1(ind);       
1244        end
1245        if ~isempty(num1)
1246            set(handles.first_i,'String',num2str(num1(1)));
1247            set(handles.last_i,'String',num2str(num1(end)));
1248        end
1249        testupdate=1;
1250        elseif isequal(mode,'series(Dj)')
1251        first_j=str2num(get(handles.first_j,'String'));
1252        last_j=str2num(get(handles.last_j,'String'));
1253        incr_j=str2num(get(handles.incr_j,'String'));
1254        num_j=first_j:incr_j:last_j;
1255        lastfieldCell=get(handles.nb_field2,'String');
1256        if ~isempty(lastfieldCell)
1257            lastfield2=lastfieldCell{1};
1258            ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1259                 (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1260        end
1261        testupdate=1;
1262        end
1263       
1264        %update the first and last times of the series
1265        if testupdate && isfield(SeriesData,'Time')
1266        if ~isempty(SeriesData.Time{1})
1267            displ_time(handles,SeriesData.Time{1});
1268        end
1269        end
1270end
1271
1272%------------------------------------------------------------------------
1273% --- Executes on button press in RUN.
1274function RUN_Callback(hObject, eventdata, handles)
1275%------------------------------------------------------------------------
1276%read root name and field type
1277set(handles.RUN,'BusyAction','queue');
1278%hseries=get(handles.RUN,'parent');
1279set(0,'CurrentFigure',handles.figure1)
1280if isequal(get(handles.GetObject,'Visible'),'on') && isequal(get(handles.GetObject,'Value'),1)
1281    Series.GetObject=1;
1282    GetObject_Callback(hObject, eventdata, handles)
1283else
1284    Series.GetObject=0;
1285end
1286SeriesData=get(handles.figure1,'UserData');
1287
1288%reinitiate waitbar position
1289Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1290waitbarpos=Series.WaitbarPos;
1291waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1292waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1293set(handles.waitbar,'Position',waitbarpos)
1294
1295% read input file parameters and set menus
1296Series.PathProject=get(handles.PathCampaign,'String');
1297RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1298RootFile=get(handles.RootFile,'String');% root name of the first field series
1299SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1300FileExt=get(handles.FileExt,'String');%file extension
1301if isempty(SeriesData)
1302    msgbox_uvmat('ERROR','no input file series')
1303    return
1304end
1305NomType=SeriesData.NomType;
1306if length(RootPath)==1 %string character input for user fct
1307    Series.RootPath=RootPath{1};
1308    Series.RootFile=RootFile{1};
1309    Series.SubDir=SubDir{1};
1310    Series.FileExt=FileExt{1};
1311    Series.NomType=NomType{1};
1312else %cell input for user fct
1313    Series.RootPath=RootPath;
1314    Series.RootFile=RootFile;
1315    Series.SubDir=SubDir;
1316    Series.FileExt=FileExt;
1317    Series.NomType=NomType;
1318end
1319if isequal(get(handles.FieldMenu,'Visible'),'on')
1320    FieldMenu=get(handles.FieldMenu,'String');
1321    FieldValue=get(handles.FieldMenu,'Value');
1322    Series.Field=FieldMenu(FieldValue);
1323end
1324menu_coord_state=get(handles.transform_fct,'Visible');
1325Series.CoordType='';%default
1326if isequal(menu_coord_state,'on')
1327%     menu_coord=get(handles.transform_fct,'String');
1328    menu_index=get(handles.transform_fct,'Value');
1329    transform_list=get(handles.transform_fct,'UserData');
1330    Series.transform_fct=transform_list{menu_index};% transform function handles
1331end
1332Series.hseries=handles.figure1; % handles to the series GUI
1333
1334%read the set of field numbers
1335first_i=str2num(get(handles.first_i,'String'));
1336last_i=str2num(get(handles.last_i,'String'));
1337incr_i=str2num(get(handles.incr_i,'String'));
1338first_j=str2num(get(handles.first_j,'String'));
1339last_j=str2num(get(handles.last_j,'String'));
1340incr_j=str2num(get(handles.incr_j,'String'));
1341if ~isequal(get(handles.first_i,'Visible'),'on')
1342   first_i=1;
1343   last_i=1;
1344   incr_i=1;
1345end
1346if ~isequal(get(handles.first_j,'Visible'),'on')
1347    first_j=1;
1348    last_j=1;
1349    incr_j=1;
1350end
1351Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1352if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1353    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1354if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1355    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1356if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1357    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1358if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1359    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1360num_i=first_i:incr_i:last_i;
1361num_j=first_j:incr_j:last_j;
1362nbfield_cell=get(handles.nb_field,'String');
1363nbfield=[]; %default
1364for iview=1:length(nbfield_cell)
1365    nb=str2num(nbfield_cell{iview});
1366    if ~isempty(nb)
1367        nbfield=[nbfield nb];
1368    end
1369end
1370nbfield=min(nbfield);
1371nbfield2_cell=get(handles.nb_field2,'String');
1372nbfield2=[]; %default
1373for iview=1:length(nbfield2_cell)
1374    nb=str2num(nbfield2_cell{iview});
1375    if ~isempty(nb)
1376        nbfield2=[nbfield2 nb];
1377    end
1378end
1379nbfield2=min(nbfield2);
1380
1381%get complementary information from the 'series' interface
1382list_action=get(handles.ACTION,'String');% list menu action
1383index_action=get(handles.ACTION,'Value');% selected string index
1384action= list_action{index_action}; % selected string
1385mode_list=get(handles.mode,'String');
1386index_mode=get(handles.mode,'Value');
1387mode=mode_list{index_mode};
1388ind_shift=0;%default
1389
1390%determine the list of input file names
1391nbmissing=0;
1392for iview=1:length(RootPath)
1393    %case of pairs (.nc files)
1394   
1395    if isequal(NomType{iview},'_i_j1-j2')|| isequal(NomType{iview},'_i1-i2_j')|| isequal(NomType{iview},'_i1-i2')|| isequal(NomType{iview},'#_ab')
1396        ind_shift=SeriesData.displ_num(iview,:);
1397        if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1398            if isequal(NomType{iview},'#_ab')
1399                mode='#_ab';
1400            end
1401            [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);
1402        else   
1403            [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1404            if isempty(num_i)
1405                msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1406                return
1407            end
1408            if num_i(1)>first_i
1409               set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1410               last_i_Callback(hObject, eventdata, handles)
1411            end
1412            if num_i(end)<last_i
1413               set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1414               last_i_Callback(hObject, eventdata, handles)
1415            end
1416            if num_j(1)>first_j
1417               set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1418               last_j_Callback(hObject, eventdata, handles)
1419            end
1420            if num_j(end)<last_j
1421               set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1422               last_j_Callback(hObject, eventdata, handles)
1423            end
1424        end
1425    else%case of images
1426        [num_i1,num_j1]=meshgrid(num_i,num_j);
1427        num_i2=num_i1;
1428        num_j2=num_j1;
1429    end
1430    if length(RootPath)>1
1431        num_i1_cell{iview}=num_i1;
1432        num_i2_cell{iview}=num_i2;
1433        num_j1_cell{iview}=num_j1;
1434        num_j2_cell{iview}=num_j2;
1435    end
1436end
1437
1438% defining the ACTION function handle
1439path_series=which('series');
1440list_path=get(handles.ACTION,'UserData');
1441index=get(handles.ACTION,'Value');
1442fct_path=list_path{index}; %path stored for the function ACTION
1443if ~isequal(fct_path,path_series)
1444    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1445    if ~exist(fct_path,'dir')
1446        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
1447        return
1448    end
1449    if ~isequal(spath,fct_path)
1450        addpath(fct_path)% add the prescribed path if not the current one
1451    end
1452end
1453eval(['h_fun=@' action ';'])%create a function handle for ACTION
1454if ~isequal(fct_path,path_series)
1455        rmpath(fct_path)% add the prescribed path if not the current one   
1456end
1457
1458% RUN ACTION
1459Series.Action=action;%name of the processing programme
1460set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1461
1462if length(RootPath)>1
1463    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1464else
1465    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
1466end
1467set(handles.RUN,'BackgroundColor',[1 0 0])
1468
1469% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1470% detect=1;
1471% while detect==1
1472%     namefigfull=[namedoc '.fig'];
1473%     hh=dir(namefigfull);
1474%     if ~isempty(hh)
1475%         detect=1;
1476%         namedoc=[namedoc '.0'];
1477%     else
1478%         detect=0;
1479%     end
1480% end
1481% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1482
1483%------------------------------------------------------------------------
1484function STOP_Callback(hObject, eventdata, handles)
1485%------------------------------------------------------------------------
1486set(handles.RUN, 'BusyAction','cancel')
1487set(handles.RUN,'BackgroundColor',[1 0 0])
1488
1489
1490%------------------------------------------------------------------------
1491function first_i_Callback(hObject, eventdata, handles)
1492%------------------------------------------------------------------------
1493last_i_Callback(hObject, eventdata, handles)
1494
1495%------------------------------------------------------------------------
1496function last_i_Callback(hObject, eventdata, handles)
1497%------------------------------------------------------------------------
1498%     hseries=get(handles.last_i,'parent');
1499% first_i=str2num(get(handles.first_i,'String'));
1500% last_i=str2num(get(handles.last_i,'String'));
1501% ref_i=ceil((first_i+last_i)/2);
1502% set(handles.ref_i,'String', num2str(ref_i))
1503% ref_i_Callback(hObject, eventdata, handles)
1504SeriesData=get(handles.figure1,'UserData');
1505if ~isfield(SeriesData,'Time')
1506    SeriesData.Time{1}=[];
1507end
1508displ_time(handles,SeriesData.Time{1});
1509
1510%------------------------------------------------------------------------
1511function first_j_Callback(hObject, eventdata, handles)
1512%------------------------------------------------------------------------
1513 last_j_Callback(hObject, eventdata, handles)
1514
1515%------------------------------------------------------------------------
1516function last_j_Callback(hObject, eventdata, handles)
1517%------------------------------------------------------------------------
1518first_j=str2num(get(handles.first_j,'String'));
1519last_j=str2num(get(handles.last_j,'String'));
1520ref_j=ceil((first_j+last_j)/2);
1521set(handles.ref_j,'String', num2str(ref_j))
1522ref_j_Callback(hObject, eventdata, handles)
1523SeriesData=get(handles.figure1,'UserData');
1524if ~isfield(SeriesData,'Time')
1525    SeriesData.Time{1}=[];
1526end
1527displ_time(handles,SeriesData.Time{1});
1528
1529
1530%------------------------------------------------------------------------
1531function ref_i_Callback(hObject, eventdata, handles)
1532%------------------------------------------------------------------------
1533mode_list=get(handles.mode,'String');
1534mode_value=get(handles.mode,'Value');
1535mode=mode_list{mode_value};
1536%hseries=get(handles.ref_i,'parent');
1537SeriesData=get(handles.figure1,'UserData');
1538%NomTypeCell=get(handles.NomType,'String');
1539NomTypeCell=SeriesData.NomType;
1540if ~isempty(NomTypeCell)
1541Val=get(handles.NomType,'Value');
1542NomType=NomTypeCell{Val};
1543% for ilist=1:length(NomType)
1544    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1545        if isequal(mode,'series(Di)')
1546            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1547%             break
1548        end
1549    end
1550end
1551
1552%------------------------------------------------------------------------
1553function ref_j_Callback(hObject, eventdata, handles)
1554%------------------------------------------------------------------------
1555mode_list=get(handles.mode,'String');
1556mode_value=get(handles.mode,'Value');
1557mode=mode_list{mode_value};
1558%hseries=get(handles.ref_i,'parent');
1559SeriesData=get(handles.figure1,'UserData');
1560NomTypeCell=SeriesData.NomType;
1561if ~isempty(NomTypeCell)
1562    Val=get(handles.NomType,'Value');
1563    NomType=NomTypeCell{Val};
1564    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1565        if isequal(mode,'series(Dj)')
1566            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1567        end
1568    end
1569end
1570
1571%------------------------------------------------------------------------
1572% --- Executes on selection change in ACTION.
1573function ACTION_Callback(hObject, eventdata, handles)
1574%------------------------------------------------------------------------
1575global nb_builtin_ACTION
1576list_ACTION=get(handles.ACTION,'String');% list menu fields
1577index_ACTION=get(handles.ACTION,'Value');% selected string index
1578ACTION= list_ACTION{index_ACTION}; % selected function name
1579path_series=which('series');%path to series.m
1580list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1581default_file=fullfile(list_path{end},ACTION);
1582% add a new function to the menu if the selected item is 'more...'
1583if isequal(ACTION,'more...')
1584    pathfct=fileparts(path_series);
1585    [FileName, PathName, filterindex] = uigetfile( ...
1586       {'*.m', ' (*.m)';
1587        '*.m',  '.m files '; ...
1588        '*.*', 'All Files (*.*)'}, ...
1589        'Pick a file',default_file);
1590    if length(FileName)<2
1591        return
1592    end
1593    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1594    if ~isequal(ext_fct,'.m')
1595        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1596        return
1597    end
1598   
1599   % insert the choice in the action menu
1600   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1601   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1602   list_path{index_ACTION}=PathName;
1603   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1604       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1605       menu_str(nb_builtin_ACTION+1:end-5)=[];
1606       list_path(nb_builtin_ACTION+1:end-4)=[];
1607       index_ACTION=index_ACTION-nbremove;
1608       set(handles.ACTION,'Value',index_ACTION)
1609       set(handles.ACTION,'String',menu_str)
1610   end
1611   list_path{index_ACTION}=PathName;
1612   set(handles.ACTION,'UserData',list_path);
1613   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1614   
1615   %record the current menu in personal file profil_perso
1616   dir_perso=prefdir;
1617   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1618   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1619       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1620   end
1621   if nb_builtin_ACTION+1<=length(menu_str)-1
1622       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1623           save(profil_perso,'series_fct','-append')
1624       else
1625           txt=ver('MATLAB');
1626           Release=txt.Release;
1627           relnumb=str2num(Release(3:4));
1628           if relnumb >= 14%recent relaese of Matlab
1629               save(profil_perso,'series_fct','-V6')
1630           else
1631               save(profil_perso, 'series_fct')
1632           end
1633       end
1634   end
1635end
1636
1637%check the current path to the selected function
1638PathName=list_path{index_ACTION};%current recorded path
1639set(handles.path,'String',PathName); %show the path to the senlected function
1640
1641%default setting for the visibility of the GUI elements
1642set(handles.RootPath,'UserData','many')
1643set(handles.SubDir,'Visible','on')
1644set(handles.RootFile,'Visible','on')
1645set(handles.NomType,'Visible','on')
1646set(handles.FileExt,'Visible','on')
1647set(handles.NbSlice,'Visible','off')
1648set(handles.NbSlice_title,'Visible','off')
1649set(handles.VelTypeMenu,'Visible','off');
1650set(handles.VelType_text,'Visible','off');
1651set(handles.VelTypeMenu_1,'Visible','off');
1652set(handles.VelType_text_1,'Visible','off');
1653view_FieldMenu(handles,'off')
1654view_FieldMenu_1(handles,'off')
1655view_TRANSFORM(handles,'off')
1656set(handles.ProjObject_frame,'Visible','off');
1657set(handles.GetMask,'Visible','off')
1658set(handles.Mask,'Visible','off')
1659set(handles.GetObject,'Visible','off');
1660set(handles.ProjObject,'Visible','off');
1661set(handles.OutputDir,'Visible','off');
1662set(handles.PARAMETERS_frame,'Visible','off');
1663set(handles.PARAMETERS_title,'Visible','off');
1664set(handles.ParamKey,'Visible','off')
1665set(handles.ParamVal,'Visible','off')
1666ParamKey={};
1667set(handles.FieldMenu,'Enable','off')
1668set(handles.VelTypeMenu,'Enable','off')
1669set(handles.FieldMenu_1,'Enable','off')
1670set(handles.VelTypeMenu_1,'Enable','off')
1671set(handles.transform_fct,'Enable','off')
1672%set the displayed GUI item needed for input parameters
1673if ~isequal(path_series,PathName)
1674    addpath(PathName)
1675end
1676eval(['h_function=@' ACTION ';']);
1677try
1678    [fid,errormsg] =fopen([ACTION '.m']);
1679    InputText=textscan(fid,'%s',1,'delimiter','\n');
1680    fclose(fid)
1681    set(handles.ACTION,'ToolTipString',InputText{1}{1})
1682end
1683if ~isequal(path_series,PathName)
1684    rmpath(PathName)
1685end
1686varargout=h_function();
1687Param_list={};
1688
1689%nb_series=length(RootFile);
1690FileExt=get(handles.FileExt,'String');
1691nb_series=length(FileExt);
1692testima_series=1; %test for a list of images only
1693testima=1;
1694testima_1=1;
1695testciv_series=1;
1696for iview=1:nb_series
1697    ext=FileExt{iview};
1698    if length(ext)<2
1699        ext='.none';
1700    end
1701    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1702    if ~testimaview
1703        if iview==1
1704            testima=0;
1705        end
1706        if iview==2
1707            testima_1=0;
1708        end
1709        testima_series=0;
1710    end
1711end
1712for ilist=1:length(varargout)-1
1713    switch varargout{ilist}
1714                       %RootFile always visible
1715         case 'RootPath'   %visible by default
1716            value=lower(varargout{ilist+1});
1717            if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1718                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1719            end
1720        case 'SubDir' %visible by default
1721            if isequal(lower(varargout{ilist+1}),'off')
1722                set(handles.SubDir,'Visible','off')
1723            end
1724        case 'RootFile'   %visible by default
1725            value=lower(varargout{ilist+1});
1726            if isequal(value,'off')
1727                set(handles.RootFile,'Visible','off')
1728            elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1729                set(handles.RootFile,'Visible','on')
1730                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1731            end
1732        case 'NomType'   %visible by default
1733            if isequal(lower(varargout{ilist+1}),'off')
1734                set(handles.NomType,'Visible','off')
1735            end
1736        case 'FileExt'   %visible by default
1737            if isequal(lower(varargout{ilist+1}),'off')
1738                set(handles.FileExt,'Visible','off')
1739            end
1740        case 'NbSlice'   %hidden by default
1741            if isequal(lower(varargout{ilist+1}),'on')
1742                set(handles.NbSlice,'Visible','on')
1743                set(handles.NbSlice_title,'Visible','on')
1744            end
1745        case 'VelTypeMenu'   %hidden by default
1746            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1747                set(handles.VelTypeMenu,'Enable','on')
1748                if nb_series >=1 && ~testima_series
1749                    set(handles.VelTypeMenu,'Visible','on')
1750                    set(handles.VelType_text,'Visible','on');
1751                    set(handles.Field_frame,'Visible','on')
1752                end
1753            end
1754            if isequal(lower(varargout{ilist+1}),'two')
1755                set(handles.VelTypeMenu_1,'Enable','on')
1756                if nb_series >=2 && ~testima_series
1757                    set(handles.VelTypeMenu_1,'Visible','on')
1758                    set(handles.VelType_text_1,'Visible','on');
1759                end
1760            end
1761        case 'FieldMenu'   %hidden by default
1762            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1763                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1764                if nb_series >=1 && ~testima_series
1765                    view_FieldMenu(handles,'on')
1766                end
1767            end
1768            if isequal(lower(varargout{ilist+1}),'two')
1769                set(handles.FieldMenu_1,'Enable','on')
1770                if nb_series >=2 && ~testima_1
1771                    view_FieldMenu_1(handles,'on')
1772                end
1773            end
1774        case 'CoordType'   %hidden by default
1775            if isequal(lower(varargout{ilist+1}),'on')
1776                set(handles.transform_fct,'Enable','on')
1777                view_TRANSFORM(handles,'on')
1778            end
1779        case 'GetObject'   %hidden by default
1780            if isequal(lower(varargout{ilist+1}),'on')   
1781                set(handles.ProjObject_frame,'Visible','on')
1782                set(handles.GetObject,'Visible','on');
1783            end
1784        case 'Mask'   %hidden by default
1785            if isequal(lower(varargout{ilist+1}),'on')   
1786                set(handles.ProjObject_frame,'Visible','on')
1787                set(handles.GetMask,'Visible','on');
1788            end
1789        case 'PARAMETER' 
1790            set(handles.PARAMETERS_frame,'Visible','on')
1791            set(handles.PARAMETERS_title,'Visible','on')
1792            set(handles.ParamKey,'Visible','on')
1793            %set(handles.ParamVal,'Visible','on')
1794            Param_str=varargout{ilist+1};
1795            Param_list=[Param_list; {Param_str}];         
1796    end
1797end
1798if ~isempty(Param_list)
1799    set(handles.ParamKey,'String',Param_list)
1800    set(handles.ParamVal,'Visible','on')
1801end
1802
1803%------------------------------------------------------------------------
1804% --- Executes on selection change in FieldMenu.
1805function FieldMenu_Callback(hObject, eventdata, handles)
1806%------------------------------------------------------------------------
1807field_str=get(handles.FieldMenu,'String');
1808field_index=get(handles.FieldMenu,'Value');
1809field=field_str{field_index(1)};
1810if isequal(field,'get_field...')   
1811     hget_field=findobj(allchild(0),'name','get_field');
1812     if ~isempty(hget_field)
1813         delete(hget_field)%delete opened versions of get_field
1814     end
1815     %hseries=get(handles.FieldMenu,'parent');
1816     SeriesData=get(handles.figure1,'UserData');
1817     filename=SeriesData.CurrentInputFile;
1818     if exist(filename,'file')
1819        get_field(filename)
1820     end
1821elseif isequal(field,'more...')
1822    str=calc_field;
1823    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1824                'SelectionMode','single',...
1825                'ListString',str);
1826       % edit the choice in the fields and action menu
1827     scalar=cell2mat(str(ind_answer));
1828     update_menu(handles.FieldMenu,scalar)
1829end
1830
1831%------------------------------------------------------------------------
1832% --- Executes on selection change in FieldMenu_1.
1833function FieldMenu_1_Callback(hObject, eventdata, handles)
1834%------------------------------------------------------------------------
1835field_str=get(handles.FieldMenu_1,'String');
1836field_index=get(handles.FieldMenu_1,'Value');
1837field=field_str{field_index};
1838if isequal(field,'get_field...')   
1839     hget_field=findobj(allchild(0),'name','get_field_1');
1840     if ~isempty(hget_field)
1841         delete(hget_field)
1842     end
1843     %hseries=get(handles.FieldMenu,'parent');
1844     SeriesData=get(handles.figure1,'UserData');
1845     filename=SeriesData.CurrentInputFile_1;
1846     if exist(filename,'file')
1847        hget_field=get_field(filename);
1848        set(hget_field,'name','get_field_1')
1849     end
1850elseif isequal(field,'more...')
1851    str=calc_field;
1852    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1853                'SelectionMode','single',...
1854                'ListString',str);
1855       % edit the choice in the fields and action menu
1856     scalar=cell2mat(str(ind_answer));
1857     update_menu(handles.FieldMenu_1,scalar)
1858end   
1859
1860
1861%%%%%%%%%%%%%
1862function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1863
1864        indsel=ind_i;
1865        indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1866        indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1867        if ~isempty(indiff)
1868            indiff2=diff(indiff);
1869            indiffp=[indiff2 1];
1870            indiffm=[1 indiff2];
1871            ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1872            ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1873                %for each multiplet, select the most recent file
1874            ind_remove=[];
1875            for i=1:length(ind_multi_m)
1876                ind_pairs=ind_multi_m(i):ind_multi_p(i);
1877                for imulti=1:length(ind_pairs)
1878                    datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1879                end
1880                [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1881                ind_s=indsort2(1:end-1);%
1882                ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1883            end
1884        end
1885
1886%------------------------------------------------------------------------
1887% --- determine the list of index pairs of processing file
1888function [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)
1889%------------------------------------------------------------------------
1890num_i1=num_i;% set of first image numbers by default
1891num_i2=num_i;
1892num_j1=num_j;
1893num_j2=num_j;
1894num_i_out=num_i;
1895num_j_out=num_j;
1896if isequal (NomType,'_i1-i2_j') || isequal (NomType,'_i1-i2')
1897    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1898    num_i2_line=num_i+ind_shift(4);
1899    % adjust the first and last field number
1900        indsel=find(num_i1_line >= 1);
1901    num_i_out=num_i(indsel);
1902    num_i1_line=num_i1_line(indsel);
1903    num_i2_line=num_i2_line(indsel);
1904    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1905    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1906    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1907    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1908elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
1909    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1910        num_j1=ind_shift(1)*ones(size(num_i));
1911        num_j2=ind_shift(2)*ones(size(num_i));
1912    else
1913        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1914        num_j2_col=num_j+ind_shift(2);
1915        % adjust the first field number
1916        indsel=find((num_j1_col >= 1));   
1917        num_j_out=num_j(indsel);
1918        num_j1_col=num_j1_col(indsel);
1919        num_j2_col=num_j2_col(indsel);
1920        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1921        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1922    end   
1923end
1924
1925%------------------------------------------------------------------------
1926% ---- find the times corresponding to the first and last indices of a series
1927function displ_time(handles,times)
1928%------------------------------------------------------------------------
1929hseries=get(handles.last_i,'parent');
1930SeriesData=get(hseries,'UserData');%
1931first_i=str2num(get(handles.first_i,'String'));
1932first_j=str2num(get(handles.first_j,'String'));
1933last_i=str2num(get(handles.last_i,'String'));
1934last_j=str2num(get(handles.last_j,'String'));
1935% index_civ=get(handles.list_pair_civ,'Value');
1936% NomType=get(handles.NomType,'String');
1937NomType=SeriesData.NomType;
1938mode_list=get(handles.mode,'String');
1939index_mode=get(handles.mode,'Value');
1940mode=mode_list{index_mode};
1941% ind_shift=0;%default
1942
1943time_first=[];
1944time_last=[];
1945if ~isfield(SeriesData,'Time')
1946    SeriesData.Time{1}=[];
1947end
1948for iview=1:length(NomType)
1949    time_first_cell{iview}='?';
1950    time_last_cell{iview}='?';%default
1951    time=SeriesData.Time{iview};
1952    if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
1953        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1954            ind_shift=SeriesData.displ_num(iview,:);
1955            if isequal(mode,'bursts')
1956                first_j=0;
1957                last_j=0;
1958            end
1959            first_i1=first_i +ind_shift(3);
1960            first_i2 =first_i +ind_shift(4);
1961            first_j1 =first_j +ind_shift(1);
1962            first_j2 =first_j +ind_shift(2);
1963            last_i1=last_i +ind_shift(3);
1964            last_i2 =last_i +ind_shift(4);   
1965            last_j1 =last_j +ind_shift(1);
1966            last_j2 =last_j +ind_shift(2);
1967            siz=size(SeriesData.Time{1});
1968            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1969                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1970                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1971            else%read the time in the nc files
1972                RootPath=get(handles.RootPath,'String');
1973                RootFile=get(handles.RootFile,'String');
1974                SubDir=get(handles.SubDir,'String');
1975                %VelType=get(handles.VelType,'String');
1976                VelType_str=get(handles.VelTypeMenu,'String');
1977                VelType_val=get(handles.VelTypeMenu,'Value');
1978                VelType=VelType_str{VelType_val};
1979                filebase=fullfile(RootPath{1},RootFile{1});
1980                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
1981                if  exist(filefirst,'file')
1982                    Attrib=nc2struct(filefirst,[]);
1983                    if isfield(Attrib,'Time')
1984                        time_first=Attrib.Time;
1985                    else
1986                        if isfield(Attrib,'absolut_time_T0')
1987                            time_first=Attrib.absolut_time_T0;
1988                        end
1989                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1990                            time_first=Attrib.absolut_time_T0_2;
1991                        end
1992                    end
1993                end
1994                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
1995                if exist(filelast,'file')
1996                   Attrib=nc2struct(filelast,[]);
1997                    if isfield(Attrib,'Time')
1998                        time_last=Attrib.Time;
1999                    else
2000                        if isfield(Attrib,'absolut_time_T0')
2001                            time_last=Attrib.absolut_time_T0;
2002                        end
2003                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2004                            time_last=Attrib.absolut_time_T0_2;
2005                        end
2006                    end
2007                end
2008            end
2009        end
2010    else
2011        siz=size(times);
2012        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
2013            time_first=times(first_i,first_j);
2014            time_last=times(last_i,last_j);
2015        end
2016    end
2017    time_first_cell{iview}=num2str(time_first,4);
2018    time_last_cell{iview}=num2str(time_last,4);
2019end
2020set(handles.time_first,'Value',1)
2021set(handles.time_last,'Value',1)
2022set(handles.time_first,'String',time_first_cell);
2023set(handles.time_last,'String',time_last_cell);
2024
2025%------------------------------------------------------------------------
2026% --- Executes on button press in GetObject.
2027function GetObject_Callback(hObject, eventdata, handles)
2028%------------------------------------------------------------------------
2029hseries=get(handles.GetObject,'parent');
2030SeriesData=get(hseries,'UserData');
2031value=get(handles.GetObject,'Value');
2032if value
2033     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2034%      DataInit.ParentButton=handles.GetObject;
2035     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2036     if ishandle(hset_object)
2037         uistack(hset_object,'top')
2038        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2039     else
2040         %get the object file
2041         defaultname=get(handles.RootPath,'String');
2042         if isempty(defaultname)
2043            defaultname={''};
2044         end
2045        [FileName, PathName, filterindex] = uigetfile( ...
2046       {'*.xml;*.mat', ' (*.xml,*.mat)';
2047       '*.xml',  '.xml files '; ...
2048        '*.mat',  '.mat matlab files '}, ...
2049        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
2050        fileinput=[PathName FileName];%complete file name
2051        testblank=findstr(fileinput,' ');%look for blanks
2052        if ~isempty(testblank)
2053            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
2054            return
2055        end
2056        sizf=size(fileinput);
2057        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2058        %read the file
2059        t=xmltree(fileinput);
2060        data=convert(t);
2061        if ~isfield(data,'Style')
2062             data.Style='points';
2063        end
2064        if ~isfield(data,'ProjMode')
2065             data.ProjMode='projection';
2066        end
2067        transform_menu=get(handles.transform_fct,'String');
2068        ichoice=get(handles.transform_fct,'Value');
2069%         if isequal(transform_menu{ichoice},'px');
2070%             data.CoordType='px';
2071%         else
2072%             data.CoordType='phys';
2073%         end
2074        data.desable_plot=1;
2075        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2076     end
2077else
2078    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2079%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2080%         close(SeriesData.hset_object)
2081%     end
2082end
2083set(hseries,'UserData',SeriesData)
2084
2085%--------------------------------------------------------------
2086function GetMask_Callback(hObject, eventdata, handles)
2087value=get(handles.GetMask,'Value');
2088if value
2089    msgbox_uvmat('ERROR','not implemented yet')
2090end
2091%--------------------------------------------------------------
2092
2093%-------------------------------------------------------------------
2094%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2095function ncbrowser_uvmat(hObject, eventdata)
2096%-------------------------------------------------------------------
2097     bla=get(gcbo,'String');
2098     ind=get(gcbo,'Value');
2099     filename=cell2mat(bla(ind));
2100      blank=find(filename==' ');
2101      filename=filename(1:blank-1);
2102     get_field(filename)
2103
2104% ------------------------------------------------------------------
2105function MenuHelp_Callback(hObject, eventdata, handles)
2106%-------------------------------------------------------------------
2107path_to_uvmat=which ('uvmat');% check the path of uvmat
2108pathelp=fileparts(path_to_uvmat);
2109helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2110if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2111else
2112    addpath (fullfile(pathelp,'uvmat_doc'))
2113    web([helpfile '#series'])
2114end
2115
2116%-------------------------------------------------------------------
2117% --- Executes on selection change in transform_fct.
2118function transform_fct_Callback(hObject, eventdata, handles)
2119%-------------------------------------------------------------------
2120global nb_transform
2121
2122% huvmat=get(handles.transform_fct,'parent');
2123menu=get(handles.transform_fct,'String');
2124ind_coord=get(handles.transform_fct,'Value');
2125coord_option=menu{ind_coord};
2126list_transform=get(handles.transform_fct,'UserData');
2127ff=functions(list_transform{end});
2128if isequal(coord_option,'more...');
2129    coord_fct='';
2130    prompt = {'Enter the name of the transform function'};
2131    dlg_title = 'user defined transform';
2132    num_lines= 1;
2133    [FileName, PathName, filterindex] = uigetfile( ...
2134       {'*.m', ' (*.m)';
2135        '*.m',  '.m files '; ...
2136        '*.*', 'All Files (*.*)'}, ...
2137        'Pick a file', ff.file);
2138    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2139        PathName(end)=[];
2140    end
2141    transform_selected =fullfile(PathName,FileName);
2142    if ~exist(transform_selected,'file')
2143          return
2144    end
2145    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2146    if ~isequal(ext_fct,'.m')
2147        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2148        return
2149    end
2150   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2151   ind_coord=get(handles.transform_fct,'Value');
2152   addpath(PathName)
2153   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2154   set(handles.transform_fct,'UserData',list_transform)
2155   rmpath(PathName)
2156   % save the new menu in the personal file 'uvmat_perso.mat'
2157   dir_perso=prefdir;%personal Matalb directory
2158   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2159   if exist(profil_perso,'file')
2160       for ilist=nb_transform+1:numel(list_transform)
2161           ff=functions(list_transform{ilist});
2162           transform_fct{ilist-nb_transform}=ff.file;
2163       end
2164        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2165   end
2166end
2167
2168%check the current path to the selected function
2169func=functions(list_transform{ind_coord});
2170set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2171
2172%------------------------------------------------------------------------
2173% --- generates a series of file names with reference numbers between range1 and
2174% --- range2 with increment incr. The reference number num_ref is the image number at the middle of the
2175% --- image pair. The set of first numbers num1 of the image pairs is also
2176% --- given as output
2177function [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)
2178%------------------------------------------------------------------------
2179[Path,Name]=fileparts(filebase);
2180filebasesub=fullfile(Path,subdir,Name);
2181filecell={};%default
2182num_i1=[];
2183num_i2=[];
2184num_j1=[];
2185num_j2=[];
2186ind0_i=first_i:incr_i:last_i;
2187nbcolumn=length(ind0_i);
2188ind0_j=first_j:incr_j:last_j;
2189nbline=length(ind0_j);
2190if isequal(mode,'#_ab')
2191    dirpair=dir([filebasesub '*_*.nc']);
2192elseif isequal(mode,'bursts')||isequal(mode,'series(Dj)') 
2193    dirpair=dir([filebasesub '_*_*-*.nc']);
2194elseif isequal(mode,'series(Di)')
2195    dirpair=dir([filebasesub '_*-*_*.nc']);
2196else
2197    msgbox_uvmat('ERROR','option *|* not yet implemented')
2198    return
2199end
2200if isempty(dirpair)
2201        msgbox_uvmat('ERROR','no pair detected in the selected range')
2202        return
2203end
2204
2205if isequal(mode,'bursts')||isequal(mode,'#_ab')
2206    icount=0;
2207    for ifile=1:length(dirpair)
2208        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2209        num1_r=str2num(str_1);
2210        if isequal(RootFile,Name) & ~isempty(num1_r)   
2211            num_i1(ifile)=num1_r;
2212            num_a(ifile)=stra2num(str_a);
2213            num_b(ifile)=stra2num(str_b);
2214        end     
2215    end
2216    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
2217    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
2218    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
2219    ind_i=ind_i(select);%set of selected indices ind_i
2220    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
2221    select=select(indsort);
2222    num_i1=num_i1(select);
2223    num_a=num_a(select);
2224    num_b=num_b(select);
2225    dirpair=dirpair(select);
2226    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
2227    ind_i(ind_remove)=[];
2228    num_a(ind_remove)=[];
2229    num_b(ind_remove)=[];
2230    num_j1=zeros(1,nbcolumn);%default
2231    num_j2=num_j1;
2232    num_j1(ind_i)=num_a;
2233    num_j2(ind_i)=num_b;
2234    num_i1=first_i:incr_i:last_i;
2235    num_i2=num_i1;
2236    nbmissing=nbcolumn-length(ind_i);
2237
2238elseif isequal(mode,'series(Di)')
2239    %ind0_i=first_i:incr_i:last_i;
2240    %nbcolumn=length(ind0_i);
2241    %ind0_j=first_j:incr_j:last_j;
2242    %nbline=length(ind0_j);
2243    %dirpair=dir([filebasesub '_*-*_*.nc']);
2244    for ifile=1:length(dirpair)
2245        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2246        num_i1_r(ifile)=str2num(str_1);
2247        num_i2_r(ifile)=str2num(str_2);
2248        num_j(ifile)=str2num(str_a);
2249    end
2250    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
2251    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
2252    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2253    ind_j=((num_j-first_j)/incr_j)+1;
2254    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2255    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2256    ind_ij=ind_ij(select);%set of selected indices ind_ij
2257    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2258    select=select(indsort);
2259    num_i1_r=num_i1_r(select);
2260    num_i2_r=num_i2_r(select);
2261    dirpair=dirpair(select);
2262    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2263    ind_ij(ind_remove)=[];
2264    num_i1_r(ind_remove)=[];
2265    num_i2_r(ind_remove)=[];
2266    num_i1=zeros(1,nbline*nbcolumn);%default
2267    num_i2=num_i1;
2268    num_i1(ind_ij)=num_i1_r;
2269    num_j2(ind_ij)=num_i2_r;
2270    num_i1=reshape(num_i1,nbline,nbcolumn);
2271    num_i2=reshape(num_i2,nbline,nbcolumn);
2272    num_j1=meshgrid(ind0_i,ind0_j);
2273    num_j2=num_j1;
2274    nbmissing=nbline*nbcolumn-length(ind_ij);
2275elseif isequal(mode,'series(Dj)')
2276    for ifile=1:length(dirpair)
2277        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2278        num_i(ifile)=str2num(str_1);
2279        num_a(ifile)=str2num(str_a);
2280        num_b(ifile)=str2num(str_b);
2281    end
2282    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
2283    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
2284    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2285    ind_j=((num_j-first_j)/incr_j)+1;
2286    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2287    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2288    ind_ij=ind_ij(select);%set of selected indices ind_ij
2289    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2290    select=select(indsort);
2291    num_i=num_i(select);
2292    num_a=num_a(select);
2293    num_b=num_b(select);
2294    dirpair=dirpair(select);
2295    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2296    ind_ij(ind_remove)=[];
2297    num_a(ind_remove)=[];
2298    num_b(ind_remove)=[];
2299    num_j1=zeros(1,nbline*nbcolumn);%default
2300    num_j2=num_j1;
2301    num_j1(ind_ij)=num_a;
2302    num_j2(ind_ij)=num_b;
2303    num_j1=reshape(num_j1,nbline,nbcolumn);
2304    num_j2=reshape(num_j2,nbline,nbcolumn);
2305    num_i1=meshgrid(ind0_i,ind0_j);
2306    num_i2=num_i1;
2307    nbmissing=nbline*nbcolumn-length(ind_ij);
2308end
2309
2310%------------------------------------------------------------------------
2311% --- generates series of file indices corresponding to a file fileinput
2312function [num_i1,num_i2,num_j1,num_j2]=find_indexseries(fileinput)
2313%------------------------------------------------------------------------
2314num_i1=NaN;%default
2315num_i2=NaN;%default
2316num_j1=NaN;%default
2317num_j2=NaN;%default
2318% refresh input root name, indices, file extension and nomenclature
2319[RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
2320if strcmp(SubDir,'')
2321    filebasesub=fullfile(RootPath,RootFile);
2322else
2323    filebasesub=fullfile(RootPath,SubDir,RootFile);
2324end
2325dirpair=[]; %default
2326switch NomType
2327    case '_1'
2328        dirpair=dir([filebasesub '_*' FileExt]);
2329    case '_1_1'
2330        dirpair=dir([filebasesub '_*_*' FileExt]);
2331    case '_i1-i2'
2332        dirpair=dir([filebasesub '_*-*' FileExt]);
2333    case '1_ab'
2334        dirpair=dir([filebasesub '*_*' FileExt]);
2335    case '_i_j1-j2'
2336        dirpair=dir([filebasesub '*_*-*' FileExt]);   
2337    case '_i1-i2_j'
2338        dirpair=dir([filebasesub '*-*_*' FileExt]);   
2339end
2340for ifile=1:length(dirpair)
2341    [RootPath,RF,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
2342    num_i1(ifile)=str2double(str_1);
2343    num_i2(ifile)=str2double(str_2);
2344    if isnan(num_i2(ifile))
2345        num_i2(ifile)=num_i1(ifile);
2346    end
2347    num_j1(ifile)=stra2num(str_a);
2348    if isnan(num_j1(ifile))
2349        num_j1(ifile)=1;
2350    end
2351    num_j2(ifile)=stra2num(str_b);
2352    if isnan(num_j2(ifile))
2353        num_j2(ifile)=num_j1(ifile);
2354    end
2355end
2356
Note: See TracBrowser for help on using the repository browser.