source: trunk/src/series.m @ 179

Last change on this file since 179 was 179, checked in by sommeria, 13 years ago

various bug repairs, in particular for 3D fields

File size: 93.6 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'));
1017% time=[];
1018% ref_time=[];
1019 ref_time=0;
1020% if isfield(SeriesData,'Time')&~isempty(SeriesData.Time{Val})&~isequal(SeriesData.Time{Val},0)
1021%     time=SeriesData.Time{Val}; %get the set of times
1022%     siztime=size(time);
1023%     nbfield=siztime(1);
1024%     nbfield2=siztime(2);
1025% %     test_imadoc=1;
1026% else
1027%     test_imadoc=0;%no image documentation file
1028    nbfield=50;
1029    nbfield2=50;%default max number of pairs
1030% end
1031%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1032% be performed, while the result is needed for next steps.
1033displ_pair={''};
1034displ_num=[];
1035ind_exist=0;
1036TimeUnit=get(handles.TimeUnit,'String');
1037if length(TimeUnit)>=1
1038    dtunit=['m' TimeUnit];
1039else
1040    dtunit='e-03';
1041end
1042if strcmp(mode,'series(Di)')
1043    nbfield
1044     for index=1:min(nbfield-1,50)
1045         filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
1046         select=(exist(filename,'file')==2);
1047         if select==1
1048               ind_exist=ind_exist+1;
1049                displ_num(1,ind_exist)=0;
1050                displ_num(2,ind_exist)=0;
1051                displ_num(3,ind_exist)=-floor(index/2);
1052                displ_num(4,ind_exist)=ceil(index/2);
1053                %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1054                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1055                if isfield(Cte,'dt2')
1056                    dt=Cte.dt2;
1057                elseif isfield(Cte,'dt')
1058                    dt=Cte.dt;
1059                end
1060                if isfield(Cte,'absolut_time_TO_2')
1061                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1062                elseif isfield(Cte,'absolut_time_TO')
1063                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1064                elseif isfield(Cte,'Time')
1065                    ref_time(ind_exist)=Cte.Time;
1066                end
1067                displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1068         end
1069     end
1070     set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
1071elseif isequal(mode,'series(Dj)')% series on the j index
1072       for index=1:min(nbfield2-1,50)
1073           filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
1074           select=(exist(filename,'file')==2);
1075           if select==1
1076               ind_exist=ind_exist+1;
1077                displ_num(1,ind_exist)=-floor(index/2);
1078                displ_num(2,ind_exist)=ceil(index/2);
1079                displ_num(3,ind_exist)=0;
1080                displ_num(4,ind_exist)=0;
1081                %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1082                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1083                if isfield(Cte,'dt2')
1084                    dt=Cte.dt2;
1085                elseif isfield(Cte,'dt')
1086                    dt=Cte.dt;
1087                end
1088                if isfield(Cte,'absolut_time_TO_2')
1089                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1090                elseif isfield(Cte,'absolut_time_TO')
1091                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1092                elseif isfield(Cte,'Time')
1093                    ref_time(ind_exist)=Cte.Time;
1094                end
1095%                 if cte_detect(2)==1;
1096%                     dt=cte_read(2);
1097%                     ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
1098%                 else
1099%                     dt=cte_read(1);
1100%                     ref_time(ind_exist)=cte_read(3);
1101%                 end
1102                displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1103           end
1104       end
1105       set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
1106elseif isequal(mode,'bursts') %case of bursts
1107    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
1108        for numod_b=(numod_a+1):nbfield2
1109            [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir);
1110            select=(exist(filename,'file')==2);
1111            if select==1
1112                ind_exist=ind_exist+1;
1113                numlist_a(ind_exist)=numod_a;
1114                numlist_b(ind_exist)=numod_b;
1115                Attr=nc2struct(filename,[]);
1116                isfield(Attr,'absolut_time_T0_2')
1117                if isfield(Attr,'dt2')
1118                   dt(ind_exist)=Attr.dt2;
1119                   ref_time(ind_exist)=Attr.absolut_time_T0_2;
1120                elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
1121                   dt(ind_exist)=Attr.dt;
1122                   ref_time(ind_exist)=Attr.absolut_time_T0;
1123                else
1124                   dt(ind_exist)=NaN;%no information on dt
1125                end
1126                %determine nom_type_ima for pair display (used in num2stra.m)
1127                switch NomType
1128                    case {'#ab'}
1129                        nom_type_ima='#a';
1130                    case {'#AB'}
1131                        nom_type_ima='#A';
1132                    otherwise
1133                         nom_type_ima='_i_j';
1134                end
1135               displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
1136                        ' :dt= ' num2str(dt(ind_exist)*1000)];
1137            end
1138         end
1139         set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
1140     end
1141     if exist('dt','var') & ~isempty(dt)
1142         [dtsort,indsort]=sort(dt);
1143         displ_num(1,:)=numlist_a(indsort);
1144         displ_num(2,:)=numlist_b(indsort);
1145         displ_num(3,:)=0;
1146         displ_num(4,:)=0;
1147         displ_pair=displ_pair(indsort);
1148         ref_time=ref_time(indsort);
1149     end
1150end
1151if ind_exist==0
1152         if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1153            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
1154        else
1155            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1156        end
1157        if isequal(mode,'bursts') %case of bursts
1158            set(handles.list_pair_civ,'String',{'j=*-*'});
1159        elseif isequal(mode,'series(Di)') %case of bursts
1160            set(handles.list_pair_civ,'String',{'Di=*|*'});
1161        elseif isequal(mode,'series(Dj)') %case of bursts
1162            set(handles.list_pair_civ,'String',{'Dj=*|*'});
1163        end
1164end
1165
1166val=get(handles.list_pair_civ,'Value');
1167if val > length(displ_pair)
1168    set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1169    val=1;
1170end
1171iview=get(handles.NomType,'Value');
1172SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1173SeriesData.ref_time=ref_time;
1174set(handles.figure1,'UserData',SeriesData)
1175list_pair_civ_Callback(hObject, eventdata, handles)
1176
1177%-------------------------------------------------------------
1178% --- Executes on selection in list_pair_civ.
1179function list_pair_civ_Callback(hObject, eventdata, handles)
1180%------------------------------------------------------------
1181
1182%update first_i and last_i according to the chosen image pairs
1183testupdate=0;
1184Val=get(handles.RootPath,'Value');
1185IndexCell=get(handles.NomType,'String');
1186%hseries=get(handles.list_pair_civ,'parent');
1187SeriesData=get(handles.figure1,'UserData');
1188NomType=SeriesData.NomType{Val};
1189list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1190index_pair=get(handles.list_pair_civ,'Value');
1191str_pair=list_pair{index_pair};
1192ind_equ=strfind(str_pair,'=');%find '='
1193ind_sep=strfind(str_pair,'|');%find pair separator '|'
1194ind_com=strfind(str_pair,':');%find ':'
1195test_bursts=0;
1196if isempty(ind_sep)
1197    ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
1198    test_bursts=1;% we are in the case of bursts
1199end
1200displ_num=[0 0 0 0]; %default
1201if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
1202    num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1203    num2_str=str_pair(ind_sep+1:ind_com-1);
1204    num1=str2double(num1_str);
1205    num2=str2double(num2_str);
1206    if isequal(num1_str(1),' ')
1207        num1_str(1)=[];
1208    end   
1209    if isequal(num2_str(end),' ')
1210        num2_str(end)=[];
1211    end
1212    switch NomType
1213       case {'_i1-i2_j'}
1214           if isequal(num1_str(1),'0')
1215               IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1216           else
1217               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1218           end
1219           displ_num(3)=num1;
1220           displ_num(4)=num2;
1221       case {'_i1-i2'}
1222           if isequal(num1_str(1),'0')
1223               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1224           else
1225               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1226           end
1227           displ_num(3)=num1;
1228           displ_num(4)=num2;
1229       case '_i_j1-j2'
1230          if test_bursts
1231              IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1232          else
1233              if isequal(num1_str(1),'0')
1234                 IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1235              else
1236                 IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1237              end
1238          end
1239          displ_num(1)=num1;
1240          displ_num(2)=num2;
1241       case {'#_ab'} %TO COMPLETE
1242           IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1243
1244    end
1245end
1246set(handles.NomType,'String',IndexCell)
1247SeriesData.displ_num(Val,:)=displ_num;
1248set(handles.figure1,'UserData',SeriesData)
1249% set(handles.NomType,'Value',Val)
1250
1251if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1252        mode_list=get(handles.mode,'String');
1253    mode_value=get(handles.mode,'Value');
1254    mode=mode_list{mode_value};
1255        if isequal(mode,'series(Di)')
1256        first_i=str2num(get(handles.first_i,'String'));
1257        last_i=str2num(get(handles.last_i,'String'));
1258        incr_i=str2num(get(handles.incr_i,'String'));
1259        num1=first_i:incr_i:last_i;
1260        lastfieldCell=get(handles.nb_field,'String');
1261        lastfield=str2num(lastfieldCell{1});
1262        if ~isempty(lastfield)
1263            ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1264            num1=num1(ind);       
1265        end
1266        if ~isempty(num1)
1267            set(handles.first_i,'String',num2str(num1(1)));
1268            set(handles.last_i,'String',num2str(num1(end)));
1269        end
1270        testupdate=1;
1271        elseif isequal(mode,'series(Dj)')
1272        first_j=str2num(get(handles.first_j,'String'));
1273        last_j=str2num(get(handles.last_j,'String'));
1274        incr_j=str2num(get(handles.incr_j,'String'));
1275        num_j=first_j:incr_j:last_j;
1276        lastfieldCell=get(handles.nb_field2,'String');
1277        if ~isempty(lastfieldCell)
1278            lastfield2=lastfieldCell{1};
1279            ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1280                 (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1281        end
1282        testupdate=1;
1283        end
1284       
1285        %update the first and last times of the series
1286        if testupdate && isfield(SeriesData,'Time')
1287        if ~isempty(SeriesData.Time{1})
1288            displ_time(handles,SeriesData.Time{1});
1289        end
1290        end
1291end
1292
1293%------------------------------------------------------------------------
1294% --- Executes on button press in RUN.
1295function RUN_Callback(hObject, eventdata, handles)
1296%------------------------------------------------------------------------
1297%read root name and field type
1298set(handles.RUN,'BusyAction','queue');
1299%hseries=get(handles.RUN,'parent');
1300set(0,'CurrentFigure',handles.figure1)
1301if isequal(get(handles.GetObject,'Visible'),'on') && isequal(get(handles.GetObject,'Value'),1)
1302    Series.GetObject=1;
1303    GetObject_Callback(hObject, eventdata, handles)
1304else
1305    Series.GetObject=0;
1306end
1307SeriesData=get(handles.figure1,'UserData');
1308
1309%reinitiate waitbar position
1310Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1311waitbarpos=Series.WaitbarPos;
1312waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1313waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1314set(handles.waitbar,'Position',waitbarpos)
1315
1316% read input file parameters and set menus
1317Series.PathProject=get(handles.PathCampaign,'String');
1318RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1319RootFile=get(handles.RootFile,'String');% root name of the first field series
1320SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1321FileExt=get(handles.FileExt,'String');%file extension
1322if isempty(SeriesData)
1323    msgbox_uvmat('ERROR','no input file series')
1324    return
1325end
1326NomType=SeriesData.NomType;
1327if length(RootPath)==1 %string character input for user fct
1328    Series.RootPath=RootPath{1};
1329    Series.RootFile=RootFile{1};
1330    Series.SubDir=SubDir{1};
1331    Series.FileExt=FileExt{1};
1332    Series.NomType=NomType{1};
1333else %cell input for user fct
1334    Series.RootPath=RootPath;
1335    Series.RootFile=RootFile;
1336    Series.SubDir=SubDir;
1337    Series.FileExt=FileExt;
1338    Series.NomType=NomType;
1339end
1340if isequal(get(handles.FieldMenu,'Visible'),'on')
1341    FieldMenu=get(handles.FieldMenu,'String');
1342    FieldValue=get(handles.FieldMenu,'Value');
1343    Series.Field=FieldMenu(FieldValue);
1344end
1345menu_coord_state=get(handles.transform_fct,'Visible');
1346Series.CoordType='';%default
1347if isequal(menu_coord_state,'on')
1348%     menu_coord=get(handles.transform_fct,'String');
1349    menu_index=get(handles.transform_fct,'Value');
1350    transform_list=get(handles.transform_fct,'UserData');
1351    Series.transform_fct=transform_list{menu_index};% transform function handles
1352end
1353Series.hseries=handles.figure1; % handles to the series GUI
1354
1355%read the set of field numbers
1356first_i=str2num(get(handles.first_i,'String'));
1357last_i=str2num(get(handles.last_i,'String'));
1358incr_i=str2num(get(handles.incr_i,'String'));
1359first_j=str2num(get(handles.first_j,'String'));
1360last_j=str2num(get(handles.last_j,'String'));
1361incr_j=str2num(get(handles.incr_j,'String'));
1362if ~isequal(get(handles.first_i,'Visible'),'on')
1363   first_i=1;
1364   last_i=1;
1365   incr_i=1;
1366end
1367if ~isequal(get(handles.first_j,'Visible'),'on')
1368    first_j=1;
1369    last_j=1;
1370    incr_j=1;
1371end
1372Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1373if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1374    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1375if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1376    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1377if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1378    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1379if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1380    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1381num_i=[first_i:incr_i:last_i];
1382num_j=[first_j:incr_j:last_j];
1383nbfield_cell=get(handles.nb_field,'String');
1384nbfield=[]; %default
1385for iview=1:length(nbfield_cell)
1386    nb=str2num(nbfield_cell{iview});
1387    if ~isempty(nb)
1388        nbfield=[nbfield nb];
1389    end
1390end
1391nbfield=min(nbfield);
1392nbfield2_cell=get(handles.nb_field2,'String');
1393nbfield2=[]; %default
1394for iview=1:length(nbfield2_cell)
1395    nb=str2num(nbfield2_cell{iview});
1396    if ~isempty(nb)
1397        nbfield2=[nbfield2 nb];
1398    end
1399end
1400nbfield2=min(nbfield2);
1401
1402%get complementary information from the 'series' interface
1403list_action=get(handles.ACTION,'String');% list menu action
1404index_action=get(handles.ACTION,'Value');% selected string index
1405action= list_action{index_action}; % selected string
1406mode_list=get(handles.mode,'String');
1407index_mode=get(handles.mode,'Value');
1408mode=mode_list{index_mode};
1409ind_shift=0;%default
1410
1411%determine the list of input file names
1412nbmissing=0;
1413for iview=1:length(RootPath)
1414    %case of pairs (.nc files)
1415   
1416    if isequal(NomType{iview},'_i_j1-j2')|| isequal(NomType{iview},'_i1-i2_j')|| isequal(NomType{iview},'_i1-i2')|| isequal(NomType{iview},'#_ab')
1417        ind_shift=SeriesData.displ_num(iview,:);
1418        if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1419            if isequal(NomType{iview},'#_ab')
1420                mode='#_ab';
1421            end
1422            [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);
1423        else   
1424            [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1425            if isempty(num_i)
1426                msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1427                return
1428            end
1429            if num_i(1)>first_i
1430               set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1431               last_i_Callback(hObject, eventdata, handles)
1432            end
1433            if num_i(end)<last_i
1434               set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1435               last_i_Callback(hObject, eventdata, handles)
1436            end
1437            if num_j(1)>first_j
1438               set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1439               last_j_Callback(hObject, eventdata, handles)
1440            end
1441            if num_j(end)<last_j
1442               set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1443               last_j_Callback(hObject, eventdata, handles)
1444            end
1445        end
1446    else%case of images
1447        [num_i1,num_j1]=meshgrid(num_i,num_j);
1448        num_i2=num_i1;
1449        num_j2=num_j1;
1450    end
1451    if length(RootPath)>1
1452        num_i1_cell{iview}=num_i1;
1453        num_i2_cell{iview}=num_i2;
1454        num_j1_cell{iview}=num_j1;
1455        num_j2_cell{iview}=num_j2;
1456    end
1457end
1458
1459% defining the ACTION function handle
1460path_series=which('series');
1461list_path=get(handles.ACTION,'UserData');
1462index=get(handles.ACTION,'Value');
1463fct_path=list_path{index}; %path stored for the function ACTION
1464if ~isequal(fct_path,path_series)
1465    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1466    if ~exist(fct_path,'dir')
1467        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
1468        return
1469    end
1470    if ~isequal(spath,fct_path)
1471        addpath(fct_path)% add the prescribed path if not the current one
1472    end
1473end
1474eval(['h_fun=@' action ';'])%create a function handle for ACTION
1475if ~isequal(fct_path,path_series)
1476        rmpath(fct_path)% add the prescribed path if not the current one   
1477end
1478
1479% RUN ACTION
1480Series.Action=action;%name of the processing programme
1481set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1482
1483if length(RootPath)>1
1484    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1485else
1486    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
1487end
1488set(handles.RUN,'BackgroundColor',[1 0 0])
1489
1490% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1491% detect=1;
1492% while detect==1
1493%     namefigfull=[namedoc '.fig'];
1494%     hh=dir(namefigfull);
1495%     if ~isempty(hh)
1496%         detect=1;
1497%         namedoc=[namedoc '.0'];
1498%     else
1499%         detect=0;
1500%     end
1501% end
1502% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1503
1504%------------------------------------------------------------------------
1505function STOP_Callback(hObject, eventdata, handles)
1506%------------------------------------------------------------------------
1507set(handles.RUN, 'BusyAction','cancel')
1508set(handles.RUN,'BackgroundColor',[1 0 0])
1509
1510
1511%------------------------------------------------------------------------
1512function first_i_Callback(hObject, eventdata, handles)
1513%------------------------------------------------------------------------
1514last_i_Callback(hObject, eventdata, handles)
1515
1516%------------------------------------------------------------------------
1517function last_i_Callback(hObject, eventdata, handles)
1518%------------------------------------------------------------------------
1519%     hseries=get(handles.last_i,'parent');
1520% first_i=str2num(get(handles.first_i,'String'));
1521% last_i=str2num(get(handles.last_i,'String'));
1522% ref_i=ceil((first_i+last_i)/2);
1523% set(handles.ref_i,'String', num2str(ref_i))
1524% ref_i_Callback(hObject, eventdata, handles)
1525SeriesData=get(handles.figure1,'UserData');
1526if ~isfield(SeriesData,'Time')
1527    SeriesData.Time{1}=[];
1528end
1529displ_time(handles,SeriesData.Time{1});
1530
1531%------------------------------------------------------------------------
1532function first_j_Callback(hObject, eventdata, handles)
1533%------------------------------------------------------------------------
1534 last_j_Callback(hObject, eventdata, handles)
1535
1536%------------------------------------------------------------------------
1537function last_j_Callback(hObject, eventdata, handles)
1538%------------------------------------------------------------------------
1539first_j=str2num(get(handles.first_j,'String'));
1540last_j=str2num(get(handles.last_j,'String'));
1541ref_j=ceil((first_j+last_j)/2);
1542set(handles.ref_j,'String', num2str(ref_j))
1543ref_j_Callback(hObject, eventdata, handles)
1544SeriesData=get(handles.figure1,'UserData');
1545if ~isfield(SeriesData,'Time')
1546    SeriesData.Time{1}=[];
1547end
1548displ_time(handles,SeriesData.Time{1});
1549
1550
1551%------------------------------------------------------------------------
1552function ref_i_Callback(hObject, eventdata, handles)
1553%------------------------------------------------------------------------
1554mode_list=get(handles.mode,'String');
1555mode_value=get(handles.mode,'Value');
1556mode=mode_list{mode_value};
1557%hseries=get(handles.ref_i,'parent');
1558SeriesData=get(handles.figure1,'UserData');
1559%NomTypeCell=get(handles.NomType,'String');
1560NomTypeCell=SeriesData.NomType;
1561if ~isempty(NomTypeCell)
1562Val=get(handles.NomType,'Value');
1563NomType=NomTypeCell{Val};
1564% for ilist=1:length(NomType)
1565    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1566        if isequal(mode,'series(Di)')
1567            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1568%             break
1569        end
1570    end
1571end
1572
1573%------------------------------------------------------------------------
1574function ref_j_Callback(hObject, eventdata, handles)
1575%------------------------------------------------------------------------
1576mode_list=get(handles.mode,'String');
1577mode_value=get(handles.mode,'Value');
1578mode=mode_list{mode_value};
1579%hseries=get(handles.ref_i,'parent');
1580SeriesData=get(handles.figure1,'UserData');
1581NomTypeCell=SeriesData.NomType;
1582if ~isempty(NomTypeCell)
1583    Val=get(handles.NomType,'Value');
1584    NomType=NomTypeCell{Val};
1585    if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
1586        if isequal(mode,'series(Dj)')
1587            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1588        end
1589    end
1590end
1591
1592%------------------------------------------------------------------------
1593% --- Executes on selection change in ACTION.
1594function ACTION_Callback(hObject, eventdata, handles)
1595%------------------------------------------------------------------------
1596global nb_builtin
1597list_ACTION=get(handles.ACTION,'String');% list menu fields
1598index_ACTION=get(handles.ACTION,'Value');% selected string index
1599ACTION= list_ACTION{index_ACTION}; % selected function name
1600path_series=which('series');%path to series.m
1601list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1602default_file=fullfile(list_path{end},ACTION);
1603% add a new function to the menu if the selected item is 'more...'
1604if isequal(ACTION,'more...')
1605    pathfct=fileparts(path_series);
1606    [FileName, PathName, filterindex] = uigetfile( ...
1607       {'*.m', ' (*.m)';
1608        '*.m',  '.m files '; ...
1609        '*.*', 'All Files (*.*)'}, ...
1610        'Pick a file',default_file);
1611    if length(FileName)<2
1612        return
1613    end
1614    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1615    if ~isequal(ext_fct,'.m')
1616        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1617        return
1618    end
1619   
1620   % insert the choice in the action menu
1621   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1622   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1623   list_path{index_ACTION}=PathName;
1624   if length(menu_str)>nb_builtin+5; %nb_builtin=nbre of functions always remaining in the initial menu
1625       nbremove=length(menu_str)-nb_builtin-5;
1626       menu_str(nb_builtin+1:end-5)=[];
1627       list_path(nb_builtin+1:end-4)=[];
1628       index_ACTION=index_ACTION-nbremove;
1629       set(handles.ACTION,'Value',index_ACTION)
1630       set(handles.ACTION,'String',menu_str)
1631   end
1632   list_path{index_ACTION}=PathName;
1633   set(handles.ACTION,'UserData',list_path);
1634   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1635   
1636   %record the current menu in personal file profil_perso
1637   dir_perso=prefdir;
1638   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1639   for ilist=nb_builtin+1:length(menu_str)-1
1640       series_fct{ilist-nb_builtin}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);
1641   end
1642   if exist(profil_perso,'file')
1643        save(profil_perso,'series_fct','-append')
1644   else
1645    txt=ver('MATLAB');
1646    Release=txt.Release;
1647        relnumb=str2num(Release(3:4));
1648        if relnumb >= 14
1649            save(profil_perso,'series_fct','-V6')
1650        else
1651            save(profil_perso, 'series_fct')
1652        end
1653   end
1654end
1655
1656%check the current path to the selected function
1657PathName=list_path{index_ACTION};%current recorded path
1658set(handles.path,'String',PathName); %show the path to the senlected function
1659
1660%default setting for the visibility of the GUI elements
1661set(handles.RootPath,'UserData','many')
1662set(handles.SubDir,'Visible','on')
1663set(handles.RootFile,'Visible','on')
1664set(handles.NomType,'Visible','on')
1665set(handles.FileExt,'Visible','on')
1666set(handles.NbSlice,'Visible','off')
1667set(handles.NbSlice_title,'Visible','off')
1668set(handles.VelTypeMenu,'Visible','off');
1669set(handles.VelType_text,'Visible','off');
1670set(handles.VelTypeMenu_1,'Visible','off');
1671set(handles.VelType_text_1,'Visible','off');
1672view_FieldMenu(handles,'off')
1673view_FieldMenu_1(handles,'off')
1674view_TRANSFORM(handles,'off')
1675set(handles.ProjObject_frame,'Visible','off');
1676set(handles.GetMask,'Visible','off')
1677set(handles.Mask,'Visible','off')
1678set(handles.GetObject,'Visible','off');
1679set(handles.ProjObject,'Visible','off');
1680set(handles.OutputDir,'Visible','off');
1681set(handles.PARAMETERS_frame,'Visible','off');
1682set(handles.PARAMETERS_title,'Visible','off');
1683set(handles.ParamKey,'Visible','off')
1684set(handles.ParamVal,'Visible','off')
1685ParamKey={};
1686set(handles.FieldMenu,'Enable','off')
1687set(handles.VelTypeMenu,'Enable','off')
1688set(handles.FieldMenu_1,'Enable','off')
1689set(handles.VelTypeMenu_1,'Enable','off')
1690set(handles.transform_fct,'Enable','off')
1691%set the displayed GUI item needed for input parameters
1692if ~isequal(path_series,PathName)
1693    addpath(PathName)
1694end
1695eval(['h_function=@' ACTION ';']);
1696[fid,errormsg] =fopen([ACTION '.m']);
1697InputText=textscan(fid,'%s',1,'delimiter','\n');
1698fclose(fid)
1699if ~isequal(path_series,PathName)
1700    rmpath(PathName)
1701end
1702set(handles.ACTION,'ToolTipString',InputText{1}{1})
1703varargout=h_function();
1704Param_list={};
1705
1706%nb_series=length(RootFile);
1707FileExt=get(handles.FileExt,'String');
1708nb_series=length(FileExt);
1709testima_series=1; %test for a list of images only
1710testima=1;
1711testima_1=1;
1712testciv_series=1;
1713for iview=1:nb_series
1714    ext=FileExt{iview};
1715    if length(ext)<2
1716        ext='.none';
1717    end
1718    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1719    if ~testimaview
1720        if iview==1
1721            testima=0;
1722        end
1723        if iview==2
1724            testima_1=0;
1725        end
1726        testima_series=0;
1727    end
1728end
1729for ilist=1:length(varargout)-1
1730    switch varargout{ilist}
1731                       %RootFile always visible
1732         case 'RootPath'   %visible by default
1733            value=lower(varargout{ilist+1});
1734            if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1735                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1736            end
1737        case 'SubDir' %visible by default
1738            if isequal(lower(varargout{ilist+1}),'off')
1739                set(handles.SubDir,'Visible','off')
1740            end
1741        case 'RootFile'   %visible by default
1742            value=lower(varargout{ilist+1});
1743            if isequal(value,'off')
1744                set(handles.RootFile,'Visible','off')
1745            elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1746                set(handles.RootFile,'Visible','on')
1747                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1748            end
1749        case 'NomType'   %visible by default
1750            if isequal(lower(varargout{ilist+1}),'off')
1751                set(handles.NomType,'Visible','off')
1752            end
1753        case 'FileExt'   %visible by default
1754            if isequal(lower(varargout{ilist+1}),'off')
1755                set(handles.FileExt,'Visible','off')
1756            end
1757        case 'NbSlice'   %hidden by default
1758            if isequal(lower(varargout{ilist+1}),'on')
1759                set(handles.NbSlice,'Visible','on')
1760                set(handles.NbSlice_title,'Visible','on')
1761            end
1762        case 'VelTypeMenu'   %hidden by default
1763            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1764                set(handles.VelTypeMenu,'Enable','on')
1765                if nb_series >=1 && ~testima_series
1766                    set(handles.VelTypeMenu,'Visible','on')
1767                    set(handles.VelType_text,'Visible','on');
1768                    set(handles.Field_frame,'Visible','on')
1769                end
1770            end
1771            if isequal(lower(varargout{ilist+1}),'two')
1772                set(handles.VelTypeMenu_1,'Enable','on')
1773                if nb_series >=2 && ~testima_series
1774                    set(handles.VelTypeMenu_1,'Visible','on')
1775                    set(handles.VelType_text_1,'Visible','on');
1776                end
1777            end
1778        case 'FieldMenu'   %hidden by default
1779            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1780                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1781                if nb_series >=1 && ~testima_series
1782                    view_FieldMenu(handles,'on')
1783                end
1784            end
1785            if isequal(lower(varargout{ilist+1}),'two')
1786                set(handles.FieldMenu_1,'Enable','on')
1787                if nb_series >=2 && ~testima_1
1788                    view_FieldMenu_1(handles,'on')
1789                end
1790            end
1791        case 'CoordType'   %hidden by default
1792            if isequal(lower(varargout{ilist+1}),'on')
1793                set(handles.transform_fct,'Enable','on')
1794                view_TRANSFORM(handles,'on')
1795            end
1796        case 'GetObject'   %hidden by default
1797            if isequal(lower(varargout{ilist+1}),'on')   
1798                set(handles.ProjObject_frame,'Visible','on')
1799                set(handles.GetObject,'Visible','on');
1800            end
1801        case 'Mask'   %hidden by default
1802            if isequal(lower(varargout{ilist+1}),'on')   
1803                set(handles.ProjObject_frame,'Visible','on')
1804                set(handles.GetMask,'Visible','on');
1805            end
1806        case 'PARAMETER' 
1807            set(handles.PARAMETERS_frame,'Visible','on')
1808            set(handles.PARAMETERS_title,'Visible','on')
1809            set(handles.ParamKey,'Visible','on')
1810            %set(handles.ParamVal,'Visible','on')
1811            Param_str=varargout{ilist+1};
1812            Param_list=[Param_list; {Param_str}];         
1813    end
1814end
1815if ~isempty(Param_list)
1816    set(handles.ParamKey,'String',Param_list)
1817    set(handles.ParamVal,'Visible','on')
1818end
1819
1820%------------------------------------------------------------------------
1821% --- Executes on selection change in FieldMenu.
1822function FieldMenu_Callback(hObject, eventdata, handles)
1823%------------------------------------------------------------------------
1824field_str=get(handles.FieldMenu,'String');
1825field_index=get(handles.FieldMenu,'Value');
1826field=field_str{field_index(1)};
1827if isequal(field,'get_field...')   
1828     hget_field=findobj(allchild(0),'name','get_field');
1829     if ~isempty(hget_field)
1830         delete(hget_field)%delete opened versions of get_field
1831     end
1832     %hseries=get(handles.FieldMenu,'parent');
1833     SeriesData=get(handles.figure1,'UserData');
1834     filename=SeriesData.CurrentInputFile;
1835     if exist(filename,'file')
1836        get_field(filename)
1837     end
1838elseif isequal(field,'more...')
1839    str=calc_field;
1840    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1841                'SelectionMode','single',...
1842                'ListString',str);
1843       % edit the choice in the fields and action menu
1844     scalar=cell2mat(str(ind_answer));
1845     update_menu(handles.FieldMenu,scalar)
1846end
1847
1848%------------------------------------------------------------------------
1849% --- Executes on selection change in FieldMenu_1.
1850function FieldMenu_1_Callback(hObject, eventdata, handles)
1851%------------------------------------------------------------------------
1852field_str=get(handles.FieldMenu_1,'String');
1853field_index=get(handles.FieldMenu_1,'Value');
1854field=field_str{field_index};
1855if isequal(field,'get_field...')   
1856     hget_field=findobj(allchild(0),'name','get_field_1');
1857     if ~isempty(hget_field)
1858         delete(hget_field)
1859     end
1860     %hseries=get(handles.FieldMenu,'parent');
1861     SeriesData=get(handles.figure1,'UserData');
1862     filename=SeriesData.CurrentInputFile_1;
1863     if exist(filename,'file')
1864        hget_field=get_field(filename);
1865        set(hget_field,'name','get_field_1')
1866     end
1867elseif isequal(field,'more...')
1868    str=calc_field;
1869    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1870                'SelectionMode','single',...
1871                'ListString',str);
1872       % edit the choice in the fields and action menu
1873     scalar=cell2mat(str(ind_answer));
1874     update_menu(handles.FieldMenu_1,scalar)
1875end   
1876
1877%-----------------------------
1878function mouse_up_gui(ggg,eventdata,handles)
1879if isequal(get(ggg,'SelectionType'),'alt')
1880    display('global CurData, UserData of GUI series')
1881    global CurData
1882    CurData=get(ggg,'UserData');
1883    evalin('base','global CurData');%make CurData global in the workspace
1884    evalin('base','CurData'); %display CurData in the workspace
1885    commandwindow
1886   % plot_text(CurData)
1887end
1888
1889%%%%%%%%%%%%%
1890function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1891
1892        indsel=ind_i;
1893        indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1894        indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1895        if ~isempty(indiff)
1896            indiff2=diff(indiff);
1897            indiffp=[indiff2 1];
1898            indiffm=[1 indiff2];
1899            ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1900            ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1901                %for each multiplet, select the most recent file
1902            ind_remove=[];
1903            for i=1:length(ind_multi_m)
1904                ind_pairs=ind_multi_m(i):ind_multi_p(i);
1905                for imulti=1:length(ind_pairs)
1906                    datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1907                end
1908                [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1909                ind_s=indsort2(1:end-1);%
1910                ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1911            end
1912        end
1913
1914%------------------------------------------------------------------------
1915% --- determine the list of index pairs of processing file
1916function [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)
1917%------------------------------------------------------------------------
1918num_i1=num_i;% set of first image numbers by default
1919num_i2=num_i;
1920num_j1=num_j;
1921num_j2=num_j;
1922num_i_out=num_i;
1923num_j_out=num_j;
1924if isequal (NomType,'_i1-i2_j') || isequal (NomType,'_i1-i2')
1925    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1926    num_i2_line=num_i+ind_shift(4);
1927    % adjust the first and last field number
1928        indsel=find(num_i1_line >= 1);
1929    num_i_out=num_i(indsel);
1930    num_i1_line=num_i1_line(indsel);
1931    num_i2_line=num_i2_line(indsel);
1932    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1933    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1934    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1935    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1936elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
1937    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1938        num_j1=ind_shift(1)*ones(size(num_i));
1939        num_j2=ind_shift(2)*ones(size(num_i));
1940    else
1941        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1942        num_j2_col=num_j+ind_shift(2);
1943        % adjust the first field number
1944        indsel=find((num_j1_col >= 1));   
1945        num_j_out=num_j(indsel);
1946        num_j1_col=num_j1_col(indsel);
1947        num_j2_col=num_j2_col(indsel);
1948        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1949        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1950    end   
1951end
1952
1953%------------------------------------------------------------------------
1954% ---- find the times corresponding to the first and last indices of a series
1955function displ_time(handles,times)
1956%------------------------------------------------------------------------
1957hseries=get(handles.last_i,'parent');
1958SeriesData=get(hseries,'UserData');%
1959first_i=str2num(get(handles.first_i,'String'));
1960first_j=str2num(get(handles.first_j,'String'));
1961last_i=str2num(get(handles.last_i,'String'));
1962last_j=str2num(get(handles.last_j,'String'));
1963% index_civ=get(handles.list_pair_civ,'Value');
1964% NomType=get(handles.NomType,'String');
1965NomType=SeriesData.NomType;
1966mode_list=get(handles.mode,'String');
1967index_mode=get(handles.mode,'Value');
1968mode=mode_list{index_mode};
1969% ind_shift=0;%default
1970
1971time_first=[];
1972time_last=[];
1973if ~isfield(SeriesData,'Time')
1974    SeriesData.Time{1}=[];
1975end
1976for iview=1:length(NomType)
1977    time_first_cell{iview}='?';
1978    time_last_cell{iview}='?';%default
1979    time=SeriesData.Time{iview};
1980    if isequal(NomType{iview},'_i1-i2_j')|isequal(NomType{iview},'_i_j1-j2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_i1-i2')
1981        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1982            ind_shift=SeriesData.displ_num(iview,:);
1983            if isequal(mode,'bursts')
1984                first_j=0;
1985                last_j=0;
1986            end
1987            first_i1=first_i +ind_shift(3);
1988            first_i2 =first_i +ind_shift(4);
1989            first_j1 =first_j +ind_shift(1);
1990            first_j2 =first_j +ind_shift(2);
1991            last_i1=last_i +ind_shift(3);
1992            last_i2 =last_i +ind_shift(4);   
1993            last_j1 =last_j +ind_shift(1);
1994            last_j2 =last_j +ind_shift(2);
1995            siz=size(SeriesData.Time{1});
1996            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1997                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1998                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1999            else%read the time in the nc files
2000                RootPath=get(handles.RootPath,'String');
2001                RootFile=get(handles.RootFile,'String');
2002                SubDir=get(handles.SubDir,'String');
2003                %VelType=get(handles.VelType,'String');
2004                VelType_str=get(handles.VelTypeMenu,'String');
2005                VelType_val=get(handles.VelTypeMenu,'Value');
2006                VelType=VelType_str{VelType_val};
2007                filebase=fullfile(RootPath{1},RootFile{1});
2008                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
2009                if  exist(filefirst,'file')
2010                    Attrib=nc2struct(filefirst,[]);
2011                    if isfield(Attrib,'Time')
2012                        time_first=Attrib.Time;
2013                    else
2014                        if isfield(Attrib,'absolut_time_T0')
2015                            time_first=Attrib.absolut_time_T0;
2016                        end
2017                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2018                            time_first=Attrib.absolut_time_T0_2;
2019                        end
2020                    end
2021                end
2022                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
2023                if exist(filelast,'file')
2024                   Attrib=nc2struct(filelast,[]);
2025                    if isfield(Attrib,'Time')
2026                        time_last=Attrib.Time;
2027                    else
2028                        if isfield(Attrib,'absolut_time_T0')
2029                            time_last=Attrib.absolut_time_T0;
2030                        end
2031                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
2032                            time_last=Attrib.absolut_time_T0_2;
2033                        end
2034                    end
2035                end
2036            end
2037        end
2038    else
2039        siz=size(times);
2040        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
2041            time_first=times(first_i,first_j);
2042            time_last=times(last_i,last_j);
2043        end
2044    end
2045    time_first_cell{iview}=num2str(time_first,4);
2046    time_last_cell{iview}=num2str(time_last,4);
2047end
2048set(handles.time_first,'Value',1)
2049set(handles.time_last,'Value',1)
2050set(handles.time_first,'String',time_first_cell);
2051set(handles.time_last,'String',time_last_cell);
2052
2053%------------------------------------------------------------------------
2054% --- Executes on button press in GetObject.
2055function GetObject_Callback(hObject, eventdata, handles)
2056%------------------------------------------------------------------------
2057hseries=get(handles.GetObject,'parent');
2058SeriesData=get(hseries,'UserData');
2059value=get(handles.GetObject,'Value');
2060if value
2061     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2062%      DataInit.ParentButton=handles.GetObject;
2063     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2064     if ishandle(hset_object)
2065         uistack(hset_object,'top')
2066        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2067     else
2068         %get the object file
2069         defaultname=get(handles.RootPath,'String');
2070         if isempty(defaultname)
2071            defaultname={''};
2072         end
2073        [FileName, PathName, filterindex] = uigetfile( ...
2074       {'*.xml;*.mat', ' (*.xml,*.mat)';
2075       '*.xml',  '.xml files '; ...
2076        '*.mat',  '.mat matlab files '}, ...
2077        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
2078        fileinput=[PathName FileName];%complete file name
2079        testblank=findstr(fileinput,' ');%look for blanks
2080        if ~isempty(testblank)
2081            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
2082            return
2083        end
2084        sizf=size(fileinput);
2085        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2086        %read the file
2087        t=xmltree(fileinput);
2088        data=convert(t);
2089        if ~isfield(data,'Style')
2090             data.Style='points';
2091        end
2092        if ~isfield(data,'ProjMode')
2093             data.ProjMode='projection';
2094        end
2095        transform_menu=get(handles.transform_fct,'String');
2096        ichoice=get(handles.transform_fct,'Value');
2097%         if isequal(transform_menu{ichoice},'px');
2098%             data.CoordType='px';
2099%         else
2100%             data.CoordType='phys';
2101%         end
2102        data.desable_plot=1;
2103        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2104     end
2105else
2106    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2107%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2108%         close(SeriesData.hset_object)
2109%     end
2110end
2111set(hseries,'UserData',SeriesData)
2112
2113%--------------------------------------------------------------
2114function GetMask_Callback(hObject, eventdata, handles)
2115value=get(handles.GetMask,'Value');
2116if value
2117    msgbox_uvmat('ERROR','not implemented yet')
2118end
2119%--------------------------------------------------------------
2120
2121%-------------------------------------------------------------------
2122%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2123function ncbrowser_uvmat(hObject, eventdata)
2124%-------------------------------------------------------------------
2125     bla=get(gcbo,'String');
2126     ind=get(gcbo,'Value');
2127     filename=cell2mat(bla(ind));
2128      blank=find(filename==' ');
2129      filename=filename(1:blank-1);
2130     get_field(filename)
2131
2132% ------------------------------------------------------------------
2133function MenuHelp_Callback(hObject, eventdata, handles)
2134%-------------------------------------------------------------------
2135path_to_uvmat=which ('uvmat');% check the path of uvmat
2136pathelp=fileparts(path_to_uvmat);
2137helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2138if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2139else
2140    addpath (fullfile(pathelp,'uvmat_doc'))
2141    web([helpfile '#series'])
2142end
2143
2144%-------------------------------------------------------------------
2145% --- Executes on selection change in transform_fct.
2146function transform_fct_Callback(hObject, eventdata, handles)
2147%-------------------------------------------------------------------
2148global nb_transform
2149
2150% huvmat=get(handles.transform_fct,'parent');
2151menu=get(handles.transform_fct,'String');
2152ind_coord=get(handles.transform_fct,'Value');
2153coord_option=menu{ind_coord};
2154list_transform=get(handles.transform_fct,'UserData');
2155ff=functions(list_transform{end});
2156if isequal(coord_option,'more...');
2157    coord_fct='';
2158    prompt = {'Enter the name of the transform function'};
2159    dlg_title = 'user defined transform';
2160    num_lines= 1;
2161    [FileName, PathName, filterindex] = uigetfile( ...
2162       {'*.m', ' (*.m)';
2163        '*.m',  '.m files '; ...
2164        '*.*', 'All Files (*.*)'}, ...
2165        'Pick a file', ff.file);
2166    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2167        PathName(end)=[];
2168    end
2169    transform_selected =fullfile(PathName,FileName);
2170    if ~exist(transform_selected,'file')
2171          return
2172    end
2173    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2174    if ~isequal(ext_fct,'.m')
2175        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2176        return
2177    end
2178   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2179   ind_coord=get(handles.transform_fct,'Value');
2180   addpath(PathName)
2181   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2182   set(handles.transform_fct,'UserData',list_transform)
2183   rmpath(PathName)
2184   % save the new menu in the personal file 'uvmat_perso.mat'
2185   dir_perso=prefdir;%personal Matalb directory
2186   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2187   if exist(profil_perso,'file')
2188       for ilist=nb_transform+1:numel(list_transform)
2189           ff=functions(list_transform{ilist});
2190           transform_fct{ilist-nb_transform}=ff.file;
2191       end
2192        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2193   end
2194end
2195
2196%check the current path to the selected function
2197func=functions(list_transform{ind_coord});
2198set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2199
2200%------------------------------------------------------------------------
2201% --- generates a series of file names with reference numbers between range1 and
2202% --- range2 with increment incr. The reference number num_ref is the image number at the middle of the
2203% --- image pair. The set of first numbers num1 of the image pairs is also
2204% --- given as output
2205function [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)
2206%------------------------------------------------------------------------
2207[Path,Name]=fileparts(filebase);
2208filebasesub=fullfile(Path,subdir,Name);
2209filecell={};%default
2210num_i1=[];
2211num_i2=[];
2212num_j1=[];
2213num_j2=[];
2214ind0_i=first_i:incr_i:last_i;
2215nbcolumn=length(ind0_i);
2216ind0_j=first_j:incr_j:last_j;
2217nbline=length(ind0_j);
2218if isequal(mode,'#_ab')
2219    dirpair=dir([filebasesub '*_*.nc']);
2220elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)') 
2221    dirpair=dir([filebasesub '_*_*-*.nc']);
2222elseif isequal(mode,'series(Di)')
2223    dirpair=dir([filebasesub '_*-*_*.nc']);
2224else
2225    msgbox_uvmat('ERROR','option *|* not yet implemented')
2226    return
2227end
2228if isempty(dirpair)
2229        msgbox_uvmat('ERROR','no pair detected in the selected range')
2230        return
2231end
2232
2233if isequal(mode,'bursts')||isequal(mode,'#_ab')
2234    icount=0;
2235    for ifile=1:length(dirpair)
2236        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2237        num1_r=str2num(str_1);
2238        if isequal(RootFile,Name) & ~isempty(num1_r)   
2239            num_i1(ifile)=num1_r;
2240            num_a(ifile)=stra2num(str_a);
2241            num_b(ifile)=stra2num(str_b);
2242        end     
2243    end
2244    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
2245    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
2246    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
2247    ind_i=ind_i(select);%set of selected indices ind_i
2248    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
2249    select=select(indsort);
2250    num_i1=num_i1(select);
2251    num_a=num_a(select);
2252    num_b=num_b(select);
2253    dirpair=dirpair(select);
2254    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
2255    ind_i(ind_remove)=[];
2256    num_a(ind_remove)=[];
2257    num_b(ind_remove)=[];
2258    num_j1=zeros(1,nbcolumn);%default
2259    num_j2=num_j1;
2260    num_j1(ind_i)=num_a;
2261    num_j2(ind_i)=num_b;
2262    num_i1=first_i:incr_i:last_i;
2263    num_i2=num_i1;
2264    nbmissing=nbcolumn-length(ind_i);
2265
2266elseif isequal(mode,'series(Di)')
2267    %ind0_i=first_i:incr_i:last_i;
2268    %nbcolumn=length(ind0_i);
2269    %ind0_j=first_j:incr_j:last_j;
2270    %nbline=length(ind0_j);
2271    %dirpair=dir([filebasesub '_*-*_*.nc']);
2272    for ifile=1:length(dirpair)
2273        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2274        num_i1_r(ifile)=str2num(str_1);
2275        num_i2_r(ifile)=str2num(str_2);
2276        num_j(ifile)=str2num(str_a);
2277    end
2278    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
2279    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
2280    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2281    ind_j=((num_j-first_j)/incr_j)+1;
2282    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2283    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2284    ind_ij=ind_ij(select);%set of selected indices ind_ij
2285    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2286    select=select(indsort);
2287    num_i1_r=num_i1_r(select);
2288    num_i2_r=num_i2_r(select);
2289    dirpair=dirpair(select);
2290    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2291    ind_ij(ind_remove)=[];
2292    num_i1_r(ind_remove)=[];
2293    num_i2_r(ind_remove)=[];
2294    num_i1=zeros(1,nbline*nbcolumn);%default
2295    num_i2=num_i1;
2296    num_i1(ind_ij)=num_i1_r;
2297    num_j2(ind_ij)=num_i2_r;
2298    num_i1=reshape(num_i1,nbline,nbcolumn);
2299    num_i2=reshape(num_i2,nbline,nbcolumn);
2300    num_j1=meshgrid(ind0_i,ind0_j);
2301    num_j2=num_j1;
2302    nbmissing=nbline*nbcolumn-length(ind_ij);
2303elseif isequal(mode,'series(Dj)')
2304    for ifile=1:length(dirpair)
2305        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2306        num_i(ifile)=str2num(str_1);
2307        num_a(ifile)=str2num(str_a);
2308        num_b(ifile)=str2num(str_b);
2309    end
2310    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
2311    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
2312    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2313    ind_j=((num_j-first_j)/incr_j)+1;
2314    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2315    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2316    ind_ij=ind_ij(select);%set of selected indices ind_ij
2317    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2318    select=select(indsort);
2319    num_i=num_i(select);
2320    num_a=num_a(select);
2321    num_b=num_b(select);
2322    dirpair=dirpair(select);
2323    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2324    ind_ij(ind_remove)=[];
2325    num_a(ind_remove)=[];
2326    num_b(ind_remove)=[];
2327    num_j1=zeros(1,nbline*nbcolumn);%default
2328    num_j2=num_j1;
2329    num_j1(ind_ij)=num_a;
2330    num_j2(ind_ij)=num_b;
2331    num_j1=reshape(num_j1,nbline,nbcolumn);
2332    num_j2=reshape(num_j2,nbline,nbcolumn);
2333    num_i1=meshgrid(ind0_i,ind0_j);
2334    num_i2=num_i1;
2335    nbmissing=nbline*nbcolumn-length(ind_ij);
2336end
2337
2338%------------------------------------------------------------------------
2339% --- generates series of file indices corresponding to a file fileinput
2340function [num_i1,num_i2,num_j1,num_j2]=find_indexseries(fileinput)
2341%------------------------------------------------------------------------
2342num_i1=NaN;%default
2343num_i2=NaN;%default
2344num_j1=NaN;%default
2345num_j2=NaN;%default
2346% refresh input root name, indices, file extension and nomenclature
2347[RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
2348if strcmp(SubDir,'')
2349    filebasesub=fullfile(RootPath,RootFile);
2350else
2351    filebasesub=fullfile(RootPath,SubDir,RootFile);
2352end
2353dirpair=[]; %default
2354switch NomType
2355    case '_i'
2356        dirpair=dir([filebasesub '_*' FileExt]);
2357    case '_i_j'
2358        dirpair=dir([filebasesub '_*_*' FileExt]);
2359    case '_i1-i2'
2360        dirpair=dir([filebasesub '_*-*' FileExt]);
2361    case '#_ab'
2362        dirpair=dir([filebasesub '*_*' FileExt]);
2363    case '_i_j1-j2'
2364        dirpair=dir([filebasesub '*_*-*' FileExt]);   
2365    case '_i1-i2_j'
2366        dirpair=dir([filebasesub '*-*_*' FileExt]);   
2367end
2368%       nom_type='#' series of indexed images wich is not series_i
2369%       [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'
2370%       nom_type='#a','#A' with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j')
2371%       nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif'
2372%       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'
2373%       nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE
2374%       nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
2375%       nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')
2376for ifile=1:length(dirpair)
2377    [RootPath,RF,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
2378    num_i1(ifile)=str2double(str_1);
2379    num_i2(ifile)=str2double(str_2);
2380    if isnan(num_i2(ifile))
2381        num_i2(ifile)=num_i1(ifile);
2382    end
2383    num_j1(ifile)=stra2num(str_a);
2384    if isnan(num_j1(ifile))
2385        num_j1(ifile)=1;
2386    end
2387    num_j2(ifile)=stra2num(str_b);
2388    if isnan(num_j2(ifile))
2389        num_j2(ifile)=num_j1(ifile);
2390    end
2391end
2392
Note: See TracBrowser for help on using the repository browser.