source: trunk/src/series.m @ 118

Last change on this file since 118 was 118, checked in by gostiaux, 10 years ago

Champs reconnu par ses paires sans temps

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