source: trunk/src/series.m @ 76

Last change on this file since 76 was 76, checked in by sommeria, 11 years ago

minor bug repairs. Projection on any abject inside the main uvmat axes is now possible
aver_stat, time_series, merge_proj: set_object now called by tag instead of name (which depends on the object)

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