source: trunk/src/series.m @ 257

Last change on this file since 257 was 252, checked in by sommeria, 14 years ago

various bugs corrected.

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