source: trunk/src/series.m @ 243

Last change on this file since 243 was 238, checked in by sommeria, 14 years ago

various bug corrections

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