source: trunk/src/series.m @ 232

Last change on this file since 232 was 206, checked in by sommeria, 14 years ago

bug fixes to deal with volumes, storage of ACTION menu in series fixed

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