source: trunk/src/civ.m @ 287

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

further cleaning after new GUI civ. The function mouse_alt_gui allows to zoom out a uicontrol and edit it

File size: 218.3 KB
RevLine 
[112]1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
[2]2%------------------------------------------------------------------------
3%  provides an interface for the software CIVx
4% function varargout = civ(varargin)
5% provides an interface for the software CIVx
6%
7%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[282]8%  Copyright Joel Sommeria, 2011, LEGI / CNRS-UJF-INPG, sommeria@legi.grenoble-inp.fr
[2]9%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
[112]10%     This file is part of the toolbox UVMAT.
11%
[2]12%     UVMAT is free software; you can redistribute it and/or modify
13%     it under the terms of the GNU General Public License as published by
14%     the Free Software Foundation; either version 2 of the License, or
15%     (at your option) any later version.
[112]16%
[2]17%     UVMAT is distributed in the hope that it will be useful,
18%     but WITHOUT ANY WARRANTY; without even the implied warranty of
19%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
21%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
22function varargout = civ(varargin)
[273]23%TODO: search range
[2]24
[287]25% Last Modified by GUIDE v2.5 19-Nov-2011 10:00:27
[2]26% Begin initialization code - DO NOT EDIT
27gui_Singleton = 1;
28gui_State = struct('gui_Name',       mfilename, ...
[112]29    'gui_Singleton',  gui_Singleton, ...
30    'gui_OpeningFcn', @civ_OpeningFcn, ...
31    'gui_OutputFcn',  @civ_OutputFcn, ...
32    'gui_LayoutFcn',  [] , ...
33    'gui_Callback',   []);
[2]34if nargin && ischar(varargin{1})
35    gui_State.gui_Callback = str2func(varargin{1});
36end
37
38if nargout
39    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
40else
41    gui_mainfcn(gui_State, varargin{:});
42end
43% End initialization code - DO NOT EDIT
44
[12]45%------------------------------------------------------------------------
[2]46% --- Executes just before civ is made visible.
[71]47function civ_OpeningFcn(hObject, eventdata, handles, param)
[12]48%------------------------------------------------------------------------
[2]49% This function has no output args, see OutputFcn.
[112]50%filebase: root name
[2]51%nom_type: nomencalture used ('png_old','_i_j'...)
52%list of field numbers to process
[112]53%subdir: subdirectory of the opened netcdf file
[282]54%ind_opening: operation number advised for beginning (1=checkciv1,2=checkfix1,3=checkpatch1,4=checkciv2,5=checkfix2,6=checkpatch2),
[2]55%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
56% Choose default command line output for civ
57handles.output = hObject;
58% Update handles structure
59guidata(hObject, handles);
[252]60set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display)
[2]61%default initial parameters
62filebase=''; % root file name ('filebase'.civ)
63ext=[];
[252]64
[273]65%% read names of the .exe file to adjust the interface according to available binaries
[276]66%path_uvmat=which('uvmat');% check the path detected for source file uvmat
67path_civ=fileparts(which('civ')); %path to civ
68addpath (path_civ) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
[273]69errormsg=[];%default error message
70xmlfile='PARAM.xml';
71if exist(xmlfile,'file')
72    try
73        t=xmltree(xmlfile);
74        sparam=convert(t);
75    catch
76        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
77        return
78    end
79else
80    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
81    return
82end
83if ~isempty(errormsg)
84    msgbox_uvmat('ERROR',errormsg);
85end
86
87test_batch=0;%default: ,no batch mode available
88if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode')
89    test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
90end
91if test_batch==0
92    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
93    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
94end
95if isfield(sparam.RunParam,'CivBin')
96    if ~exist(sparam.RunParam.CivBin,'file')
[276]97        sparam.RunParam.CivBin=fullfile(path_civ,sparam.RunParam.CivBin);
[273]98    end
99else
100    sparam.RunParam.CivBin='';
101end
102
103%% load the list of previously browsed files in menu Open
104 dir_perso=prefdir; % path to the directory .matlab for personal data
105 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
106 if exist(profil_perso,'file')
107      h=load (profil_perso);
108      if isfield(h,'MenuFile')
109          set(handles.MenuFile_1,'Label',h.MenuFile{1})
110          %set(handles.MenuFile_1,'Label',h.MenuFile_1);
111      end
112%       if isfield(h,'MenuFile_2')
113%           set(handles.MenuFile_2,'Label',h.MenuFile_2);
114%       end
115%       if isfield(h,'MenuFile_3')
116%           set(handles.MenuFile_3,'Label',h.MenuFile_3);
117%       end
118%       if isfield(h,'MenuFile_4')
119%           set(handles.MenuFile_4,'Label',h.MenuFile_4);
120%       end
121%       if isfield(h,'MenuFile_5')
122%           set(handles.MenuFile_5,'Label',h.MenuFile_5);
123%       end
124end
125
[71]126%default input parameters:
[153]127num_i1=1; % set of field i numbers
128num_i2=1; % set of field i numbers
129num_j1=1; % set of field j numbers (fields a)
130num_j2=1; % second set of field j numbers (fields b)
[273]131%subdir='A'; % subdir for the netcdf result files
132ind_opening=0; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
[112]133%load the initial parameters if the interface is started from uvmat
[71]134if exist('param','var')&&isstruct(param)% the interface is opened from uvmat
135    filebase=param.RootName;
136    nom_type_read=param.NomType;
[153]137    num_i1=param.num1;
138    if isnan(num_i1),num_i1=1;end
139    num_i2=param.num2;
140    if isnan(num_i2),num_i2=num_i1;end
141    num_j1=param.num_a;
142    if isnan(num_j1),num_j1=1;end
143    num_j2=param.num_b;
144    if isnan(num_j2),num_j2=num_j1;end
[71]145    subdir=param.SubDir;
146    ind_opening=param.IndOpening;
147    ext=param.ImaExt;
[2]148end
[153]149browse.num_i1=num_i1;
150browse.num_i2=num_i2;
151browse.num_j1=num_j1;
152browse.num_j2=num_j2;
[122]153if ~isempty(ext) && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
[112]154    set(handles.ImaExt,'String',ext)
[128]155    browse.ext_ima=ext;
[112]156    if exist('nom_type_read','var')
157        browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
158    end
[2]159elseif isequal(ext,'.nc')
160    if exist('nom_type_read','var')
161        browse.nom_type_nc=nom_type_read;% the netcdf  nomenclature is stored
162    end
163end
[71]164set(handles.RootName,'String',filebase);
[2]165set(handles.ImaDoc,'String',ext)
166
167%initiate advised operations
[273]168enable_civ1(handles,0)
169enable_civ2(handles,0)
170%enable_pair1(handles,'on')
171enable_fix1(handles,0)
172enable_patch1(handles,0)
173enable_fix2(handles,0)
174enable_patch2(handles,0)
[282]175set(handles.CheckCiv1,'Value',0)
176set(handles.CheckFix1,'Value',0)
177set(handles.CheckPatch1,'Value',0)
178set(handles.CheckCiv2,'Value',0)
179set(handles.CheckFix2,'Value',0)
180set(handles.CheckPatch2,'Value',0)
[273]181%set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
[2]182if isequal(ind_opening,1)
[282]183    set(handles.CheckCiv1,'Value',1)
[273]184    enable_civ1(handles,1)
[2]185elseif isequal(ind_opening,2)
[282]186    set(handles.CheckFix1,'Value',1)
[273]187    enable_fix1(handles,1)
[2]188elseif isequal(ind_opening,3)
[282]189    set(handles.CheckPatch1,'Value',1)
[273]190    enable_patch1(handles,1)
[2]191elseif isequal(ind_opening,4)
[282]192    set(handles.CheckCiv2,'Value',1)
[273]193    enable_civ2(handles,1)
[2]194elseif isequal(ind_opening,5)
[282]195    set(handles.CheckFix2,'Value',1)
[273]196    enable_fix2(handles,1)
[112]197    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
[282]198    set(handles.ListPairCiv2,'Enable','On')
199    set(handles.ListPairCiv2,'Enable','On')
[112]200    enable_pair1(handles,'off')
[2]201elseif isequal(ind_opening,6)
[282]202    set(handles.CheckPatch2,'Value',1)
[273]203    enable_patch2(handles,1)
[2]204    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
[282]205    set(handles.ListPairCiv2,'Enable','On')
[2]206    enable_pair1(handles,'off')
207end
208
209% set the range of fields (1:1 by default) and selected pair
[153]210if isequal(num_i2,num_i1)
211    num_ref_i=num_i1;
[2]212else
[153]213    num_ref_i=floor((num_i1+num_i2)/2);
214    browse.incr_pair(1)=num_i2-num_i1;
[2]215    browse.incr_pair(2)=0;
216end
[153]217if isequal(num_j1,num_j2)
218    if isnan(num_j1)
[2]219        num_ref_j=1;
220    else
[153]221        num_ref_j=num_j1;
[2]222    end
223else
[153]224    num_ref_j=floor((num_j1+num_j2)/2);
225    browse.incr_pair(2)=num_j2-num_j1;
[2]226end
227set(handles.first_i,'String',num2str(num_ref_i));
228set(handles.last_i,'String',num2str(num_ref_i));
229set(handles.first_j,'String',num2str(num_ref_j));
230set(handles.last_j,'String',num2str(num_ref_j));
231set(handles.ref_i,'String',num2str(num_ref_i));
232set(handles.ref_j,'String',num2str(num_ref_j));
[273]233% set(handles.ref_i_civ2,'String',num2str(num_ref_i));
234% set(handles.ref_j_civ2,'String',num2str(num_ref_j));
235set(handles.RootName,'UserData',browse);
[220]236if exist('param','var') && isfield(param,'RootName') && ~isempty(param.RootName)%varargin the interface is opened from uvmat
[112]237    RootName_Callback(hObject, eventdata, handles);
[2]238end
239
[12]240%------------------------------------------------------------------------
[2]241% --- Outputs from this function are returned to the command line.
242function varargout = civ_OutputFcn(hObject, eventdata, handles)
[12]243%------------------------------------------------------------------------
[2]244% varargout  cell array for returning output args (see VARARGOUT);
245% hObject    handle to figure
246% eventdata  reserved - to be defined in a future version of MATLAB
247% handles    structure with handles and user data (see GUIDATA)
248% Get default command line output from handles structure
249varargout{1} = handles.output;
250
[273]251% --------------------------------------------------------------------
252function MenuBrowse_Callback(hObject, eventdata, handles)
253
[2]254%get the input file properties
[71]255filebase=get(handles.RootName,'String');
[2]256oldfile=''; %default
[39]257if isempty(filebase)|| isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
[112]258    dir_perso=prefdir;
259    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
260    if exist(profil_perso,'file')
261        h=load (profil_perso);
262        if isfield(h,'filebase')&& ischar(h.filebase)
263            oldfile=h.filebase;
264        end
265        if isfield(h,'RootPath') && ischar(h.RootPath)
266            oldfile=h.RootPath;
267        end
268    end
269else
270    oldfile=filebase;
271end
[2]272ind_opening=1;%default
273browse.incr_pair=[0 0]; %default
[238]274menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
[174]275       '*.xml',  '.xml files '; ...
276        '*.civ',  '.civ files '; ...
277        '*.png','.png image files'; ...
278        '*.jpg',' jpeg image files'; ...
279        '*.tif','.tif image files'; ...
280        '*.avi;*.AVI','.avi movie files'; ...
281        '*.nc','.netcdf files'; ...
282        '*.*',  'All Files (*.*)'};
[2]283[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
[112]284fileinput=[PathName FileName];%complete file name
[2]285sizf=size(fileinput);
286if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
287[path,name,ext]=fileparts(fileinput);
288testeditxml=0;
289if isequal(ext,'.xml')
290    testeditxml=1;
291    t_browse=xmltree(fileinput);
292    head_element=get(t_browse,1);
[45]293    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
[2]294        testeditxml=0;
295    end
296end
[45]297if testeditxml==1 || isequal(ext,'.xls')
[112]298    heditxml=editxml({fileinput});
299    set(heditxml,'Tag','browser')
300    waitfor(heditxml,'Tag','idle')
301    if ~ishandle(heditxml)
302        return
303    end
304    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
305    set(handles.browse,'UserData',fileinput)% store for future opening with browser
306    fileinput=get(attr,'UserData');
307    if ~exist(fileinput,'file')
308        return
309    end
[2]310end
[82]311[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
[2]312filebase=fullfile(RootPath,RootFile);
[89]313num_i1=str2double(str1);
314if isnan(num_i1),num_i1=1;end
315num_i2=str2double(str2);
316if isnan(num_i2),num_i2=num_i1;end
[54]317num_j1=stra2num(str_a);
[89]318if isnan(num_j1),num_j1=1;end
[54]319num_j2=stra2num(str_b);
[112]320if isnan(num_j2),num_j2=num_j1;end
[282]321if isequal(get(handles.ListCompareMode,'Value'),1)
[2]322    browse=[];%initialisation
323else
[273]324    browse=get(handlesRootName,'UserData');
[2]325end
[122]326browse.num_i1=num_i1;
327browse.num_i2=num_i2;
328browse.num_j1=num_j1;
329browse.num_j2=num_j2;
330if length(ext)>1 && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
[2]331    browse.nom_type_ima=nom_type;
[122]332    browse.ext_ima=ext;
[177]333    set(handles.ImaExt,'String',ext)
[2]334end
335set(handles.ImaDoc,'String',ext);
336
337%%%%% read the state of the selected netcdf file to advise default operation
338if isequal(ext,'.nc')
339    browse.nom_type_nc=nom_type;
[112]340    ind_opening=2;% propose 'fix' as the default option
[246]341    Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','absolut_time_T0','fix','patch','civ2','fix2');
342    if ~isempty(Data.CivStage)%test for civ files
343        ind_opening=Data.CivStage;
[282]344        set(handles.ListPairMode,'Value',3)
[246]345    end
346    if ~isempty(Data.absolut_time_T0)%test for civx files
[282]347        set(handles.ListPairMode,'Value',1)
[2]348        if isfield(Data,'fix') && isequal(Data.fix,1)
349            ind_opening=3;
350        end
[246]351        if isequal(Data.patch,1)
[2]352            ind_opening=4;
353        end
[246]354        if isequal(Data.civ2,1)
[2]355            ind_opening=5;
356        end
[246]357        if  isequal(Data.fix2,1)
[2]358            ind_opening=6;
359        end
360        testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
361    else
[112]362        ind_opening=3; %GUI used only for patch
[2]363        testciv=0;
364    end
365    set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
366    set(handles.subdir_civ2,'String',subdir);
367    browse.testciv=testciv;
368    browse.ind_opening=ind_opening;
369end
[71]370set(handles.RootName,'String',filebase);
[2]371set(handles.ImaDoc,'String',ext);
[45]372if ~isempty(num_i1)
[82]373    ref_i=num_i1;
[45]374    if ~isempty(num_i2)
375        ref_i=floor((ref_i+num_i2)/2);% reference image number corresponding to the file
376        browse.incr_pair(1)=num_i2-num_i1;
[2]377        browse.incr_pair(2)=0;
378    end
379    set(handles.first_i,'String',num2str(ref_i));
380    set(handles.last_i,'String',num2str(ref_i));
[71]381    set(handles.ref_i,'String',num2str(ref_i));
[273]382%     set(handles.ref_i_civ2,'String',num2str(ref_i))
[2]383end
[45]384if isempty(num_j1)
[2]385    set(handles.ref_j,'String','1');
[71]386    set(handles.ref_j_civ2,'String','1');
[2]387else
[45]388    ref_j=num_j1;
389    if ~isempty(num_j2)
390        ref_j=floor((num_j1+num_j2)/2);
[112]391        browse.incr_pair(2)=num_j2-num_j1;
[2]392    end
393    set(handles.first_j,'String',num2str(ref_j));
394    set(handles.last_j,'String',num2str(ref_j));
[112]395    set(handles.ref_j,'String',num2str(ref_j));
[273]396%     set(handles.ref_j_civ2,'String',num2str(ref_j));
[2]397end
398
399% set default operation options
[273]400enable_civ1(handles,0)
401enable_civ2(handles,0')
[2]402enable_pair1(handles,'on')
[273]403enable_fix1(handles,0)
404enable_patch1(handles,0)
405enable_fix2(handles,0)
406enable_patch2(handles,0)
[282]407set(handles.CheckCiv1,'Value',0)
408set(handles.CheckFix1,'Value',0)
409set(handles.CheckPatch1,'Value',0)
410set(handles.CheckCiv2,'Value',0)
411set(handles.CheckFix2,'Value',0)
412set(handles.CheckPatch2,'Value',0)
[273]413% set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
[2]414if isequal(ind_opening,1)
[282]415    set(handles.CheckCiv1,'Value',1)
[2]416    enable_civ1(handles,'on')
417elseif isequal(ind_opening,2)
[282]418    set(handles.CheckFix1,'Value',1)
[2]419    enable_fix1(handles,'on')
420elseif isequal(ind_opening,3)
[282]421    set(handles.CheckPatch1,'Value',1)
[2]422    enable_patch1(handles)
423elseif isequal(ind_opening,4)
[282]424    set(handles.CheckCiv2,'Value',1)
[224]425    enable_civ2(handles,'on')
[2]426elseif isequal(ind_opening,5)
427    enable_pair1(handles,'off')
[282]428    set(handles.CheckFix2,'Value',1)
[2]429    enable_fix2(handles)
[112]430    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
[282]431    set(handles.ListPairCiv2,'Enable','On')
432    set(handles.ListPairCiv2,'Enable','On')
[2]433elseif isequal(ind_opening,6)
434    enable_pair1(handles,'off')
[282]435    set(handles.CheckPatch2,'Value',1)
[2]436    enable_patch2(handles)
437    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
[282]438    set(handles.ListPairCiv2,'Enable','On')
[2]439end
[273]440set(handles.RootName,'UserData',browse);% store information from browser
[71]441RootName_Callback(hObject, eventdata, handles);
[2]442
[273]443
444% -----------------------------------------------------------------------
445% --- Open again the file whose name has been recorded in MenuFile_1
446function MenuFile_1_Callback(hObject, eventdata, handles)
[12]447%------------------------------------------------------------------------
[273]448fileinput=get(handles.MenuFile_1,'Label');
449display_file_name(hObject, eventdata, handles,fileinput)
450
451% -----------------------------------------------------------------------
452% --- Open again the file whose name has been recorded in MenuFile_2
453function MenuFile_2_Callback(hObject, eventdata, handles)
454%------------------------------------------------------------------------
455fileinput=get(handles.MenuFile_2,'Label');
456display_file_name(hObject, eventdata, handles,fileinput)
457
458% -----------------------------------------------------------------------
459% --- Open again the file whose name has been recorded in MenuFile_3
460function MenuFile_3_Callback(hObject, eventdata, handles)
461%------------------------------------------------------------------------
462fileinput=get(handles.MenuFile_3,'Label');
463display_file_name(hObject, eventdata, handles,fileinput)
464
465% -----------------------------------------------------------------------
466% --- Open again the file whose name has been recorded in MenuFile_4
467function MenuFile_4_Callback(hObject, eventdata, handles)
468%------------------------------------------------------------------------
469fileinput=get(handles.MenuFile_4,'Label');
470display_file_name(hObject, eventdata, handles,fileinput)
471
472% -----------------------------------------------------------------------
473% --- Open again the file whose name has been recorded in MenuFile_5
474function MenuFile_5_Callback(hObject, eventdata, handles)
475%------------------------------------------------------------------------
476fileinput=get(handles.MenuFile_5,'Label');
477display_file_name(hObject, eventdata, handles,fileinput)
478
479%------------------------------------------------------------------------
[2]480function ImaDoc_Callback(hObject, eventdata, handles)
[12]481%------------------------------------------------------------------------
[71]482RootName_Callback(hObject, eventdata, handles)
[2]483
[12]484%------------------------------------------------------------------------
[54]485% --- function activated when a new filebase (image series) is introduced
[71]486function RootName_Callback(hObject, eventdata, handles)
[12]487%------------------------------------------------------------------------
[273]488filebase=get(handles.RootName,'String');
489display_file_name(hObject, eventdata, handles,filebase)
490
491%------------------------------------------------------------------------
492function display_file_name(hObject, eventdata, handles,filebase)
493%------------------------------------------------------------------------
[282]494set(handles.ListCompareMode,'Visible','on')
[122]495ext_ima='';%default
[2]496nom_type_ima=[];%default
497field_count=1;%default
498nom_type_nc=[];
499time=[];
[71]500TimeUnit='frame'; %default
501CoordUnit='px';%default
[2]502pxcmx_search=[];%default
503pxcmy_search=[];%default
[273]504
[128]505ext_imadoc=get(handles.ImaDoc,'String');
[273]506browse=get(handles.RootName,'UserData');%default
[122]507if isfield(browse,'nom_type_ima')
508    nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
[133]509end
510if isfield(browse,'ext_ima')
[122]511    ext_ima=browse.ext_ima;
[2]512end
[122]513if isfield(browse,'nom_type_nc')
514    nom_type_nc=browse.nom_type_nc;% get an image nomenclature type already determined by an input image name
515end
516if isfield(browse,'num_i1')
517    field_count=browse.num_i1;% get an image index type already determined by an input file
518end
[252]519set(handles.civ,'UserData',[]); %refresh list of previous civ files (for STATUS)
[2]520
521%default first_i and j and increments
[137]522first_i=str2double(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
523if isnan(first_i)|| first_i < 1
[2]524    first_i=1; %default first_i
525end
[137]526last_i=str2double(get(handles.last_i,'String'));
527if isnan(last_i)|| last_i < first_i
[2]528    last_i=first_i;  %default last_i
529end
[137]530first_j=str2double(get(handles.first_j,'String'));
531if isnan(first_j)|| first_j < 1
[2]532    first_j=1; %default first_j
533end
[137]534last_j=str2double(get(handles.last_j,'String'));
535if isnan(last_j)|| last_j < first_j
[2]536    last_j=first_j; %default last_j
537end
[137]538incr_i=str2double(get(handles.incr_i,'String'));
539if isnan(incr_i) || incr_i < 1;
[2]540    set(handles.incr_i,'String','1') %default incr_i
541end
[137]542incr_j=str2double(get(handles.incr_j,'String'));
543if isnan(incr_j) || incr_j < 1;
[2]544    set(handles.incr_j,'String','1') %default incr_j
545end
546dt=[];%default
547testmode=0;%default
548nbfield=[]; %default
549nburst=[];%default
550pxcmx=1;
[112]551pxcmy=1;
[2]552
[112]553%look for an image documentation file
[128]554if ~strcmp(ext_imadoc,'.xml') && ~strcmp(ext_imadoc,'.civ')&& ~strcmpi(ext_imadoc,'.avi')
[2]555    if exist([filebase '.xml'],'file')
[128]556        ext_imadoc='.xml';
[2]557    elseif exist([filebase '.civxml'],'file')
[128]558        ext_imadoc='.civxml';
[2]559    elseif exist([filebase '.civ'],'file')
[128]560        ext_imadoc='.civ';
[112]561    elseif exist([filebase '.avi'],'file')
[128]562        ext_imadoc='.avi';
[2]563    elseif exist([filebase '.AVI'],'file')
[128]564        ext_imadoc='.AVI';
[2]565    end
[128]566    set(handles.ImaDoc,'String',ext_imadoc)
[2]567end
568
569%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
[84]570mode=''; %default
571set(handles.ImaDoc,'BackgroundColor',[1 1 0])
572drawnow
[128]573if isequal(ext_imadoc,'.civxml') || isequal(ext_imadoc,'.xml')|| isequal(ext_imadoc,'.civ')
[2]574    set(handles.ref_i,'Visible','On')%use a reference index
575    set(handles.ref_j,'Visible','On')
[128]576elseif isequal(ext_imadoc,'.avi') || isequal(ext_imadoc,'.AVI')
[2]577    set(handles.ref_j,'Visible','Off')
578else
579    set(handles.ref_i,'Visible','Off')
580    set(handles.ref_j,'Visible','Off')
581end
[12]582testima_xml=0;
[128]583if isequal(ext_imadoc,'.civxml')%TO ABANDON
[122]584    [nbfield,nbfield2,time]=read_civxml([filebase '.civxml']);
[2]585    mode='pair j1-j2';
586    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
[112]587        nom_type_ima='_i_j';
[2]588    end
[128]589elseif isequal(ext_imadoc,'.xml')
[73]590    [XmlData,warntext]=imadoc2struct([filebase '.xml']);
[2]591    ext_ima_read=[];
592    nom_type_read=[];
[12]593    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
[2]594        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
[112]595        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
[45]596        if ~exist(fullname,'file')
[12]597            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
598        end
[2]599    end
[84]600    if isfield(XmlData,'Time')
[85]601        time=XmlData.Time;
[84]602        nbfield=size(time,1);
[122]603        nbfield2=size(time,2);
[127]604        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
[122]605        if isequal(nbfield,1) && ~isequal(nbfield2,1)% .Time is a line vector
[127]606            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D'))
[84]607                time=time';
[122]608                nbfield=nbfield2;
609                nbfield2=1;
[84]610            end
611        end
612    end
[71]613    if isfield(XmlData,'TimeUnit')
614        TimeUnit=XmlData.TimeUnit;
[2]615    end
[71]616    if isfield(XmlData,'Npx')
617        npx=XmlData.Npx;
618        npy=XmlData.Npy;
619    end
[2]620    pxcmx_search=1;
621    pxcmy_search=1;
622    if isfield(XmlData,'GeometryCalib')
623        tsai=XmlData.GeometryCalib;
[112]624        if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R')
625            rot2D=tsai.R(1:2,[1,2]);
626            pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
627            pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
[2]628        end
[112]629        if isfield(tsai,'CoordUnit')
630            CoordUnit=tsai.CoordUnit;
[2]631        end
[112]632    end
[128]633elseif strcmp(ext_imadoc,'.civ')% case of .civ image documentation file
[112]634    [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
635    if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
636    elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
637    end
[128]638    nom_type_ima='001a';
639elseif strcmpi(ext_imadoc,'.avi')
[112]640    nom_type_ima='*';
[128]641    ext_ima=ext_imadoc;
[282]642    set(handles.ListPairMode,'Value',1);
643    set(handles.ListPairMode,'String',{'series(Di)'})
[112]644    dt=0.04;%default
[128]645    if exist([filebase ext_imadoc],'file')==2
646        info=aviinfo([filebase ext_imadoc]);%read infos on the avi movie
[112]647        dt=1/info.FramesPerSecond;%time interval between successive frames
648        nbfield=info.NumFrames;%number of frames
649    end
650    time=(dt*(0:nbfield-1))';%list of image times
[2]651end
652if isempty(time)
653    set(handles.ImaDoc,'String',''); %xml file not used for timing
654end
655set(handles.ImaDoc,'BackgroundColor',[1 1 1])
656
[122]657%get the imabe nomenclature type if not defined by the input file nor by the xml file
658dirima=[];%default
[12]659if isempty(nom_type_ima)
660    %look for double image series '_i_j'
661    dirima=dir([filebase '_' num2str(first_i) '_' num2str(first_j) '.*']);
662    if isempty(dirima)
[112]663        % look for images series  with sub marker '_'
664        dirima=dir([filebase '_*' num2str(first_i) '.*']);
665        if isempty(dirima)
666            % look for other images series
667            dirima=dir([filebase '*' num2str(first_i) '.*']);
[122]668            if isempty(dirima)
669                % look for other images series witth letter appendix
670                appendix=char(96+first_j);
671                dirima=dir([filebase '*' num2str(first_i) appendix '.*']);
[112]672            end
673        end
[12]674    end
[112]675end
[122]676for ilist=1:numel(dirima)
677    [pp,ff,fc,str2,str_a,str_b,ext_list,nom_type_list]=name2display(dirima(ilist).name);
678    form=imformats(ext_list(2:end));
679    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
680        ext_ima=ext_list;
681        nom_type_ima=nom_type_list;
682            break
683    end
684end
685% no image documentation file found: look for a series of existing files,images by priority or .nc files
686if isempty(nom_type_ima)
[128]687    ext_search=ext_imadoc;
[122]688    nom_type_search=nom_type_nc;
689else
690    ext_search=ext_ima;
691    nom_type_search=nom_type_ima;
692end
693if isempty(time) && ~strcmp(nom_type_search,'none') && ~strcmp(nom_type_search,'') && ~strcmp(nom_type_search,'*')
[12]694    subdir=get(handles.subdir_civ1,'String');
695    incr_pair=[0 0];%default
696    if isfield(browse,'incr_pair')
[112]697        incr_pair=browse.incr_pair;
[12]698    end
[112]699    %     nbdetect=0;%test of detected images
[122]700    field_i=browse.num_i2;
[153]701    imagename=name_generator(filebase,field_i,1,ext_search,nom_type_search);
702    imagename_plus='';
[12]703    idetect=1;
[153]704    while idetect %look for the maximum file number in the series
705        imagename_plus=name_generator(filebase,field_i+1,1,ext_search,nom_type_search);
706        idetect=(exist(imagename_plus,'file')==2)&& ~strcmp(imagename,imagename_plus);
[81]707        if idetect
[12]708            field_i=field_i+1;
[81]709        end
[112]710        %SEE CASE OF NETCDF FILES
711        %             nbdetect=nbdetect+(exist(imagename,'file')==2);
[12]712    end
[122]713    nbfield=field_i;% last detected field number
714    field_i=browse.num_i1;%look for the minimum file number in the series
[153]715    imagename_min='';
[12]716    idetect=1;
[112]717    while idetect==1
[153]718        imagename_min=name_generator(filebase,field_i-1,1,ext_search,nom_type_search);
719        idetect=(exist(imagename_min,'file')==2)&& ~strcmp(imagename,imagename_min);
[81]720        if idetect
[112]721            field_i=field_i-1;
[81]722        end
[12]723    end
[122]724    first_i=max(field_i,1);
725    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
726        field_i=browse.num_i1;
727        field_j=browse.num_j2;
[177]728        imagename=name_generator(filebase,field_i,field_j,ext_search,nom_type_search);
[153]729        imagename_plus='';
[89]730        jdetect=1;
731        while jdetect==1 %look for the maximum file number in the series
[153]732            imagename_plus=name_generator(filebase,field_i,field_j+1,ext_search,nom_type_search);
733            jdetect=(exist(imagename_plus,'file')==2)&& ~strcmp(imagename,imagename_plus);
[89]734            if jdetect
735                field_j=field_j+1;
736            end
737            %SEE CASE OF NETCDF FILES
738            %             nbdetect=nbdetect+(exist(imagename,'file')==2);
739        end
[122]740        nbfield2=field_j;% last detected field number
[120]741     end
[122]742 
[89]743    %determine the set of times and possible intervals for CIV
[137]744    %   dt=(1/1000)*str2double(get(handles.dt,'String'));
[122]745    time=(0:nbfield-1)';% time=file index -1  by default
746    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
747        [x,y]=meshgrid(0:nbfield2-1,0:nbfield-1);
[120]748        time=x+y;
[89]749    end
[2]750end
[120]751
[2]752if exist('time','var')
753    if size(time,1)+size(time,2)>=3 % if there are at least two time values to define dt
754        nbfield=size(time,1);
755        nbfield2=size(time,2);
[273]756        set(handles.ImaDoc,'UserData',time); %store the set of times
[71]757        set(handles.dt_unit,'String',['dt in m' TimeUnit]);
[273]758%         set(handles.dt_unit_civ2,'String',['dt in m' TimeUnit]);
[71]759        set(handles.TimeUnit,'String',TimeUnit);
[2]760        set(handles.nb_field,'String',num2str(nbfield));
761        set(handles.nb_field2,'String',num2str(nbfield2));
762    end
763end
[71]764set(handles.CoordUnit,'String',CoordUnit)
[273]765set(handles.SearchRange,'UserData',[pxcmx_search pxcmy_search]);
[2]766% npxy=[npy npx];
[71]767set(handles.ImaExt,'String',ext_ima)
[2]768set(handles.first_i,'String',num2str(first_i));
769set(handles.last_i,'String',num2str(last_i));%
770set(handles.first_j,'String',num2str(first_j));
771set(handles.last_j,'String',num2str(last_j));%
772browse.nom_type_ima=nom_type_ima;
[273]773set(handles.RootName,'UserData',browse)% store the nomenclature type
[2]774
[273]775%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
[177]776test_ima_i=numel(nom_type_ima)>1 && isempty(regexp(nom_type_ima(2:end),'\D','once'));%images with single indexing
[122]777if test_ima_i || isequal(nom_type_nc,'_i1-i2')||~(exist('nbfield2','var')&&(nbfield2~=1))
[282]778    set(handles.ListPairMode,'Value',1)
779    set(handles.ListPairMode,'String',{'series(Di)'})   
[2]780elseif (nbfield==1)% simple series in j
[282]781    set(handles.ListPairMode,'Value',1)
782    set(handles.ListPairMode,'String',{'series(Dj)'})
[2]783else
[282]784    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
[122]785    if nbfield2 <= 10
[282]786        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' for small burst
[2]787    end
788end
789
790
[177]791%% desable status and RUN button
[2]792set(handles.RUN, 'Enable','On')
793set(handles.RUN,'BackgroundColor',[1 0 0])
[122]794set(handles.BATCH,'Enable','On')
795set(handles.BATCH,'BackgroundColor',[1 0 0])
[178]796if isfield(handles,'status')
[177]797set(handles.status,'Value',0);%suppress status display
798status_Callback(hObject, eventdata, handles)
[178]799end
[112]800
[177]801%% store the root input filename for future opening
[2]802dir_perso=prefdir;
803profil_perso=fullfile(prefdir,'uvmat_perso.mat');
804RootPath=fileparts(filebase);
805if exist(profil_perso,'file')
806    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
807else
[147]808    txt=ver('MATLAB');
809    Release=txt.Release;
[137]810    relnumb=str2double(Release(3:4));
[2]811    if relnumb >= 14
[112]812        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
[2]813    else
814        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
815    end
816end
817
[273]818%% update the subdir
819pathdir=fileparts(filebase);%path to the current xml file
820listot=dir(pathdir);
821idir=0;
822listdir={''};%default
823for ilist=1:length(listot)
824    if listot(ilist).isdir
825        name=listot(ilist).name;
826        if ~isequal(name,'.') && ~isequal(name,'..')
827            idir=idir+1;
828            listdir{idir,1}=listot(ilist).name;
829        end
830    end
831end
[282]832set(handles.ListSubdirCiv1,'Value',1)
833set(handles.ListSubDirCiv2,'Value',1)
834set(handles.ListSubdirCiv1,'String',[listdir;'new...'])
835set(handles.ListSubDirCiv2,'String',[listdir;'new...'])
[273]836if isempty(listdir)
837    dirname=listdir{1};
838else
839    dirname='CIV'; %default civ directory name
840end
841set(handles.subdir_civ1,'String',dirname)
842set(handles.subdir_civ2,'String',dirname)
843%check wether the current subdir exists:
844% subdir_civ1=get(handles.subdir_civ1,'String');
845% subdir_civ2=get(handles.subdir_civ2,'String');
846
[282]847ListPairMode_Callback(hObject, eventdata, handles)
[273]848
[12]849%------------------------------------------------------------------------
[282]850% --- Executes on button press in ListPairMode.
851function ListPairMode_Callback(hObject, eventdata, handles)
[12]852%------------------------------------------------------------------------
[273]853browse=get(handles.RootName,'UserData');
[282]854compare_list=get(handles.ListCompareMode,'String');
855val=get(handles.ListCompareMode,'Value');
[2]856compare=compare_list{val};
857if strcmp(compare,'displacement')
858    mode='displacement';
859else
[282]860    mode_list=get(handles.ListPairMode,'String');
[236]861    if ischar(mode_list)
862        mode_list={mode_list};
863    end
[282]864    mode_value=get(handles.ListPairMode,'Value');
[2]865    mode=mode_list{mode_value};
866end
867displ_num=[];%default
[137]868ref_i=str2double(get(handles.ref_i,'String'));
[2]869% last_i=str2num(get(handles.last_i,'String'));
[273]870time=get(handles.ImaDoc,'UserData'); %get the set of times
[2]871siztime=size(time);
872nbfield=siztime(1);
873nbfield2=siztime(2);
874indchosen=1;  %%first pair selected by default
875if isequal(mode,'pair j1-j2')%| isequal(mode,'st_pair j1-j2')
876    dt=1;
877    displ='';
878    index=0;
879    numlist_a=[];
880    numlist_B=[];
881    %get all the time intervals in bursts
882    displ_dt=1;%default
883    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
884    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
885        for numod_b=(numod_a+1):nbfield2
[112]886            index=index+1;
887            numlist_a(index)=numod_a;
888            numlist_b(index)=numod_b;
889            if ~isempty(time)
[54]890                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
[2]891                displ_dt(index)=dt(numod_a,numod_b);
[112]892            else
893                displ_dt(index)=1;
894            end
895        end
896    end
897    [dtsort,indsort]=sort(displ_dt);
898    if ~isempty(numlist_a)
899        displ_num(1,:)=numlist_a(indsort);
900        displ_num(2,:)=numlist_b(indsort);
901    end
902    displ_num(3,:)=0;
903    displ_num(4,:)=0;
904    set(handles.jtext,'Visible','Off')
[2]905    set(handles.first_j,'Visible','Off')
906    set(handles.last_j,'Visible','Off')
907    set(handles.incr_j,'Visible','Off')
908    set(handles.nb_field2,'Visible','Off')
909    set(handles.ref_j,'Visible','Off')
910elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
[112]911    for index=1:min(nbfield2-1,200)
912        displ_num(1,index)=-floor(index/2);
913        displ_num(2,index)=ceil(index/2);
914        displ_num(3,index)=0;
915        displ_num(4,index)=0;
916    end
917    set(handles.jtext,'Visible','On')
918    set(handles.first_j,'Visible','On')
919    set(handles.last_j,'Visible','On')
920    set(handles.incr_j,'Visible','On')
921    set(handles.nb_field2,'Visible','On')
922    set(handles.ref_j,'Visible','On')
923    if nbfield > 1
[2]924        set(handles.itext,'Visible','On')
925        set(handles.first_i,'Visible','On')
926        set(handles.last_i,'Visible','On')
927        set(handles.incr_i,'Visible','On')
928        set(handles.nb_field,'Visible','On')
929        set(handles.ref_i,'Visible','On')
930    else
931        set(handles.itext,'Visible','Off')
932        set(handles.first_i,'Visible','Off')
933        set(handles.last_i,'Visible','Off')
934        set(handles.incr_i,'Visible','Off')
935        set(handles.nb_field,'Visible','Off')
936        set(handles.ref_i,'Visible','Off')
937    end
[112]938elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
939    for index=1:200%min(nbfield-1,200)
940        displ_num(1,index)=0;
941        displ_num(2,index)=0;
942        displ_num(3,index)=-floor(index/2);
943        displ_num(4,index)=ceil(index/2);
944    end
945    set(handles.itext,'Visible','On')
946    set(handles.first_i,'Visible','On')
947    set(handles.last_i,'Visible','On')
948    set(handles.incr_i,'Visible','On')
949    set(handles.nb_field,'Visible','On')
950    set(handles.ref_i,'Visible','On')
951    if nbfield2 > 1
[2]952        set(handles.jtext,'Visible','On')
953        set(handles.first_j,'Visible','On')
954        set(handles.last_j,'Visible','On')
955        set(handles.incr_j,'Visible','On')
956        set(handles.nb_field2,'Visible','On')
957        set(handles.ref_j,'Visible','On')
[112]958    else
[2]959        set(handles.jtext,'Visible','Off')
960        set(handles.first_j,'Visible','Off')
961        set(handles.last_j,'Visible','Off')
962        set(handles.incr_j,'Visible','Off')
963        set(handles.nb_field2,'Visible','Off')
964        set(handles.ref_j,'Visible','Off')
965    end
966elseif isequal(mode,'displacement')%the pairs have the same indices
[112]967    displ_num(1,1)=0;
968    displ_num(2,1)=0;
969    displ_num(3,1)=0;
970    displ_num(4,1)=0;
971    if nbfield > 1
[2]972        set(handles.itext,'Visible','On')
973        set(handles.first_i,'Visible','On')
974        set(handles.last_i,'Visible','On')
975        set(handles.incr_i,'Visible','On')
976        set(handles.nb_field,'Visible','On')
977        set(handles.ref_i,'Visible','On')
978    else
979        set(handles.itext,'Visible','Off')
980        set(handles.first_i,'Visible','Off')
981        set(handles.last_i,'Visible','Off')
982        set(handles.incr_i,'Visible','Off')
983        set(handles.nb_field,'Visible','Off')
984        set(handles.ref_i,'Visible','Off')
985    end
986    if nbfield2 > 1
[112]987        set(handles.jtext,'Visible','On')
988        set(handles.first_j,'Visible','On')
989        set(handles.last_j,'Visible','On')
990        set(handles.incr_j,'Visible','On')
991        set(handles.nb_field2,'Visible','On')
992        set(handles.ref_j,'Visible','On')
[2]993    else
994        set(handles.jtext,'Visible','Off')
995        set(handles.first_j,'Visible','Off')
996        set(handles.last_j,'Visible','Off')
997        set(handles.incr_j,'Visible','Off')
998        set(handles.nb_field2,'Visible','Off')
999        set(handles.ref_j,'Visible','Off')
1000    end
[112]1001end
[282]1002set(handles.ListPairCiv1,'UserData',displ_num);
[2]1003find_netcpair_civ1(hObject, eventdata, handles)
1004find_netcpair_civ2(hObject, eventdata, handles)
1005
[12]1006%------------------------------------------------------------------------
[282]1007% determine the menu for checkciv1 pairs depending on existing netcdf file at the middle of
[2]1008% the field series set by first_i, incr, last_i
1009function find_netcpair_civ1(hObject, eventdata, handles)
[12]1010%------------------------------------------------------------------------
[2]1011set(gcf,'Pointer','watch')
1012%nomenclature types
[71]1013filebase=get(handles.RootName,'String');
[2]1014[filepath,Nme,ext_dir]=fileparts(filebase);
[273]1015browse=get(handles.RootName,'UserData');
[282]1016compare_list=get(handles.ListCompareMode,'String');
1017val=get(handles.ListCompareMode,'Value');
[2]1018compare=compare_list{val};
1019if strcmp(compare,'displacement')
1020    mode='displacement';
1021else
[282]1022    mode_list=get(handles.ListPairMode,'String');
1023    mode_value=get(handles.ListPairMode,'Value');
[273]1024    if isempty(mode_list)
1025        return
1026    end
[2]1027    mode=mode_list{mode_value};
1028end
1029
1030% nomenclature type of the .nc files
1031nom_type_ima=[];%default
1032if isfield(browse,'nom_type_ima')
1033    nom_type_ima=browse.nom_type_ima;
1034end
1035
[112]1036%determine nom_type_nc:
[2]1037nom_type_nc=[];%default
1038if isfield(browse,'nom_type_nc')
1039    nom_type_nc=browse.nom_type_nc;
1040end
1041if isempty(nom_type_nc)
[112]1042    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
[2]1043end
1044browse.nom_type_nc=nom_type_nc;
[273]1045set(handles.RootName,'UserData',browse)
[2]1046
1047%reads .nc subdirectoy and image numbers from the interface
1048subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
[45]1049ref_i=str2double(get(handles.ref_i,'String'));
[2]1050if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1051    ref_j=0;
1052else
[45]1053    ref_j=str2double(get(handles.ref_j,'String'));
[2]1054end
[273]1055time=get(handles.ImaDoc,'UserData');%get the set of times
[2]1056if isempty(time)
1057    time=[0 1];
[112]1058end
[71]1059dt_unit=1000;%default
[282]1060displ_num=get(handles.ListPairCiv1,'UserData');
[2]1061
[112]1062%eliminate the first pairs inconsistent with the position
1063if isempty(displ_num)
1064    nbpair=0;
1065else
[2]1066    nbpair=length(displ_num(1,:));%nbre of displayed pairs
1067    if  isequal(mode,'series(Di)')  %| isequal(mode,'st_series(Di)')
1068        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
1069    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1070        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1071    end
[112]1072end
[2]1073nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1074
[282]1075%look for existing processed pairs involving the field at the middle of the series if checkciv1 will not
[2]1076% be performed, while the result is needed for next steps.
1077displ_pair={''};
[273]1078select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
[2]1079testpair=0;
[282]1080% case with no checkciv1 operation, netcdf files need to exist for reading
1081if get(handles.CheckCiv1,'Value')==0 %
[112]1082    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
1083        msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
[282]1084        set(handles.ListPairCiv1,'String',{});
[112]1085        return
[2]1086    end
[112]1087    for ipair=1:nbpair
[2]1088        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1089            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[273]1090        select(ipair)=exist(filename,'file')==2;% put flag to 0 if the file does not exist
1091    end   
1092    % case of no displayed pair
1093    if isequal(select,zeros(size(1:nbpair)))
1094        if isfield(browse,'incr_pair') && ~isequal(browse.incr_pair,[0 0])
[2]1095            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1096            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
1097            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1098            num_j2=ref_j+ceil(browse.incr_pair(2)/2);
1099            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
1100            select(1)=exist(filename,'file')==2;
1101            testpair=1;
1102        else
[112]1103            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1104                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
1105            else
1106                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
1107            end
[282]1108            set(handles.ListPairCiv1,'String',{''});
[112]1109            %COMPLETER CAS STEREO
[2]1110            return
1111        end
1112    end
1113end
1114if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
1115    if testpair
[73]1116        displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
[2]1117    else
[73]1118        for ipair=1:nbpair
1119            if select(ipair)
1120                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1121                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1122                    displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1123                else
1124                    displ_pair{ipair}='...'; %pair not displayed in the menu
1125                end
1126            end
1127        end
[2]1128    end
1129elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
1130    if testpair
[112]1131        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
[2]1132    else
[112]1133        for ipair=1:nbpair
1134            if select(ipair)
1135                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1136                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1137                    displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1138                end
1139            elseif testpair
1140                displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
1141            else
1142                displ_pair{ipair}='...'; %pair not displayed in the menu
1143            end
1144        end
1145    end
[2]1146elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
1147    for ipair=1:nbpair
1148        if select(ipair)
[112]1149            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1150            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1151                ' :dt= ' num2str(dt*1000)];
1152        else
1153            displ_pair{ipair}='...'; %pair not displayed in the menu
1154        end
1155    end
[2]1156elseif isequal(mode,'displacement')
[112]1157    displ_pair={'Di=Dj=0'};
1158end
[282]1159set(handles.ListPairCiv1,'String',displ_pair');
[229]1160ichoice=find(select,1);
[45]1161if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
[282]1162initial=get(handles.ListPairCiv1,'Value');%initial choice of pair
[112]1163if initial>nbpair
[282]1164    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
[45]1165end
1166if numel(select)>=initial && ~isequal(select(initial),1)
[282]1167    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
[2]1168end
[45]1169
[282]1170%set(handles.ListPairCiv2,'String',displ_pair');
1171initial=get(handles.ListPairCiv2,'Value');
[2]1172if initial>length(displ_pair')%|~isequal(select(initial),1)
1173    if ichoice <= length(displ_pair')
[282]1174        set(handles.ListPairCiv2,'Value',ichoice);% same pair proposed by default for civ2
[2]1175    else
[282]1176        set(handles.ListPairCiv2,'Value',1);% same pair proposed by default for civ2
[2]1177    end
1178end
[282]1179set(handles.ListPairCiv2,'String',displ_pair');
[2]1180set(gcf,'Pointer','arrow')
[12]1181
1182%------------------------------------------------------------------------
[282]1183% determine the menu for checkciv2 pairs depending on the existing netcdf file at the
[112]1184%middle of the series set by first_i, incr, last_i
[2]1185function find_netcpair_civ2(hObject, eventdata, handles)
[12]1186%------------------------------------------------------------------------
[2]1187set(gcf,'Pointer','watch')
1188%nomenclature types
[71]1189filebase=get(handles.RootName,'String');
[2]1190[filepath,Nme,ext_dir]=fileparts(filebase);
[273]1191browse=get(handles.RootName,'UserData');
[282]1192compare_list=get(handles.ListCompareMode,'String');
1193val=get(handles.ListCompareMode,'Value');
[2]1194compare=compare_list{val};
1195if strcmp(compare,'displacement')
1196    mode='displacement';
1197else
[282]1198    mode_list=get(handles.ListPairMode,'String');
[270]1199    if isempty(mode_list)
1200        msgbox_uvmat('ERROR','please enter an input image or netcdf file')
1201        return
1202    end
[282]1203    mode_value=get(handles.ListPairMode,'Value');
[2]1204    mode=mode_list{mode_value};
1205end
1206
1207% nomenclature type of the .nc files
1208nom_type_ima='ima_num';%default
1209if isfield(browse,'nom_type_ima')
1210    nom_type_ima=browse.nom_type_ima;
1211end
1212nom_type_nc='_i1-i2';%default
1213if isfield(browse,'nom_type_nc')
1214    nom_type_nc=browse.nom_type_nc;
1215end
[94]1216if isequal(nom_type_ima,'png_old') || isequal(nom_type_ima,'netc_old')|| isequal(nom_type_ima,'raw_SMD')|| isequal(nom_type_nc,'netc_old')
[2]1217    nom_type_nc='netc_old';%nom_type for the netcdf files
[94]1218elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
[2]1219    nom_type_nc='none';
[94]1220elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
[112]1221    nom_type_nc='_i1-i2';
[2]1222else
1223    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
1224        nom_type_nc='_i1-i2_j'; % PIV in volume
1225    else
1226        nom_type_nc='_i_j1-j2';
[112]1227    end
[2]1228end
1229browse.nom_type_nc=nom_type_nc;
[273]1230set(handles.RootName,'UserData',browse)
[2]1231
1232%reads .nc subdirectory and image numbers from the interface
1233subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
1234subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
[45]1235% first_i=str2num(get(handles.first_i,'String'));
1236% last_i=str2num(get(handles.last_i,'String'));
1237% incr=str2num(get(handles.incr_i,'String'));
1238% num1=first_i:incr:last_i;
1239% if isempty(num1)
[282]1240%     set(handles.ListPairCiv2,'Value',1);
1241%     set(handles.ListPairCiv2,'String',{''});
[45]1242%     return
1243% end
[273]1244ref_i=str2double(get(handles.ref_i,'String'));
[2]1245if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1246    ref_j=0;
1247else
[273]1248    ref_j=str2double(get(handles.ref_j,'String'));
[2]1249end
[273]1250time=get(handles.ImaDoc,'UserData'); %get the set of times
[2]1251if isempty(time)
1252    time=[0 1];%default
1253end
[71]1254%dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
[73]1255%dt_unit=1000;
[282]1256displ_num=get(handles.ListPairCiv1,'UserData');
[2]1257
1258
[112]1259%eliminate the first pairs inconsistent with the position
[2]1260if isempty(displ_num)
1261    nbpair=0;
1262else
1263    nbpair=length(displ_num(1,:));%nbre of displayed pairs
[112]1264    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
[2]1265        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
[112]1266    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1267        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1268    end
1269end
1270nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1271
[282]1272%look for existing processed pairs involving the field at the middle of the series if checkciv1 will not
[2]1273% be performed, while the result is needed for next steps.
1274displ_pair={''}; %default
1275select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
[282]1276if get(handles.CheckCiv2,'Value')==0 & get(handles.CheckCiv1,'Value')==0 & get(handles.CheckFix1,'Value')==0 & get(handles.CheckPatch1,'Value')==0%&...
[112]1277    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
1278        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
[282]1279        set(handles.ListPairCiv2,'Value',1);
1280        set(handles.ListPairCiv2,'String',{''});
[112]1281        return
[2]1282    end
[112]1283    for ipair=1:nbpair
[2]1284        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1285            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1286        select(ipair)=exist(filename,'file')==2;
1287    end
1288    if  isequal(select,zeros(size(1:nbpair)))
[112]1289        if isfield(browse,'incr_pair')
[2]1290            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1291            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
1292            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1293            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
1294            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
1295            select(1)=exist(filename,'file')==2;
1296        else
[112]1297            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1298                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
1299            else
1300                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
1301            end
[282]1302            set(handles.ListPairCiv2,'Value',1);
1303            set(handles.ListPairCiv2,'String',{''});
[2]1304            return
1305        end
1306    end
1307end
[112]1308if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
1309    for ipair=1:nbpair
1310        if select(ipair)
1311            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
[2]1312                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1313                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
[112]1314            end
1315        else
1316            displ_pair{ipair}='...'; %pair not displayed in the menu
1317        end
1318    end
[2]1319elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
[112]1320    for ipair=1:nbpair
1321        if select(ipair)
1322            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1323                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1324                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1325            end
1326        else
1327            displ_pair{ipair}='...'; %pair not displayed in the menu
1328        end
1329    end
[2]1330elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
1331    for ipair=1:nbpair
1332        if select(ipair)
[112]1333            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1334            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1335                ' :dt= ' num2str(dt*1000)];
1336        else
1337            displ_pair{ipair}='...'; %pair not displayed in the menu
1338        end
1339    end
[2]1340elseif isequal(mode,'displacement')
[112]1341    displ_pair={'Di=Dj=0'};
1342end
[282]1343val=get(handles.ListPairCiv2,'Value');
[229]1344ichoice=find(select,1);
[137]1345if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
[282]1346if get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0
[2]1347    val=ichoice;% first valid pair proposed by default in the menu
1348end
1349if val>length(displ_pair')
[282]1350    set(handles.ListPairCiv2,'Value',1);% first valid pair proposed by default in the menu
[2]1351else
[282]1352    set(handles.ListPairCiv2,'Value',val);
[2]1353end
[282]1354set(handles.ListPairCiv2,'String',displ_pair');
[12]1355set(gcf,'Pointer','arrow')
[2]1356
1357
[41]1358
[227]1359
[12]1360%------------------------------------------------------------------------
[282]1361% --- Executes on selection change in ListPairCiv1.
1362function ListPairCiv1_Callback(hObject, eventdata, handles)
[12]1363%------------------------------------------------------------------------
[282]1364%reproduce by default the chosen pair in the checkciv2 menu
1365list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
1366index_pair=get(handles.ListPairCiv1,'Value');
1367displ_num=get(handles.ListPairCiv1,'UserData');
[137]1368% num_a=displ_num(1,index_pair);
1369% num_b=displ_num(2,index_pair);
[282]1370list_pair2=get(handles.ListPairCiv2,'String');%get the menu of image pairs
[2]1371if index_pair<=length(list_pair2)
[282]1372    set(handles.ListPairCiv2,'Value',index_pair);
[2]1373end
1374
[112]1375%update first_i and last_i according to the chosen image pairs
[282]1376mode_list=get(handles.ListPairMode,'String');
1377mode_value=get(handles.ListPairMode,'Value');
[2]1378mode=mode_list{mode_value};
1379if isequal(mode,'series(Di)')
[137]1380    first_i=str2double(get(handles.first_i,'String'));
1381    last_i=str2double(get(handles.last_i,'String'));
1382    incr_i=str2double(get(handles.incr_i,'String'));
[2]1383    num1=first_i:incr_i:last_i;
[137]1384    lastfield=str2double(get(handles.nb_field,'String'));
1385    if ~isnan(lastfield)
[229]1386        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1387            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1388        num1=num1(test_find);
[2]1389    end
1390    set(handles.first_i,'String',num2str(num1(1)));
1391    set(handles.last_i,'String',num2str(num1(end)));
1392elseif isequal(mode,'series(Dj)')
[137]1393    first_j=str2double(get(handles.first_j,'String'));
1394    last_j=str2double(get(handles.last_j,'String'));
1395    incr_j=str2double(get(handles.incr_j,'String'));
[2]1396    num_j=first_j:incr_j:last_j;
[137]1397    lastfield2=str2double(get(handles.nb_field2,'String'));
1398    if ~isnan(lastfield2)
[229]1399        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1400            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1401        num1=num_j(test_find);
[2]1402    end
1403    set(handles.first_j,'String',num2str(num1(1)));
1404    set(handles.last_j,'String',num2str(num1(end)));
[112]1405end
[2]1406
[12]1407%------------------------------------------------------------------------
[282]1408% --- Executes on selection change in ListPairCiv2.
1409function ListPairCiv2_Callback(hObject, eventdata, handles)
[12]1410%------------------------------------------------------------------------
[282]1411index_pair=get(handles.ListPairCiv2,'Value');%get the selected position index in the menu
[2]1412
[112]1413%update first_i and last_i according to the chosen image pairs
[282]1414mode_list=get(handles.ListPairMode,'String');
1415mode_value=get(handles.ListPairMode,'Value');
[2]1416mode=mode_list{mode_value};
1417if isequal(mode,'series(Di)')
[137]1418    first_i=str2double(get(handles.first_i,'String'));
1419    last_i=str2double(get(handles.last_i,'String'));
1420    incr_i=str2double(get(handles.incr_i,'String'));
[2]1421    num1=first_i:incr_i:last_i;
[137]1422    lastfield=str2double(get(handles.nb_field,'String'));
1423    if ~isnan(lastfield)
[229]1424        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1425            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1426        num1=num1(test_find);
[2]1427    end
1428    set(handles.first_i,'String',num2str(num1(1)));
1429    set(handles.last_i,'String',num2str(num1(end)));
1430elseif isequal(mode,'series(Dj)')
[137]1431    first_j=str2double(get(handles.first_j,'String'));
1432    last_j=str2double(get(handles.last_j,'String'));
1433    incr_j=str2double(get(handles.incr_j,'String'));
[2]1434    num_j=first_j:incr_j:last_j;
[137]1435    lastfield2=str2double(get(handles.nb_field2,'String'));
1436    if ~isnan(lastfield2)
[229]1437        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1438            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1439        num1=num_j(test_find);
[2]1440    end
1441    set(handles.first_j,'String',num2str(num1(1)));
1442    set(handles.last_j,'String',num2str(num1(end)));
[112]1443end
[2]1444
[177]1445%------------------------------------------------------------------------
1446% --- Executes on button press in RUN: processing on local computer
[67]1447function RUN_Callback(hObject, eventdata, handles)
1448%------------------------------------------------------------------------
[73]1449set(handles.RUN, 'Enable','Off')
1450set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[67]1451batch=0;
[229]1452errormsg=launch_jobs(hObject, eventdata, handles,batch);
[73]1453set(handles.RUN, 'Enable','On')
1454set(handles.RUN,'BackgroundColor',[1 0 0])
[36]1455
[177]1456% start status callback to visualise results
[229]1457if ~isempty(errormsg)
1458    display(errormsg)
1459    msgbox_uvmat('ERROR',errormsg)
[282]1460elseif  isfield(handles,'status') %&& ~isequal(get(handles.ListPairMode,'Value'),3)
[225]1461    set(handles.status,'Value',1);%suppress status display
1462    status_Callback(hObject, eventdata, handles)
[178]1463end
[177]1464
[12]1465%------------------------------------------------------------------------
[2]1466% --- Executes on button press in BATCH: remote processing
1467function BATCH_Callback(hObject, eventdata, handles)
[177]1468% -----------------------------------------------------------------------
[73]1469set(handles.BATCH, 'Enable','Off')
1470set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[67]1471batch=1;
[229]1472errormsg=launch_jobs(hObject, eventdata, handles, batch);
[73]1473set(handles.BATCH, 'Enable','On')
1474set(handles.BATCH,'BackgroundColor',[1 0 0])
[67]1475
[177]1476% start status callback to visualise results
[229]1477if ~isempty(errormsg)
1478    display(errormsg)
1479    msgbox_uvmat('ERROR',errormsg)
1480elseif isfield(handles,'status')
1481    set(handles.status,'Value',1);%suppress status display
1482    status_Callback(hObject, eventdata, handles)
[178]1483end
[227]1484
[67]1485%------------------------------------------------------------------------
[133]1486% --- Lauch command called by RUN and BATCH: remote processing
[229]1487function errormsg=launch_jobs(hObject, eventdata, handles, batch)
[67]1488%-----------------------------------------------------------------------
[229]1489errormsg='';%default
[272]1490
[282]1491%%read the civ GUI
1492Param=read_GUI(handles.civ)
[133]1493%% check the selected list of operations:
[2]1494operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
[282]1495box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
[284]1496
[180]1497index_first=find(box_test==1,1);
1498if isempty(index_first)
[229]1499    errormsg='no selected operation';
[2]1500    return
1501end
[180]1502index_last=find(box_test==1,1,'last');
[159]1503box_used=box_test(index_first : index_last);
[2]1504[box_missing,ind_missing]=min(box_used);
[180]1505if isequal(box_missing,0); %there is a missing step in the sequence of operations
[229]1506    errormsg=['missing' cell2mat(operations(ind_missing))];
[2]1507    return
1508end
1509
[272]1510%% check mask if selecetd
1511%could be included in get_mask callback ?
[282]1512if isequal(get(handles.CheckMask,'Value'),1)
[276]1513    maskname=get(handles.txt_MaskName,'String');
[12]1514    if ~exist(maskname,'file')
1515        get_mask_civ1_Callback(hObject, eventdata, handles);
1516    end
[2]1517end
[282]1518if isequal(get(handles.CheckMask,'Value'),1)
1519    maskname=get(handles.txt_MaskName,'String');
[12]1520    if ~exist(maskname,'file')
1521        get_mask_fix1_Callback(hObject, eventdata, handles);
1522    end
[2]1523end
[282]1524if isequal(get(handles.CheckMask,'Value'),1)
[276]1525    maskname=get(handles.txt_Mask,'String');
[12]1526    if ~exist(maskname,'file')
[112]1527        get_mask_civ2_Callback(hObject, eventdata, handles);
[12]1528    end
[2]1529end
[282]1530if isequal(get(handles.CheckMask,'Value'),1)
[287]1531    maskname=get(handles.txt_MaskName,'String');
[12]1532    if ~exist(maskname,'file')
[112]1533        get_mask_fix2_Callback(hObject, eventdata, handles);
[12]1534    end
[2]1535end
1536
[177]1537%% reinitialise status callback
[178]1538if isfield(handles,'status')
[180]1539    set(handles.status,'Value',0);%suppress status display
1540    status_Callback(hObject, eventdata, handles)
[178]1541end
[133]1542
1543%% set the list of files and check them
1544display('checking the files...')
[227]1545[ref_i,ref_j,errormsg]=find_ref_indices(handles);
1546if ~isempty(errormsg)
1547    return
1548end
[263]1549[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,xx,yy,compare]=...
[273]1550    set_civ_filenames(handles,ref_i,ref_j,box_test);
[274]1551% ADDED
1552   [Rootbat,Filebat]=fileparts(filecell.nc.civ1{1,1});%output netcdf file (without extention)
1553%ADDED
[177]1554set(handles.civ,'UserData',filecell);%store for futur use of status callback
[137]1555if isempty(filecell)% (error message displayed in fct set_civ_filenames)
[133]1556    return
1557end
1558nbfield=numel(num1_civ1);
1559nbslice=numel(num_a_civ1);
1560
[272]1561%% read the PARAM.xml file to get the binaries (and batch_mode if batch)
[276]1562path_civ=fileparts(which('civ')); %path to the source directory of uvmat
[112]1563xmlfile='PARAM.xml';
[133]1564if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
[54]1565    t=xmltree(xmlfile);
[67]1566    s=convert(t);
[272]1567else
1568    errormsg=['no file ' xmlfile];
1569    return
[2]1570end
[272]1571
1572test_interp=0; %eviter les variables test_ (LG)
1573
[127]1574if batch
[67]1575    if isfield(s,'BatchParam')
[284]1576        Param.xml=s.BatchParam;
1577        if isfield(Param.xml,'BatchMode')
1578            batch_mode=Param.xml.BatchMode;
[257]1579            if ~ismember(batch_mode,{'sge','oar'})
1580                errormsg=['batch mode ' batch_mode ' not supported by UVMAT'];
1581                return
1582            end
[67]1583        end
1584    else
[229]1585        errormsg='no batch civ binaries defined in PARAM.xml';
[67]1586        return
1587    end
[257]1588else % run
[67]1589    if isfield(s,'RunParam')
[284]1590        Param.xml=s.RunParam;
[67]1591    else
[225]1592        msgbox_uvmat('ERROR','no run civ binaries defined in PARAM.xml')
[67]1593        return
1594    end
[225]1595end
[238]1596
[272]1597%% check batch mode supported
1598if batch
1599    switch batch_mode
1600        case 'sge'
1601            test_command='qstat';
1602        case 'oar'
1603            test_command='oartat';
1604    end   
1605    [s,w]=system(test_command);
1606    if ~isequal(s,0)
1607        msgbox_uvmat('ERROR',[batch_mode ' batch system not available'])
1608        return
1609    end
1610end
1611
1612%% check if the binaries exist
[273]1613if isequal(get(handles.Matlab,'checked'),'on')
1614    CivMode='Matlab';
1615else
1616    CivMode='CivX';
1617end
[280]1618binary_list={};
[257]1619switch CivMode
[280]1620    case 'CivX'
1621        binary_list={'Civ1Bin','Civ2Bin','PatchBin','FixBin'};
1622    case 'CivAll'
1623        binary_list={'Civ'}
[257]1624    case 'Matlab'
1625        if batch
[272]1626            % vérifier Matlab installé sur le cluster
1627            % difficile a faire a priori
[257]1628        end         
[225]1629end
[280]1630for bin_name=binary_list
[284]1631    if isfield(Param.xml,bin_name{1})
1632        if ~exist(Param.xml.(bin_name{1}),'file')%look for the full path if the file name has been defined with a relative path in PARAM.xml
1633            fullname=fullfile(path_civ,Param.xml.(bin_name{1}))
[280]1634            if exist(fullname,'file')
[284]1635                Param.xml.(bin_name{1})=fullname;
[280]1636            else
[284]1637                msgbox_uvmat('ERROR',['Binary ' Param.xml.(bin_name{1}) ' defined in PARAM.xml does not exist'])
[280]1638                return
1639            end
1640        else
[284]1641            [path,name,ext]=fileparts(Param.xml.(bin_name{1}));
[280]1642            currentdir=pwd;
1643            cd(path);
1644            binpath=pwd;%path of the binary
[284]1645            Param.xml.(bin_name{1})=fullfile(binpath,[name ext]);
1646            %                      display(Param.xml.(bin_name{1}));
[280]1647            cd(currentdir);
1648        end
1649       
1650    end
1651end
[2]1652
[272]1653display('files OK, processing...')
[2]1654
1655
[133]1656%% MAIN LOOP
[273]1657time=get(handles.ImaDoc,'UserData'); %get the set of times
[265]1658
[134]1659super_cmd=[];
[269]1660batch_file_list=[];
[265]1661   
[2]1662for ifile=1:nbfield
1663    for j=1:nbslice
[257]1664        % initiate system command
1665        switch CivMode
1666            case 'CivX'
1667                if isunix % check: necessaire aussi en RUN?
[272]1668                    cmd=['#!/bin/bash \n '...
1669                        '#$ -cwd \n '...
1670                        'hostname && date \n '...
1671                        'umask 002 \n'];%allow writting access to created files for user group
1672                else
1673                    cmd=[];
[257]1674                end
1675            case 'CivAll'
1676                %         if CivAll
1677                CivAllxml=xmltree;% xml contents,  all parameters
1678                CivAllCmd='';
1679                CivAllxml=set(CivAllxml,1,'name','CivDoc');
[2]1680        end
[272]1681       
1682       
1683        % define output file name
[282]1684        if Param.CheckCiv2==1 || Param.CheckFix2==1 || Param.CheckPatch2==1
[272]1685            OutputFile=filecell.nc.civ2{ifile,j};
1686        else
1687            OutputFile=filecell.nc.civ1{ifile,j};
1688        end
1689        OutputFile=regexprep(OutputFile,'.nc','');
[269]1690
[282]1691        if Param.CheckCiv1
[272]1692            % read image-dependent parameters
[284]1693            Param.Civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
1694            Param.Civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
1695            Param.Civ1.Dt=(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
1696            Param.Civ1.T0=((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
1697            Param.Civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
1698            Param.Civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
[285]1699            Param.Civ1.pxcmx=1; %velocities are expressed in pixel dispalcement
1700            Param.Civ1.pxcmy=1;
[284]1701
[285]1702            A=imread(filecell.ima1.civ1{1,1});%read the first image to get the size
1703            sizim=size(A);
1704            Param.Civ1.npx=(sizim(2));
1705            Param.Civ1.npy=(sizim(1));
1706            %TODO : civ should not need npx and npy
[284]1707
[272]1708            % read mask parameters
[284]1709            if Param.Civ1.CheckMask % the lines below should be changed with the new gui
1710                %matbe they when check_mask the Maskname is read
[285]1711                if exist(Param.Civ1.MaskName,'file')
1712                    Param.Civ1.MaskFlag='y';
[2]1713                else
[285]1714                    maskbase=[filecell.filebase '_' Param.Civ1.MaskName]; %
[137]1715                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1716                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
[285]1717                    Param.Civ1.MaskName=name_generator(maskbase,num1_mask,1,'.png','_i');
1718                    if exist(Param.Civ1.MaskName,'file')
[284]1719                        Param.Civ1.maskflag='y';
[12]1720                    else
[285]1721                        Param.Civ1.MaskName='noFile use default';
1722                        Param.Civ1.MaskFlag='n';
[12]1723                    end
[2]1724                end
[272]1725            else
[285]1726                Param.Civ1.MaskName='noFile use default';
1727                Param.Civ1.MaskFlag='n';
[2]1728            end
[272]1729           
[282]1730            % read grid parameters=
[284]1731            if Param.Civ1.CheckGrid
[285]1732                Param.Civ1.GridFlag='y';
1733                if isequal(Param.Civ1.GridName(end-3:end),'grid')
1734                    nbslice_grid=str2double(Param.Civ1.GridName(1:end-4)); %
[137]1735                    if ~isnan(nbslice_grid)
[2]1736                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[285]1737                        Param.Civ1.GridName=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1738                        if ~exist(Param.Civ1.GridName,'file')
[112]1739                            msgbox_uvmat('ERROR','grid file absent for civ1')
[2]1740                        end
[285]1741                    elseif ~exist(Param.Civ1.GridName,'file')
[2]1742                        msgbox_uvmat('ERROR','grid file absent for civ1')
1743                    end
1744                end
1745            else
[285]1746                Param.Civ1.GridName='noFile use default';
1747                Param.Civ1.GridFlag='n';
[2]1748            end
[257]1749           
[285]1750            % send command
[257]1751            switch CivMode
1752                case 'CivX'
[284]1753                    cmd=[cmd...
1754                        cmd_civ1(filecell.nc.civ1{ifile,j},Param) '\n'];
[257]1755                case 'CivAll'
1756                    CivAllCmd=[CivAllCmd ' civ1 '];
[284]1757                    str=CIV1_CMD_Unified(filecell.nc.civ1{ifile,j},'',Param.Civ1);
[257]1758                    fieldnames=fields(str);
1759                    [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
1760                    for ilist=1:length(fieldnames)
1761                        val=eval(['str.' fieldnames{ilist}]);
1762                        if ischar(val)
1763                            [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
1764                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1765                        end
[112]1766                    end
[2]1767            end
1768        end
1769       
[282]1770        if Param.CheckFix1
[272]1771           switch CivMode
[257]1772                case 'CivX'
[285]1773                    cmd=[cmd...
1774                        cmd_fix(filecell.nc.civ1{ifile,j},Param,'Fix1') '\n'];
[257]1775                case 'CivAll'
1776                    fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
[272]1777                    fix1.fi1=num2str(param.fix1.flagindex1(1));
1778                    fix1.fi2=num2str(param.fix1.flagindex1(2));
1779                    fix1.fi3=num2str(param.fix1.flagindex1(3));
1780                    fix1.threshC=num2str(param.fix1.thresh_vecC1);
1781                    fix1.threshV=num2str(param.fix1.thresh_vel1);
[257]1782                    fieldnames=fields(fix1);
1783                    [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
1784                    for ilist=1:length(fieldnames)
1785                        val=eval(['fix1.' fieldnames{ilist}]);
1786                        if ischar(val)
1787                            [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
1788                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1789                        end
1790                    end
1791                    CivAllCmd=[CivAllCmd ' fix1 '];
[112]1792            end
1793        end
1794       
[282]1795        %CheckPatch1
1796        if Param.CheckPatch1==1
[257]1797            switch CivMode
1798                case 'CivX'
[286]1799                    cmd=[cmd...
1800                        cmd_patch(filecell.nc.civ1{ifile,j},Param,'Patch1') '\n'];
[257]1801                case 'CivAll'
1802                    patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1803                    patch1.nopt=subdomain_patch1;
1804                    patch1.maxdiff=thresh_patch1;
1805                    patch1.ro=rho_patch1;
1806                    test_grid=get(handles.get_gridpatch1,'Value');
1807                    if test_grid
1808                        patch1.gridflag='y';
1809                        gridname=get(handles.grid_patch1,'String');
1810                        if isequal(gridname(end-3:end),'grid')
1811                            nbslice_grid=str2double(gridname(1:end-4)); %
1812                            if ~isnan(nbslice_grid)
1813                                num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
1814                                patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1815                                if ~exist(patch1.gridPatch,'file')
1816                                    msgbox_uvmat('ERROR','grid file absent for patch1')
1817                                end
1818                            elseif exist(gridname,'file')
1819                                patch1.gridPatch=gridname;
1820                            else
[112]1821                                msgbox_uvmat('ERROR','grid file absent for patch1')
1822                            end
[2]1823                        end
[257]1824                    else
1825                        patch1.gridPatch='none';
1826                        patch1.gridflag='n';
1827                        patch1.m=nx_patch1;
1828                        patch1.n=ny_patch1;
[2]1829                    end
[257]1830                    patch1.convectFlow='n';
1831                    fieldnames=fields(patch1);
1832                    [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
1833                    for ilist=1:length(fieldnames)
1834                        val=eval(['patch1.' fieldnames{ilist}]);
1835                        if ischar(val)
1836                            [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
1837                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1838                        end
[112]1839                    end
[257]1840                    CivAllCmd=[CivAllCmd ' patch1 '];
[112]1841            end
[2]1842        end
[282]1843        if Param.CheckCiv2==1
[272]1844            param.civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
1845            param.civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
1846            param.civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
1847            param.civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
1848            param.civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
1849            param.civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
1850            param.civ2.filename_nc1=filecell.nc.civ1{ifile,j};
1851            param.civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
[287]1852            if Param.Civ2.CheckMask
[276]1853                maskdispl=get(handles.txt_Mask,'String');
[12]1854                if exist(maskdispl,'file')
[272]1855                    param.civ2.maskname=maskdispl;
1856                    param.civ2.maskflag='y';
[2]1857                else
[136]1858                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1859                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1860                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
[272]1861                    param.civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1862                    if exist(param.civ2.maskname,'file')
1863                        param.civ2.maskflag='y';
[12]1864                    else
[272]1865                        param.civ2.maskname='noFile use default';
1866                        param.civ2.maskflag='n';
[12]1867                    end
[2]1868                end
[287]1869            else
1870                param.civ2.maskname='noFile use default';
1871                param.civ2.maskflag='n';
[2]1872            end
[276]1873            gridname=get(handles.txt_GridName,'String');
[2]1874            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
[137]1875                nbslice_grid=str2double(gridname(1:end-4)); %
1876                if ~isnan(nbslice_grid)
[272]1877                    param.civ2.gridflag='y';
[2]1878                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[272]1879                    param.civ2.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1880                    if exist(param.civ2.gridname,'file')
1881                        param.civ2.gridflag='y';
[2]1882                    else
[272]1883                        param.civ2.gridname='noFile use default';
1884                        param.civ2.gridflag='n';
[2]1885                    end
1886                elseif exist(gridname,'file')
[272]1887                    param.civ2.gridflag='y';
[2]1888                else
[272]1889                    param.civ2.gridname='noFile use default';
1890                    param.civ2.gridflag='n';
[2]1891                end
1892            end
[257]1893            switch CivMode
1894                case 'CivX'
[275]1895                    cmd_CIV2=CIV2_CMD(filecell.nc.civ2{ifile,j},param);%creates the cmx file [fullfile(Rootbat,Filebat) '.civ2.cmx]
[257]1896                    cmd=[cmd cmd_CIV2 '\n'];
1897                case 'CivAll'
1898                    CivAllCmd=[CivAllCmd ' civ2 '];
[272]1899                    str=CIV2_CMD_Unified(filecell.nc.civ2{ifile,j},'',param.civ2);
[257]1900                    fieldnames=fields(str);
1901                    [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
1902                    for ilist=1:length(fieldnames)
1903                        val=eval(['str.' fieldnames{ilist}]);
1904                        if ischar(val)
1905                            [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
1906                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1907                        end
[2]1908                    end
1909            end
[112]1910        end
1911       
[282]1912        % CheckFix2
1913        if Param.CheckFix2==1
1914            test_mask=get(handles.CheckMask,'Value');
[112]1915            if test_mask==0
1916                maskname=''; %no mask used
[2]1917            else
[287]1918                maskdispl=get(handles.txt_MaskName,'String');
[136]1919                maskbase=[filecell.filebase '_' maskdispl]; %
[137]1920                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]1921                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
1922                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
[112]1923            end
[257]1924            switch CivMode
1925                case 'CivX'
1926                    if isunix
[284]1927                        cmd_FIX=[Param.xml.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
[257]1928                            ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
1929                            ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
1930                    else
[284]1931                        cmd_FIX=['"' Param.xml.FixBin '" -f "' filecell.nc.civ2{ifile,j} '" -fi1 ' num2str(flagindex2(1)) ...
[257]1932                            ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
1933                            ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName "' maskname '"'];
1934                        cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
[112]1935                    end
[257]1936                    cmd=[cmd cmd_FIX '\n'];
1937                case 'CivAll'
1938                    fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
1939                    fix2.fi1=num2str(flagindex2(1));
1940                    fix2.fi2=num2str(flagindex2(2));
1941                    fix2.fi3=num2str(flagindex2(3));
1942                    fix2.threshC=num2str(thresh_vec2C);
1943                    fix2.threshV=num2str(thresh_vel2);
1944                    fieldnames=fields(fix2);
1945                    [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
1946                    for ilist=1:length(fieldnames)
1947                        val=eval(['fix2.' fieldnames{ilist}]);
1948                        if ischar(val)
1949                            [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
1950                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
1951                        end
1952                    end
1953                    CivAllCmd=[CivAllCmd ' fix2 '];
[112]1954            end
1955        end
1956       
[282]1957        %CheckPatch2
1958        if Param.CheckPatch2==1
[257]1959            switch CivMode
1960                case 'CivX'
[284]1961                    cmd_PATCH=cmd_patch(filecell.nc.civ2{ifile,j},param.Patch2,Param.xml.PatchBin);
[257]1962                    cmd=[cmd cmd_PATCH '\n'];
1963                case 'CivAll'
1964                    patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
1965                    patch2.nopt=subdomain_patch2;
1966                    patch2.maxdiff=thresh_patch2;
1967                    patch2.ro=rho_patch2;
1968                    test_grid=get(handles.get_gridpatch2,'Value');
1969                    if test_grid
1970                        patch2.gridflag='y';
1971                        gridname=get(handles.grid_patch2,'String');
1972                        if isequal(gridname(end-3:end),'grid')
1973                            nbslice_grid=str2double(gridname(1:end-4)); %
1974                            if ~isnan(nbslice_grid)
1975                                num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
1976                                patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1977                                if ~exist(patch2.gridPatch,'file')
1978                                    msgbox_uvmat('ERROR','grid file absent for patch2')
1979                                end
1980                            elseif exist(gridname,'file')
1981                                patch2.gridPatch=gridname;
1982                            else
[112]1983                                msgbox_uvmat('ERROR','grid file absent for patch2')
[12]1984                            end
[2]1985                        end
[257]1986                    else
1987                        patch2.gridPatch='none';
1988                        patch2.gridflag='n';
1989                        patch2.m=nx_patch2;
1990                        patch2.n=ny_patch2;
[2]1991                    end
[257]1992                    patch2.convectFlow='n';
1993                    fieldnames=fields(patch2);
1994                    [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
1995                    for ilist=1:length(fieldnames)
1996                        val=eval(['patch2.' fieldnames{ilist}]);
1997                        if ischar(val)
1998                            [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
1999                            [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
2000                        end
[112]2001                    end
[257]2002                    CivAllCmd=[CivAllCmd ' patch2 '];
[112]2003            end
[12]2004        end
[257]2005 
2006        switch CivMode
2007            case {'CivX','CivAll'}
2008                if isequal(CivMode,'CivAll')
[272]2009                    save(CivAllxml,[OutputFile '.xml']);
2010                    cmd=[cmd sparam.CivBin ' -f ' OutputFile '.xml '  CivAllCmd ' >' OutputFile '.log' '\n'];
[238]2011                end
[272]2012               
2013                % create the .bat file used in run or batch
2014                filename_bat=[OutputFile '.bat'];
[257]2015                [fid,message]=fopen(filename_bat,'w');
2016                if isequal(fid,-1)
2017                    msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
2018                    return
[238]2019                end
[257]2020                fprintf(fid,cmd);
2021                fclose(fid);
[269]2022               
[279]2023                if isunix
2024                    system(['chmod +x ' filename_bat]);
2025                end
2026               
[269]2027                batch_file_list{length(batch_file_list)+1}=filename_bat;
2028               
2029%                 if batch
2030%                     switch batch_mode
2031%                         case 'sge'                           
2032%                             display(['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
2033%                             eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
2034%                         case 'oar'
2035% %                             eval(  ['!chmod +x ' filename_bat]);
2036% %                             %eval(  ['!oarsub -n CIVX -l /core=1,walltime=00:10:00  ' filename_bat]);                   
2037% %                             eval(  ['!oarsub -n CIVX -l "/core=1+{type = ''smalljob''}/licence=1,walltime=00:10:00"   ' filename_bat]);
2038%
2039%                     cmd_str=['sh ' filename_bat];
2040%                     super_cmd{length(super_cmd)+1}=cmd_str;
2041%                           
2042%                     end
2043%                 else
2044%                     %% to lauch the jobs locally :
2045%                     if(isunix)
2046%                         cmd_str=['. ' filename_bat];
2047%                     else %case of Windows
2048%                         cmd_str=['@call "' regexprep(filename_bat,'\\','\\\\') '"'];
2049%                     end
2050%                     super_cmd=[super_cmd cmd_str '\n'];
2051%                     disp(cmd_str);
2052%                 end
[257]2053            case 'Matlab'
2054                drawnow
[282]2055                if Param.CheckCiv1==1
[284]2056                    Param.Civ1=Param.Civ1;
[252]2057                end
[282]2058                if Param.CheckFix1==1
[257]2059                    fix1.WarnFlags=[];
[282]2060                    if get(handles.CheckFmin2,'Value')
[257]2061                        fix1.WarnFlags=[fix1.WarnFlags -2];
2062                    end
[282]2063                    if get(handles.CheckF3,'Value')
[257]2064                        fix1.WarnFlags=[fix1.WarnFlags 3];
2065                    end
2066                    fix1.LowerBoundCorr=thresh_vecC1;
[287]2067                    if get(handles.num_MinVel,'Value')
[257]2068                        fix1.UppperBoundVel=thresh_vel1;
2069                    else
2070                        fix1.LowerBoundVel=thresh_vel1;
2071                    end
[282]2072                    if get(handles.CheckMask,'Value')
[257]2073                        fix1.MaskName=maskname;
2074                    end
2075                    Param.Fix1=fix1;
[252]2076                end
[282]2077                if Param.CheckPatch1==1
[263]2078                    if strcmp(compare,'stereo PIV')
2079                        filebase_A=filecell.filebase;
2080                        [pp,ff]=fileparts(filebase_A);
2081                        filebase_B=fullfile(pp,get(handles.RootName_1,'String'));
2082                        RUN_STLIN(filecell.ncA.civ1{ifile,j},filecell.nc.civ1{ifile,j},'civ1',filecell.st{ifile,j},...
2083                            str2num(nx_patch1),str2num(ny_patch1),str2num(thresh_patch1),[filebase_A '.xml'],[filebase_B '.xml'])
2084                    else
2085                        Param.Patch1.Rho=rho_patch1;
2086                        Param.Patch1.Threshold=thresh_patch1;
2087                        Param.Patch1.SubDomain=subdomain_patch1;
2088                    end
[257]2089                end
[282]2090                if Param.CheckCiv2==1
[272]2091                    Param.Civ2=param.civ2;
[257]2092                end
[282]2093                if Param.CheckFix2==1
[257]2094                    fix2.WarnFlags=[];
[287]2095                    if get(handles.CheckFmin2,'Value')
[257]2096                        fix2.WarnFlags=[fix2.WarnFlags -2];
2097                    end
[287]2098                    if get(handles.CheckF4,'Value')
[257]2099                        fix2.WarnFlags=[fix2.WarnFlags 4];
2100                    end
[287]2101                    if get(handles.CheckF3,'Value')
[257]2102                        fix2.WarnFlags=[fix2.WarnFlags 3];
2103                    end
2104                    fix2.LowerBoundCorr=thresh_vec2C;
[287]2105                    if get(handles.num_MinVel,'Value')
[257]2106                        fix2.UppperBoundVel=thresh_vel2;
2107                    else
2108                        fix2.LowerBoundVel=thresh_vel2;
2109                    end
[282]2110                    if get(handles.CheckMask,'Value')
[257]2111                        fix2.MaskName=maskname;
2112                    end
2113                    Param.Fix2=fix2;
2114                end
[282]2115                if Param.CheckPatch2==1
[263]2116                    if strcmp(compare,'stereo PIV')
2117                        filebase_A=filecell.filebase;
2118                        [pp,ff]=fileparts(filebase_A);
2119                        filebase_B=fullfile(pp,get(handles.RootName_1,'String'));
2120                        RUN_STLIN(filecell.ncA.civ2{ifile,j},filecell.nc.civ2{ifile,j},'civ2',filecell.st{ifile,j},...
2121                            str2num(nx_patch2),str2num(ny_patch2),str2num(thresh_patch2),[filebase_A '.xml'],[filebase_B '.xml'])
[270]2122                    else
2123                        Param.Patch2.Rho=rho_patch2;
2124                        Param.Patch2.Threshold=thresh_patch2;
2125                        Param.Patch2.SubDomain=subdomain_patch2;
[263]2126                    end
[257]2127                end
[263]2128                if ~strcmp(compare,'stereo PIV')
2129                    [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
2130                    if isempty(errormsg)
2131                        display([filecell.nc.civ1{ifile,j} ' written'])
2132                    else
2133                        msgbox_uvmat('ERROR',errormsg)
2134                    end
[270]2135
[263]2136                end
[257]2137        end
[112]2138    end
[2]2139end
[134]2140
[265]2141if batch
[269]2142    switch batch_mode                       
2143        case 'sge'
2144            for p=1:length(batch_file_list)
2145                cmd=['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' batch_file_list{p}];
2146                display(cmd);eval(cmd);
2147            end
[279]2148        case 'oar_old'
2149                for p=1:length(batch_file_list)
2150                    oar_command=['!oarsub -n CIVX -q nicejob '...
2151                   '-E ' regexprep(batch_file_list{p},'.bat','.errors') ' -O ' regexprep(batch_file_list{p},'.bat','.log ')...
2152                    '-l "/core=1+{type = ''smalljob''}/licence=1,walltime=00:60:00"   ' batch_file_list{p}];
2153                display(oar_command);eval(oar_command);
[265]2154                end
[279]2155       
2156           
2157       case 'oar_perl'
2158                filename_joblist=fullfile(Rootbat,'job_list.txt');
2159                fid=fopen(filename_joblist,'w');
2160
2161                for p=1:length(batch_file_list)
2162                    oar_command=['oarsub -n CIVX '...
2163                        '-l "/core=1,walltime=00:10:00"   ' batch_file_list{p}];
2164                    fprintf(fid,[oar_command '\n']);
[265]2165                end
[279]2166                fclose(fid)
2167                oar_command=['oarsub -t container -n civx-container -l /core=24,walltime=00:35:00 "/fsnet/data/legi/calcul9/home/gostiaux/Documents/MATLAB/uvmat_dev/oar-dispatch -f '...
2168                    filename_joblist '"'];
2169                filename_oarcommand=fullfile(Rootbat,'oar_command');
2170                fid=fopen(filename_oarcommand,'w');
2171                fprintf(fid,[oar_command '\n']);
2172                fclose(fid);
2173%                 display(oar_command);
2174                eval(['! . ' filename_oarcommand]);
2175
2176        case 'oar'%'oar_mpi'
2177                filename_joblist=fullfile(Rootbat,'job_list.txt');
2178                fid=fopen(filename_joblist,'w');
2179
2180                for p=1:length(batch_file_list)
2181                    fprintf(fid,[batch_file_list{p} '\n']);
[265]2182                end
[279]2183                fclose(fid)
2184               
2185               
2186%                 oarsub -S ./oar.sub
2187
2188               
2189               
2190
2191               
2192            %             for p=0:floor(length(batch_file_list)/6);               
2193%                 filename_batch_group=fullfile(Rootbat,['job_list_' num2str(p) '.bat']);
2194%                 fid=fopen(filename_batch_group,'w');
2195%                 if fid==-1
2196%                     msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
2197%                     return
2198%                 end
2199%                 if p==floor(length(batch_file_list)/6)
2200%                     kmax=mod(length(batch_file_list),6);
2201%                 else
2202%                     kmax=6;
2203%                 end
2204%                 for k=1:kmax
2205%                     fprintf(fid,['sh ' batch_file_list{p*6+k} '\n']);
2206%                 end
2207%                 fclose(fid);
2208%                 system(['chmod +x ' filename_batch_group]);
2209%                 eval(  ['!oarsub -n CIVX -q nicejob '...
2210%                     '-E '  flname '.errors -O ' flname '.log '...
2211%                     '-l "/core=1+{type = ''smalljob''}/licence=1,walltime=00:60:00"   ' filename_batch_group]);
2212%             end
[269]2213        case 'oar_new' % to be develloped with Patrick Begou
2214                filename_joblist=fullfile(Rootbat,'job_list.txt');
2215                fid=fopen(filename_superbat,'w');
2216                if fid==-1
2217                    msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
2218                    return
[265]2219                end
[269]2220                for p=1:length(batch_file_list)
2221                    fprintf(fid,[batch_file_list{p} '\n']);
2222                end
2223                fclose(fid);
2224                walltime=datestr(length(super_cmd)*10/24/60,13);
2225                eval(  ['!oarsub -n CIVX -q nicejob -l "/core=1+{type = ''smalljob''}/licence=1,walltime=' walltime '"   ' filename_superbat]);
2226    end
2227else
2228    if ~isequal(CivMode,'Matlab')
2229        filename_superbat=fullfile(Rootbat,'job_list.bat');
2230        fid=fopen(filename_superbat,'w');
2231        if fid==-1
2232            msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
2233            return
2234        end
2235        for p=1:length(batch_file_list)
2236            if isunix
2237                fprintf(fid,['sh ' batch_file_list{p} '\n']);
2238            else
2239                fprintf(fid,['@call "' regexprep(filename_bat,'\\','\\\\') '"' '\n']);
[265]2240            end
[269]2241        end
2242        fclose(fid);
2243        if(isunix)
2244            system(['chmod +x ' filename_superbat]);
2245        end
2246        system([filename_superbat ' &']);% execute main commmand
[265]2247    end
[269]2248   
[265]2249end
2250
[2]2251
[137]2252%% save interface state
[2]2253if isfield(filecell,'nc')
2254    if isfield(filecell.nc,'civ2')
2255        fileresu=filecell.nc.civ2{1,1};
2256    else
2257        fileresu=filecell.nc.civ1{1,1};
2258    end
2259end
2260[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
2261namedoc=fullfile(RootPath,subdir,RootFile);
[112]2262detect=1;
[2]2263while detect==1
2264    namefigfull=[namedoc '.fig'];
2265    hh=dir(namefigfull);
2266    if ~isempty(hh)
2267        detect=1;
2268        namedoc=[namedoc '.0'];
2269    else
2270        detect=0;
2271    end
2272end
2273saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
2274
[273]2275%Save info in personal profile (initiate browser next time) TODO
2276MenuFile={};
2277dir_perso=prefdir;
2278profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2279if exist(profil_perso,'file')
2280    hh=load (profil_perso);
2281      if isfield(hh,'MenuFile')
2282          MenuFile=hh.MenuFile;
2283      end
2284      MenuFile=[filecell.ima1.civ1(1,1); MenuFile];
2285      save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
2286else
2287    MenuFile=filecell.ima1.civ1(1,1);
2288    save (profil_perso,'MenuFile')
2289end
2290
2291
[227]2292%------------------------------------------------------------------------
2293% --- determine the list of reference indices of processing file
2294function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
2295%------------------------------------------------------------------------
2296errormsg=''; %default error message
2297first_i=str2double(get(handles.first_i,'String'));%first index i
2298last_i=str2double(get(handles.last_i,'String'));%last index i
2299incr_i=str2double(get(handles.incr_i,'String'));% increment
2300if isequal(get(handles.first_j,'Visible'),'on')
2301    first_j=str2double(get(handles.first_j,'String'));%first index j
2302    last_j=str2double(get(handles.last_j,'String'));%last index j
2303    incr_j=str2double(get(handles.incr_j,'String'));% increment
2304else
2305    first_j=1;
2306    last_j=1;
2307    incr_j=1;
2308end
2309ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
2310ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
2311if isnan(first_i)||isnan(first_j)
2312    errormsg='first field number not defined';
2313elseif isnan(last_i)||isnan(last_j)
2314    errormsg='last field number not defined';
2315elseif isnan(incr_i)||isnan(incr_j)
2316    errormsg='increment in field number not defined';
2317elseif last_i < first_i || last_j < first_j
2318    errormsg='last field number must be larger than the first one';
2319end
[134]2320
[227]2321%------------------------------------------------------------------------
2322% --- determine the list of filenames and indices needed for launch_job
[263]2323function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2,compare]=...
[282]2324    set_civ_filenames(handles,ref_i,ref_j,checkbox)
[12]2325%------------------------------------------------------------------------
[85]2326filecell=[];%default
[136]2327
2328%% get the root names nomenclature and numbers
[71]2329filebase=get(handles.RootName,'String');
[136]2330
2331if isempty(filebase)||isequal(filebase,'')
2332    msgbox_uvmat('ERROR','no input files')
2333    return
2334end
2335
[137]2336%filebase=regexprep(filebase,'\.fsnet','fsnet');% temporary fix for cluster Coriolis
[136]2337filecell.filebase=filebase;
2338
[273]2339browse=get(handles.RootName,'UserData');
[282]2340compare_list=get(handles.ListCompareMode,'String');
2341val=get(handles.ListCompareMode,'Value');
[2]2342compare=compare_list{val};
2343if strcmp(compare,'displacement')
2344    mode='displacement';
2345else
[282]2346    mode_list=get(handles.ListPairMode,'String');
2347    mode_value=get(handles.ListPairMode,'Value');
[2]2348    mode=mode_list{mode_value};
2349end
[137]2350%time=get(handles.RootName,'UserData'); %get the set of times
[71]2351ext_ima=get(handles.ImaExt,'String');
[2]2352nom_type_nc=browse.nom_type_nc;
[122]2353if isfield(browse,'nom_type_ima')
2354    nom_type_ima2=browse.nom_type_ima;
2355end
2356if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
2357if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
[2]2358[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
[227]2359    find_pair_indices(handles,ref_i,ref_j,mode);
[282]2360%determine the new filebase for 'displacement' ListPairMode (comparison of two series)
[2]2361filebase_B=filebase;% root name of the second field series for stereo
2362if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
[127]2363%     test_disp=1;
[2]2364    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
2365    [Path2,Name2]=fileparts(filebase_B);
2366    Path1=Path2;
[71]2367    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
[2]2368    filebase_A=fullfile(Path1,Name1);
2369    if length(Name1)>6
2370        Name1=Name1(end-5:end);
2371    end
2372    if length(Name2)>6
2373        Name2=Name2(end-5:end);
2374    end
2375    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
2376else
[127]2377%     test_disp=0;
[2]2378    filebase_A=filebase;
2379    nom_type_ima1=nom_type_ima2;
2380    filebase_AB=filebase;
2381end
2382if strcmp(compare,'displacement')
[112]2383    filebase_ima1=filebase_A;
2384    filebase_ima2=filebase_B;
2385    filebase_nc=filebase_AB; %root name for the result of civ2
[2]2386else
[112]2387    filebase_ima1=filebase_B;
2388    filebase_ima2=filebase_B;
2389    filebase_nc=filebase_B;
2390end
[2]2391
2392%determine reference files for fix:
2393file_ref_fix1={};%default
2394file_ref_fix2={};
2395nbfield=length(num1_civ1);
2396nbslice=length(num_a_civ1);
[282]2397if checkbox(2)==1% fix1 performed
[2]2398    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
2399    if ~isempty(ref)
[137]2400        first_i=str2double(get(handles.first_i,'String'));
2401        last_i=str2double(get(handles.last_i,'String'));
2402        incr_i=str2double(get(handles.incr_i,'String'));
2403        first_j=str2double(get(handles.first_j,'String'));
2404        last_j=str2double(get(handles.last_j,'String'));
2405        incr_j=str2double(get(handles.incr_j,'String'));
[127]2406        num_i_ref=first_i:incr_i:last_i;
2407        num_j_ref=first_j:incr_j:last_j;
[2]2408        if isequal(mode,'displacement')
2409            num_i1=num_i_ref;
2410            num_i2=num_i_ref;
2411            num_j1=num_j_ref;
2412            num_j2=num_j_ref;
2413        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
2414            num_i1=num_i_ref;
2415            num_i2=num_i1;
2416            num_j1=ref.num_a*ones(size(num_i_ref));
2417            num_j2=ref.num_b*ones(size(num_i_ref));
2418        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
2419            delta1=floor((ref.num2-ref.num1)/2);
2420            delta2=ceil((ref.num2-ref.num1)/2);
2421            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2422            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2423            if isempty(ref.num_a)
2424                ref.num_a=1;
2425            end
2426            num_j1=ref.num_a*ones(size(num_i1));
2427            num_j2=num_j1;
2428        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
2429            delta1=floor((ref.num_b-ref.num_a)/2);
2430            delta2=ceil((ref.num_b-ref.num_a)/2);
2431            num_i1=ref.num1*ones(size(num_i_ref));
2432            num_i2=num_i1;
2433            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2434            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2435        end
2436        for ifile=1:nbfield
2437            for j=1:nbslice
2438                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2439                file_ref_fix1(ifile,j)={file_ref};
2440                if ~exist(file_ref,'file')
2441                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
[12]2442                    filecell=[];
[2]2443                    return
2444                end
2445            end
2446        end
2447    end
2448end
2449
[282]2450%determine reference files for checkfix2:
2451if checkbox(5)==1% fix2 performed
[2]2452    ref=get(handles.ref_fix2,'UserData');
2453    if ~isempty(ref)
[127]2454        first_i=str2double(get(handles.first_i,'String'));
2455        last_i=str2double(get(handles.last_i,'String'));
2456        incr_i=str2double(get(handles.incr_i,'String'));
2457        first_j=str2double(get(handles.first_j,'String'));
2458        last_j=str2double(get(handles.last_j,'String'));
2459        incr_j=str2double(get(handles.incr_j,'String'));
[229]2460        num_i_ref=first_i:incr_i:last_i;
2461        num_j_ref=first_j:incr_j:last_j;
[2]2462        if isequal(mode,'displacement')
2463            num_i1=num_i_ref;
2464            num_i2=num_i_ref;
2465            num_j1=num_j_ref;
2466            num_j2=num_j_ref;
2467        elseif isequal(mode,'pair j1-j2')
2468            num_i1=num_i_ref;
2469            num_i2=num_i1;
2470            num_j1=ref.num_a;
2471            num_j2=ref.num_b;
2472        elseif isequal(mode,'series(Di)')
2473            delta1=floor((ref.num2-ref.num1)/2);
2474            delta2=ceil((ref.num2-ref.num1)/2);
2475            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2476            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2477            num_j1=ref.num_a*ones(size(num_i1));
2478            num_j2=num_j1;
2479        elseif isequal(mode,'series(Dj)')
2480            delta1=floor((ref.num_b-ref.num_a)/2);
2481            delta2=ceil((ref.num_b-ref.num_a)/2);
2482            num_i1=ref.num1*ones(size(num_i_ref));
2483            num_i2=num_i1;
2484            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2485            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2486        end
2487        for ifile=1:nbfield
2488            for j=1:nbslice
2489                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2490                file_ref_fix2(ifile,j)={file_ref};
2491                if ~exist(file_ref,'file')
2492                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
[122]2493                    filecell={};
[2]2494                    return
2495                end
2496            end
2497        end
2498    end
2499end
2500
2501%check dir
2502subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
2503subdir_civ2=get(handles.subdir_civ2,'String');
[174]2504if isequal(subdir_civ1,''),subdir_civ1='CIV'; end% put default subdir
[2]2505if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
[266]2506% currentdir=pwd;%store the current working directory
[2]2507[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
2508if ~exist(Path_ima,'dir')
[12]2509    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
[122]2510    filecell={};
[2]2511    return
2512end
[127]2513[xx,message]=fileattrib(Path_ima);
[122]2514if ~isempty(message) && ~isequal(message.UserWrite,1)
[112]2515    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
[122]2516    filecell={};
[266]2517%     cd(currentdir);
[112]2518    return
[2]2519end
2520
2521%check the existence of the netcdf and image files involved
[282]2522% %%%%%%%%%%%%  case CheckCiv1 activated   %%%%%%%%%%%%%
2523if checkbox(1)==1;
[112]2524    detect=1;
[127]2525    vers=0;
2526    subdir_civ1_new=subdir_civ1;
[153]2527    while detect==1 %create a new subdir if the netcdf files already exist
[122]2528        for ifile=1:nbfield
[112]2529            for j=1:nbslice
[122]2530                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);
[112]2531                detect=exist(filename,'file')==2;
2532                if detect% if a netcdf file already exists
[137]2533                    indstr=regexp(subdir_civ1_new,'\D');
2534                    if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2535                        vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2536                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2537                    else
2538                        vers=vers+1;
[137]2539                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) '_' num2str(vers)];       
[127]2540                    end
[137]2541                    subdir_civ2=subdir_civ1_new;
[112]2542                    break
2543                end
2544                filecell.nc.civ1(ifile,j)={filename};
2545            end
2546            if detect% if a netcdf file already exists
2547                break
2548            end
2549        end
[134]2550 
[112]2551        %create the new subdir_civ1
[127]2552        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
[263]2553%             cd(Path_ima);         
2554            [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
[134]2555
[128]2556            if ~strcmp(msg1,'')
2557                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
[122]2558                filecell={};
2559                return
[163]2560            elseif isunix         
[266]2561                [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
[128]2562                if ~strcmp(msg2,'')
[266]2563                    msgbox_uvmat('ERROR',['pb of permission for  ' fullfile(Path_ima,subdir_civ1_new) ': ' msg2])%error message for directory creation
[128]2564                    filecell={};
2565                    return
2566                end
[112]2567            end
[263]2568%             cd(currentdir);
[112]2569        end
2570        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
2571            for ifile=1:nbfield
2572                for j=1:nbslice
[122]2573                    filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);%
[112]2574                    detect=exist(filename,'file')==2;
[2]2575                    if detect% if a netcdf file already exists
[137]2576                       indstr=regexp(subdir_civ1_new,'\D');
2577                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2578                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2579                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2580                       else
2581                           vers=vers+1;
[137]2582                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
[127]2583                       end
2584                       subdir_civ2=subdir_civ1;
2585                       break
[2]2586                    end
[112]2587                    filecell.ncA.civ1(ifile,j)={filename};
2588                end
2589                if detect% if a netcdf file already exists
2590                    break
2591                end
2592            end
2593            %create the new subdir_civ1
[263]2594            if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2595%                    cd(Path_ima);         
2596                [xx,msg1]=mkdir(fullfile(Path_ima,subdir_civ1_new));
2597%                             cd(currentdir);
[252]2598                if ~strcmp(msg1,'')
[128]2599                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
[263]2600%                     cd(currentdir)
[122]2601                    filecell={};
2602                    return
[128]2603                else
[266]2604                    [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
[128]2605                    if ~strcmp(msg2,'')
2606                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
[263]2607%                         cd(currentdir)
[128]2608                        filecell={};
2609                        return
2610                    end
[112]2611                end
2612            end
2613        end
2614    end
[127]2615    subdir_civ1=subdir_civ1_new;
[2]2616    % get image names
2617    for ifile=1:nbfield
[112]2618        for j=1:nbslice
[2]2619            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2620            idetect(j)=exist(filename,'file')==2;
2621            filecell.ima1.civ1(ifile,j)={filename}; %first image
2622            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2623            idetect_1(j)=exist(filename,'file')==2;
2624            filecell.ima2.civ1(ifile,j)={filename};%second image
[112]2625        end
2626        [idetectmin,indexj]=min(idetect);
2627        if idetectmin==0,
2628            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
[122]2629            filecell={};
[266]2630           % cd(currentdir)
[112]2631            return
2632        end
2633        [idetectmin,indexj]=min(idetect_1);
2634        if idetectmin==0,
2635            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
[122]2636            filecell={};
[266]2637            %cd(currentdir)
[112]2638            return
2639        end
2640    end
2641    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2642        for ifile=1:nbfield
2643            for j=1:nbslice
2644                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2645                idetect(j)=exist(filename,'file')==2;
2646                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2647                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2648                idetect_1(j)=exist(filename,'file')==2;
2649                filecell.imaA2.civ1(ifile,j)={filename};%second image
2650            end
[2]2651            [idetectmin,indexj]=min(idetect);
[112]2652            if idetectmin==0,
2653                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
[122]2654                filecell={};
[266]2655               % cd(currentdir)
[2]2656                return
[112]2657            end
[2]2658            [idetectmin,indexj]=min(idetect_1);
[112]2659            if idetectmin==0,
2660                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
[122]2661                filecell={};
[266]2662               % cd(currentdir)
[2]2663                return
[112]2664            end
2665        end
[2]2666    end
[112]2667   
[282]2668    %%%%%%%%%%%%%  checkfix1 or checkpatch1 activated but no checkciv1   %%%%%%%%%%%%%
2669elseif (checkbox(2)==1 || checkbox(3)==1);
[2]2670    for ifile=1:nbfield
2671        for j=1:nbslice
2672            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
[112]2673                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2674            detect=exist(filename,'file')==2;
[122]2675            if detect==0
2676                msgbox_uvmat('ERROR',[filename ' not found'])
2677                filecell={};
[266]2678               % cd(currentdir)
[122]2679                return
2680            end
[2]2681            filecell.nc.civ1(ifile,j)={filename};
2682        end
2683    end
2684    if strcmp(compare,'stereo PIV')
[112]2685        for ifile=1:nbfield
2686            for j=1:nbslice
2687                filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2688                filecell.ncA.civ1(ifile,j)={filename};
2689                if ~exist(filename,'file')
2690                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2691                    set(handles.RUN, 'Enable','On')
2692                    set(handles.RUN,'BackgroundColor',[1 0 0])
[122]2693                    filecell={};
[266]2694                    %cd(currentdir)
[112]2695                    return
[2]2696                end
2697            end
[112]2698        end
[2]2699    end
2700end
2701
[282]2702%%%%%%%%%%%%%  if checkciv2 performed with pairs different than checkciv1  %%%%%%%%%%%%%
[2]2703testdiff=0;
[282]2704if (checkbox(4)==1)&&...
2705        ((get(handles.ListPairCiv1,'Value')~=get(handles.ListPairCiv2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
[2]2706    testdiff=1;
[112]2707    detect=1;
[127]2708    vers=0;
2709    subdir_civ2_new=subdir_civ2;
[2]2710    while detect==1 %create a new subdir if the netcdf files already exist
[112]2711        for ifile=1:nbfield
2712            for j=1:nbslice
[127]2713                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2_new);%
[112]2714                detect=exist(filename,'file')==2;
2715                if detect% if a netcdf file already exists
[127]2716                    indstr=regexp(subdir_civ2,'\D');
2717                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2718                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2719                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2720                    else
2721                        vers=vers+1;
2722                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2723                    end
[112]2724                    break
2725                end
2726                filecell.nc.civ2(ifile,j)={filename};
2727            end
2728            if detect% if a netcdf file already exists
2729                break
2730            end
2731        end
[128]2732        %create the new subdir_civ2_new
2733        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
[174]2734            [xx,m2]=mkdir(fullfile(Path_ima,subdir_civ2_new));
[266]2735            [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
[112]2736            if ~isequal(m2,'')
[266]2737                msgbox_uvmat('ERROR',['cannot create ' fullfile(Path_ima,subdir_civ2_new) ': ' m2])
[122]2738                filecell={};
[266]2739               % cd(currentdir)
[122]2740                return
[112]2741            end
2742        end
2743        if strcmp(compare,'stereo PIV')%check second nc series
2744            for ifile=1:nbfield
2745                for j=1:nbslice
2746                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[122]2747                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
[112]2748                    detect=exist(filename,'file')==2;
[2]2749                    if detect% if a netcdf file already exists
[127]2750                        indstr=regexp(subdir_civ2,'\D');
2751                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2752                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2753                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2754                        else
2755                           vers=vers+1;
2756                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2757                        end
[112]2758                        break
[2]2759                    end
[112]2760                    filecell.ncA.civ2(ifile,j)={filename};
2761                end
2762                if detect% if a netcdf file already exists
2763                    break
2764                end
2765            end
[122]2766            subdir_civ2=subdir_civ2_new;
[112]2767            %create the new subdir_civ1
[127]2768            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2769                [xx,m2]=mkdir(subdir_civ2_new);
[266]2770                 [xx,msg2] = fileattrib(fullfile(Path_ima,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
[112]2771                if ~isequal(m2,'')
[266]2772                    msgbox_uvmat('ERROR', ['cannot create ' fullfile(Path_ima,subdir_civ2_new) ': ' m2])%error message for directory creation
2773                  %  cd(currentdir)
[122]2774                    filecell={};
2775                    return
[112]2776                end
2777            end
2778        end
2779    end
[127]2780    subdir_civ2=subdir_civ2_new;
[2]2781end
[266]2782%cd(currentdir);%come back to the current working directory
[2]2783
[282]2784%%%%%%%%%%%%%  if checkciv2 results are obtained or used  %%%%%%%%%%%%%
2785if checkbox(4)==1 || checkbox(5)==1 || checkbox(6)==1 %civ2
2786    %check source netcdf file of checkciv1 estimates
2787    if checkbox(1)==0; %no civ1 performed
[2]2788        for ifile=1:nbfield
2789            for j=1:nbslice
2790                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2791                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2792                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2793                if ~exist(filename,'file')
2794                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[122]2795                    filecell={};
[2]2796                    return
2797                end
2798                if ~testdiff % civ2 or patch2 are written in the same file as civ1
[282]2799                    if checkbox(4)==0 ; %check the existence of civ2 if it is not calculated
[248]2800                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2801                        if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
[2]2802                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2803                            filecell=[];
[2]2804                            return
[248]2805                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
2806                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2807                            filecell=[];
2808                            return
[112]2809                        end
[282]2810                    elseif checkbox(3)==0; %check the existence of patch if it is not calculated
[275]2811                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch');
[248]2812                        if ~isempty(Data.CivStage)
2813                            if Data.CivStage<3 %test for civ files
2814                                msgbox_uvmat('ERROR',['no patch data in ' filename])
2815                                filecell=[];
2816                                return
2817                            end
2818                        elseif isempty(Data.patch)||isequal(Data.patch,0)
[2]2819                            msgbox_uvmat('ERROR',['no patch data in ' filename])
[12]2820                            filecell=[];
[2]2821                            return
2822                        end
[112]2823                    end
[2]2824                end
2825            end
2826        end
2827        if strcmp(compare,'stereo PIV')
2828            for ifile=1:nbfield
2829                for j=1:nbslice
2830                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2831                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2832                    filecell.ncA.civ2(ifile,j)={filename};
2833                    if ~exist(filename,'file')
2834                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2835                        set(handles.RUN, 'Enable','On')
2836                        set(handles.RUN,'BackgroundColor',[1 0 0])
2837                        return
2838                    end
2839                end
2840            end
2841        end
2842    end
[112]2843   
2844    detect=1;
[282]2845    %     while detect==1%creates a new subdir if the netcdf files already contain checkciv2 data
[112]2846    for ifile=1:nbfield
2847        for j=1:nbslice
2848            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[2]2849                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
[112]2850            detect=exist(filename,'file')==2;
2851            filecell.nc.civ2(ifile,j)={filename};
[2]2852        end
[112]2853    end
[282]2854    %get first image names for checkciv2
2855    if checkbox(1)==1 && isequal(num1_civ1,num1_civ2) && isequal(num_a_civ1,num_a_civ2)
[2]2856        filecell.ima1.civ2=filecell.ima1.civ1;
[282]2857    elseif checkbox(4)==1
[2]2858        for ifile=1:nbfield
2859            for j=1:nbslice
2860                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2861                idetect_2(j)=exist(filename,'file')==2;
2862                filecell.ima1.civ2(ifile,j)={filename};%first image
2863            end
[112]2864            [idetectmin,indexj]=min(idetect_2);
[2]2865            if idetectmin==0,
[112]2866                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2867                filecell=[];
2868                return
[2]2869            end
2870        end
2871    end
2872   
[282]2873    %get second image names for checkciv2
2874    if checkbox(1)==1 && isequal(num2_civ1,num2_civ2) && isequal(num_b_civ1,num_b_civ2)
[2]2875        filecell.ima2.civ2=filecell.ima2.civ1;
[282]2876    elseif checkbox(4)==1
[2]2877        for ifile=1:nbfield
2878            for j=1:nbslice
2879                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2880                idetect_3(j)=exist(filename,'file')==2;
2881                filecell.ima2.civ2(ifile,j)={filename};%first image
2882            end
[112]2883            [idetectmin,indexj]=min(idetect_3);
[2]2884            if idetectmin==0,
[112]2885                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2886                filecell=[];
2887                return
[2]2888            end
2889        end
2890    end
2891end
[282]2892if (checkbox(5) || checkbox(6)) && ~checkbox(4)  % need to read an existing netcdf civ2 file
[2]2893    if ~testdiff
2894        filecell.nc.civ2=filecell.nc.civ1;% file already checked
[112]2895    else     % check the civ2 files
[2]2896        for ifile=1:nbfield
2897            for j=1:nbslice
2898                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[112]2899                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
[2]2900                filecell.nc.civ2(ifile,j)={filename};
2901                if ~exist(filename,'file')
2902                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[12]2903                    filecell=[];
[2]2904                    return
2905                else
[248]2906                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2907                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
2908                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2909                            filecell=[];
2910                            return
2911                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
[2]2912                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2913                        filecell=[];
[2]2914                        return
2915                    end
2916                end
2917            end
2918        end
2919    end
2920end
2921
2922%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2923if strcmp(compare,'stereo PIV')
[282]2924    if  checkbox(3) && isequal(get(handles.test_stereo1,'Value'),1)
[2]2925        for ifile=1:nbfield
2926            for j=1:nbslice
2927                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2928                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2929                filecell.st(ifile,j)={filename};
2930            end
2931        end
2932    end
[282]2933    if  checkbox(6) && isequal(get(handles.CheckStereo,'Value'),1)
[2]2934        for ifile=1:nbfield
2935            for j=1:nbslice
2936                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2937                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2938                filecell.st(ifile,j)={filename};
2939            end
2940        end
[112]2941    end
[2]2942end
2943set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
2944set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
2945browse.nom_type_nc=nom_type_nc;
[273]2946set(handles.RootName,'UserData',browse); %update the nomenclature type for uvmat
[2]2947
2948
2949%COPY IMAGES TO THE FORMAT .png IF NEEDED
[45]2950if isequal(nom_type_ima1,'*')%case of movie files
2951    nom_type_imanew1='_i';
[2]2952else
2953    nom_type_imanew1=nom_type_ima1;
2954end
[45]2955if isequal(nom_type_ima2,'*')%case of movie files
2956    nom_type_imanew2='_i';
[2]2957else
2958    nom_type_imanew2=nom_type_ima2;
2959end
2960if ~isequal(ext_ima,'.png')
[45]2961    %%type of image file
2962    type_ima1='none';%default
2963    movieobject1=[];%default
[133]2964    if strcmpi(ext_ima,'.avi')
[45]2965        hhh=which('mmreader');
2966        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2967            type_ima1='movie';
2968            movieobject1=mmreader([filebase_ima2 ext_ima]);
2969        else
2970            type_ima1='avi';
2971        end
[133]2972    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2973        form=imformats(ext_ima(2:end));
2974        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2975            if isequal(nom_type_ima1,'*');
2976                type_ima1='multimage';%image series in a single image file
2977            else
2978                type_ima1='image';
2979            end
2980        end
[45]2981    end
2982    type_ima2='none';%default
2983    movieobject2=[];
[133]2984    if strcmpi(ext_ima,'.avi')
[45]2985        hhh=which('mmreader');
2986        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2987            type_ima2='movie';
2988            movieobject2=mmreader([filebase_ima2 ext_ima]);
2989        else
2990            type_ima2='avi';
2991        end
[133]2992    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2993        form=imformats(ext_ima(2:end));
2994        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2995            if isequal(nom_type_ima1,'*');
2996                type_ima2='multimage';%image series in a single image file
2997            else
2998                type_ima2='image';
2999            end
3000        end
[45]3001    end
[71]3002    %npxy=get(handles.ImaExt,'UserData');
[112]3003    % %     if numel(npxy)<2
3004    %
3005    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
3006    %         A=imread(filename);
3007    %         npxy=size(A);
3008    % %     end
3009    %     npy=npxy(1);
3010    %     npx=npxy(2);
[282]3011    if checkbox(1) %if civ1 is performed
[224]3012        h = waitbar(0,'copy images to the .png format for civ1');% display a wait bar
[112]3013        for ifile=1:nbfield
[2]3014            waitbar(ifile/nbfield);
3015            for j=1:nbslice
[112]3016                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
3017                if ~exist(filename,'file')
3018                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
3019                    imwrite(A,filename,'BitDepth',16);
3020                end
3021                filecell.ima1.civ1(ifile,j)={filename};
3022                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
3023                if ~exist(filename,'file')
3024                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
3025                    imwrite(A,filename,'BitDepth',16);
3026                end
3027                filecell.ima2.civ1(ifile,j)={filename};
[2]3028            end
3029        end
3030        close(h)
3031    end
[282]3032    if checkbox(4) %if civ2 is performed
[229]3033        h = waitbar(0,'copy images to the .png format for civ2');% display a wait bar
[2]3034        for ifile=1:nbfield
3035            waitbar(ifile/nbfield);
3036            for j=1:nbslice
[112]3037                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
3038                if ~exist(filename,'file')
3039                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
3040                    imwrite(A,filename,'BitDepth',16);
3041                end
3042                filecell.ima1.civ2(ifile,j)={filename};
3043                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
3044                if ~exist(filename,'file')
3045                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
3046                    imwrite(A,filename,'BitDepth',16);
3047                end
3048                filecell.ima2.civ2(ifile,j)={filename};
[2]3049            end
3050        end
3051        close(h);
3052    end
3053end
3054
[12]3055%------------------------------------------------------------------------
[227]3056% --- determine the list of index pairs of processing file
3057function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
3058    find_pair_indices(handles,ref_i,ref_j,mode)
3059%------------------------------------------------------------------------
3060
[282]3061list_civ1=get(handles.ListPairCiv1,'String');
3062index_civ1=get(handles.ListPairCiv1,'Value');
[227]3063str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
3064if isempty(str_civ1)||isequal(str_civ1,'')
3065    msgbox_uvmat('ERROR','no image pair selected for civ1')
3066    return
3067end
[282]3068list_civ2=get(handles.ListPairCiv2,'String');
3069index_civ2=get(handles.ListPairCiv2,'Value');
[227]3070if index_civ2>length(list_civ2)
3071    list_civ2=list_civ1;
3072    index_civ2=index_civ1;
3073end
3074str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
3075
3076if isequal (mode,'series(Di)')
3077    lastfield=str2double(get(handles.nb_field,'String'));
3078    num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers
3079    num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i));
3080    num_a_civ1=ref_j;
3081    num_b_civ1=ref_j;
[229]3082    num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));
[227]3083    num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
3084    num_a_civ2=ref_j;
3085    num_b_civ2=ref_j;   
3086   
3087    % adjust the first and last field number
3088    lastfield=str2double(get(handles.nb_field,'String'));
3089    if isnan(lastfield)
3090        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
3091    else
3092        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
3093    end
3094    if length(indsel)>=1
3095        firstind=indsel(1);
3096        lastind=indsel(end);
3097        set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields
3098        set(handles.last_i,'String',num2str(ref_i(lastind)))
3099        ref_i=ref_i(indsel);
3100        num1_civ1=num1_civ1(indsel);
3101        num1_civ2=num1_civ2(indsel);
3102        num2_civ1=num2_civ1(indsel);
3103        num2_civ2=num2_civ2(indsel);
3104    end
3105elseif isequal (mode,'series(Dj)')
3106    lastfield_j=str2double(get(handles.nb_field2,'String'));
3107    num1_civ1=ref_i;% set of first image numbers
3108    num2_civ1=ref_i;
3109    num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j));
3110    num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j));
3111    num1_civ2=ref_i;
3112    num2_civ2=ref_i;
3113    num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j));
3114    num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j));
3115    % adjust the first and last field number
3116    if isnan(lastfield_j)
3117        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3118    else
3119        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3120    end
3121    if length(indsel)>=1
3122        firstind=indsel(1);
3123        lastind=indsel(end);
3124        set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields
3125        set(handles.last_j,'String',num2str(ref_j(lastind)))
3126        ref_j=ref_j(indsel);
3127        num_a_civ1=num_a_civ1(indsel);
3128        num_b_civ1=num_b_civ1(indsel);
3129        num_a_civ2=num_a_civ2(indsel);
3130        num_b_civ2=num_b_civ2(indsel);
3131    end
3132elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[282]3133    displ_num=get(handles.ListPairCiv1,'UserData');
[227]3134    num1_civ1=ref_i;
3135    num2_civ1=ref_i;
3136    num_a_civ1=displ_num(1,index_civ1);
3137    num_b_civ1=displ_num(2,index_civ1);
3138    num1_civ2=ref_i;
3139    num2_civ2=ref_i;
3140    num_a_civ2=displ_num(1,index_civ2);
3141    num_b_civ2=displ_num(2,index_civ2);
3142elseif isequal(mode,'displacement')
3143    num1_civ1=ref_i;
3144    num2_civ1=ref_i;
3145    num_a_civ1=ref_j;
3146    num_b_civ1=ref_j;
3147    num1_civ2=ref_i;
3148    num2_civ2=ref_i;
3149    num_a_civ2=ref_j;
3150    num_b_civ2=ref_j;
3151end
3152
3153
3154%------------------------------------------------------------------------
[12]3155% --- STEREO Interp
[67]3156function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
[12]3157%------------------------------------------------------------------------
[224]3158namelog=[filename_nc(1:end-3) '_stinterp.log'];
[67]3159cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
[2]3160    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
3161
[12]3162%------------------------------------------------------------------------
[282]3163% --- Executes on button press in CheckCiv1.
3164function CheckCiv1_Callback(hObject, eventdata, handles)
[12]3165%------------------------------------------------------------------------
[282]3166state=get(handles.CheckCiv1,'Value');
[273]3167enable_civ1(handles,state)
3168if state
[2]3169    enable_pair1(handles,'on')
3170end
3171find_netcpair_civ1(hObject, eventdata, handles);
3172
[12]3173%------------------------------------------------------------------------
[282]3174% --- Executes on button press in CheckFix1.
3175function CheckFix1_Callback(hObject, eventdata, handles)
[12]3176%------------------------------------------------------------------------
[282]3177enable_fix1(handles,get(handles.CheckFix1,'Value'))
[2]3178
[12]3179%------------------------------------------------------------------------
[282]3180% --- Executes on button press in CheckPatch1.
3181function CheckPatch1_Callback(hObject, eventdata, handles)
[12]3182%------------------------------------------------------------------------
[282]3183enable_patch1(handles,get(handles.CheckPatch1,'Value'))
[2]3184
[12]3185%------------------------------------------------------------------------
[282]3186% --- Executes on button press in CheckCiv2.
3187function CheckCiv2_Callback(hObject, eventdata, handles)
[12]3188%------------------------------------------------------------------------
[282]3189state=get(handles.CheckCiv2,'Value');
[2]3190enable_civ2(handles,state)
3191if state
3192    find_netcpair_civ2(hObject, eventdata, handles)
3193    enable_pair1(handles,'on')
3194end
3195
[12]3196%------------------------------------------------------------------------
[282]3197% --- Executes on button press in CheckFix2.
3198function CheckFix2_Callback(hObject, eventdata, handles)
[12]3199%------------------------------------------------------------------------
[282]3200state=get(handles.CheckFix2,'Value');
[273]3201enable_fix2(handles,state)
3202if state
3203    find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
[2]3204end
3205
[12]3206%------------------------------------------------------------------------
[282]3207% --- Executes on button press in CheckPatch2.
3208function CheckPatch2_Callback(hObject, eventdata, handles)
[12]3209%------------------------------------------------------------------------
[282]3210state=get(handles.CheckPatch2,'Value');
[273]3211enable_patch2(handles,state)
3212if state
3213    find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
[2]3214end
3215
[12]3216%------------------------------------------------------------------------
3217function first_i_Callback(hObject, eventdata, handles)
3218%------------------------------------------------------------------------
3219% last_i_Callback(hObject, eventdata, handles)
[137]3220first_i=str2double(get(handles.first_i,'String'));
[12]3221% last_i=str2num(get(handles.last_i,'String'));
3222% ref_i=ceil((first_i+last_i)/2);
3223set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
[273]3224%set(handles.ref_i_civ2,'String', num2str(first_i))% reference index for pair dt = first index
[12]3225ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3226
[12]3227%------------------------------------------------------------------------
3228function first_j_Callback(hObject, eventdata, handles)
3229%------------------------------------------------------------------------
3230first_j=str2num(get(handles.first_j,'String'));
3231set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3232ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3233
[12]3234%------------------------------------------------------------------------
[287]3235% --- Executes on button press in SearchRange: determine the search range num_Searchx,num_Searchy
[273]3236function SearchRange_Callback(hObject, eventdata, handles)
[12]3237%------------------------------------------------------------------------
[2]3238%determine pair numbers
[273]3239if strcmp(get(handles.umin,'Visible'),'off')
3240    set(handles.u_title,'Visible','on')
3241    set(handles.v_title,'Visible','on')
3242    set(handles.umin,'Visible','on')
3243    set(handles.umax,'Visible','on')
3244    set(handles.vmin,'Visible','on')
3245    set(handles.vmax,'Visible','on')
3246    set(handles.CoordUnit,'Visible','on')
3247    set(handles.TimeUnit,'Visible','on')
3248    set(handles.slash_title,'Visible','on')
3249    set(handles.min_title,'Visible','on')
3250    set(handles.max_title,'Visible','on')
3251    set(handles.unit_title,'Visible','on')
3252else
3253    get_search_range(hObject, eventdata, handles)
[2]3254end
3255
[12]3256%------------------------------------------------------------------------
[287]3257% ---  determine the search range num_Searchx,num_Searchy and shift
[273]3258function get_search_range(hObject, eventdata, handles)
3259umin=str2double(get(handles.umin,'String'));
3260umax=str2double(get(handles.umax,'String'));
3261vmin=str2double(get(handles.umin,'String'));
3262vmax=str2double(get(handles.vmax,'String'));
3263%switch min_title and max_title in case of error
3264if umax<=umin
3265    umin_old=umin;
3266    umin=umax;
3267    umax=umin_old;
3268    set(handles.umin,'String', num2str(umin))
3269    set(handles.umax,'String', num2str(umax))
3270end
3271if vmax<=vmin
3272    vmin_old=vmin;
3273    vmin=vmax;
3274    vmax=vmin_old;
3275    set(handles.vmin,'String', num2str(vmin))
3276    set(handles.vmax,'String', num2str(vmax))
3277end   
3278if ~(isnan(umin)||isnan(umax)||isnan(vmin)||isnan(vmax))
[282]3279    list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
3280    index=get(handles.ListPairCiv1,'Value');
3281    displ_num=get(handles.ListPairCiv1,'UserData');
[273]3282    time=get(handles.ImaDoc,'UserData'); %get the set of times
3283    pxcm_xy=get(handles.SearchRange,'UserData');
3284    pxcmx=pxcm_xy(1);
3285    pxcmy=pxcm_xy(2);
[282]3286    mode_list=get(handles.ListPairMode,'String');
3287    mode_value=get(handles.ListPairMode,'Value');
[273]3288    mode=mode_list{mode_value};
3289    if isequal (mode, 'series(Di)' )
3290        ref_i=str2double(get(handles.ref_i,'String'));
3291        num1=ref_i-floor(index/2);%  first image numbers
3292        num2=ref_i+ceil(index/2);
3293        num_a=1;
3294        num_b=1;
3295    elseif isequal (mode, 'series(Dj)')
3296        num1=1;
3297        num2=1;
3298        ref_j=str2double(get(handles.ref_j,'String'));
3299        num_a=ref_j-floor(index/2);%  first image numbers
3300        num_b=ref_j+ceil(index/2);
3301    elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
3302        ref_i=str2double(get(handles.ref_i,'String'));
3303        num1=ref_i;
3304        num2=ref_i;
3305        num_a=displ_num(1,index);
3306        num_b=displ_num(2,index);
3307    end
3308    dt=time(num2,num_b)-time(num1,num_a);
[282]3309    ibx=str2double(get(handles.num_Bx,'String'));
3310    iby=str2double(get(handles.num_By,'String'));
[273]3311    umin=dt*pxcmx*umin;
3312    umax=dt*pxcmx*umax;
3313    vmin=dt*pxcmy*vmin;
3314    vmax=dt*pxcmy*vmax;
3315    shiftx=round((umin+umax)/2);
3316    shifty=round((vmin+vmax)/2);
3317    isx=(umax+2-shiftx)*2+ibx;
3318    isx=2*ceil(isx/2)+1;
3319    isy=(vmax+2-shifty)*2+iby;
3320    isy=2*ceil(isy/2)+1;
[282]3321    set(handles.num_Shiftx,'String',num2str(shiftx));
3322    set(handles.num_Shifty,'String',num2str(shifty));
[287]3323    set(handles.num_Searchx,'String',num2str(isx));
3324    set(handles.num_Searchy,'String',num2str(isy));
[273]3325end
3326
3327%------------------------------------------------------------------------
[282]3328% --- Executes on carriage return on the subdir checkciv1 edit window
[2]3329function subdir_civ1_Callback(hObject, eventdata, handles)
[12]3330%------------------------------------------------------------------------
[2]3331subdir=get(handles.subdir_civ1,'String');
[273]3332set(handles.subdir_civ2,'String',subdir);% set civ2 directory the same as civ1 by default
[282]3333menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
[273]3334ichoice=find(strcmp(subdir,menu_str),1);
3335if isempty(ichoice)
3336    ilist=numel(menu_str); %select 'new...' in the menu
3337else
3338    ilist=ichoice;
3339end
[282]3340set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
3341if get(handles.CheckCiv1,'Value')==0
[2]3342    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
3343end
3344
[12]3345%------------------------------------------------------------------------
[282]3346% --- Executes on carriage return on the subdir checkciv1 edit window
[2]3347function subdir_civ2_Callback(hObject, eventdata, handles)
[12]3348%------------------------------------------------------------------------
[273]3349subdir=get(handles.subdir_civ1,'String');
[282]3350menu_str=get(handles.ListSubDirCiv2,'String');% read the list of subdirectories for update
[273]3351ichoice=find(strcmp(subdir,menu_str),1);
3352if isempty(ichoice)
3353    ilist=numel(menu_str); %select 'new...' in the menu
3354else
3355    ilist=ichoice;
3356end
[282]3357set(handles.ListSubDirCiv2,'Value',ilist)% select the selected subdir in the menu
[2]3358%update the list of available pairs from netcdf files in the new directory
[282]3359if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
[2]3360    find_netcpair_civ2(hObject, eventdata, handles);
3361end
3362
[276]3363% %------------------------------------------------------------------------
[282]3364% % --- Executes on button press in CheckMask: select box for mask option
[276]3365% function check_Mask_Callback(hObject, eventdata, handles)
3366% %------------------------------------------------------------------------
[282]3367% maskval=get(handles.CheckMask,'Value');
[276]3368% if isequal(maskval,0)
3369%     set(handles.txt_MaskName,'Visible','off')
3370% %     set(handles.txt_MaskName,'String','')
3371% else
3372%     mask_displ='no mask'; %default
3373%     filebase=get(handles.RootName,'String');
3374%     [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
3375%     if isequal(flag_mask,1)
3376%         mask_displ=[num2str(nbslice_mask) 'mask'];
[282]3377%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[276]3378%         common_path=fileparts(filebase);
3379%         filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
3380%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3381%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
3382%             mask_displ='no mask';
3383%         end
3384%     end
3385%     if isequal(mask_displ,'no mask')
3386%         [FileName, PathName, filterindex] = uigetfile( ...
3387%             {'*.png', ' (*.png)';
3388%             '*.png',  '.png files '; ...
3389%             '*.*', 'All Files (*.*)'}, ...
3390%             'Pick a mask file *.png',filebase);
3391%         mask_displ=fullfile(PathName,FileName);
3392%         if exist(mask_displ,'file')
3393%             set(handles.txt_MaskName,'Visible','on')
3394%             set(handles.txt_MaskName,'String',mask_displ)
3395% %             mask_displ='no mask';
3396%         end
3397%     end
3398%     if isequal(mask_displ,'no mask')
[282]3399%         set(handles.CheckMask,'Value',0)
3400%         set(handles.CheckMask,'Value',0)
3401%         set(handles.CheckMask,'Value',0)
3402%         set(handles.CheckMask,'Value',0)
[276]3403%     else
[282]3404%         set(handles.CheckMask,'Value',1)
3405%         set(handles.CheckMask,'Value',1)
[276]3406%     end
3407%     set(handles.txt_MaskName,'String',mask_displ)
[282]3408%     set(handles.txt_MaskName,'String',mask_displ)
[276]3409%     set(handles.txt_Mask,'String',mask_displ)
[287]3410%     set(handles.txt_MaskName,'String',mask_displ)
[276]3411% end
[282]3412% set(handles.CheckMask,'Value',maskval)%update the checkciv2 mask with the same option as checkciv1
[2]3413
[12]3414%------------------------------------------------------------------------
[282]3415% --- Executes on button press in CheckMask.
[2]3416function get_mask_fix1_Callback(hObject, eventdata, handles)
[12]3417%------------------------------------------------------------------------
[282]3418maskval=get(handles.CheckMask,'Value');
[2]3419if isequal(maskval,0)
[282]3420    set(handles.txt_MaskName,'String','')
[2]3421else
[112]3422    mask_displ='no mask'; %default
3423    filebase=get(handles.RootName,'String');
3424    [nbslice, flag_mask]=get_mask(filebase,handles);
3425    if isequal(flag_mask,1)
3426        mask_displ=[num2str(nbslice) 'mask'];
[282]3427    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3428        filebase_a=get(handles.RootName_1,'String');
[2]3429        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3430        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3431            mask_displ='no mask';
3432        end
[112]3433    end
3434    if isequal(mask_displ,'no mask')
3435        [FileName, PathName, filterindex] = uigetfile( ...
3436            {'*.png', ' (*.png)';
[12]3437            '*.png',  '.png files '; ...
3438            '*.*', 'All Files (*.*)'}, ...
3439            'Pick a mask file *.png',filebase);
[112]3440        mask_displ=fullfile(PathName,FileName);
3441        if ~exist(mask_displ,'file')
3442            mask_displ='no mask';
3443        end
[12]3444    end
[112]3445    if isequal(mask_displ,'no mask')
[282]3446        set(handles.CheckMask,'Value',0)
3447        set(handles.CheckMask,'Value',0)
3448        set(handles.CheckMask,'Value',0)
[112]3449    else
[282]3450        %set(handles.CheckMask,'Value',1)
3451        set(handles.CheckMask,'Value',1)
[112]3452    end
[282]3453    set(handles.txt_MaskName,'String',mask_displ)
[276]3454    set(handles.txt_Mask,'String',mask_displ)
[287]3455    set(handles.txt_MaskName,'String',mask_displ)
[12]3456end
3457
3458%------------------------------------------------------------------------
[282]3459% --- Executes on button press in CheckMask: select box for mask option
[2]3460function get_mask_civ2_Callback(hObject, eventdata, handles)
[12]3461%------------------------------------------------------------------------
[282]3462maskval=get(handles.CheckMask,'Value');
[2]3463if isequal(maskval,0)
[276]3464    set(handles.txt_Mask,'String','')
[2]3465else
[112]3466    mask_displ='no mask'; %default
3467    filebase=get(handles.RootName,'String');
3468    [nbslice, flag_mask]=get_mask(filebase,handles);
3469    if isequal(flag_mask,1)
3470        mask_displ=[num2str(nbslice) 'mask'];
[282]3471    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3472        filebase_a=get(handles.RootName_1,'String');
[2]3473        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3474        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3475            mask_displ='no mask';
3476        end
[112]3477    end
3478    if isequal(mask_displ,'no mask')
3479        [FileName, PathName, filterindex] = uigetfile( ...
3480            {'*.png', ' (*.png)';
[12]3481            '*.png',  '.png files '; ...
3482            '*.*', 'All Files (*.*)'}, ...
3483            'Pick a mask file *.png',filebase);
[112]3484        mask_displ=fullfile(PathName,FileName);
3485        if ~exist(mask_displ,'file')
3486            mask_displ='no mask';
3487        end
[12]3488    end
[112]3489    if isequal(mask_displ,'no mask')
[282]3490        set(handles.CheckMask,'Value',0)
3491        set(handles.CheckMask,'Value',0)
[112]3492    else
[282]3493        set(handles.CheckMask,'Value',1)
[112]3494    end
[276]3495    set(handles.txt_Mask,'String',mask_displ)
[287]3496    set(handles.txt_MaskName,'String',mask_displ)
[12]3497end
3498
3499%------------------------------------------------------------------------
[282]3500% --- Executes on button press in CheckMask.
[2]3501function get_mask_fix2_Callback(hObject, eventdata, handles)
[12]3502%------------------------------------------------------------------------
[282]3503maskval=get(handles.CheckMask,'Value');
[2]3504if isequal(maskval,0)
[287]3505    set(handles.txt_MaskName,'String','')
[2]3506else
[12]3507    mask_displ='no mask'; %default
[71]3508    filebase=get(handles.RootName,'String');
[12]3509    [nbslice, flag_mask]=get_mask(filebase,handles);
3510    if isequal(flag_mask,1)
[112]3511        mask_displ=[num2str(nbslice) 'mask'];
[282]3512    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3513        filebase_a=get(handles.RootName_1,'String');
3514        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3515        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[112]3516            mask_displ='no mask';
3517        end
[12]3518    end
3519    if isequal(mask_displ,'no mask')
3520        [FileName, PathName, filterindex] = uigetfile( ...
[112]3521            {'*.png', ' (*.png)';
3522            '*.png',  '.png files '; ...
3523            '*.*', 'All Files (*.*)'}, ...
3524            'Pick a mask file *.png',filebase);
3525        mask_displ=fullfile(PathName,FileName);
[12]3526        if ~exist(mask_displ,'file')
[2]3527            mask_displ='no mask';
3528        end
[12]3529    end
3530    if isequal(mask_displ,'no mask')
[282]3531        set(handles.CheckMask,'Value',0)
[112]3532    end
[287]3533    set(handles.txt_MaskName,'String',mask_displ)
[2]3534end
3535
[12]3536%------------------------------------------------------------------------
3537% --- function called to look for mask files
[2]3538function [nbslice, flag_mask]=get_mask(filebase,handles)
[12]3539%------------------------------------------------------------------------
[112]3540%detect mask files, images with appropriate file base
[2]3541%[filebase '_' xx 'mask'], xx=nbslice
3542%flag_mask=1 indicates detection
3543
3544flag_mask=0;%default
3545nbslice=1;
3546
3547% subdir=get(handles.subdir_civ1,'String');
3548[Path,Name]=fileparts(filebase);
[12]3549if ~isdir(Path)
3550    msgbox_uvmat('ERROR','no path for input files')
3551    return
3552end
[272]3553% currentdir=pwd;
3554% cd(Path);%move in the dir of the root name filebase
3555maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
3556% cd(currentdir);%come back to the current working directory
[12]3557if ~isempty(maskfiles)
[112]3558    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3559    % else
[2]3560    flag_mask=1;
3561    maskname=maskfiles(1).name;% take the first mask file in the list
3562    [Path2,Name,ext]=fileparts(maskname);
3563    Namedouble=double(Name);
3564    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3565    ind_mask=findstr('mask',Name);
3566    i=ind_mask-1;
[137]3567    while val(i)==0 && i>0
[112]3568        i=i-1;
[2]3569    end
[137]3570    nbslice=str2double(Name(i+1:ind_mask-1));
3571    if ~isnan(nbslice) && Name(i)=='_'
[112]3572        flag_mask=1;
[2]3573    else
[112]3574        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3575        return
3576        nbslice=1;
[2]3577    end
[112]3578end
[2]3579
[12]3580%------------------------------------------------------------------------
3581% --- function called to look for grid files
[2]3582function [nbslice, flag_mask]=get_grid(filebase,handles)
[12]3583%------------------------------------------------------------------------
[2]3584flag_mask=0;%default
3585nbslice=1;
3586[Path,Name]=fileparts(filebase);
3587currentdir=pwd;
3588cd(Path);%move in the dir of the root name filebase
3589maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3590cd(currentdir);%come back to the current working directory
3591if ~isempty(maskfiles)
3592    flag_mask=1;
3593    maskname=maskfiles(1).name;% take the first mask file in the list
3594    [Path2,Name,ext]=fileparts(maskname);
3595    Namedouble=double(Name);
3596    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3597    ind_mask=findstr('grid',Name);
3598    i=ind_mask-1;
[137]3599    while val(i)==0 && i>0
[112]3600        i=i-1;
[2]3601    end
[137]3602    nbslice=str2double(Name(i+1:ind_mask-1));
3603    if ~isnan(nbslice) && Name(i)=='_'
[112]3604        flag_mask=1;
[2]3605    else
[112]3606        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3607        return
3608        nbslice=1;
[2]3609    end
[12]3610end
[2]3611
[12]3612%------------------------------------------------------------------------
3613% --- transform numbers to letters
[122]3614function str=num2stra(num,nom_type)
[12]3615%------------------------------------------------------------------------
[122]3616if isempty(nom_type)
3617    str='';
3618elseif strcmp(nom_type(end),'a')
[2]3619    str=char(96+num);
[122]3620elseif strcmp(nom_type(end),'A')
3621    str=char(96+num);
3622elseif isempty(nom_type(2:end))%a single index
[2]3623    str='';
3624else
3625    str=num2str(num);
3626end
[12]3627
3628%------------------------------------------------------------------------
[282]3629% --- Executes on button press in ListSubdirCiv1.
3630function ListSubdirCiv1_Callback(hObject, eventdata, handles)
[12]3631%------------------------------------------------------------------------
[282]3632list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
3633val=get(handles.ListSubdirCiv1,'Value');
[273]3634subdir=list_subdir_civ1{val};
3635if strcmp(subdir,'new...')
3636    subdir='CIV'; %default subdirectory
[2]3637end
[273]3638set(handles.subdir_civ1,'String',subdir);
3639find_netcpair_civ1(hObject, eventdata, handles)
3640% end
[2]3641
[12]3642%------------------------------------------------------------------------
[282]3643% --- Executes on button press in ListSubDirCiv2.
3644function ListSubDirCiv2_Callback(hObject, eventdata, handles)
[12]3645%------------------------------------------------------------------------
[282]3646list_subdir_civ2=get(handles.ListSubDirCiv2,'String');
3647val=get(handles.ListSubDirCiv2,'Value');
[273]3648subdir=list_subdir_civ2{val};
3649if strcmp(subdir,'new...')
3650    subdir='CIV'; %default subdirectory
[2]3651end
[273]3652set(handles.subdir_civ2,'String',subdir);
[282]3653%     set(handles.ListSubDirCiv2,'Value',1);
[2]3654
[273]3655
[12]3656%------------------------------------------------------------------------
[282]3657% --- Executes on button press in CheckGrid.
3658function CheckGrid_Callback(hObject, eventdata, handles)
[12]3659%------------------------------------------------------------------------
[276]3660value=get(hObject,'Value');
3661hparent=get(hObject,'parent');
3662hchildren=get(hparent,'children');
3663handle_txtbox=findobj(hchildren,'tag','txt_GridName');
3664handle_dx=findobj(hchildren,'tag','num_Dx');
3665handle_dy=findobj(hchildren,'tag','num_Dy');
[2]3666testgrid=0;
[276]3667filegrid='';
[2]3668if value
[112]3669    filebase=get(handles.RootName,'String');
[276]3670    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
[2]3671    if isequal(flag_grid,1)
[112]3672        filegrid=[num2str(nbslice) 'grid'];
3673        testgrid=1;
[276]3674    else % browse for a grid
3675        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
3676        if exist(filegrid,'file')
3677            filebase=filegrid;
3678        end
[2]3679        [FileName, PathName, filterindex] = uigetfile( ...
[112]3680            {'*.grid', ' (*.grid)';
3681            '*.grid',  '.grid files '; ...
3682            '*.*', 'All Files (*.*)'}, ...
3683            'Pick a file',filebase);
[2]3684        filegrid=fullfile(PathName,FileName);
[276]3685        set(hObject,'UserData',filegrid);%store for future use
[2]3686        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3687            testgrid=1;
3688        end
[112]3689    end
[2]3690end
3691if testgrid
[276]3692    set(handle_dx,'Visible','off');
3693    set(handle_dy,'Visible','off');
3694    set(handle_txtbox,'Visible','on')
3695    set(handle_txtbox,'String',filegrid)
[112]3696else
[276]3697    set(hObject,'Value',0);
3698    set(handle_dx,'Visible','on');
3699    set(handle_dy,'Visible','on');
3700    set(handle_txtbox,'Visible','off')
[2]3701end
3702
[282]3703%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
[276]3704PanelName=get(hparent,'tag');
3705if strcmp(PanelName,'panel_Civ1')
[282]3706    hchildren=get(handles.Civ2,'children');
[276]3707    handle_checkbox=findobj(hchildren,'tag','check_Grid');
3708    handle_txtbox=findobj(hchildren,'tag','txt_GridName');
3709    handle_dx=findobj(hchildren,'tag','num_Dx');
3710    handle_dy=findobj(hchildren,'tag','num_Dy');
3711    set(handle_checkbox,'UserData',filegrid);%store for future use
3712    if testgrid
3713        set(handle_checkbox,'Value',1);
3714        set(handle_dx,'Visible','off');
3715        set(handle_dy,'Visible','off');
3716        set(handle_txtbox,'Visible','on')
3717        set(handle_txtbox,'String',filegrid)
3718    else
3719        set(handle_checkbox,'Value',0);
[282]3720        set(handles.CheckGrid,'Value',0);
[276]3721        set(handle_dx,'Visible','on');
3722        set(handle_dy,'Visible','on');
3723        set(handle_txtbox,'Visible','off')
3724    end
3725end
[12]3726%------------------------------------------------------------------------
[282]3727% --- Executes on button press in CheckMask.
3728function CheckMask_Callback(hObject, eventdata, handles)
[276]3729%------------------------------------------------------------------------
3730value=get(hObject,'Value');
3731testmask=0;
3732if value
3733    filebase=get(handles.RootName,'String');
3734    [nbslice, flag_mask]=get_mask(filebase,handles);% look for a mask with appropriate name
3735    if isequal(flag_mask,1)
3736        filemask=[num2str(nbslice) 'mask'];
3737        testmask=1;
3738    else % browse for a mask
[282]3739        filemask=get(handles.CheckMask,'UserData');%look for previous mask name stored as UserData
[276]3740        if exist(filemask,'file')
3741            filebase=filemask;
3742        end
3743        [FileName, PathName, filterindex] = uigetfile( ...
3744            {'*.png', ' (*.png)';
3745            '*.png',  '.png files '; ...
3746            '*.*', 'All Files (*.*)'}, ...
3747            'Pick a mask file *.png',filebase);
3748        filemask=fullfile(PathName,FileName);
[282]3749        set(handles.CheckMask,'UserData',filemask);%store for future use
[276]3750        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filemask,'file'))
3751            testmask=1;
3752        end
3753    end
3754end
3755if testmask
3756    set(handles.num_Dx,'Visible','off');
3757    set(handles.num_Dy,'Visible','off');
3758    set(handles.num_Dx,'Visible','off');
3759    set(handles.num_Dy,'Visible','off');
3760    set(handles.txt_MaskName,'Visible','on')
3761    set(handles.txt_MaskName,'String',filemask)
3762else
[282]3763    set(handles.CheckMask,'Value',0);
3764    set(handles.CheckGrid,'Value',0);
[276]3765    set(handles.num_Dx,'Visible','on');
3766    set(handles.num_Dy,'Visible','on');
3767    set(handles.num_Dx,'Visible','on');
3768    set(handles.num_Dy,'Visible','on');
3769    set(handles.txt_MaskName,'Visible','off')
3770end
3771
3772%------------------------------------------------------------------------
[282]3773% --- Executes on button press in CheckGrid.
[2]3774function browse_gridciv2_Callback(hObject, eventdata, handles)
[12]3775%------------------------------------------------------------------------
[282]3776value=get(handles.CheckGrid,'Value');
[2]3777if value
[112]3778    filebase=get(handles.RootName,'String');
[39]3779    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3780    if isequal(flag_grid,1)
3781        mask_displ=[num2str(nbslice) 'grid'];
[276]3782        set(handles.txt_GridName,'String',mask_displ)
3783        set(handles.num_Dx,'Visible','off');
3784        set(handles.num_Dy,'Visible','off');
[112]3785    else
[2]3786        [FileName, PathName, filterindex] = uigetfile( ...
[112]3787            {'*.grid', ' (*.grid)';
3788            '*.grid',  '.grid files '; ...
3789            '*.*', 'All Files (*.*)'}, ...
3790            'Pick a file',filebase);
[2]3791        filegrid=fullfile(PathName,FileName);
[229]3792        if isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file')
[282]3793            set(handles.CheckGrid,'Value',0);
[276]3794            set(handles.txt_GridName,'string','');
3795            set(handles.num_Dx,'Visible','on');
3796            set(handles.num_Dy,'Visible','on');
3797            set(handles.txt_GridName,'string','');
[2]3798        else
[276]3799            set(handles.txt_GridName,'string',filegrid);
3800            set(handles.num_Dx,'Visible','off');
3801            set(handles.num_Dy,'Visible','off');
3802            set(handles.txt_GridName,'string',filegrid);
[2]3803        end
3804    end
3805else
[276]3806    set(handles.txt_GridName,'string','');
3807    set(handles.num_Dx,'Visible','on');
3808    set(handles.num_Dy,'Visible','on');
3809    set(handles.txt_GridName,'string','');
[2]3810end
3811
[282]3812% % --- Executes on button press in CheckGrid.
[2]3813% function browse_gridciv2_Callback(hObject, eventdata, handles)
[112]3814%
[71]3815% filebase=get(handles.RootName,'String');
[2]3816% [FileName, PathName, filterindex] = uigetfile( ...
3817%        {'*.grid', ' (*.grid)';
3818%         '*.grid',  '.grid files '; ...
3819%         '*.*', 'All Files (*.*)'}, ...
3820%         'Pick a file',filebase);
3821% filegrid=fullfile(PathName,FileName);
[276]3822% set(handles.txt_GridName,'string',filegrid);
3823% set(handles.num_Dx,'String',' ');
3824% set(handles.num_Dy,'String',' ');
[2]3825% % set(handles.grid_patch2,'string',filegrid);
3826
3827% --- Executes on button press in get_gridpatch1.
3828function get_gridpatch1_Callback(hObject, eventdata, handles)
3829% hObject    handle to get_gridpatch1 (see GCBO)
3830% eventdata  reserved - to be defined in a future version of MATLAB
3831% handles    structure with handles and user data (see GUIDATA)
3832
[71]3833filebase=get(handles.RootName,'String');
[2]3834[FileName, PathName, filterindex] = uigetfile( ...
[112]3835    {'*.grid', ' (*.grid)';
3836    '*.grid',  '.grid files '; ...
3837    '*.*', 'All Files (*.*)'}, ...
3838    'Pick a file',filebase);
[2]3839filegrid=fullfile(PathName,FileName);
3840set(handles.grid_patch1,'string',filegrid);
3841% set(handles.grid_patch2,'string',filegrid
3842
[12]3843%------------------------------------------------------------------------
[2]3844% --- Executes on button press in get_gridpatch2.
3845function get_gridpatch2_Callback(hObject, eventdata, handles)
[12]3846%------------------------------------------------------------------------
[2]3847
[12]3848%------------------------------------------------------------------------
[2]3849function enable_civ1(handles,state)
[12]3850%------------------------------------------------------------------------
[273]3851if state
3852    RootName=get(handles.RootName,'String');
3853    if isempty(RootName)
3854         msgbox_uvmat('ERROR','No input file')
3855        return
3856    end
[282]3857    set(handles.Civ1,'Visible','on')   
3858    set(handles.PairIndices,'Visible','on')
[273]3859%     set(handles.frame_civ1,'BackgroundColor',[1 1 0])
3860%     set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
3861%     set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
[2]3862else
[282]3863    set(handles.Civ1,'Visible','off') 
[273]3864%     set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
3865%     set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
3866%     set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
[2]3867end
3868
[282]3869% set(handles.num_Bx,'Visible',state)
3870% set(handles.num_By,'Visible',state)
[287]3871% set(handles.num_Searchx,'Visible',state)
3872% set(handles.num_Searchy,'Visible',state)
[282]3873% set(handles.num_Shiftx,'Visible',state)
3874% set(handles.num_Shifty,'Visible',state)
3875% set(handles.num_Rho,'Visible',state)
3876% set(handles.num_Dx,'Visible',state)
3877% set(handles.num_Dy,'Visible',state)
3878% set(handles.SearchRange,'Visible',state)
3879% set(handles.u_title,'Visible',state)
3880% set(handles.v_title,'Visible',state)
3881% set(handles.min_title,'Visible',state)
3882% set(handles.max_title,'Visible',state)
3883% set(handles.umin,'Visible',state)
3884% set(handles.umax,'Visible',state)
3885% set(handles.vmin,'Visible',state)
3886% set(handles.vmax,'Visible',state)
3887% set(handles.txt_GridName,'Visible',state)
3888% set(handles.txt_MaskName,'Visible',state)
3889% set(handles.CheckGrid,'Visible',state)
3890% set(handles.CheckMask,'Visible',state)
3891% set(handles.parameters,'Visible',state)
3892% set(handles.grid,'Visible',state)
3893% set(handles.num_Dx,'Visible',state)
3894% set(handles.num_Dy,'Visible',state)
3895% set(handles.check_Threshold,'Visible',state)
3896% if isequal(state,'off')
3897%     set(handles.num_MinIma,'Visible','off')
3898%     set(handles.num_MaxIma,'Visible','off')
3899%     set(handles.check_Threshold,'Value',0)
3900% end
3901% set(handles.dx_civ1_title,'Visible',state)
3902% set(handles.dy_civ1_title,'Visible',state)
3903% set(handles.ImaThreshold_title,'Visible',state)
3904% set(handles.ib_title,'Visible',state)
3905% set(handles.is_title,'Visible',state)
3906% set(handles.shift_title,'Visible',state)
3907% set(handles.rho_title,'Visible',state)
3908% set(handles.TestCiv1,'Visible',state)
3909%set(handles.ListPairMode,'Visible',state)
3910
[12]3911%------------------------------------------------------------------------
[2]3912function enable_fix1(handles,state)
[12]3913%------------------------------------------------------------------------
[273]3914
[2]3915if isequal(state,0)
3916    state='off';
3917end
3918if isequal(state,1)
3919    state='on';
[273]3920    RootName=get(handles.RootName,'String');
3921    if isempty(RootName)
3922         msgbox_uvmat('ERROR','No input file')
3923        return
3924    end
[2]3925end
3926if isequal(state,'on')
[282]3927    set(handles.Fix1,'Visible','on')
[273]3928%     set(handles.frame_fix1,'BackgroundColor',[1 1 0])
[2]3929else
[282]3930    set(handles.Fix1,'Visible','off')
[273]3931    %set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
[2]3932end
[282]3933% % set(handles.REMOVE,'Visible',state)
3934% set(handles.CheckFmin2,'Visible',state)
3935% set(handles.CheckF2,'Visible',state)
3936% set(handles.CheckF3,'Visible',state)
3937% set(handles.num_MinCorr,'Visible',state)
3938% set(handles.thresh_vecC_title,'Visible',state)
[287]3939% set(handles.num_MinVel,'Visible',state)
3940% set(handles.TitleMinVel,'Visible',state)
[282]3941% set(handles.txt_MaskName,'Visible',state)
3942% set(handles.CheckMask,'Visible',state)
3943% set(handles.get_ref_fix1,'Visible',state)
3944% set(handles.ref_fix1,'Visible',state)
[287]3945% set(handles.num_MinVel,'Visible',state)
[282]3946% set(handles.field_ref1,'Visible',state)
[2]3947
[12]3948%------------------------------------------------------------------------
[273]3949function enable_patch1(handles,state)
[12]3950%------------------------------------------------------------------------
[273]3951if state
3952    RootName=get(handles.RootName,'String');
3953    if isempty(RootName)
3954        msgbox_uvmat('ERROR','No input file')
3955        return
3956    end
[282]3957    set(handles.Patch1,'Visible','on')
[273]3958else
[282]3959    set(handles.Patch1,'Visible','off')
[273]3960end
3961return
[2]3962set(handles.frame_patch1,'BackgroundColor',[1 1 0])
3963set(handles.rho_patch1,'Visible','on')
3964set(handles.rho_text1,'Visible','on')
[282]3965if get(handles.ListPairMode,'Value')==2
[224]3966    set(handles.thresh_patch1,'Visible','on')
3967    set(handles.thresh_text1,'Visible','on')
3968end
[2]3969set(handles.subdomain_patch1,'Visible','on')
3970set(handles.subdomain_text1,'Visible','on')
3971set(handles.nx_patch1,'Visible','on')
[274]3972set(handles.num_Ny,'Visible','on')
[2]3973set(handles.nx_patch1_title,'Visible','on')
3974set(handles.ny_patch1_title,'Visible','on')
[112]3975% if ~isempty(patch_newBin)
[224]3976set(handles.test_interp,'Visible','off');
[282]3977stereo_test=get(handles.ListCompareMode,'Value');
[252]3978if stereo_test==3
3979    set(handles.test_stereo1,'Visible','on')
3980end
[100]3981% end
[252]3982%set(handles.get_gridpatch1,'Visible','on')
3983%set(handles.grid_patch1,'string','none');
3984%set(handles.grid_patch1,'Visible','on')
[2]3985
[273]3986% %------------------------------------------------------------------------
3987% function desable_patch1(handles)
3988% %------------------------------------------------------------------------
3989% return
3990% set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
3991% set(handles.rho_patch1,'Visible','off')
3992% set(handles.rho_text1,'Visible','off')
3993% set(handles.thresh_patch1,'Visible','off')
3994% set(handles.thresh_text1,'Visible','off')
3995% set(handles.subdomain_patch1,'Visible','off')
3996% set(handles.subdomain_text1,'Visible','off')
3997% set(handles.nx_patch1,'Visible','off')
[274]3998% set(handles.num_Ny,'Visible','off')
[273]3999% set(handles.nx_patch1_title,'Visible','off')
4000% set(handles.ny_patch1_title,'Visible','off')
4001% set(handles.test_stereo1,'Visible','off')
4002% %set(handles.test_interp,'Visible','off')
4003% %set(handles.get_gridpatch1,'Visible','off')
4004% %set(handles.grid_patch1,'Visible','off')
[2]4005
[12]4006%------------------------------------------------------------------------
[2]4007function enable_civ2(handles,state)
[12]4008%------------------------------------------------------------------------
[273]4009if state
4010    RootName=get(handles.RootName,'String');
4011    if isempty(RootName)
4012         msgbox_uvmat('ERROR','No input file')
4013        return
4014    end
[282]4015    set(handles.Civ2,'Visible','on')
[2]4016else
[282]4017    set(handles.Civ2,'Visible','off')
[2]4018end
[273]4019
[282]4020%
[287]4021% set(handles.num_Bx,'Visible',state)
4022% set(handles.num_By,'Visible',state)
4023% set(handles.CheckDecimal,'Visible',state)
4024% set(handles.CheckDeformation,'Visible',state)
4025% set(handles.num_Rho,'Visible',state)
[282]4026% set(handles.num_Dx,'Visible',state)
4027% set(handles.num_Dy,'Visible',state)
4028% set(handles.CheckGrid,'Visible',state)
4029% set(handles.CheckMask,'Visible',state)
4030% set(handles.parameters,'Visible',state)
4031% set(handles.grid,'Visible',state)
4032% set(handles.parameters_text,'Visible',state)
4033% set(handles.grid_text,'Visible',state)
4034% set(handles.txt_GridName,'Visible',state)
4035% set(handles.txt_Mask,'Visible',state)
4036% set(handles.dx_civ2_title,'Visible',state)
4037% set(handles.dy_civ2_title,'Visible',state)
4038% set(handles.ibx_civ2_text,'Visible',state)
4039% set(handles.rho_civ2_title,'Visible',state)
4040% set(handles.ImaThreshold2,'Visible',state)
4041% set(handles.ImaThreshold_title2,'Visible',state)
4042% if isequal(state,'off')
[287]4043%     set(handles.num_MinIma,'Visible','off')
4044%     set(handles.num_MaxIma,'Visible','off')
[282]4045%     set(handles.ImaThreshold2,'Value',0)
4046%     if isequal(get(handles.CheckFix2,'Value'),0) & isequal(get(handles.CheckPatch2,'Value'),0)
4047%         set(handles.ListPairCiv2,'Visible','off')
4048%         set(handles.subdir_civ2,'Visible','off')
4049%         set(handles.subdir_civ2_text,'Visible','off')
4050%         set(handles.dt_unit_civ2,'Visible','off')
4051%         %set(handles.ref_i_civ2,'Visible','off')
4052%         set(handles.i_ref_civ2_title,'Visible','off')
4053%         set(handles.j_ref_civ2_title,'Visible','off')
4054%         set(handles.ref_j_civ2,'Visible','off')
4055%     end
4056% else
4057%     set(handles.ListPairCiv2,'Visible','on')
4058%     set(handles.subdir_civ2,'Visible','on')
4059%     set(handles.subdir_civ2_text,'Visible','on')
4060%     set(handles.dt_unit_civ2,'Visible','on')
4061%   %  set(handles.ref_i_civ2,'Visible','on')
4062%     set(handles.i_ref_civ2_title,'Visible','on')
4063%     set(handles.j_ref_civ2_title,'Visible','on')
4064%     set(handles.ref_j_civ2,'Visible','on')
4065% end
4066% set(handles.rho_civ2_title,'Visible',state)
[2]4067
[12]4068%------------------------------------------------------------------------
[273]4069function enable_fix2(handles,state)
[12]4070%------------------------------------------------------------------------
[273]4071% if isequal(state,'on')
[282]4072%     set(handles.Fix2,'Visible','on') 
[273]4073%     
4074% %     set(handles.frame_civ2,'BackgroundColor',[1 1 0])
4075% %     set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
4076% %     set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
4077% %     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
4078% else
4079if state
4080    RootName=get(handles.RootName,'String');
4081    if isempty(RootName)
4082         msgbox_uvmat('ERROR','No input file')
4083        return
4084    end
[282]4085    set(handles.Fix2,'Visible','on')
[273]4086else
[282]4087    set(handles.Fix2,'Visible','off')
[273]4088end
[2]4089
[282]4090% set(handles.frame_fix2,'BackgroundColor',[1 1 0])
4091% set(handles.REMOVE2,'Visible','on')
[287]4092% set(handles.CheckFmin2,'Visible','on')
4093% set(handles.CheckF4,'Visible','on')
4094% set(handles.CheckF3,'Visible','on')
4095% set(handles.num_MinCorr,'Visible','on')
[282]4096% set(handles.thresh_vec2C_text,'Visible','on')
[287]4097% set(handles.num_MinVel,'Visible','on')
4098% set(handles.TitleMinVel,'Visible','on')
4099% set(handles.txt_MaskName,'Visible','on')
[282]4100% set(handles.CheckMask,'Visible','on')
4101% set(handles.ListPairCiv2,'Visible','on')
4102% set(handles.subdir_civ2,'Visible','on')
4103% set(handles.subdir_civ2_text,'Visible','on')
4104% set(handles.get_ref_fix2,'Visible','on')
4105% set(handles.ref_fix2,'Visible','on')
[287]4106% set(handles.num_MinVel,'Visible','on')
[282]4107% set(handles.field_ref2,'Visible','on')
4108
[273]4109% %------------------------------------------------------------------------
4110% function desable_fix2(handles)
4111% %------------------------------------------------------------------------
4112% set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
4113% set(handles.REMOVE2,'Visible','off')
[287]4114% set(handles.CheckFmin2,'Visible','off')
4115% set(handles.CheckF4,'Visible','off')
4116% set(handles.CheckF3,'Visible','off')
4117% set(handles.num_MinCorr,'Visible','off')
[273]4118% set(handles.thresh_vec2C_text,'Visible','off')
[287]4119% set(handles.num_MinVel,'Visible','off')
4120% set(handles.TitleMinVel,'Visible','off')
4121% set(handles.txt_MaskName,'Visible','off')
[282]4122% set(handles.CheckMask,'Visible','off')
[273]4123% set(handles.get_ref_fix2,'Visible','off')
4124% set(handles.ref_fix2,'Visible','off')
[287]4125% set(handles.num_MinVel,'Visible','off')
[273]4126% set(handles.field_ref2,'Visible','off')
[282]4127% if isequal(get(handles.CheckCiv2,'Value'),0) & isequal(get(handles.CheckPatch2,'Value'),0)
4128%     set(handles.ListPairCiv2,'Visible','off')
[273]4129%     set(handles.subdir_civ2,'Visible','off')
4130%     set(handles.subdir_civ2_text,'Visible','off')
4131% end
[2]4132
[12]4133%------------------------------------------------------------------------
[273]4134function enable_patch2(handles,state)
[12]4135%------------------------------------------------------------------------
[273]4136if state
4137RootName=get(handles.RootName,'String');
4138    if isempty(RootName)
4139         msgbox_uvmat('ERROR','No input file')
4140        return
4141    end
[282]4142    set(handles.Patch2,'Visible','on')
[273]4143else
[282]4144set(handles.Patch2,'Visible','off')
[252]4145end
[273]4146% set(handles.frame_patch2,'BackgroundColor',[1 1 0])
[274]4147% set(handles.num_SmoothParam,'Visible','on')
4148% set(handles.num_SmoothingParam,'Visible','on')
4149% set(handles.num_MaxDiff,'Visible','on')
[273]4150% set(handles.thresh_text2,'Visible','on')
[274]4151% set(handles.num_SubdomainSize,'Visible','on')
[273]4152% set(handles.subdomain_text2,'Visible','on')
[274]4153% set(handles.num_Nx,'Visible','on')
4154% set(handles.num_Ny,'Visible','on')
[273]4155% set(handles.nx_patch2_title,'Visible','on')
4156% set(handles.ny_patch2_title,'Visible','on')
4157% % set(handles.get_gridpatch2,'Visible','on')
4158% % set(handles.grid_patch2,'Visible','on')
[282]4159% set(handles.ListPairCiv2,'Visible','on')
[273]4160% set(handles.subdir_civ2,'Visible','on')
4161% set(handles.subdir_civ2_text,'Visible','on')
[282]4162% stereo_test=get(handles.ListCompareMode,'Value');
[273]4163% if stereo_test==3
[282]4164%     set(handles.CheckStereo,'Visible','on')
[273]4165% end
[2]4166
[273]4167% %------------------------------------------------------------------------
4168% function desable_patch2(handles)
4169% %------------------------------------------------------------------------
[282]4170% %set(handles.checkpatch2,'Visible','off')
[273]4171% return
4172% set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
[274]4173% set(handles.num_SmoothParam,'Visible','off')
4174% set(handles.num_SmoothingParam,'Visible','off')
4175% set(handles.num_MaxDiff,'Visible','off')
[273]4176% set(handles.thresh_text2,'Visible','off')
[274]4177% set(handles.num_SubdomainSize,'Visible','off')
[273]4178% set(handles.subdomain_text2,'Visible','off')
[274]4179% set(handles.num_Nx,'Visible','off')
4180% set(handles.num_Ny,'Visible','off')
[273]4181% set(handles.nx_patch2_title,'Visible','off')
4182% set(handles.ny_patch2_title,'Visible','off')
4183% % set(handles.get_gridpatch2,'Visible','off')
4184% % set(handles.grid_patch2,'Visible','off')
[282]4185% if isequal(get(handles.CheckCiv2,'Value'),0) & isequal(get(handles.CheckFix2,'Value'),0)
4186%     set(handles.ListPairCiv2,'Visible','off')
[273]4187%     set(handles.subdir_civ2,'Visible','off')
4188%     set(handles.subdir_civ2_text,'Visible','off')
4189% end
[282]4190% set(handles.CheckStereo,'Visible','off')
[12]4191%------------------------------------------------------------------------
[2]4192function enable_pair1(handles,state)
[12]4193%------------------------------------------------------------------------
[2]4194set(handles.subdir_civ1,'Visible',state)
[282]4195set(handles.ListSubdirCiv1,'Visible',state)
[2]4196set(handles.SUBDIR_CIV1_txt,'Visible',state)
[273]4197%set(handles.frame_subdirciv1,'Visible',state)
[282]4198set(handles.ListPairCiv1,'Visible',state)
[273]4199set(handles.PairCiv1_title,'Visible',state)
[71]4200%set(handles.dt_unit,'Visible',state)
[273]4201%set(handles.PAIR_frame,'Visible',state)
[2]4202
[12]4203%------------------------------------------------------------------------
[282]4204% --- Read the parameters for checkciv1 on the interface
[285]4205% function par=read_param_civ1(handles,filecell)
4206% % not deeden anymore
4207% %------------------------------------------------------------------------
4208% ibx_val=str2double(get(handles.num_Bx,'String'));
4209% par.ibx=num2str(ibx_val);
4210% iby_val=str2double(get(handles.num_By,'String'));
4211% par.iby=num2str(iby_val);
[287]4212% isx=get(handles.num_Searchx,'String');
4213% if isnan(str2double(isx)), isx='41'; set(handles.num_Searchx,'String','41'), end; %default
4214% if str2double(isx)<ibx_val+8,isx=num2str(ibx_val+8); set(handles.num_Searchx,'String',num2str(ibx_val+8)); end
4215% isy=get(handles.num_Searchy,'String');
4216% if isnan(str2double(isy)), isy='41'; set(handles.num_Searchy,'String','41'), end;%default
4217% if str2double(isy)<iby_val+8,isy=num2str(iby_val+8); set(handles.num_Searchy,'String',num2str(iby_val+8)); end
4218% par.isx=get(handles.num_Searchx,'String');
4219% par.isy=get(handles.num_Searchy,'String');
[285]4220% par.shiftx=get(handles.num_Shiftx,'String');
4221% par.shifty=get(handles.num_Shifty,'String');
4222% if isnan(str2double(par.isx))
4223%     par.isx='41';%default
[287]4224%     set(handles.num_Searchx,'String','41');
[272]4225% end
[285]4226% if isnan(str2double(par.isy))
4227%     par.isy='41'; %default
[287]4228%     set(handles.num_Searchy,'String','41');
[285]4229% end
4230% if isnan(str2double(par.shiftx))
4231%     par.shiftx='0';%default
4232%     set(handles.num_Shiftx,'String','0');
4233% end
4234% if isnan(str2double(par.shifty))
4235%     par.shifty='0'; %default
4236%     set(handles.num_Shifty,'String','0');
4237% end
4238% par.rho=get(handles.num_Rho,'String');
4239% if isequal(get(handles.num_Rho,'Style'),'popupmenu')
4240%     index=get(handles.num_Rho,'Value');
4241%     par.rho=par.rho{index};
4242% end
4243% dummy=get(handles.num_Dx,'String');
4244% par.dx=dummy{1};
4245% dummy=get(handles.num_Dy,'String');
4246% par.dy=dummy{1};
4247% if isnan(str2double(par.dx))
4248%     if isempty(get(handles.txt_GridName,'String'));
4249%         par.dx='0'; %just read by civ program, not used
4250%     else
4251%         par.dx='20';%default
4252%         set(handles.num_Dx,'String','20');
4253%     end
4254% end
4255% if isnan(str2double(par.dy))
4256%     if isempty(get(handles.txt_GridName,'String'));
4257%         par.dy='0';%just read by civ program, not used
4258%     else
4259%         par.dy='20';%default
4260%         set(handles.dy_civ1_title,'String','20');
4261%     end
4262% end
4263% par.pxcmx='1'; %velocities are expressed in pixel dispalcement
4264% par.pxcmy='1';
4265% % if exist('file_ima','var')
4266% A=imread(filecell.ima1.civ1{1,1});%read the first image to get the size
4267% sizim=size(A);
4268% par.npx=num2str(sizim(2));
4269% par.npy=num2str(sizim(1));
4270% %TODO : civ should not need npx and npy
4271%
4272%
4273% % end
4274% %time=get(handles.RootName,'UserData'); %get the set of times
4275% dummy=get(handles.txt_GridName,'String');
4276% par.gridname=dummy{1};
4277% par.gridflag='y';
4278% if strcmp(par.gridname,'')|| isempty(par.gridname)
4279%     par.gridname='nogrid';
4280%     par.gridflag='n';
4281% end
4282%
[272]4283 
4284           
4285%------------------------------------------------------------------------
[2]4286function par=read_param_civ2(handles,file_ima)
[12]4287%------------------------------------------------------------------------
[287]4288par.ibx=get(handles.num_Bx,'String');
4289par.iby=get(handles.num_By,'String');
4290par.rho=get(handles.num_Rho,'String');
4291par.decimal=int2str(get(handles.CheckDecimal,'Value'));
4292par.deformation=int2str(get(handles.CheckDeformation,'Value'));
[276]4293par.dx=get(handles.num_Dx,'String');
4294par.dy=get(handles.num_Dy,'String');
[127]4295if isnan(str2double(par.dx))
[276]4296    if isempty(get(handles.txt_GridName,'String'));
[112]4297        par.dx='0'; %just read by civ program, not used
4298    else
[12]4299        par.dx='20';%default
[276]4300        set(handles.num_Dx,'String','20');
[112]4301    end
4302end
[127]4303if isnan(str2double(par.dy))
[276]4304    if isempty(get(handles.txt_GridName,'String'));
[112]4305        par.dy='0';%just read by civ program, not used
4306    else
[12]4307        par.dy='20';%default
[276]4308        set(handles.num_Dy,'String','20');
[112]4309    end
4310end
4311par.pxcmx='1';
4312par.pxcmy='1';
[12]4313A=imread(file_ima);%read the first image to get the size
4314sizim=size(A);
4315par.npx=num2str(sizim(2));
4316par.npy=num2str(sizim(1));
[127]4317%time=get(handles.RootName,'UserData'); %get the set of times
[276]4318par.gridname=get(handles.txt_GridName,'String');
[12]4319par.gridflag='y';
[127]4320if strcmp(par.gridname,'')|| isempty(par.gridname)
[12]4321    par.gridname='nogrid';
4322    par.gridflag='n';
4323end
[2]4324
[272]4325function cmd_CIV1=CIV1_CMD(filename,param)
4326%TODO : include filename in par_civ1
[12]4327%------------------------------------------------------------------------
[2]4328%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4329
4330%changes : filename_cmx -> filename ( no extension )
[272]4331
[275]4332filename=regexprep(filename,'.nc','');
[272]4333
[284]4334if isequal(Param.Civ1.Dt,'0')
4335    Param.Civ1.Dt='1' ;%case of 'displacement' mode
[112]4336end
[284]4337Param.Civ1.filename_ima_a=regexprep(Param.Civ1.filename_ima_a,'.png','');
4338Param.Civ1.filename_ima_b=regexprep(Param.Civ1.filename_ima_b,'.png','');
[230]4339fid=fopen([filename '.civ1.cmx'],'w');
[12]4340fprintf(fid,['##############   CMX file' '\n' ]);
[284]4341fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4342fprintf(fid,   ['LastImage  ' regexprep(Param.Civ1.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
[112]4343fprintf(fid,  ['XX' '\n' ]);
[284]4344fprintf(fid,  ['Mask ' Param.Civ1.maskflag '\n' ]);
4345fprintf(fid,  ['MaskName ' regexprep(Param.Civ1.maskname,'\\','\\\\') '\n' ]);
4346fprintf(fid,   ['ImageSize ' Param.Civ1.npx ' ' Param.Civ1.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4347fprintf(fid,   ['CorrelationBoxesSize ' Param.Civ1.ibx ' ' Param.Civ1.iby '\n' ]);
4348fprintf(fid,   ['SearchBoxeSize ' Param.Civ1.isx ' ' Param.Civ1.isy '\n' ]);
4349fprintf(fid,   ['RO ' Param.Civ1.rho '\n' ]);
4350fprintf(fid,   ['GridSpacing ' Param.Civ1.dx ' ' Param.Civ1.dy '\n' ]);
[112]4351fprintf(fid,   ['XX 1.0' '\n' ]);
[284]4352fprintf(fid,   ['Dt_TO ' Param.Civ1.Dt ' ' Param.Civ1.T0 '\n' ]);
4353fprintf(fid,  ['PixCmXY ' Param.Civ1.pxcmx ' ' Param.Civ1.pxcmy '\n' ]);
[112]4354fprintf(fid,  ['XX 1' '\n' ]);
[284]4355fprintf(fid,   ['ShiftXY ' Param.Civ1.shiftx ' '  Param.Civ1.shifty '\n' ]);
4356fprintf(fid,  ['Grid ' Param.Civ1.gridflag '\n' ]);
4357fprintf(fid,   ['GridName ' regexprep(Param.Civ1.gridname,'\\','\\\\') '\n' ]);
[112]4358fprintf(fid,   ['XX 85' '\n' ]);
4359fprintf(fid,   ['XX 1.0' '\n' ]);
4360fprintf(fid,   ['XX 1.0' '\n' ]);
4361fprintf(fid,   ['Hart 1' '\n' ]);
4362fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4363fprintf(fid,   ['Deformation 0' '\n' ]);
4364fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4365fprintf(fid,   ['IntensityMin 0' '\n' ]);
4366fprintf(fid,  ['SeuilImage n' '\n' ]);
4367fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
[284]4368fprintf(fid,   ['ImageToUse ' Param.Civ1.term_a ' ' Param.Civ1.term_b '\n' ]); % VERIFIER ?
[112]4369fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
[12]4370fclose(fid);
[112]4371
[163]4372% cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
4373% cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4374% namelog=regexprep(namelog,'\\','\\\\');
[12]4375if(isunix)
[272]4376    cmd_CIV1=['cp -f ' filename '.civ1.cmx ' filename '.cmx'];
4377    cmd_CIV1=[cmd_CIV1 '\n'...
[284]4378        Param.xml.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
[219]4379    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' filename '.log' ' ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.nc'];%rename .log as .civ1.log and set the netcdf result file for group user writting
[282]4380   % cmd_CIV1=[cmd_CIV1 '\n' 'mv ' filename '.cmx' ' ' filename '.checkciv1.cmx' '\n'];%rename .cmx as .checkciv1.cmx
[163]4381else %Windows system
[269]4382%                     flname=regexprep(flname,'\\','\\\\');
[282]4383%                     cmd=[cmd 'copy /Y "' flname '.checkciv1.cmx" "' flname '.cmx"\n'];
[269]4384%     filename=regexprep(filename,'\\','\\\\');
[272]4385    cmd_CIV1=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx"'];% copy the .civ1.cmx parameter file to .cmx
[284]4386    cmd_CIV1=[cmd_CIV1 '\n "' regexprep(Param.xml.Civ1Bin,'\\','\\\\') '" -f "' filename '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
[272]4387%     namelog=regexprep(namelog,'\\','\\\\');
4388    cmd_CIV1=[cmd_CIV1 '\n ' 'copy /Y "' filename '.log' '" "' filename '.civ1.log"']; %preserve the log file as .civ1.log
4389
[282]4390    %  cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.checkciv1.cmx"'];
[12]4391end
[2]4392
[12]4393%------------------------------------------------------------------------
[282]4394% --- CheckCiv1  Unified
[94]4395function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
[12]4396%------------------------------------------------------------------------
[2]4397%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[282]4398%global CivBin%name of the executable for checkciv1 calculation
[2]4399
[112]4400civ1.image1=par.filename_ima_a;
4401civ1.image2=par.filename_ima_b;
4402civ1.imageSize_X=par.npx;
4403civ1.imageSize_Y=par.npy;
4404civ1.outputFileName=[filename '.nc'];
4405civ1.correlationBoxesSize_X=par.ibx;
4406civ1.correlationBoxesSize_Y=par.iby;
4407civ1.searchBoxesSize_X=par.isx;
4408civ1.searchBoxesSize_Y=par.isy;
4409civ1.globalShift_X=par.shiftx;
4410civ1.globalShift_Y=par.shifty;
4411civ1.ro=par.rho;
4412civ1.hart='y';
4413if isequal(par.gridflag,'y')
4414    civ1.grid=par.gridname;
4415else
4416    civ1.grid='n';
4417    civ1.gridSpacing_X=par.dx;
4418    civ1.gridSpacing_Y=par.dy;
4419end
4420if isequal(par.maskflag,'y')
4421    civ1.mask=par.maskname;
4422end
[229]4423civ1.dt=par.Dt;
[112]4424civ1.unit='pixel';
4425civ1.absolut_time_T0=par.T0;
4426civ1.pixcmx=par.pxcmx;
4427civ1.pixcmy=par.pxcmy;
4428civ1.convectFlow='n';
[12]4429
[112]4430xml_civ1_parameters=civ1;
4431
[12]4432%------------------------------------------------------------------------
[282]4433% --- CheckCiv2  Unified
[94]4434function civ2=CIV2_CMD_Unified(filename,namelog,par)
[12]4435%------------------------------------------------------------------------
[2]4436%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[282]4437%global CivBin%name of the executable for checkciv1 calculation
[275]4438
[272]4439filename=regexprep(filename,'.nc','');
[2]4440
4441civ2.image1=par.filename_ima_a;
4442civ2.image2=par.filename_ima_b;
[112]4443civ2.imageSize_X=par.npx;
[2]4444civ2.imageSize_Y=par.npy;
4445civ2.inputFileName=[par.filename_nc1 '.nc'];
4446civ2.outputFileName=[filename '.nc'];
4447civ2.correlationBoxesSize_X=par.ibx;
4448civ2.correlationBoxesSize_Y=par.iby;
4449civ2.ro=par.rho;
[287]4450%checkciv2.decimalShift=par.CheckDecimal;
4451%checkciv2.CheckDeformation=par.CheckDeformation;
[2]4452if isequal(par.decimal,'1')
4453    civ2.decimalShift='y';
4454else
4455    civ2.decimalShift='n';
4456end
4457if isequal(par.deformation,'1')
4458    civ2.deformation='y';
4459else
4460    civ2.deformation='n';
4461end
4462if isequal(par.gridflag,'y')
4463    civ2.grid=par.gridname;
4464else
4465    civ2.grid='n';
4466    civ2.gridSpacing_X=par.dx;
4467    civ2.gridSpacing_Y=par.dy;
4468end
4469civ2.gridSpacing_X='10';
4470civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4471if isequal(par.maskflag,'y')
4472    civ2.mask=par.maskname;
4473else
4474    civ2.mask='n';
4475end
4476civ2.dt=par.Dt;
4477civ2.unit='pixel';
4478civ2.absolut_time_T0=par.T0;
4479civ2.pixcmx=par.pxcmx;
4480civ2.pixcmy=par.pxcmy;
4481civ2.convectFlow='n';
4482civ2.pixcmx=par.pxcmx;
4483civ2.pixcmy=par.pxcmy;
4484civ2.convectFlow='n';
4485
[12]4486%------------------------------------------------------------------------
[282]4487% --- CheckCiv2  CheckCiv2  CheckCiv2 CheckCiv2
[272]4488function cmd_CIV2=CIV2_CMD(filename,param)
[12]4489%------------------------------------------------------------------------
[2]4490%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[282]4491% global civ2Bin sge%name of the executable for checkciv1 calculation
[275]4492filename=regexprep(filename,'.nc','');
4493if isequal(param.civ2.Dt,'0')
[272]4494    param.civ2.Dt='1' ;%case of 'displacement' mode
[112]4495end
[272]4496param.civ2.filename_ima_a=regexprep(param.civ2.filename_ima_a,'.png','');
4497param.civ2.filename_ima_b=regexprep(param.civ2.filename_ima_b,'.png','');% bug : .png appears two times ?
[174]4498[fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
4499if isequal(fid,-1)
4500    msgbox_uvmat('ERROR',errormsg)
4501    cmd_CIV2='';
4502    return
4503end
[94]4504fprintf(fid,['##############   CMX file' '\n' ]);
[272]4505fprintf(fid,   ['FirstImage ' regexprep(param.civ2.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4506fprintf(fid,   ['LastImage  ' regexprep(param.civ2.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
[94]4507fprintf(fid,  ['XX' '\n' ]);
[272]4508fprintf(fid, ['Mask ' param.civ2.maskflag '\n' ]);
4509fprintf(fid, ['MaskName ' regexprep(param.civ2.maskname,'\\','\\\\') '\n' ]);% for windows compatibility
4510fprintf(fid, ['ImageSize ' param.civ2.npx ' ' param.civ2.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4511fprintf(fid, ['CorrelationBoxesSize ' param.civ2.ibx ' ' param.civ2.iby '\n' ]);
4512fprintf(fid, ['SearchBoxeSize ' param.civ2.ibx ' ' param.civ2.iby '\n']);
4513fprintf(fid, ['RO ' param.civ2.rho '\n']);
4514fprintf(fid, ['GridSpacing ' param.civ2.dx ' ' param.civ2.dy '\n']);
[94]4515fprintf(fid, ['XX 1.0' '\n' ]);
[272]4516fprintf(fid, ['Dt_TO ' param.civ2.Dt ' ' param.civ2.T0 '\n' ]);
4517fprintf(fid, ['PixCmXY ' param.civ2.pxcmx ' ' param.civ2.pxcmy '\n' ]);
[94]4518fprintf(fid, ['XX 1' '\n' ]);
[122]4519fprintf(fid, 'ShiftXY 0 0\n');
[272]4520fprintf(fid, ['Grid ' param.civ2.gridflag '\n' ]);
4521fprintf(fid, ['GridName ' regexprep(param.civ2.gridname,'\\','\\\\') '\n']);
[94]4522fprintf(fid, ['XX 85' '\n' ]);
4523fprintf(fid, ['XX 1.0' '\n' ]);
4524fprintf(fid, ['XX 1.0' '\n' ]);
4525fprintf(fid, ['Hart 1' '\n' ]);
[272]4526fprintf(fid, ['DecimalShift ' param.civ2.decimal '\n']);
4527fprintf(fid, ['Deformation ' param.civ2.deformation '\n']);
[94]4528fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4529fprintf(fid,   ['IntensityMin 0' '\n' ]);
4530fprintf(fid,  ['SeuilImage n' '\n' ]);
4531fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
[272]4532fprintf(fid,   ['ImageToUse ' param.civ2.term_a ' ' param.civ2.term_b '\n' ]); % VERIFIER ?
4533fprintf(fid, ['ImageUsedBefore ' regexprep(param.civ2.filename_nc1,'\\','\\\\') '\n']);
[94]4534fclose(fid);
4535
[134]4536if(isunix)
[230]4537    cmd_CIV2=['cp -f ' filename '.civ2.cmx ' filename '.cmx\n'];
[284]4538    cmd_CIV2=[cmd_CIV2 Param.xml.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
[230]4539    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' filename '.log' ' ' filename '.civ2.log' '\n' 'chmod g+w ' filename '.nc'];%preserve the log file as .civ2.log
[282]4540%    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' filename '.cmx' ' ' filename '.checkciv2.cmx' '\n'];%rename .cmx as .checkciv2.cmx, the result file is named [filename '.nc'] by CIVx
[230]4541
[163]4542else
[174]4543    filename=regexprep(filename,'\\','\\\\');
[272]4544    cmd_CIV2=['copy /Y "' filename '.civ2.cmx" "' filename '.cmx"'];
[284]4545    cmd_CIV2=[cmd_CIV2 '\n "' regexprep(Param.xml.Civ2Bin,'\\','\\\\') '" -f "' filename  '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
[272]4546    cmd_CIV2=[cmd_CIV2 '\n ' 'copy /Y "' filename '.log' '" "' filename '.civ2.log"'];
[282]4547 %    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.checkciv2.cmx"'];
[134]4548end
4549
4550
[12]4551%------------------------------------------------------------------------
[2]4552%--read images and convert them to the uint16 format used for PIV
[45]4553function A=read_image(filename,type_ima,num,movieobject)
[12]4554%------------------------------------------------------------------------
[2]4555%num is the view number needed for an avi movie
[45]4556switch type_ima
4557    case 'movie'
4558        A=read(movieobject,num);
4559    case 'avi'
[112]4560        mov=aviread(filename,num);
4561        A=frame2im(mov(1));
[45]4562    case 'multimage'
4563        A=imread(filename,num);
[112]4564    case 'image'
[45]4565        A=imread(filename);
4566end
4567siz=size(A);
4568if length(siz)==3;%color images
[2]4569    A=sum(double(A),3);
4570    A=uint16(A);
4571end
4572
[12]4573%------------------------------------------------------------------------
[2]4574function ref_i_Callback(hObject, eventdata, handles)
[12]4575%------------------------------------------------------------------------
[282]4576mode_list=get(handles.ListPairMode,'String');
4577mode_value=get(handles.ListPairMode,'Value');
[2]4578mode=mode_list{mode_value};
[45]4579find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
[12]4580if isequal(mode,'series(Di)') || ...% we do patch2 only
[282]4581        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
[2]4582    find_netcpair_civ2(hObject, eventdata, handles);
4583end
4584
[12]4585%------------------------------------------------------------------------
[2]4586function ref_j_Callback(hObject, eventdata, handles)
[12]4587%------------------------------------------------------------------------
[282]4588mode_list=get(handles.ListPairMode,'String');
4589mode_value=get(handles.ListPairMode,'Value');
[2]4590mode=mode_list{mode_value};
[282]4591if isequal(get(handles.CheckCiv1,'Value'),0)|| isequal(mode,'series(Dj)')
[2]4592    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4593end
[45]4594if isequal(mode,'series(Dj)') || ...
[282]4595        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
[2]4596    find_netcpair_civ2(hObject, eventdata, handles);
4597end
[12]4598
4599%------------------------------------------------------------------------
[71]4600function ref_i_civ2_Callback(hObject, eventdata, handles)
4601%------------------------------------------------------------------------
[282]4602mode_list=get(handles.ListPairMode,'String');
4603mode_value=get(handles.ListPairMode,'Value');
[71]4604mode=mode_list{mode_value};
4605find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4606
4607%------------------------------------------------------------------------
4608function ref_j_civ2_Callback(hObject, eventdata, handles)
4609%------------------------------------------------------------------------
[282]4610mode_list=get(handles.ListPairMode,'String');
4611mode_value=get(handles.ListPairMode,'Value');
[71]4612mode=mode_list{mode_value};
[112]4613if  isequal(mode,'series(Dj)')
[71]4614    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4615end
4616
4617%------------------------------------------------------------------------
[282]4618% --- Executes on button press in ListCompareMode.
4619function ListCompareMode_Callback(hObject, eventdata, handles)
[12]4620%------------------------------------------------------------------------
[282]4621test=get(handles.ListCompareMode,'Value');
[263]4622if test==2 || test==3 % case 'dispalcemen' or 'stereo PIV'
[71]4623    filebase=get(handles.RootName,'String');
[273]4624    browse=get(handlesRootName,'Userdata');
[2]4625    browse.nom_type_ima1=browse.nom_type_ima;
[273]4626    set(handlesRootName,'UserData',browse);
[2]4627    set(handles.sub_txt,'Visible','on')
[112]4628    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
[282]4629    mode_store=get(handles.ListPairMode,'String');%get the present 'mode'
4630    set(handles.ListCompareMode,'UserData',mode_store);%store the mode display
4631    set(handles.ListPairMode,'Visible','off')
[2]4632    if test==2
[282]4633        set(handles.ListPairMode,'Visible','off')
4634        set(handles.ListPairMode,'Value',1) % mode 'civX' selected by default
[2]4635    else
[282]4636        set(handles.ListPairMode,'Visible','on')
4637        set(handles.ListPairMode,'Value',3) % mode 'Matlab' selected for stereo
[2]4638    end
4639   
[273]4640    %% menuopen an image file with the browser
[2]4641    ind_opening=1;%default
4642    browse.incr_pair=[0 0]; %default
[71]4643    oldfile=get(handles.RootName,'String');
[229]4644     menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
4645       '*.xml',  '.xml files '; ...
4646        '*.civ',  '.civ files '; ...
4647        '*.png','.png image files'; ...
4648        '*.jpg',' jpeg image files'; ...
4649        '*.tif','.tif image files'; ...
4650        '*.avi;*.AVI','.avi movie files'; ...
4651        '*.nc','.netcdf files'; ...
4652        '*.*',  'All Files (*.*)'};
4653    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file of the second series',oldfile);
[112]4654    fileinput=[PathName FileName];%complete file name
[2]4655    sizf=size(fileinput);
[229]4656    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[275]4657    [path,name,ext]=fileparts(fileinput);
[2]4658    [path1]=fileparts(filebase);
[263]4659    if isunix
4660        [status,path]=system(['readlink ' path])
4661        [status,path1]=system(['readlink ' path1])% look for the true path in case of symbolic paths
4662    end
[2]4663    if ~strcmp(path1,path)
[263]4664        msgbox_uvmat('ERROR','The second image series must be in the same directory as the first one')
[2]4665        return
[263]4666     end
4667%     set(handles.RootName_1,'String',name);
[2]4668    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
[263]4669    set(handles.RootName_1,'String',RootFile);
[273]4670    browse=get(handlesRootName,'UserData');
[2]4671    browse.nom_type_ima_1=nom_type;
[273]4672    set(handlesRootName,'UserData',browse)
[2]4673   
4674    %check image extension
[71]4675    if ~strcmp(ext,get(handles.ImaExt,'String'))
[263]4676        msgbox_uvmat('ERROR','The second image series must have the same extension name as the first one')
[2]4677        return
4678    end
4679   
[229]4680    %% check coincidence of image sizes
[263]4681%     ref_i=get(handles.ref_i,'string');
4682%     ref_j=get(handles.ref_j,'string');
4683%     [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
[282]4684%     A=imread(filecell.ima1.checkciv1{1});
[263]4685%     A_1=imread(fileinput);
4686%     npxy=size(A);
4687%     npxy_1=size(A_1);
4688%     if ~isequal(size(A),size(A_1))
4689%         msgbox_uvmat('ERROR','The two input image series do not have the same size')
4690%         return
4691%     end
[2]4692else
[282]4693    set(handles.ListPairMode,'Visible','on')
[71]4694    set(handles.RootName_1,'Visible','Off');
[2]4695    set(handles.sub_txt,'Visible','off')
[71]4696    set(handles.RootName_1,'String',[]);
[282]4697    mode_store=get(handles.ListCompareMode,'UserData');
4698    set(handles.ListPairMode,'Value',1)
4699    set(handles.ListPairMode,'String',mode_store)
[2]4700    set(handles.test_stereo1,'Value',0)
[282]4701    set(handles.CheckStereo,'Value',0)
4702    set(handles.ListPairMode,'Value',1) % mode 'civX' selected by default
[2]4703end
[282]4704if test==3 && get(handles.CheckPatch1,'Value')
[263]4705    set(handles.test_stereo1,'Visible','on')
[252]4706else
[263]4707    set(handles.test_stereo1,'Visible','off')
[252]4708end
[282]4709if test==3 && get(handles.CheckPatch2,'Value')
4710    set(handles.CheckStereo,'Visible','on')
[252]4711else
[282]4712    set(handles.CheckStereo,'Visible','off')
[252]4713end
[2]4714mode_Callback(hObject, eventdata, handles)
4715
[12]4716%------------------------------------------------------------------------
[2]4717% --- Executes on button press in get_ref_fix1.
4718function get_ref_fix1_Callback(hObject, eventdata, handles)
[12]4719%------------------------------------------------------------------------
[71]4720filebase=get(handles.RootName,'String');
[2]4721[FileName, PathName, filterindex] = uigetfile( ...
[112]4722    {'*.nc', ' (*.nc)';
4723    '*.nc',  'netcdf files '; ...
4724    '*.*', 'All Files (*.*)'}, ...
4725    'Pick a file',filebase);
4726
[2]4727fileinput=[PathName FileName];
4728sizf=size(fileinput);
[122]4729if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4730[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4731ref.filebase=fullfile(Path,File);
4732ref.num_a=stra2num(str_a);
4733ref.num_b=stra2num(str_b);
[89]4734ref.num1=str2double(field_count);
4735ref.num2=str2double(str2);
[2]4736browse=[];%initialisation
4737if ~isequal(ref.ext,'.nc')
4738    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4739    return
4740end
4741set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
4742set(handles.ref_fix1,'UserData',ref)
4743menu_field{1}='civ1';
4744Data=nc2struct(fileinput,[]);
[45]4745if isfield(Data,'patch') && isequal(Data.patch,1)
[2]4746    menu_field{2}='filter1';
4747end
[45]4748if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]4749    menu_field{3}='civ2';
4750end
[45]4751if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]4752    menu_field{4}='filter2';
4753end
4754set(handles.field_ref1,'String',menu_field);
4755set(handles.field_ref1,'Value',length(menu_field));
[287]4756set(handles.num_MinVel,'Value',2);
4757set(handles.num_MinVel,'String','1');%default threshold
[2]4758set(handles.ref_fix1,'Enable','on')
[12]4759
4760%------------------------------------------------------------------------
[2]4761% --- Executes on button press in get_ref_fix2.
4762function get_ref_fix2_Callback(hObject, eventdata, handles)
[12]4763%------------------------------------------------------------------------
[2]4764if isequal(get(handles.get_ref_fix2,'Value'),1)
[71]4765    filebase=get(handles.RootName,'String');
[2]4766    [FileName, PathName, filterindex] = uigetfile( ...
[112]4767        {'*.nc', ' (*.nc)';
4768        '*.nc',  'netcdf files '; ...
4769        '*.*', 'All Files (*.*)'}, ...
4770        'Pick a file',filebase);
[2]4771    fileinput=[PathName FileName];
4772    sizf=size(fileinput);
[45]4773    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4774    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4775    ref.filebase=fullfile(Path,File);
4776    ref.num_a=stra2num(str_a);
4777    ref.num_b=stra2num(str_b);
4778    ref.num1=str2num(field_count);
4779    ref.num2=str2num(str2);
4780    browse=[];%initialisation
4781    if ~isequal(ref.ext,'.nc')
4782        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4783        return
4784    end
4785    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
[112]4786    set(handles.ref_fix2,'UserData',ref)
[2]4787    menu_field{1}='civ1';
4788    Data=nc2struct(fileinput,[]);
4789    if isfield(Data,'patch') & isequal(Data.patch,1)
4790        menu_field{2}='filter1';
4791    end
4792    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4793        menu_field{3}='civ2';
4794    end
4795    if isfield(Data,'patch2') & isequal(Data.patch2,1)
4796        menu_field{4}='filter2';
4797    end
4798    set(handles.field_ref2,'String',menu_field);
4799    set(handles.field_ref2,'Value',length(menu_field));
[287]4800    set(handles.num_MinVel,'Value',2);
4801    set(handles.num_MinVel,'String','1');%default threshold
[2]4802    set(handles.ref_fix2,'Enable','on')
4803    set(handles.ref_fix2,'Visible','on')
4804    set(handles.field_ref2,'Visible','on')
4805else
4806    set(handles.ref_fix2,'Visible','off')
4807    set(handles.field_ref2,'Visible','off')
4808end
4809
[12]4810%------------------------------------------------------------------------
[2]4811function ref_fix1_Callback(hObject, eventdata, handles)
[12]4812%------------------------------------------------------------------------
[287]4813set(handles.num_MinVel,'Value',1);
[12]4814set(handles.field_ref1,'Value',1)
4815set(handles.field_ref1,'String',{' '})
4816set(handles.ref_fix1,'UserData',[]);
4817set(handles.ref_fix1,'String','');
4818set(handles.thresh_vel1,'String','0');
[112]4819
[12]4820%------------------------------------------------------------------------
[2]4821function ref_fix2_Callback(hObject, eventdata, handles)
[12]4822%------------------------------------------------------------------------
[287]4823set(handles.num_MinVel,'Value',1);
[12]4824set(handles.field_ref2,'Value',1)
4825set(handles.field_ref2,'String',{' '})
4826set(handles.ref_fix2,'UserData',[]);
4827set(handles.ref_fix2,'String','');
[287]4828set(handles.num_MinVel,'String','0');
[2]4829
[12]4830%------------------------------------------------------------------------
[2]4831% --- Executes on button press in test_stereo1.
4832function test_stereo1_Callback(hObject, eventdata, handles)
[12]4833%------------------------------------------------------------------------
[2]4834if isequal(get(handles.test_stereo1,'Value'),0)
4835    set(handles.subdomain_patch1,'Visible','on')
4836    set(handles.rho_patch1,'Visible','on')
4837else
4838    set(handles.subdomain_patch1,'Visible','off')
4839    set(handles.rho_patch1,'Visible','off')
4840end
4841
[12]4842%------------------------------------------------------------------------
[282]4843% --- Executes on button press in CheckStereo.
[273]4844function StereoCheck_Callback(hObject, eventdata, handles)
[12]4845%------------------------------------------------------------------------
[282]4846if isequal(get(handles.CheckStereo,'Value'),0)
[274]4847    set(handles.num_SubdomainSize,'Visible','on')
4848    set(handles.num_SmoothParam,'Visible','on')
[2]4849else
[274]4850    set(handles.num_SubdomainSize,'Visible','off')
4851    set(handles.num_SmoothParam,'Visible','off')
[2]4852end
4853
[12]4854%------------------------------------------------------------------------
[276]4855% --- Executes on button press in check_Threshold.
[2]4856function ImaThreshold_Callback(hObject, eventdata, handles)
[12]4857%------------------------------------------------------------------------
[276]4858if isequal(get(handles.check_Threshold,'Value'),1)
[282]4859    set(handles.num_MinIma,'Visible','on')
4860    set(handles.num_MaxIma,'Visible','on')
[2]4861else
[282]4862    set(handles.num_MinIma,'Visible','off')
4863    set(handles.num_MaxIma,'Visible','off')
[2]4864end
4865
[12]4866%------------------------------------------------------------------------
[2]4867% --- Executes on button press in ImaThreshold2.
4868function ImaThreshold2_Callback(hObject, eventdata, handles)
[12]4869%------------------------------------------------------------------------
[2]4870if isequal(get(handles.ImaThreshold2,'Value'),1)
[287]4871    set(handles.num_MinIma,'Visible','on')
4872    set(handles.num_MaxIma,'Visible','on')
[2]4873else
[287]4874    set(handles.num_MinIma,'Visible','off')
4875    set(handles.num_MaxIma,'Visible','off')
[2]4876end
4877
[224]4878%------------------------------------------------------------------------
[225]4879% --- Executes on button press in TestCiv1: display image correlation function
[150]4880function TestCiv1_Callback(hObject, eventdata, handles)
[224]4881%------------------------------------------------------------------------
[233]4882set(handles.TestCiv1,'BackgroundColor',[1 1 0])
4883drawnow
[150]4884test_civ1=get(handles.TestCiv1,'Value');
4885if test_civ1
[227]4886    ref_i=str2double(get(handles.ref_i,'String'));
4887    if strcmp(get(handles.ref_j,'Visible'),'on')
4888        ref_j=str2double(get(handles.ref_j,'String'));
4889    else
4890        ref_j=1;%default
4891    end
[224]4892    [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
[273]4893        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
[224]4894    Data.ListVarName={'ny','nx','A'};
4895    Data.VarDimName={'ny','nx',{'ny','nx'}};
4896    Data.A=imread(filecell.ima1.civ1{1});
4897    Data.ny=[size(Data.A,1) 1];
4898    Data.nx=[1 size(Data.A,2)];
[227]4899    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1});
[231]4900    par_civ1.filename_ima_a=filecell.ima1.civ1{1};
4901    par_civ1.filename_ima_b=filecell.ima2.civ1{1};
4902    par_civ1.T0=0;
4903    par_civ1.Dt=1;
[246]4904    Param.Civ1=par_civ1;
4905    Data=civ_uvmat(Param);
[231]4906    Data.ListVarName=[Data.ListVarName {'ny','nx','A'}];
4907    Data.VarDimName=[Data.VarDimName {'ny','nx',{'ny','nx'}}];
4908    Data.A=imread(filecell.ima1.civ1{1});
4909    Data.ny=[size(Data.A,1) 1];
4910    Data.nx=[1 size(Data.A,2)];
4911    hview_field=view_field(Data);
4912    set(0,'CurrentFigure',hview_field)
4913    hhview_field=guihandles(hview_field);
4914    set(hview_field,'CurrentAxes',hhview_field.axes3)
4915    ViewData=get(hview_field,'UserData');
4916    ViewData.CivHandle=handles.civ;% indicate the handle of the civ GUI in view_field
[224]4917    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
[236]4918    ViewData.axes3.X=Data.Civ1_X; %keep the set of points in memeory
4919    ViewData.axes3.Y=Data.Civ1_Y;
[231]4920    set(hview_field,'UserData',ViewData)
[224]4921    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4922    if isempty(corrfig)
4923        corrfig=figure;
4924        set(corrfig,'tag','corrfig')
4925        set(corrfig,'name','image correlation')
4926        set(corrfig,'DeleteFcn',{@closeview_field})%
4927    end
[233]4928    set(handles.TestCiv1,'BackgroundColor',[1 0 0])
[224]4929else
4930    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4931    if ~isempty(corrfig)
4932        delete(corrfig)
4933    end
4934    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4935    if ~isempty(hview_field)
4936        delete(hview_field)
4937    end
[150]4938end
[71]4939
[224]4940function closeview_field(gcbo,eventdata)
4941hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4942    if ~isempty(hview_field)
4943        delete(hview_field)
4944    end
[177]4945%-------------------------------------------------------------------
4946% --- Executes on button press in status.
4947function status_Callback(hObject, eventdata, handles)
4948%-------------------------------------------------------------------
4949val=get(handles.status,'Value');
4950if val==0
[252]4951    set(handles.status,'BackgroundColor',[0 1 0])
[177]4952    hfig=findobj(allchild(0),'name','civ_status');
4953    if ~isempty(hfig)
4954        delete(hfig)
4955    end
4956    return
4957end
[252]4958set(handles.status,'BackgroundColor',[1 1 0])
4959drawnow
[177]4960listtype={'civ1','fix1','patch1','civ2','fix2','patch2'};
[282]4961Param.CheckCiv1=get(handles.CheckCiv1,'Value');
4962Param.CheckFix1=get(handles.CheckFix1,'Value');
4963Param.CheckPatch1=get(handles.CheckPatch1,'Value');
4964Param.CheckCiv2=get(handles.CheckCiv2,'Value');
4965Param.CheckFix2=get(handles.CheckFix2,'Value');
4966Param.CheckPatch2=get(handles.CheckPatch2,'Value');
[284]4967box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
4968
[180]4969option_civ=find(box_test,1,'last');%last selected option (non-zero index of box_test)
[252]4970filecell=get(handles.civ,'UserData');%retrieve the list of output files expected for PIV
4971test_new=0;
[177]4972if ~isfield(filecell,'nc')
[252]4973    test_new=1;
[227]4974    [ref_i,ref_j,errormsg]=find_ref_indices(handles);
4975    if ~isempty(errormsg)
4976        msgbox_uvmat('ERROR',errormsg)
4977        return
4978    end
[252]4979    filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the output file expected from the GUI status
[177]4980end
4981if ~isequal(box_test(4:6),[0 0 0])
[252]4982    civ_files=filecell.nc.civ2;%case of civ2 operations
[177]4983else
4984    civ_files=filecell.nc.civ1;
4985end
4986[root,filename,ext]=fileparts(civ_files{1});
4987[rootroot,subdir,extdir]=fileparts(root);
4988hfig=findobj(allchild(0),'name','civ_status');
4989if isempty(hfig)
[252]4990    hfig=figure('DeleteFcn',@stop_status);
[177]4991    set(hfig,'name','civ_status')
[182]4992    hlist=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @open_view_field,'tag','list');
[252]4993    uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','msgbox','Max',2,'String','checking files...');
[177]4994    uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
[182]4995    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','OK','FontWeight','bold','FontUnits','normalized','FontSize',0.9,'Callback',@close_GUI);
[177]4996    BarPosition=[0.05 0.81 0.01 0.05];
4997    hwaitbar=uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
[252]4998    drawnow
[177]4999end
[188]5000% datnum=[];
[177]5001Tabchar={};
5002nbfiles=numel(civ_files);
5003count=0;
[188]5004testrecent=0;
[177]5005while count<nbfiles
5006    count=0;
[188]5007    datnum=zeros(1,nbfiles);
[177]5008    for ifile=1:nbfiles
5009        detect=exist(civ_files{ifile},'file'); % check the existence of the file
[179]5010        option=0;
[177]5011        if detect==0
[179]5012            option_str='not created';
[177]5013        else
[219]5014            datfile=dir(civ_files{ifile});
[188]5015            if isfield(datfile,'datenum')
5016                datnum(ifile)=datfile.datenum;%only available in recent matlab versions
5017                testrecent=1;
5018            end
[177]5019            filefound(ifile)={datfile.name};
5020            lastfield='';
5021            % check the content  netcdf file
5022            Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','patch2','fix2','civ2','patch','fix');
5023            if ~isempty(Data.patch2) && isequal(Data.patch2,1)
[179]5024                option=6;
5025                option_str='patch2';
[177]5026            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
[179]5027                option=5;
5028                option_str='fix2';
[177]5029            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
[179]5030                option=4;
5031                option_str='civ2';
[177]5032            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
[179]5033                option=3;
5034                option_str='patch1';
[177]5035            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
[179]5036                option=2;
5037                option_str='fix1';
[177]5038            else
[179]5039                option=1;
5040                option_str='civ1';
[177]5041            end
5042        end
[179]5043        if option >= option_civ
[177]5044            count=count+1;
5045        end
5046        [rr,filename,ext]=fileparts(civ_files{ifile});
[179]5047        Tabchar{ifile,1}=[fullfile([subdir extdir],filename) ext  '...' option_str];
[177]5048    end
[219]5049    datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[188]5050    if isempty(datnum)
5051        if testrecent
5052            message='no civ result created yet';
5053        else
5054            message='';
5055        end
[177]5056    else
[219]5057        datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[177]5058        [first,ind]=min(datnum);
5059        [last,indlast]=max(datnum);
[252]5060        if test_new
5061            message='existing file status, no processing launched yet';
5062        else
[177]5063        message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
5064            ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
[252]5065        end
[177]5066    end
5067    hfig=findobj(allchild(0),'name','civ_status');
[252]5068    if isempty(hfig)% the status list has been deleted
[177]5069        return
5070    else
5071        hlist=findobj(hfig,'tag','list');
5072        hmsgbox=findobj(hfig,'tag','msgbox');
5073        hwaitbar=findobj(hfig,'tag','waitbar');
5074        set(hlist,'String',Tabchar)
5075        set(hmsgbox,'String', message)
[252]5076        if count>0 && ~test_new
[177]5077            BarPosition(3)=0.9*count/nbfiles;
5078            set(hwaitbar,'Position',BarPosition)
5079        end
5080    end
5081    set(hlist,'UserData',rootroot)
[252]5082    pause(10)% wait 10 seconds for next check
[177]5083end
[150]5084
[177]5085   
[252]5086%------------------------------------------------------------------------   
5087% call 'view_field.fig' to display the  field selected in the list of 'status'
[177]5088function open_view_field(hObject, eventdata)
[252]5089%------------------------------------------------------------------------
5090list=get(hObject,'String');
5091index=get(hObject,'Value');
5092rootroot=get(hObject,'UserData');
5093filename=list{index};
5094ind_dot=findstr(filename,'...');
5095filename=filename(1:ind_dot-1);
5096filename=fullfile(rootroot,filename);
5097delete(get(hObject,'parent'))%delete the display figure to stop the check process
5098if exist(filename,'file')%visualise the vel field if it exists
5099    uvmat(filename)
5100    set(gcbo,'Value',1)
5101end
[150]5102
[252]5103%------------------------------------------------------------------------   
5104% launched by pressing OK on the status figure
[182]5105function close_GUI(hObject, eventdata)
[252]5106%------------------------------------------------------------------------
5107    delete(gcbf)
5108   
5109%------------------------------------------------------------------------   
5110% launched by deleting the status figure
5111function stop_status(hObject, eventdata)
5112%------------------------------------------------------------------------
5113hciv=findobj(allchild(0),'tag','civ');
5114hhciv=guidata(hciv);
5115set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
5116set(hhciv.status,'BackgroundColor',[0 1 0])
[220]5117
[252]5118%------------------------------------------------------------------------
[282]5119% % --- Executes on button press in ListPairMode.
[273]5120% function CivMode_Callback(hObject, eventdata, handles)
5121% %------------------------------------------------------------------------
[282]5122% Listprog=get(handles.ListPairMode,'String');
5123% index=get(handles.ListPairMode,'Value');
[273]5124% prog=Listprog{index};
5125% switch prog
5126%     case 'CivX'
5127%         set(handles.thresh_patch1,'Visible','off')
5128%         set(handles.thresh_text1,'Visible','off')
[274]5129%         set(handles.num_MaxDiff,'Visible','off')
[273]5130%         set(handles.thresh_text2,'Visible','off')
[282]5131%         set(handles.num_Rho,'Style','edit')
5132%         set(handles.num_Rho,'String','1')
[273]5133%         set(handles.BATCH,'Enable','on')
5134%     case 'CivAll'
[282]5135%         if get(handles.CheckPatch1,'Value')
[273]5136%             set(handles.thresh_patch1,'Visible','on')
5137%             set(handles.thresh_text1,'Visible','on')
5138%         end
[282]5139%         set(handles.num_Rho,'Style','edit')
5140%         set(handles.num_Rho,'String','1')
[273]5141%         set(handles.BATCH,'Enable','on')
5142%     case 'CivUvmat'
5143%       
5144% end
5145
5146
[282]5147% --- Executes on button press in CheckStereo.
5148function CheckStereo_Callback(hObject, eventdata, handles)
5149% hObject    handle to CheckStereo (see GCBO)
[273]5150% eventdata  reserved - to be defined in a future version of MATLAB
5151% handles    structure with handles and user data (see GUIDATA)
5152
[282]5153% Hint: get(hObject,'Value') returns toggle state of CheckStereo
[273]5154
5155
5156
[274]5157function num_SubdomainSize_Callback(hObject, eventdata, handles)
5158% hObject    handle to num_SubdomainSize (see GCBO)
[273]5159% eventdata  reserved - to be defined in a future version of MATLAB
5160% handles    structure with handles and user data (see GUIDATA)
5161
[274]5162% Hints: get(hObject,'String') returns contents of num_SubdomainSize as text
5163%        str2double(get(hObject,'String')) returns contents of num_SubdomainSize as a double
[273]5164
5165
5166
[274]5167function num_SmoothingParam_Callback(hObject, eventdata, handles)
5168% hObject    handle to num_SmoothingParam (see GCBO)
[273]5169% eventdata  reserved - to be defined in a future version of MATLAB
5170% handles    structure with handles and user data (see GUIDATA)
5171
[274]5172% Hints: get(hObject,'String') returns contents of num_SmoothingParam as text
5173%        str2double(get(hObject,'String')) returns contents of num_SmoothingParam as a double
[273]5174
5175
5176
[274]5177function num_MaxDiff_Callback(hObject, eventdata, handles)
5178% hObject    handle to num_MaxDiff (see GCBO)
[273]5179% eventdata  reserved - to be defined in a future version of MATLAB
5180% handles    structure with handles and user data (see GUIDATA)
5181
[274]5182% Hints: get(hObject,'String') returns contents of num_MaxDiff as text
5183%        str2double(get(hObject,'String')) returns contents of num_MaxDiff as a double
[273]5184
5185
[274]5186function num_Nx_Callback(hObject, eventdata, handles)
5187% hObject    handle to num_Nx (see GCBO)
[273]5188% eventdata  reserved - to be defined in a future version of MATLAB
5189% handles    structure with handles and user data (see GUIDATA)
5190
[274]5191% Hints: get(hObject,'String') returns contents of num_Nx as text
5192%        str2double(get(hObject,'String')) returns contents of num_Nx as a double
[273]5193
5194
[274]5195function num_Ny_Callback(hObject, eventdata, handles)
5196% hObject    handle to num_Ny (see GCBO)
[273]5197% eventdata  reserved - to be defined in a future version of MATLAB
5198% handles    structure with handles and user data (see GUIDATA)
5199
[274]5200% Hints: get(hObject,'String') returns contents of num_Ny as text
5201%        str2double(get(hObject,'String')) returns contents of num_Ny as a double
[273]5202
5203
5204% --------------------------------------------------------------------
5205function MenuHelp_Callback(hObject, eventdata, handles)
[276]5206path_civ=fileparts(which ('civ'));
5207helpfile=fullfile(path_civ,'uvmat_doc','uvmat_doc.html');
5208if isempty(dir(helpfile))
5209    msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[273]5210else
[276]5211    addpath (fullfile(path_civ,'uvmat_doc'))
[273]5212    web([helpfile '#civ'])
[224]5213end
[273]5214
5215% --------------------------------------------------------------------
5216function CivX_Callback(hObject, eventdata, handles)
5217%set(handles.thresh_patch1,'Visible','off')
5218set(handles.thresh_text1,'Visible','off')
[274]5219set(handles.num_MaxDiff,'Visible','off')
[273]5220set(handles.thresh_text2,'Visible','off')
[282]5221set(handles.num_Rho,'Style','edit')
5222set(handles.num_Rho,'String','1')
[273]5223set(handles.BATCH,'Enable','on')
5224
5225% --------------------------------------------------------------------
5226function Matlab_Callback(hObject, eventdata, handles)
5227set(handles.Matlab,'checked','on')
5228set(handles.CivX,'checked','off')
[282]5229if get(handles.CheckPatch1,'Value')
[273]5230    set(handles.thresh_patch1,'Visible','on')
5231    set(handles.thresh_text1,'Visible','on')
5232end
[282]5233if get(handles.CheckPatch2,'Value')
[274]5234    set(handles.num_MaxDiff,'Visible','on')
[273]5235    set(handles.thresh_text2,'Visible','on')
5236end
[282]5237set(handles.num_Rho,'Style','popupmenu')
5238set(handles.num_Rho,'Value',1)
5239set(handles.num_Rho,'String',{'1';'2'})
[273]5240set(handles.BATCH,'Enable','off')
5241
5242% --------------------------------------------------------------------
5243% --- read a panel with handle 'handle' producing a structure 'struct'
5244function struct=read_panel(handle)
5245hchild=get(handle,'children');
5246for ichild=1:numel(hchild)
[282]5247    if strcmp(get(hchild(ichild),'Visible'),'on')
5248        object_style=get(hchild(ichild),'Style');
5249        tag=get(hchild(ichild),'tag');
5250        check_input=1;%default
5251        switch object_style
5252            case 'edit'
5253                switch(tag(1:4))
5254                    case 'num_'
5255                        input=str2double(get(hchild(ichild),'String'));
5256                        %deal with undefined input: retrieve the default value stored as UserData
5257                        if isnan(input)
5258                            input=get(hchild(ichild),'UserData');
5259                            set(hchild(ichild),'String',num2str(input))
5260                        end
5261                    case 'txt_'
5262                        input=get(hchild(ichild),'String');
5263                end
5264                key=tag(5:end);
5265            case 'checkbox'
5266                input=get(hchild(ichild),'Value');
5267                key=tag(7:end);
5268            otherwise
5269                check_input=0;
5270        end
5271        if check_input
5272            eval(['struct.' key '=input;'])
5273        end
[273]5274    end
5275end
[284]5276
5277
5278
5279function cmd=cmd_civ1(filename,Param)
5280%TODO : include filename in par_civ1
5281%------------------------------------------------------------------------
5282%pixels per cm and matrix of the image times, read from the .civ file by uvmat
5283
5284%changes : filename_cmx -> filename ( no extension )
5285
[285]5286filename=regexprep(filename,'.nc','');
[284]5287
5288if isequal(Param.Civ1.Dt,'0')
5289    Param.Civ1.Dt='1' ;%case of 'displacement' mode
5290end
5291Param.Civ1.filename_ima_a=regexprep(Param.Civ1.filename_ima_a,'.png','');
5292Param.Civ1.filename_ima_b=regexprep(Param.Civ1.filename_ima_b,'.png','');
5293fid=fopen([filename '.civ1.cmx'],'w');
5294fprintf(fid,['##############   CMX file' '\n' ]);
5295fprintf(fid,   ['FirstImage ' regexprep(Param.Civ1.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
5296fprintf(fid,   ['LastImage  ' regexprep(Param.Civ1.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
5297fprintf(fid,  ['XX' '\n' ]);
[285]5298fprintf(fid,  ['Mask ' Param.Civ1.MaskFlag '\n' ]);
5299fprintf(fid,  ['MaskName ' regexprep(Param.Civ1.MaskName,'\\','\\\\') '\n' ]);
[284]5300fprintf(fid,   ['ImageSize ' num2str(Param.Civ1.npx) ' ' num2str(Param.Civ1.npy) '\n' ]);   %VERIFIER CAS GENERAL ?
5301fprintf(fid,   ['CorrelationBoxesSize ' num2str(Param.Civ1.Bx) ' ' num2str(Param.Civ1.By) '\n' ]);
[287]5302fprintf(fid,   ['SearchBoxeSize ' num2str(Param.Civ1.Searchx) ' ' num2str(Param.Civ1.Searchy) '\n' ]);
[284]5303fprintf(fid,   ['RO ' num2str(Param.Civ1.Rho) '\n' ]);
5304fprintf(fid,   ['GridSpacing ' num2str(Param.Civ1.Dx) ' ' num2str(Param.Civ1.Dy) '\n' ]);
5305fprintf(fid,   ['XX 1.0' '\n' ]);
5306fprintf(fid,   ['Dt_TO ' num2str(Param.Civ1.Dt) ' ' num2str(Param.Civ1.T0) '\n' ]);
5307fprintf(fid,  ['PixCmXY ' num2str(Param.Civ1.pxcmx) ' ' num2str(Param.Civ1.pxcmy) '\n' ]);
5308fprintf(fid,  ['XX 1' '\n' ]);
5309fprintf(fid,   ['ShiftXY ' num2str(Param.Civ1.Shiftx) ' '  num2str(Param.Civ1.Shifty) '\n' ]);
[285]5310fprintf(fid,  ['Grid ' Param.Civ1.GridFlag '\n' ]);
5311fprintf(fid,   ['GridName ' regexprep(Param.Civ1.GridName,'\\','\\\\') '\n' ]);
[284]5312fprintf(fid,   ['XX 85' '\n' ]);
5313fprintf(fid,   ['XX 1.0' '\n' ]);
5314fprintf(fid,   ['XX 1.0' '\n' ]);
5315fprintf(fid,   ['Hart 1' '\n' ]);
5316fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
5317fprintf(fid,   ['Deformation 0' '\n' ]);
5318fprintf(fid,  ['CorrelationMin 0' '\n' ]);
5319fprintf(fid,   ['IntensityMin 0' '\n' ]);
5320fprintf(fid,  ['SeuilImage n' '\n' ]);
5321fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
5322fprintf(fid,   ['ImageToUse ' Param.Civ1.term_a ' ' Param.Civ1.term_b '\n' ]); % VERIFIER ?
5323fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
5324fclose(fid);
5325
5326% cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
5327% cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
5328% namelog=regexprep(namelog,'\\','\\\\');
5329if(isunix)
5330    cmd=['cp -f ' filename '.civ1.cmx ' filename '.cmx \n '];% the cmx file gives the name to the nc file
5331    cmd=[cmd Param.xml.Civ1Bin ' -f ' filename '.cmx >' filename '.civ1.log \n ' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
5332%     cmd=[cmd '\n' 'mv ' filename '.log' ' ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.civ1.log' '\n' 'chmod g+w ' filename '.nc'];%rename .log as .civ1.log and set the netcdf result file for group user writting
5333%    cmd=[cmd '\n' 'mv ' filename '.cmx' ' ' filename '.civ1.cmx' '\n'];%rename .cmx as .civ1.cmx
5334    cmd=[cmd 'rm ' filename '.cmx'];
5335else %Windows system
5336    filename=regexprep(filename,'\\','\\\\');
5337    cmd=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx" \n '];
5338    cmd=[cmd '"' regexprep(Param.xml.Civ1Bin,'\\','\\\\')...
5339        '" -f "' filename '.cmx" >"' filename '.civ1.log" \n ' ]; % redirect standard output to the log file
5340%     namelog=regexprep(namelog,'\\','\\\\');
5341%     cmd=[cmd '\n ' 'copy /Y "' filename '.log' '" "' filename '.civ1.log"']; %preserve the log file as .civ1.log
5342    cmd=[cmd 'del "' filename '.cmx'];
5343end
[285]5344
5345
5346function cmd=cmd_fix(filename,Param,fixname)
5347%%
5348filename=regexprep(filename,'.nc','');
[287]5349MaskName_string='';%default
5350if Param.(fixname).CheckMask
5351    MaskName_string=[' -maskName "' Param.(fixname).MaskName];
5352end
5353MaxVel_string='';%default
5354if ~isempty(Param.(fixname).MaxVel)
5355    MaxVel_string=[' -threshV ' num2str(Param.(fixname).MaxVel)]
5356end
[285]5357if isunix
[287]5358    cmd=[Param.xml.FixBin ' -f ' filename '.nc -fi1 ' num2str(Param.(fixname).CheckFmin2) ...
5359        ' -fi2 ' num2str(Param.(fixname).CheckF2) ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
5360        ' -threshC ' num2str(Param.(fixname).MinCorr) MaxVel_string MaskName_string...
5361        ' >' filename '.' lower(fixname) '.log 2>&1'];
[285]5362else
5363    cmd=['"' Param.xml.FixBin '" -f "' filename '.nc" -fi1 ' num2str(Param.(fixname).CheckFmin2)...
5364        ' -fi2 ' num2str(Param.(fixname).CheckF2) ' -fi3 ' num2str(Param.(fixname).CheckF3) ...
5365        ' -threshC ' num2str(Param.(fixname).MinCorr)...
[286]5366        ' -maskName "' Param.(fixname).MaskName...
5367        '" > "' filename '.' lower(fixname) '.log" 2>&1'];
[285]5368%         ' -threshV ' num2str(Param.(fixname).thresh_vel)...
5369    cmd=regexprep(cmd,'\\','\\\\');
5370end
[286]5371
5372
5373function cmd=cmd_patch(filename,Param,patchname)
5374%% ------------------------------------------------------------------------
5375filename=regexprep(filename,'.nc','');
5376% if test_interp==0
5377if isunix
5378    cmd=[Param.xml.PatchBin...
5379        ' -f ' filename '.nc -m ' num2str(Param.(patchname).Nx)...
5380        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).SmoothingParam)...
5381        ' -nopt ' num2str(Param.(patchname).SubdomainSize) ...
5382        '  > ' filename '.' lower(patchname) '.log 2>&1']; % redirect standard output to the log file
5383else
5384    cmd=['"' Param.xml.PatchBin...
5385        '" -f "' filename '.nc" -m ' num2str(Param.(patchname).Nx)...
5386        ' -n ' num2str(Param.(patchname).Ny) ' -ro ' num2str(Param.(patchname).SmoothingParam)...
5387        ' -nopt ' num2str(Param.(patchname).SubdomainSize)...
5388        '  > "' filename '.' lower(patchname) '.log" 2>&1']; % redirect standard output to the log file
5389    cmd=regexprep(cmd,'\\','\\\\');
5390end
5391% else %nouveau programme patch
5392%     cmd=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
5393%         ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
5394% end
[287]5395
5396
5397% --- Executes on button press in CheckStereo.
5398function CheckStereo_Callback(hObject, eventdata, handles)
5399% hObject    handle to CheckStereo (see GCBO)
5400% eventdata  reserved - to be defined in a future version of MATLAB
5401% handles    structure with handles and user data (see GUIDATA)
5402
5403% Hint: get(hObject,'Value') returns toggle state of CheckStereo
Note: See TracBrowser for help on using the repository browser.