source: trunk/src/series.m @ 342

Last change on this file since 342 was 342, checked in by sommeria, 12 years ago

various bugs corrected

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