source: trunk/src/series.m @ 188

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

various bug repairs and cleaning

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